Simplify: fix variable bug, deduplicate config patterns, remove dead code

This commit is contained in:
bigbong420 committed 2026-03-29 14:37:03 -04:00
1 parent 4ac6d60d02
commit 6e5f0e25cf
5 files changed
+23 -43

No files matched your search

+4 -4
View File
@@ -639,8 +639,8 @@ function rewrite_nginx_config(): void
function rewrite_php_config(string $key): void
{
$db = get_db_instance();
$all_versions = $all_versions;
$stmt=$db->prepare("SELECT system_account FROM users WHERE instance = ? AND php=? AND todelete!=1 AND id NOT IN (SELECT user_id FROM new_account);");
// collect user sockets that need to move between PHP versions
$all_accounts = [];
$tmp_stmt=$db->prepare("SELECT system_account FROM users WHERE instance = ? AND todelete!=1 AND id NOT IN (SELECT user_id FROM new_account);");
$tmp_stmt->execute([$key]);
@@ -650,7 +650,7 @@ function rewrite_php_config(string $key): void
$all_accounts[] = $sa;
}
}
foreach(array_replace(PHP_VERSIONS, DISABLED_PHP_VERSIONS) as $php_key => $version){
foreach($all_versions as $php_key => $version){
$stmt->execute([$key, $php_key]);
$php = "[www]
user = www-data
@@ -693,14 +693,14 @@ env[HOME]=/
file_put_contents("/etc/php/$version/fpm/pool.d/$key/www.conf", $php);
}
// restart FPM: first stop all to release sockets, remove stale sockets, then start all
foreach(array_replace(PHP_VERSIONS, DISABLED_PHP_VERSIONS) as $php_key => $version){
foreach($all_versions as $php_key => $version){
exec('systemctl stop '.escapeshellarg("php$version-fpm@$key").' 2>/dev/null');
}
foreach($all_accounts as $sa){
@unlink("/run/php/$sa");
}
usleep(200000); // 200ms for sockets to fully release
foreach(array_replace(PHP_VERSIONS, DISABLED_PHP_VERSIONS) as $php_key => $version){
foreach($all_versions as $php_key => $version){
exec('systemctl start '.escapeshellarg("php$version-fpm@$key"));
}
}
-4
View File
@@ -200,9 +200,7 @@ if(!empty($msg)){
echo '<p>'.sprintf(_('Enter system account password to check your %s mail:'), $user['system_account'].'@' . ADDRESS).'</td><td><form action="squirrelmail/src/redirect.php" method="post" target="_blank"><input type="hidden" name="login_username" value="'.$user['system_account'].'"><input type="password" name="secretkey"><button type="submit">'._('Login to webmail').'</button></form></p>';
echo '<h3>'._('Onion domains').'</h3>';
echo '<table border="1">';
//echo '<tr><th>'._('Onion').'</th><th>'._('Private key').'</th><th>'._('Enabled').'</th><th>'._('SMTP enabled').'</th><th>'._('Nr. of intros').'</th><th>'._('Max streams per rend circuit').'</th><th>'._('Action').'</th></tr>';
echo '<tr><th>'._('Onion').'</th><th>'._('Private key').'</th><th>'._('Enabled').'</th><th>'._('SMTP enabled').'</th><th>'._('Nr. of intros').'</th><th>'._('Max streams per rend circuit').'</th><th>'._('Description').'</th><th>'._('Action').'</th></tr>';
//$stmt=$db->prepare('SELECT onion, private_key, enabled, enable_smtp, num_intros, max_streams FROM onions WHERE user_id = ?;');
$stmt=$db->prepare('SELECT onion, private_key, enabled, enable_smtp, num_intros, max_streams, description FROM onions WHERE user_id = ?;');
$stmt->execute([$user['id']]);
$count_onions = 0;
@@ -222,7 +220,6 @@ while($onion=$stmt->fetch(PDO::FETCH_ASSOC)){
echo '>'._('Enabled').'</label></td>';
echo '<td><input type="number" name="num_intros" min="3" max="20" value="'.$onion['num_intros'].'"></td>';
echo '<td><input type="number" name="max_streams" min="0" max="65535" value="'.$onion['max_streams'].'"></td>';
//added description
echo '<td><input type="text" name="description" maxlength="50" value="'.htmlspecialchars($onion['description'] ?? '', ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8').'"></td>';
if(in_array($onion['enabled'], [0, 1])){
echo '<td><button type="submit" name="action" value="edit_onion">'._('Save').'</button>';
@@ -234,7 +231,6 @@ while($onion=$stmt->fetch(PDO::FETCH_ASSOC)){
}
if($count_onions<MAX_NUM_USER_ONIONS){
echo "<form action=\"home.php\" method=\"post\"><input type=\"hidden\" name=\"csrf_token\" value=\"$_SESSION[csrf_token]\">";
//echo '<tr><td colspan="6">'._('Add additional hidden service:').'<br>';
echo '<tr><td colspan="7">'._('Add additional hidden service:').'<br>';
echo '<label><input type="radio" name="onion_type" value="3"';
echo (!isset($_POST['onion_type']) || $_POST['onion_type']==3) ? ' checked' : '';
+1 -1
View File
@@ -381,8 +381,8 @@ foreach(SERVICE_INSTANCES as $instance){
rewrite_torrc($instance);
exec("systemctl enable ".escapeshellarg("tor@$instance"));
exec("systemctl start ".escapeshellarg("tor@$instance"));
rewrite_php_config($instance);
foreach(PHP_VERSIONS as $version){
rewrite_php_config($instance);
exec("systemctl enable ".escapeshellarg("php$version-fpm@$instance"));
exec("systemctl start ".escapeshellarg("php$version-fpm@$instance"));
}