Cleanup changing user code in maintenance.php and account_manager.php.

This commit is contained in:
Retro_Guy 2024-11-29 11:14:11 -07:00
parent 33bff45270
commit 2eeb873a45
2 changed files with 26 additions and 9 deletions

View File

@ -4,17 +4,28 @@ chdir($spoolnews_path);
include "config.inc.php";
include "newsportal.php";
$processUser = posix_getpwuid(posix_geteuid());
echo "You are running as user: " . $processUser['name'] . "\n";
// Change to webserver user if root
$uinfo = posix_getpwnam($CONFIG['webserver_user']);
/* Change to non root user */
change_identity($uinfo["uid"], $uinfo["gid"]);
$processUser = posix_getpwuid(posix_geteuid());
if ($processUser['name'] != $CONFIG['webserver_user']) {
echo "You are running as: " . $processUser['name'] . "\n";
echo 'Please run this scripts as: ' . $CONFIG['webserver_user'] . "\n";
echo "You are running as user: " . $processUser['name'] . "\n";
echo 'Please run this script as: ' . $CONFIG['webserver_user'] . "\n";
exit();
}
/* Everything below runs as $CONFIG['webserver_user'] */
echo "You are running as user: " . $processUser['name'] . "\n";
$processUser = posix_getpwuid(posix_geteuid());
if ($processUser['name'] != $CONFIG['webserver_user']) {
echo "You are running as user: " . $processUser['name'] . "\n";
echo 'Please run this script as: ' . $CONFIG['webserver_user'] . "\n";
exit();
}
$keyfile = $spooldir . '/keys.dat';
$keys = unserialize(file_get_contents($keyfile));
@ -128,7 +139,7 @@ function get_user_by_hash($postinghash)
echo "Hash file not found\n";
return;
}
if(isset($posthash[$postinghash])) {
if (isset($posthash[$postinghash])) {
echo $posthash[$postinghash] . ' : ' . $postinghash . "\n";
} else {
echo "$postinghash not found in database\n";

View File

@ -28,14 +28,18 @@ if (! isset($argv[1])) {
}
if ($argv[1] != '-newsection') {
$processUser = posix_getpwuid(posix_geteuid());
echo "You are running as user: " . $processUser['name'] . "\n";
// Change to webserver user if root
$uinfo = posix_getpwnam($CONFIG['webserver_user']);
/* Change to non root user */
change_identity($uinfo["uid"], $uinfo["gid"]);
$processUser = posix_getpwuid(posix_geteuid());
if ($processUser['name'] != $CONFIG['webserver_user']) {
echo "You are running as: " . $processUser['name'] . "\n";
echo 'Please run this scripts as: ' . $CONFIG['webserver_user'] . "\n";
echo "You are running as user: " . $processUser['name'] . "\n";
echo 'Please run this script as: ' . $CONFIG['webserver_user'] . "\n";
exit();
}
/* Everything below runs as $CONFIG['webserver_user'] */
@ -43,13 +47,12 @@ if ($argv[1] != '-newsection') {
$processUser = posix_getpwuid(posix_geteuid());
if ($processUser['name'] != $CONFIG['webserver_user']) {
echo "You are running as: " . $processUser['name'] . "\n";
echo 'Please run this scripts as: ' . $CONFIG['webserver_user'] . "\n";
echo "You are running as user: " . $processUser['name'] . "\n";
echo 'Please run this script as: ' . $CONFIG['webserver_user'] . "\n";
exit();
}
$logfile = $logdir . '/import.log';
$lockfile = $lockdir . '/' . $config_name . '-spoolnews.lock';
$pid = file_get_contents($lockfile);
@ -57,9 +60,12 @@ if ($argv[1] != '-newsection') {
print "Starting Import...\n";
file_put_contents($lockfile, getmypid()); // create lockfile
} else {
print "Import currently running\n";
print "Spoolnews currently running\n";
exit();
}
} else {
$processUser = posix_getpwuid(posix_geteuid());
echo "You are running as user: " . $processUser['name'] . "\n";
}
if ($argv[1][0] == '-') {