Simplify: fix variable bug, deduplicate config patterns, remove dead code
This commit is contained in:
1 parent
4ac6d60d02
commit
6e5f0e25cf
5 files changed
+23
-43
No files matched your search
+9
-26
@@ -83,14 +83,14 @@ if [ ! -f /etc/debian_version ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
DEBIAN_VERSION=$(cat /etc/debian_version | cut -d. -f1)
|
||||
DEBIAN_FULL=$(cat /etc/debian_version)
|
||||
DEBIAN_VERSION=$(echo "$DEBIAN_FULL" | cut -d. -f1)
|
||||
if [ "$DEBIAN_VERSION" -lt 13 ]; then
|
||||
log_error "Debian 13 (Trixie) or newer is required. You have: $(cat /etc/debian_version)"
|
||||
log_error "Upgrade to Debian 13 first."
|
||||
log_error "Debian 13 (Trixie) or newer is required. You have: $DEBIAN_FULL"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
log_ok "Running as root on Debian $(cat /etc/debian_version)"
|
||||
log_ok "Running as root on Debian $DEBIAN_FULL"
|
||||
|
||||
# Auto-clone repo if not running from within it
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" && pwd)"
|
||||
@@ -339,15 +339,8 @@ sed -i "s|const ONION_KEY_ENCRYPTION_KEY=''|const ONION_KEY_ENCRYPTION_KEY='$ONI
|
||||
|
||||
# Replace default onion domain everywhere
|
||||
DEFAULT_ONION="dhosting4xxoydyaivckq7tsmtgi4wfs3flpeyitekkmqwu4v4r46syd.onion"
|
||||
sed -i "s/$DEFAULT_ONION/$ONION_ADDR/g" \
|
||||
/etc/postfix/sql/alias.cf \
|
||||
/etc/postfix/sender_login_maps \
|
||||
/etc/postfix/main.cf \
|
||||
/var/www/skel/www/index.hosting.html \
|
||||
/var/www/common.php \
|
||||
/etc/postfix/canonical \
|
||||
/etc/postfix-clearnet/canonical \
|
||||
/var/www/html/squirrelmail/config/config.php
|
||||
ONION_CONFIG_FILES="/etc/postfix/sql/alias.cf /etc/postfix/sender_login_maps /etc/postfix/main.cf /var/www/skel/www/index.hosting.html /var/www/common.php /etc/postfix/canonical /etc/postfix-clearnet/canonical /var/www/html/squirrelmail/config/config.php"
|
||||
sed -i "s/$DEFAULT_ONION/$ONION_ADDR/g" $ONION_CONFIG_FILES
|
||||
|
||||
log_ok "Configuration applied"
|
||||
log_step "Step 9: Configure Dovecot"
|
||||
@@ -441,13 +434,11 @@ log_step "Step 13: Configure MySQL"
|
||||
mysql -e "CREATE USER IF NOT EXISTS 'phpmyadmin'@'%' IDENTIFIED BY '$DB_PMA_PASS';
|
||||
CREATE DATABASE IF NOT EXISTS phpmyadmin;
|
||||
GRANT ALL PRIVILEGES ON phpmyadmin.* TO 'phpmyadmin'@'%';
|
||||
CREATE USER IF NOT EXISTS 'hosting'@'%' IDENTIFIED BY '$DB_HOSTING_PASS';
|
||||
GRANT ALL PRIVILEGES ON *.* TO 'hosting'@'%' WITH GRANT OPTION;
|
||||
FLUSH PRIVILEGES;"
|
||||
|
||||
mysql phpmyadmin < /var/www/html/phpmyadmin/sql/create_tables.sql 2>/dev/null || true
|
||||
|
||||
mysql -e "CREATE USER IF NOT EXISTS 'hosting'@'%' IDENTIFIED BY '$DB_HOSTING_PASS';
|
||||
GRANT ALL PRIVILEGES ON *.* TO 'hosting'@'%' WITH GRANT OPTION;
|
||||
FLUSH PRIVILEGES;"
|
||||
sed -i "s|\$cfg\['blowfish_secret'\] = '.*'|\$cfg['blowfish_secret'] = '$BLOWFISH_SECRET'|" \
|
||||
/var/www/html/phpmyadmin/config.inc.php
|
||||
sed -i "s|YOUR_PASSWORD|$DB_PMA_PASS|g" /var/www/html/phpmyadmin/config.inc.php 2>/dev/null || true
|
||||
@@ -478,15 +469,7 @@ if [ -n "$VANITY_PREFIX" ] && [ -n "$VANITY_SECRET" ]; then
|
||||
|
||||
# Update all config files with the vanity address
|
||||
NEW_ONION=$(cat /var/lib/tor/hidden_service/hostname | tr -d '[:space:]')
|
||||
sed -i "s|$ONION_ADDR|$NEW_ONION|g" \
|
||||
/etc/postfix/sql/alias.cf \
|
||||
/etc/postfix/sender_login_maps \
|
||||
/etc/postfix/main.cf \
|
||||
/var/www/skel/www/index.hosting.html \
|
||||
/var/www/common.php \
|
||||
/etc/postfix/canonical \
|
||||
/etc/postfix-clearnet/canonical \
|
||||
/var/www/html/squirrelmail/config/config.php
|
||||
sed -i "s|$ONION_ADDR|$NEW_ONION|g" $ONION_CONFIG_FILES
|
||||
|
||||
# Rebuild postfix maps with new address
|
||||
postmap /etc/postfix/canonical /etc/postfix/sender_login_maps /etc/postfix/transport
|
||||
|
||||
@@ -85,13 +85,14 @@ BACKUP_DIR="/root/hosting-backup-$(date +%Y%m%d-%H%M%S)"
|
||||
mkdir -p "$BACKUP_DIR"
|
||||
if [ -f /var/www/common.php ]; then
|
||||
cp /var/www/common.php "$BACKUP_DIR/common.php.bak"
|
||||
DBHOST=$(php8.2 -r "require('/var/www/common.php'); echo DBHOST;" 2>/dev/null || echo "127.0.0.1")
|
||||
DBUSER=$(php8.2 -r "require('/var/www/common.php'); echo DBUSER;" 2>/dev/null || echo "hosting")
|
||||
DBPASS=$(php8.2 -r "require('/var/www/common.php'); echo DBPASS;" 2>/dev/null || echo "")
|
||||
DBNAME=$(php8.2 -r "require('/var/www/common.php'); echo DBNAME;" 2>/dev/null || echo "hosting")
|
||||
ADMIN_PASSWORD=$(php8.2 -r "require('/var/www/common.php'); echo ADMIN_PASSWORD;" 2>/dev/null || echo "")
|
||||
ADDRESS=$(php8.2 -r "require('/var/www/common.php'); echo ADDRESS;" 2>/dev/null || echo "")
|
||||
ONION_KEY_ENCRYPTION_KEY=$(php8.2 -r "require('/var/www/common.php'); echo ONION_KEY_ENCRYPTION_KEY;" 2>/dev/null || echo "")
|
||||
eval $(php8.2 -r "
|
||||
require('/var/www/common.php');
|
||||
echo 'DBHOST=' . escapeshellarg(DBHOST) . '\n';
|
||||
echo 'DBPASS=' . escapeshellarg(DBPASS) . '\n';
|
||||
echo 'ADMIN_PASSWORD=' . escapeshellarg(ADMIN_PASSWORD) . '\n';
|
||||
echo 'ADDRESS=' . escapeshellarg(ADDRESS) . '\n';
|
||||
echo 'ONION_KEY_ENCRYPTION_KEY=' . escapeshellarg(ONION_KEY_ENCRYPTION_KEY) . '\n';
|
||||
" 2>/dev/null)
|
||||
log_ok "Secrets extracted from current config"
|
||||
else
|
||||
log_error "No /var/www/common.php found. Run install.sh first."
|
||||
@@ -133,7 +134,7 @@ if [ "$OLD_BINARIES_HASH" != "$NEW_BINARIES_HASH" ] && [ -n "$OLD_BINARIES_HASH"
|
||||
CHANGES="$CHANGES - PHP $ver (new, not yet built)\n"
|
||||
else
|
||||
INSTALLED_VER=$("/usr/bin/php$MAJOR_MINOR" -v 2>/dev/null | grep -oP 'PHP \K[0-9.]+' || echo "unknown")
|
||||
if [ "$installed_VER" != "$ver" ]; then
|
||||
if [ "$INSTALLED_VER" != "$ver" ]; then
|
||||
CHANGES="$CHANGES - PHP $MAJOR_MINOR: installed=$INSTALLED_VER, repo=$ver\n"
|
||||
fi
|
||||
fi
|
||||
|
||||
+4
-4
@@ -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"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
@@ -381,8 +381,8 @@ foreach(SERVICE_INSTANCES as $instance){
|
||||
rewrite_torrc($instance);
|
||||
exec("systemctl enable ".escapeshellarg("tor@$instance"));
|
||||
exec("systemctl start ".escapeshellarg("tor@$instance"));
|
||||
foreach(PHP_VERSIONS as $version){
|
||||
rewrite_php_config($instance);
|
||||
foreach(PHP_VERSIONS as $version){
|
||||
exec("systemctl enable ".escapeshellarg("php$version-fpm@$instance"));
|
||||
exec("systemctl start ".escapeshellarg("php$version-fpm@$instance"));
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user