2020-11-29 01:55:31 +01:00
|
|
|
<?php
|
|
|
|
// This file runs maintenance scripts and should be executed by cron regularly
|
|
|
|
include "config.inc.php";
|
2023-07-12 17:01:52 +02:00
|
|
|
include "newsportal.php";
|
2022-12-15 07:19:27 +01:00
|
|
|
include $config_dir."/scripts/rslight-lib.php";
|
2023-07-24 19:33:13 +02:00
|
|
|
include $config_dir."/gpg.conf";
|
2020-11-29 01:55:31 +01:00
|
|
|
|
|
|
|
$menulist = file($config_dir."menu.conf", FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
|
|
|
|
|
|
|
|
# Start or verify NNTP server
|
|
|
|
if(isset($CONFIG['enable_nntp']) && $CONFIG['enable_nntp'] == true) {
|
|
|
|
# Create group list for nntp.php
|
2023-04-14 03:52:30 +02:00
|
|
|
$fp1=$spooldir."/".$config_name."/groups.txt";
|
|
|
|
unlink($fp1);
|
|
|
|
touch($fp1);
|
2020-11-29 01:55:31 +01:00
|
|
|
foreach($menulist as $menu) {
|
|
|
|
if(($menu[0] == '#') || trim($menu) == "") {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$menuitem=explode(':', $menu);
|
|
|
|
if($menuitem[2] == '1') {
|
|
|
|
$in_gl = file($config_dir.$menuitem[0]."/groups.txt");
|
|
|
|
foreach($in_gl as $ok_group) {
|
|
|
|
if(($ok_group[0] == ':') || (trim($ok_group) == "")) {
|
|
|
|
continue;
|
|
|
|
}
|
2021-01-22 04:56:24 +01:00
|
|
|
$ok_group = preg_split("/( |\t)/", trim($ok_group), 2);
|
2023-04-14 03:52:30 +02:00
|
|
|
file_put_contents($fp1, $ok_group[0]."\r\n", FILE_APPEND);
|
2020-11-29 01:55:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-04-30 01:16:32 +02:00
|
|
|
exec($CONFIG['php_exec']." ".$config_dir."/scripts/nntp.php > /dev/null 2>&1");
|
2020-11-29 01:55:31 +01:00
|
|
|
if(is_numeric($CONFIG['local_ssl_port'])) {
|
2021-04-30 01:16:32 +02:00
|
|
|
exec($CONFIG['php_exec']." ".$config_dir."/scripts/nntp-ssl.php > /dev/null 2>&1");
|
2020-11-29 01:55:31 +01:00
|
|
|
}
|
|
|
|
}
|
2021-04-30 01:16:32 +02:00
|
|
|
# Generate user count file (must be root)
|
|
|
|
exec($CONFIG['php_exec']." ".$config_dir."/scripts/count_users.php");
|
|
|
|
echo "Updated user count\n";
|
2021-10-29 07:58:58 +02:00
|
|
|
|
2022-12-11 22:51:56 +01:00
|
|
|
$uinfo=posix_getpwnam($CONFIG['webserver_user']);
|
2021-10-29 07:58:58 +02:00
|
|
|
$cwd = getcwd();
|
2022-12-15 07:19:27 +01:00
|
|
|
$webtmp = preg_replace('/spoolnews/','tmp/',$cwd);
|
|
|
|
|
2021-10-29 07:58:58 +02:00
|
|
|
@mkdir($webtmp,0755,'recursive');
|
2022-12-11 22:51:56 +01:00
|
|
|
@chown($webtmp, $uinfo["uid"]);
|
|
|
|
@chgrp($webtmp, $uinfo["gid"]);
|
|
|
|
@mkdir($ssldir,0755);
|
|
|
|
@chown($ssldir, $uinfo["uid"]);
|
|
|
|
@chgrp($ssldir, $uinfo["gid"]);
|
2021-10-29 07:58:58 +02:00
|
|
|
|
2023-01-08 18:12:27 +01:00
|
|
|
$pemfile = $ssldir.'/server.pem';
|
|
|
|
create_node_ssl_cert($pemfile);
|
|
|
|
|
2022-05-16 08:01:53 +02:00
|
|
|
$overview = $spooldir.'/articles-overview.db3';
|
|
|
|
touch($overview);
|
2022-12-11 22:51:56 +01:00
|
|
|
@chown($overview, $uinfo["uid"]);
|
|
|
|
@chgrp($overview, $uinfo["gid"]);
|
2023-07-24 19:33:13 +02:00
|
|
|
|
|
|
|
if($rslight_gpg['enable'] == '1') {
|
|
|
|
$gnupg = $rslight_gpg['gnupghome'];
|
|
|
|
if(!is_dir($gnupg)) {
|
|
|
|
mkdir($gnupg, 0700);
|
|
|
|
chown($gnupg, $uinfo["uid"]);
|
|
|
|
chgrp($gnupg, $uinfo["gid"]);
|
|
|
|
}
|
|
|
|
}
|
2020-11-29 01:55:31 +01:00
|
|
|
/* Change to non root user */
|
|
|
|
change_identity($uinfo["uid"],$uinfo["gid"]);
|
|
|
|
/* Everything below runs as $CONFIG['webserver_user'] */
|
|
|
|
|
2021-07-07 12:07:16 +02:00
|
|
|
@mkdir($logdir,0755,'recursive');
|
|
|
|
@mkdir($lockdir,0755,'recursive');
|
2023-04-14 03:52:30 +02:00
|
|
|
|
2020-11-29 01:55:31 +01:00
|
|
|
if(isset($CONFIG['enable_nocem']) && $CONFIG['enable_nocem'] == true) {
|
|
|
|
@mkdir($spooldir."nocem",0755,'recursive');
|
2021-04-30 01:16:32 +02:00
|
|
|
exec($CONFIG['php_exec']." ".$config_dir."/scripts/nocem.php");
|
2020-11-29 01:55:31 +01:00
|
|
|
}
|
2023-07-24 19:33:13 +02:00
|
|
|
// Set up server gpg keys
|
|
|
|
if($rslight_gpg['enable'] == '1') {
|
|
|
|
if(!is_file($webtmp.'/server_pubkey.key')) {
|
|
|
|
$domain = 'rslight@'.$rslight_gpg['domain_name'];
|
|
|
|
$interBBS_mail = $config_dir.'/scripts/create_gpg_keys.sh "'.$gnupg.'" "'.$webtmp.'/server_pubkey.key" '.$domain;
|
|
|
|
exec($interBBS_mail);
|
|
|
|
}
|
|
|
|
}
|
2020-11-29 01:55:31 +01:00
|
|
|
|
|
|
|
reset($menulist);
|
|
|
|
foreach($menulist as $menu) {
|
|
|
|
if(($menu[0] == '#') || (trim($menu) == "")) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$menuitem=explode(':', $menu);
|
|
|
|
chdir("../".$menuitem[0]);
|
2021-11-18 04:20:32 +01:00
|
|
|
if($CONFIG['remote_server'] !== '') {
|
2020-11-29 01:55:31 +01:00
|
|
|
# Send articles
|
|
|
|
echo "Sending articles\n";
|
2021-04-30 01:16:32 +02:00
|
|
|
echo exec($CONFIG['php_exec']." ".$config_dir."/scripts/send.php");
|
2020-11-29 01:55:31 +01:00
|
|
|
# Refresh spool
|
|
|
|
if(isset($spoolnews) && ($spoolnews == true)) {
|
2021-04-30 01:16:32 +02:00
|
|
|
exec($CONFIG['php_exec']." ".$config_dir."/scripts/spoolnews.php");
|
2020-11-29 01:55:31 +01:00
|
|
|
echo "Refreshed spoolnews\n";
|
|
|
|
}
|
2021-11-18 04:20:32 +01:00
|
|
|
}
|
2020-11-29 01:55:31 +01:00
|
|
|
# Expire articles
|
2021-04-30 01:16:32 +02:00
|
|
|
exec($CONFIG['php_exec']." ".$config_dir."/scripts/expire.php");
|
2020-11-29 01:55:31 +01:00
|
|
|
echo "Expired articles\n";
|
|
|
|
}
|
2021-12-02 05:02:31 +01:00
|
|
|
# Run RSS Feeds
|
|
|
|
exec($CONFIG['php_exec']." ".$config_dir."/scripts/rss-feeds.php");
|
|
|
|
echo "RSS Feeds updated\n";
|
2020-11-29 01:55:31 +01:00
|
|
|
# Rotate log files
|
|
|
|
log_rotate();
|
|
|
|
echo "Log files rotated\n";
|
2021-06-11 09:50:54 +02:00
|
|
|
# Rotate keys
|
|
|
|
rotate_keys();
|
|
|
|
echo "Keys rotated\n";
|
2020-11-29 01:55:31 +01:00
|
|
|
|
|
|
|
function log_rotate() {
|
|
|
|
global $logdir;
|
|
|
|
$rotate = filemtime($logdir.'/rotate');
|
|
|
|
if((time() - $rotate) > 86400) {
|
2021-05-24 11:18:03 +02:00
|
|
|
$log_files=scandir($logdir);
|
2020-11-29 01:55:31 +01:00
|
|
|
foreach($log_files as $logfile) {
|
2021-05-24 11:18:03 +02:00
|
|
|
if(substr($logfile, -4) != '.log' ) {
|
2020-11-29 01:55:31 +01:00
|
|
|
continue;
|
|
|
|
}
|
2021-05-24 11:18:03 +02:00
|
|
|
$logfile=$logdir.'/'.$logfile;
|
2020-11-29 01:55:31 +01:00
|
|
|
@unlink($logfile.'.5');
|
|
|
|
@rename($logfile.'.4', $logfile.'.5');
|
|
|
|
@rename($logfile.'.3', $logfile.'.4');
|
|
|
|
@rename($logfile.'.2', $logfile.'.3');
|
|
|
|
@rename($logfile.'.1', $logfile.'.2');
|
|
|
|
@rename($logfile, $logfile.'.1');
|
|
|
|
echo 'Rotated: '.$logfile."\n";
|
|
|
|
}
|
|
|
|
unlink($logdir.'/rotate');
|
|
|
|
touch($logdir.'/rotate');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-11 09:50:54 +02:00
|
|
|
function rotate_keys() {
|
|
|
|
global $spooldir;
|
|
|
|
$keyfile = $spooldir.'/keys.dat';
|
|
|
|
$newkeys = array();
|
|
|
|
if(filemtime($keyfile)+14400 > time()) {
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
$new = true;
|
|
|
|
if(is_file($keyfile)) {
|
|
|
|
$keys = unserialize(file_get_contents($keyfile));
|
|
|
|
$new = false;
|
|
|
|
}
|
|
|
|
if($new !== true) {
|
|
|
|
$newkeys[0] = base64_encode(openssl_random_pseudo_bytes(44));
|
|
|
|
$newkeys[1] = $keys[0];
|
|
|
|
} else {
|
|
|
|
$newkeys[0] = base64_encode(openssl_random_pseudo_bytes(44));
|
|
|
|
$newkeys[1] = base64_encode(openssl_random_pseudo_bytes(44));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
file_put_contents($keyfile, serialize($newkeys));
|
|
|
|
touch($keyfile);
|
|
|
|
}
|
|
|
|
|
2020-11-29 01:55:31 +01:00
|
|
|
function change_identity( $uid, $gid )
|
|
|
|
{
|
|
|
|
if( !posix_setgid( $gid ) )
|
|
|
|
{
|
|
|
|
print "Unable to setgid to " . $gid . "!\n";
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !posix_setuid( $uid ) )
|
|
|
|
{
|
|
|
|
print "Unable to setuid to " . $uid . "!\n";
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|