Debian 13 support, PHP 8.4/8.5, security hardening, install script

- Debian 13 (Trixie) compatibility:
  - Build uw-imap c-client from source (removed from trixie)
  - Fix OpenSSL 3 include paths for c-client
  - Split libnginx-mod-http-brotli package name
  - Add -lgomp and -std=c++17 to PHP CXXFLAGS
  - Fix Dovecot 2.4 config syntax in setup
  - Use 127.0.0.1 for DB (works in FPM chroot)

- PHP version updates:
  - Add PHP 8.5.4 and 8.4.19
  - Remove PHP 8.1 (EOL)
  - Update igbinary to master, imagick to 3.8.1, brotli to 0.18.3
  - Remove php-rar (unmaintained, incompatible with 8.4+)
  - setup.php uses DEFAULT_PHP_VERSION for FPM sockets
  - Users can switch PHP version from dashboard

- Security hardening:
  - CSRF tokens use bin2hex(random_bytes(32))
  - Admin password uses password_hash/password_verify
  - Session regeneration on login
  - All output escaped with htmlspecialchars
  - Nginx rewrite rules validated (flag whitelist, reject injection)
  - Path traversal protection in FileManager
  - SQL injection fix in password change
  - Security headers (CSP script-src:none, X-Frame-Options, etc)
  - Onion private keys encrypted at rest (libsodium)
  - SFTP password encrypted in session with expiry
  - Admin brute-force rate limiting
  - CSRF token on login form
  - Zero JavaScript - all pages work without JS
  - mt_rand replaced with random_int
  - Cookie secure flag precedence fix
  - PDO ERRMODE_EXCEPTION
  - Generic login error messages (no username enumeration)
  - FileManager rename validation

- Self-bootstrapping install.sh:
  - Auto-clones repo if run standalone (curl | bash support)
  - Interactive prompts or --non-interactive flag
  - Optional vanity .onion generation via mkp224o
  - Password generation or custom input
  - Credentials saved to /root/hosting-credentials.txt
This commit is contained in:
bigbong420 committed 2026-03-29 11:44:22 -04:00
1 parent 71dd2804fb
commit 229ce3a0dc
10 files changed
+873 -96

No files matched your search

+29 -9
View File
@@ -11,10 +11,27 @@ print_header(_('Admin panel'), 'td{padding:5px;}', '_blank');
<h1><?php echo _('Hosting - Admin panel'); ?></h1>
<?php
$error=false;
if($_SERVER['REQUEST_METHOD']==='POST' && isset($_POST['pass']) && $_POST['pass']===ADMIN_PASSWORD){
if(!($error=check_captcha_error())){
$_SESSION['logged_in']=true;
$_SESSION['csrf_token']=sha1(uniqid());
$rate_limited=false;
if(!isset($_SESSION['admin_attempts'])){
$_SESSION['admin_attempts']=0;
$_SESSION['admin_last_attempt']=0;
}
if($_SERVER['REQUEST_METHOD']==='POST' && isset($_POST['pass'])){
// rate limit: after 5 failed attempts, enforce increasing delay
$delay = min(pow(2, max(0, $_SESSION['admin_attempts'] - 4)), 60);
if($_SESSION['admin_attempts'] >= 5 && (time() - $_SESSION['admin_last_attempt']) < $delay){
$rate_limited=true;
$error=sprintf(_('Too many failed attempts. Please wait %d seconds.'), $delay - (time() - $_SESSION['admin_last_attempt']));
}elseif(password_verify($_POST['pass'], ADMIN_PASSWORD)){
if(!($error=check_captcha_error())){
session_regenerate_id(true);
$_SESSION['logged_in']=true;
$_SESSION['csrf_token']=bin2hex(random_bytes(32));
$_SESSION['admin_attempts']=0;
}
}else{
$_SESSION['admin_attempts']++;
$_SESSION['admin_last_attempt']=time();
}
}
if(empty($_SESSION['logged_in'])){
@@ -25,7 +42,7 @@ if(empty($_SESSION['logged_in'])){
echo '</table></form>';
if($error){
echo '<p role="alert" style="color:red">'.$error.'</p>';
}elseif(isset($_POST['pass'])){
}elseif(isset($_POST['pass']) && !$rate_limited){
echo '<p role="alert" style="color:red">'._('Wrong password!').'</p>';
}
echo '<p>'._("If you disabled cookies, please re-enable them. You can't log in without!").'</p>';
@@ -54,7 +71,7 @@ if(empty($_SESSION['logged_in'])){
$accounts[$tmp[0]] []= [$tmp[1], $tmp[2]];
}
foreach($accounts as $account => $onions){
echo "<tr><td>$account</td><td>";
echo '<tr><td>'.htmlspecialchars($account, ENT_QUOTES, 'UTF-8').'</td><td>';
$first = true;
foreach($onions as $onion){
if($first){
@@ -62,10 +79,11 @@ if(empty($_SESSION['logged_in'])){
}else{
echo '<br>';
}
$safe_onion = htmlspecialchars($onion[0], ENT_QUOTES, 'UTF-8');
if($onion[1]=='1'){
echo "<a href=\"http://$onion[0].onion\">$onion[0].onion</a>";
echo "<a href=\"http://$safe_onion.onion\">$safe_onion.onion</a>";
}else{
echo "$onion[0].onion";
echo "$safe_onion.onion";
}
}
echo '</td><td><button type="submit" name="action" value="edit_'.$onions[0][0].'">'._('Edit').'</button><button type="submit" name="action" value="delete_'.$onions[0][0].'">'._('Delete').'</button><button type="submit" name="action" value="suspend_'.$onions[0][0].'">'._('Suspend').'</button></td></tr>';
@@ -88,7 +106,9 @@ if(empty($_SESSION['logged_in'])){
echo '<tr><th>'._('Username').'</th><th>'._('Onion address').'</th><th>'._('Action').'</th></tr>';
$stmt=$db->query('SELECT users.username, onions.onion FROM users INNER JOIN new_account ON (users.id=new_account.user_id) INNER JOIN onions ON (onions.user_id=users.id) WHERE new_account.approved=0 ORDER BY users.username;');
while($tmp=$stmt->fetch(PDO::FETCH_NUM)){
echo "<tr><td>$tmp[0]</td><td><a href=\"http://$tmp[1].onion\">$tmp[1].onion</a></td><td><button type=\"submit\" name=\"action\" value=\"approve_$tmp[1]\">"._('Approve').'</button><button type="submit" name="action" value="delete_'.$tmp[1].'">'._('Delete').'</button></td></tr>';
$safe_user = htmlspecialchars($tmp[0], ENT_QUOTES, 'UTF-8');
$safe_onion = htmlspecialchars($tmp[1], ENT_QUOTES, 'UTF-8');
echo "<tr><td>$safe_user</td><td><a href=\"http://$safe_onion.onion\">$safe_onion.onion</a></td><td><button type=\"submit\" name=\"action\" value=\"approve_$safe_onion\">"._('Approve').'</button><button type="submit" name="action" value="delete_'.$safe_onion.'">'._('Delete').'</button></td></tr>';
}
echo '</table></form>';
}elseif( str_starts_with( $_REQUEST[ 'action' ], 'delete' ) ){
+24 -13
View File
@@ -3,17 +3,32 @@ require('../common.php');
$db = get_db_instance();
$user=check_login();
if(!empty($_POST['sftp_pass'])){
$_SESSION['sftp_pass']=$_POST['sftp_pass'];
$sftp_key = random_bytes(SODIUM_CRYPTO_SECRETBOX_KEYBYTES);
$sftp_nonce = random_bytes(SODIUM_CRYPTO_SECRETBOX_NONCEBYTES);
$_SESSION['sftp_enc'] = base64_encode($sftp_nonce . sodium_crypto_secretbox($_POST['sftp_pass'], $sftp_nonce, $sftp_key));
$_SESSION['sftp_key'] = base64_encode($sftp_key);
$_SESSION['sftp_expiry'] = time() + 3600; // 1 hour expiry
}
if(empty($_SESSION['sftp_pass'])){
$sftp_pass = '';
if(!empty($_SESSION['sftp_enc']) && !empty($_SESSION['sftp_key']) && ($_SESSION['sftp_expiry'] ?? 0) > time()){
$raw = base64_decode($_SESSION['sftp_enc']);
$key = base64_decode($_SESSION['sftp_key']);
$nonce = substr($raw, 0, SODIUM_CRYPTO_SECRETBOX_NONCEBYTES);
$cipher = substr($raw, SODIUM_CRYPTO_SECRETBOX_NONCEBYTES);
$sftp_pass = sodium_crypto_secretbox_open($cipher, $nonce, $key);
}
if(empty($sftp_pass)){
unset($_SESSION['sftp_enc'], $_SESSION['sftp_key'], $_SESSION['sftp_expiry']);
send_login();
exit;
}
$ssh=ssh2_connect('127.0.0.1') or die (_('No Connection to SFTP server!'));
if(@!ssh2_auth_password($ssh, $user['system_account'], $_SESSION['sftp_pass'])){
if(@!ssh2_auth_password($ssh, $user['system_account'], $sftp_pass)){
unset($_SESSION['sftp_enc'], $_SESSION['sftp_key'], $_SESSION['sftp_expiry']);
send_login();
exit;
}
sodium_memzero($sftp_pass);
$sftp = ssh2_sftp($ssh);
//prepare reusable data
const TYPES=[
@@ -93,8 +108,10 @@ if(!isset($_REQUEST['O']) || !in_array($_REQUEST['O'], array('A', 'D'))){
}
if(!empty($_REQUEST['path'])){
$dir='/'.trim(rawurldecode($_REQUEST['path']),'/').'/';
$dir=str_replace('..', '\.\.', $dir);
$dir=preg_replace('~//+~', '/', $dir);
if(str_contains($dir, '..')){
$dir='/www/';
}
}else{
$dir='/www/';
}
@@ -147,6 +164,9 @@ if(isset($_POST['rename_2']) && !empty($_POST['files'])){
die($error);
}
foreach($_POST['files'] as $old=>$new){
if(str_contains($new, '/') || str_contains($new, '..') || str_contains($old, '/') || str_contains($old, '..')){
continue;
}
@ssh2_sftp_rename($sftp, "$dir/$old", "$dir/$new");
}
}
@@ -317,15 +337,6 @@ foreach($list as $element){
<button type="submit" name="edit"><?php echo _('Edit'); ?></button>
<button type="submit" name="unzip"><?php echo _('Unzip'); ?></button><br><br>
</form>
<script>
document.getElementById('checkAllParent').innerHTML = '<input type="checkbox" onclick="toggle(this);">';
function toggle(source) {
let checkboxes = document.getElementsByClassName('fileCheck');
for(let i=0, n=checkboxes.length;i<n;i++) {
checkboxes[i].checked = source.checked;
}
}
</script>
</body></html>
<?php
+48 -15
View File
@@ -127,22 +127,20 @@ if(isset($_POST['action']) && $_POST['action']==='del_domain_2' && !empty($_POST
}
del_user_domain($user['id'], $_POST['domain']);
}
if(isset($_REQUEST['action']) && isset($_REQUEST['onion']) && $_REQUEST['action']==='edit_onion'){
if(isset($_POST['action']) && isset($_POST['onion']) && $_POST['action']==='edit_onion'){
if($error=check_csrf_error()){
die($error);
}
//$stmt=$db->prepare('SELECT onions.version, onions.instance FROM onions INNER JOIN users ON (users.id=onions.user_id) WHERE onions.onion = ? AND users.id = ? AND onions.enabled IN (0, 1);');
$stmt=$db->prepare('SELECT onions.version, onions.instance, onions.description FROM onions INNER JOIN users ON (users.id=onions.user_id) WHERE onions.onion = ? AND users.id = ? AND onions.enabled IN (0, 1);');
$description = trim($_POST['description'] ?? $_REQUEST['description'] ?? '');
$description = mb_substr($description, 0, 50); // Limit 50
$stmt->execute([$_REQUEST['onion'], $user['id']]);
$stmt=$db->prepare('SELECT onions.version, onions.instance, onions.description FROM onions INNER JOIN users ON (users.id=onions.user_id) WHERE onions.onion = ? AND users.id = ? AND onions.enabled IN (0, 1);');
$description = trim($_POST['description'] ?? '');
$description = mb_substr($description, 0, 50);
$stmt->execute([$_POST['onion'], $user['id']]);
if($onion=$stmt->fetch(PDO::FETCH_ASSOC)){
//$stmt=$db->prepare('UPDATE onions SET enabled = ?, enable_smtp = ?, num_intros = ?, max_streams = ? WHERE onion = ?;');
$stmt=$db->prepare('UPDATE onions SET enabled = ?,enable_smtp = ?,num_intros = ?,max_streams = ?,description = ?WHERE onion = ?;');
$enabled = isset($_REQUEST['enabled']) ? 1 : 0;
$enable_smtp = isset($_REQUEST['enable_smtp']) ? 1 : 0;
$num_intros = intval($_REQUEST['num_intros']);
$enabled = isset($_POST['enabled']) ? 1 : 0;
$enable_smtp = isset($_POST['enable_smtp']) ? 1 : 0;
$num_intros = intval($_POST['num_intros']);
if($num_intros<3){
$num_intros = 3;
}elseif($onion['version']==2 && $num_intros>10){
@@ -150,17 +148,37 @@ if(isset($_REQUEST['action']) && isset($_REQUEST['onion']) && $_REQUEST['action'
}elseif($num_intros>20){
$num_intros = 20;
}
$max_streams = intval($_REQUEST['max_streams']);
$max_streams = intval($_POST['max_streams']);
if($max_streams<0){
$max_streams = 0;
}elseif($max_streams>65535){
$max_streams = 65535;
}
//$stmt->execute([$enabled, $enable_smtp, $num_intros, $max_streams, $_REQUEST['onion']]);
$stmt->execute([$enabled,$enable_smtp,$num_intros,$max_streams,$description,$_REQUEST['onion']]);
$stmt->execute([$enabled,$enable_smtp,$num_intros,$max_streams,$description,$_POST['onion']]);
enqueue_instance_reload($onion['instance']);
}
}
if(isset($_POST['action']) && $_POST['action']==='change_php'){
if($error=check_csrf_error()){
die($error);
}
$new_php = intval($_POST['php']);
if($new_php === 0 || array_key_exists($new_php, PHP_VERSIONS)){
$stmt=$db->prepare('UPDATE users SET php = ? WHERE id = ?;');
$stmt->execute([$new_php, $user['id']]);
$user['php'] = $new_php;
$stmt=$db->prepare('SELECT instance FROM onions WHERE user_id = ?;');
$stmt->execute([$user['id']]);
$instances = [];
while($row=$stmt->fetch(PDO::FETCH_ASSOC)){
$instances[$row['instance']] = true;
}
foreach(array_keys($instances) as $instance){
rewrite_php_config($instance);
}
rewrite_nginx_config();
}
}
if(isset($_REQUEST['action']) && isset($_POST['domain']) && $_POST['action']==='edit_domain'){
if($error=check_csrf_error()){
die($error);
@@ -192,7 +210,7 @@ while($onion=$stmt->fetch(PDO::FETCH_ASSOC)){
++$count_onions;
echo "<form action=\"home.php\" method=\"post\"><input type=\"hidden\" name=\"csrf_token\" value=\"$_SESSION[csrf_token]\"><input type=\"hidden\" name=\"onion\" value=\"$onion[onion]\"><tr><td><a href=\"http://$onion[onion].onion\" target=\"_blank\">$onion[onion].onion</a></td><td>";
if(isset($_REQUEST['show_priv'])){
echo "<pre>$onion[private_key]</pre>";
echo '<pre>'.htmlspecialchars(decrypt_private_key($onion['private_key']), ENT_QUOTES, 'UTF-8').'</pre>';
}else{
echo '<a href="home.php?show_priv=1">'._('Show private key').'</a>';
}
@@ -286,6 +304,21 @@ if($count_dbs<MAX_NUM_USER_DBS){
?>
<p><a href="password.php?type=sql"><?php echo _('Change MySQL password'); ?></a></p>
<p><?php printf(_('You can use <a href="/phpmyadmin/" target="_blank">PHPMyAdmin</a> and <a href="/adminer/?username=%s" target="_blank">Adminer</a> for web based database administration.'), rawurlencode($user['mysql_user'])); ?></p>
<h3><?php echo _('PHP Version'); ?></h3>
<form action="home.php" method="post">
<input type="hidden" name="csrf_token" value="<?php echo $_SESSION['csrf_token']; ?>">
<select name="php">
<option value="0"<?php echo $user['php'] == 0 ? ' selected' : ''; ?>><?php echo _('None'); ?></option>
<?php
foreach(PHP_VERSIONS as $key => $version){
echo "<option value=\"$key\"";
echo $user['php'] == $key ? ' selected' : '';
echo ">PHP $version</option>";
}
?>
</select>
<button type="submit" name="action" value="change_php"><?php echo _('Save'); ?></button>
</form>
<h3><?php echo _('System Account'); ?></h3>
<table border="1">
<tr><th><?php echo _('Username'); ?></th><th><?php echo _('Host'); ?></th><th><?php echo _('SFTP Port'); ?></th><th><?php echo _('POP3 Port'); ?></th><th><?php echo _('IMAP Port'); ?></th><th><?php echo _('SMTP port'); ?></th></tr>
+14 -11
View File
@@ -2,6 +2,9 @@
require('../common.php');
header('Content-Type: text/html; charset=UTF-8');
session_start();
if(empty($_SESSION['login_csrf'])){
$_SESSION['login_csrf']=bin2hex(random_bytes(32));
}
if(!empty($_SESSION['hosting_username']) && empty($_SESSION['2fa_code'])){
header('Location: home.php');
exit;
@@ -29,7 +32,10 @@ if($_SERVER['REQUEST_METHOD']==='POST'){
} else {
$db = get_db_instance();
$ok=true;
if($error=check_captcha_error()){
if(!isset($_POST['login_csrf']) || !hash_equals($_SESSION['login_csrf'], $_POST['login_csrf'])){
$msg.='<p role="alert" style="color:red">'._('Error: Invalid request token.').'</p>';
$ok=false;
}elseif($error=check_captcha_error()){
$msg.='<p role="alert" style="color:red">'.$error.'</p>';
$ok=false;
}elseif(!isset($_POST['username']) || $_POST['username']===''){
@@ -52,24 +58,21 @@ if($_SERVER['REQUEST_METHOD']==='POST'){
$stmt=$db->prepare('SELECT new_account.approved FROM new_account INNER JOIN users ON (users.id=new_account.user_id) WHERE users.id=?;');
$stmt->execute([$tmp['id']]);
if($tmp=$stmt->fetch(PDO::FETCH_NUM)){
if(REQUIRE_APPROVAL && !$tmp[0]){
$msg.='<p role="alert" style="color:red">'._('Error: Your account is pending admin approval. Please try again later.').'</p>';
}else{
$msg.='<p role="alert" style="color:red">'._('Error: Your account is pending creation. Please try again in a minute.').'</p>';
}
$msg.='<p role="alert" style="color:red">'._('Error: Invalid username or password.').'</p>';
$ok=false;
}elseif(!isset($_POST['pass']) || !password_verify($_POST['pass'], $password)){
$msg.='<p role="alert" style="color:red">'._('Error: wrong password.').'</p>';
$msg.='<p role="alert" style="color:red">'._('Error: Invalid username or password.').'</p>';
$ok=false;
}
}else{
$msg.='<p role="alert" style="color:red">'._('Error: username was not found. If you forgot it, you can enter youraccount.onion instead.').'</p>';
$msg.='<p role="alert" style="color:red">'._('Error: Invalid username or password.').'</p>';
$ok=false;
}
}
if($ok){
session_regenerate_id(true);
$_SESSION['hosting_username']=$username;
$_SESSION['csrf_token']=sha1(uniqid());
$_SESSION['csrf_token']=bin2hex(random_bytes(32));
if($tfa){
$code = bin2hex(random_bytes(3));
$_SESSION['2fa_code'] = $code;
@@ -101,7 +104,7 @@ if($tfa){
$encrypted = gnupg_encrypt($gpg, _('To login, please enter the following code to confirm ownership of your key:')."\n\n".$_SESSION['2fa_code']."\n");
echo $msg;
echo '<p>'._('To login, please decrypt the following PGP encrypted message and confirm the code:').'</p>';
echo "<textarea readonly=\"readonly\" onclick=\"this.select()\" rows=\"10\" cols=\"70\">$encrypted</textarea>";
echo '<textarea readonly="readonly" rows="10" cols="70">'.htmlspecialchars($encrypted, ENT_QUOTES, 'UTF-8').'</textarea>';
?>
<form action="login.php" method="post"><input type="hidden" name="csrf_token" value="<?php echo $_SESSION['csrf_token']; ?>">
<table border="1">
@@ -119,7 +122,7 @@ if($tfa){
main_menu('login.php');
echo $msg;
?>
<form method="POST" action="login.php"><table>
<form method="POST" action="login.php"><input type="hidden" name="login_csrf" value="<?php echo $_SESSION['login_csrf']; ?>"><table>
<tr><td><?php echo _('Username'); ?></td><td><input type="text" name="username" value="<?php
if(isset($_POST['username'])){
echo htmlspecialchars($_POST['username']);
+3 -2
View File
@@ -26,8 +26,9 @@ if($_SERVER['REQUEST_METHOD']==='POST'){
$stmt->execute([$user['id'], $hash]);
$msg.='<p role="alert" style="color:green">'._('Successfully changed system account password, change will take effect within the next minute.').'</p>';
}elseif($_REQUEST['type']==='sql'){
$stmt=$db->prepare("SET PASSWORD FOR '$user[mysql_user]'@'%'=PASSWORD(?);");
$stmt->execute([$_POST['newpass']]);
$safe_user = preg_replace('/[^a-zA-Z0-9]/', '', $user['mysql_user']);
$stmt=$db->prepare("ALTER USER ?@'%' IDENTIFIED BY ?;");
$stmt->execute([$safe_user, $_POST['newpass']]);
$db->exec('FLUSH PRIVILEGES;');
$msg.='<p role="alert" style="color:green">'._('Successfully changed sql password.').'</p>';
}else{
+2 -2
View File
@@ -55,7 +55,7 @@ if(!empty($user['pgp_key'])){
$_SESSION['enable_2fa_code'] = bin2hex(random_bytes(3));
if($encrypted = gnupg_encrypt($gpg, _('To enable 2FA, please enter the following code to confirm ownership of your key:')."\n\n$_SESSION[enable_2fa_code]\n")){
echo '<p>'._('To enable 2FA using your PGP key, please decrypt the following PGP encrypted message and confirm the code:').'</p>';
echo "<textarea readonly=\"readonly\" onclick=\"this.select()\" rows=\"10\" cols=\"70\">$encrypted</textarea>";
echo '<textarea readonly="readonly" rows="10" cols="70">'.htmlspecialchars($encrypted, ENT_QUOTES, 'UTF-8').'</textarea>';
?>
<form action="pgp.php" method="post"><input type="hidden" name="csrf_token" value="<?php echo $_SESSION['csrf_token']; ?>">
<table border="1">
@@ -72,7 +72,7 @@ if(!empty($user['pgp_key'])){
<form action="pgp.php" method="post">
<input type="hidden" name="csrf_token" value="<?php echo $_SESSION['csrf_token']; ?>">
<table border="1">
<tr><td><textarea name="pgp_key" rows="10" cols="70"><?php echo $user['pgp_key']; ?></textarea></td></tr>
<tr><td><textarea name="pgp_key" rows="10" cols="70"><?php echo htmlspecialchars($user['pgp_key'], ENT_QUOTES, 'UTF-8'); ?></textarea></td></tr>
<tr><td><button type="submit"><?php echo _('Update PGP key'); ?></button></td></tr>
</table>
</form>