Files
hosting/var/www/html/password.php
T
bigbong420 229ce3a0dc 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
2026-03-29 11:44:22 -04:00

67 lines
2.9 KiB
PHP

<?php
require('../common.php');
$db = get_db_instance();
$user=check_login();
if(!isset($_REQUEST['type'])){
$_REQUEST['type']='acc';
}
$msg='';
if($_SERVER['REQUEST_METHOD']==='POST'){
if($error=check_csrf_error()){
$msg.='<p role="alert" style="color:red">'.$error.'</p>';
}
if(!isset($_POST['pass']) || !password_verify($_POST['pass'], $user['password'])){
$msg.='<p role="alert" style="color:red">'._('Wrong password!').'</p>';
}elseif(!isset($_POST['confirm']) || !isset($_POST['newpass']) || $_POST['newpass']!==$_POST['confirm']){
$msg.='<p role="alert" style="color:red">'._('Wrong password!').'</p>';
}else{
if($_REQUEST['type']==='acc'){
$hash=password_hash($_POST['newpass'], PASSWORD_DEFAULT);
$stmt=$db->prepare('UPDATE users SET password=? WHERE id=?;');
$stmt->execute([$hash, $user['id']]);
$msg.='<p role="alert" style="color:green">'._('Successfully changed account password.').'</p>';
}elseif($_REQUEST['type']==='sys'){
$stmt=$db->prepare('INSERT INTO pass_change (user_id, password) VALUES (?, ?);');
$hash=get_system_hash($_POST['newpass']);
$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'){
$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{
$msg.='<p role="alert" style="color:red">'._("Couldn't update password: Unknown reset type.").'</p>';
}
}
}
header('Content-Type: text/html; charset=UTF-8');
print_header(_('Change password'));
echo $msg;
echo '<form method="POST" action="password.php"><input type="hidden" name="csrf_token" value="'.$_SESSION['csrf_token'].'"><table>';
echo '<tr><td>'._('Reset type:').'</td><td><select name="type">';
echo '<option value="acc"';
if($_REQUEST['type']==='acc'){
echo ' selected';
}
echo '>'._('Account').'</option>';
echo '<option value="sys"';
if($_REQUEST['type']==='sys'){
echo ' selected';
}
echo '>'._('System account').'</option>';
echo '<option value="sql"';
if($_REQUEST['type']==='sql'){
echo ' selected';
}
echo '>'._('MySQL').'</option>';
echo '</select></td></tr>';
echo '<tr><td>'._('Account password:').'</td><td><input type="password" name="pass" required autofocus></td></tr>';
echo '<tr><td>'._('New password:').'</td><td><input type="password" name="newpass" required></td></tr>';
echo '<tr><td>'._('Confirm password:').'</td><td><input type="password" name="confirm" required></td></tr>';
echo '<tr><td colspan="2"><button type="submit">'._('Reset').'</button></td></tr>';
echo '</table></form>';
echo '<p><a href="home.php">'._('Go back to dashboard').'</a></p>';
echo '</body></html>';