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

+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