Merge pull request #159 from bigbong420/upgrades
Debian 13 support, PHP 8.4/8.5, install script, security fixes
This commit is contained in:
15 files changed
+1216
-105
No files matched your search
@@ -15,9 +15,47 @@ Once you are done, you can open a pull request, or [email me](mailto:daniel@danw
|
||||
Installation Instructions:
|
||||
--------------------------
|
||||
|
||||
The configuration was tested with a standard Debian bookworm and Ubuntu 24.04 LTS installation. It's recommended you install Debian bookworm (or newer) on your server, but with a little tweaking you may also get this working on other distributions and/or versions. If you want to build it on a raspberry pi, please do not use the raspbian images as several things will break. Download an image for your pi model from [https://raspi.debian.net/daily-images/](https://raspi.debian.net/daily-images/) instead.
|
||||
The configuration was tested with Debian 13 (Trixie) and Ubuntu 24.04 LTS. It's recommended you install Debian 13 or Ubuntu 24.04 on your server, but with a little tweaking you may also get this working on other distributions and/or versions. If you want to build it on a raspberry pi, please do not use the raspbian images as several things will break. Download an image for your pi model from [https://raspi.debian.net/daily-images/](https://raspi.debian.net/daily-images/) instead.
|
||||
|
||||
Because I regularly get asked to make a video tutorial on how to set this up, I decided to create a tutorial which you can [watch on YouTube](https://www.youtube.com/watch?v=f2-SOlnIYmg). It is basically just copy-pasting commands, but maybe it helps someone.
|
||||
### Automated Install
|
||||
|
||||
The easiest way to install is with the automated installer:
|
||||
|
||||
```
|
||||
apt update && apt install git && git clone https://github.com/DanWin/hosting && cd hosting
|
||||
./install.sh
|
||||
```
|
||||
|
||||
The installer handles everything: package installation, PHP/ImageMagick compilation, Tor configuration, MySQL setup, and service provisioning. It will prompt for passwords or generate them automatically.
|
||||
|
||||
Options:
|
||||
```
|
||||
./install.sh --non-interactive # Skip prompts, generate random passwords
|
||||
./install.sh --vanity <prefix> # Generate a vanity .onion address
|
||||
./install.sh --skip-binaries # Skip compiling (use if already built)
|
||||
./install.sh --db-pass <pass> # Set hosting MySQL password
|
||||
./install.sh --pma-pass <pass> # Set phpMyAdmin MySQL password
|
||||
./install.sh --admin-pass <pass> # Set admin panel password
|
||||
```
|
||||
|
||||
Vanity .onion generation uses [mkp224o](https://github.com/cathugger/mkp224o) (compiled automatically). Only characters a-z and 2-7 are valid. A 4-char prefix takes minutes, 5 chars takes 10-30 minutes, 6+ chars takes hours.
|
||||
|
||||
Credentials are saved to `/root/hosting-credentials.txt`.
|
||||
|
||||
### Updating
|
||||
|
||||
```
|
||||
cd hosting
|
||||
./update.sh # Update code, preserve config
|
||||
./update.sh --rebuild # Also rebuild PHP/ImageMagick
|
||||
./update.sh --code-only # Only update PHP files
|
||||
```
|
||||
|
||||
The update script backs up your configuration, pulls the latest code, restores passwords and onion address, and restarts services. It detects if `install_binaries.sh` changed and warns you to rebuild.
|
||||
|
||||
### Manual Install
|
||||
|
||||
If you prefer to install manually, follow the steps below.
|
||||
|
||||
Uninstall packages that may interfere with this setup:
|
||||
```
|
||||
@@ -30,7 +68,7 @@ If you have problems resolving hostnames after this step, temporarily switch to
|
||||
rm /etc/resolv.conf && echo "nameserver 1.1.1.1" > /etc/resolv.conf
|
||||
```
|
||||
|
||||
Add additional repositories:
|
||||
Add additional repositories (Debian only — Ubuntu has nginx and brotli natively):
|
||||
```
|
||||
apt update && apt install git apt-transport-tor curl lsb-release
|
||||
curl -sSL https://deb.torproject.org/torproject.org/A3C4F0F979CAA22CDBA8F512EE8CBC9E886DDD89.asc > /etc/apt/trusted.gpg.d/torproject.asc
|
||||
@@ -117,7 +155,7 @@ Install sodium_compat for v3 hidden_service support
|
||||
cd /var/www && composer install
|
||||
```
|
||||
|
||||
Create a mysql user for phpmyadmin and cofigure it in `/var/www/html/phpmyadmin/config.inc.php` and fill `$cfg['blowfish_secret']` with random characters:
|
||||
Create a mysql user for phpmyadmin and configure it in `/var/www/html/phpmyadmin/config.inc.php` and fill `$cfg['blowfish_secret']` with random characters:
|
||||
```
|
||||
mysql
|
||||
CREATE USER 'phpmyadmin'@'%' IDENTIFIED BY 'MY_PASSWORD';
|
||||
@@ -146,7 +184,50 @@ php /var/www/setup.php
|
||||
|
||||
Enable systemd timers to regularly run various managing tasks:
|
||||
```
|
||||
systemctl enable hosting-del.timer && systemctl enable hosting.timer
|
||||
systemctl enable hosting-del.timer && systemctl enable hosting.timer && systemctl enable hosting-autoscale.timer
|
||||
```
|
||||
|
||||
Final step is to reboot wait about 5 minutes for all services to start and check if everything is working by creating a test account.
|
||||
Final step is to reboot, wait about 5 minutes for all services to start, and check if everything is working by creating a test account.
|
||||
|
||||
PHP Versions:
|
||||
--------------------------
|
||||
|
||||
Users can choose between PHP 8.2, 8.3, 8.4, and 8.5 at registration and change their version from the dashboard. The default is PHP 8.5.
|
||||
|
||||
Auto-Scaling:
|
||||
--------------------------
|
||||
|
||||
Tor instances scale automatically based on account count. The `hosting-autoscale.timer` runs hourly and adds a new instance for every ~250 accounts. Instance IDs go `a` through `z`, then `aa`, `ab`, etc. You can also manually set instances in `SERVICE_INSTANCES` in `/var/www/common.php` and run `setup.php`.
|
||||
|
||||
Security:
|
||||
--------------------------
|
||||
|
||||
- CSRF tokens use cryptographically secure random bytes
|
||||
- Admin password stored as bcrypt hash
|
||||
- Session ID regenerated on login
|
||||
- All dynamic output escaped with `htmlspecialchars()`
|
||||
- Nginx rewrite rules validated against config injection
|
||||
- Onion private keys encrypted at rest with libsodium
|
||||
- SFTP passwords encrypted in session with 1-hour expiry
|
||||
- Admin login rate-limited with exponential backoff
|
||||
- Content Security Policy with `script-src 'none'`
|
||||
- No JavaScript on any page
|
||||
- Generic login error messages to prevent username enumeration
|
||||
- FileManager path traversal protection
|
||||
|
||||
TODO: Multi-Server / Clustering:
|
||||
--------------------------
|
||||
|
||||
- [ ] Database replication (MariaDB primary-replica)
|
||||
- [ ] Shared storage for /home across nodes (GlusterFS/CephFS)
|
||||
- [ ] Load balancer for Tor-facing nodes
|
||||
- [ ] Centralized config (shared database or etcd)
|
||||
- [ ] Cross-node instance assignment based on server load
|
||||
- [ ] Distributed autoscale across servers
|
||||
- [ ] Redis-based PHP session sharing
|
||||
- [ ] Mail routing to correct node per account
|
||||
- [ ] Health monitoring across nodes
|
||||
- [ ] Rolling updates with traffic draining
|
||||
- [ ] Onion key migration tool between servers
|
||||
- [ ] Shared ClamAV/Rspamd on dedicated nodes
|
||||
- [ ] Coordinated backup orchestration
|
||||
@@ -0,0 +1,6 @@
|
||||
[Unit]
|
||||
Description=Auto-scale Tor hosting instances based on account count
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/usr/bin/php8.5 /var/www/autoscale.php
|
||||
@@ -0,0 +1,9 @@
|
||||
[Unit]
|
||||
Description=Check and auto-scale hosting instances every hour
|
||||
|
||||
[Timer]
|
||||
OnCalendar=hourly
|
||||
Persistent=true
|
||||
|
||||
[Install]
|
||||
WantedBy=timers.target
|
||||
Executable
+561
@@ -0,0 +1,561 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
# Tor Hosting - Automated Installer for Debian 13 (Trixie) / Ubuntu 24.04 LTS
|
||||
# https://github.com/DanWin/hosting
|
||||
#
|
||||
# One-liner install:
|
||||
# curl -sSL https://raw.githubusercontent.com/DanWin/hosting/master/install.sh | bash
|
||||
# Or with options:
|
||||
# curl -sSL https://raw.githubusercontent.com/DanWin/hosting/master/install.sh | bash -s -- --non-interactive
|
||||
|
||||
REPO_URL="https://github.com/DanWin/hosting.git"
|
||||
REPO_BRANCH="master"
|
||||
ORIGINAL_ARGS=("$@")
|
||||
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
CYAN='\033[0;36m'
|
||||
BOLD='\033[1m'
|
||||
NC='\033[0m'
|
||||
# Restore state from env vars (set when re-exec'd after auto-clone)
|
||||
NONINTERACTIVE=${HOSTING_NONINTERACTIVE:-false}
|
||||
SKIP_BINARIES=${HOSTING_SKIP_BINARIES:-false}
|
||||
VANITY_PREFIX="${HOSTING_VANITY_PREFIX:-}"
|
||||
VANITY_THREADS="${HOSTING_VANITY_THREADS:-}"
|
||||
DB_HOSTING_PASS="${HOSTING_DB_PASS:-}"
|
||||
DB_PMA_PASS="${HOSTING_PMA_PASS:-}"
|
||||
ADMIN_PASS="${HOSTING_ADMIN_PASS:-}"
|
||||
BLOWFISH_SECRET=""
|
||||
ONION_ENC_KEY=""
|
||||
log_info() { echo -e "${CYAN}[INFO]${NC} $1"; }
|
||||
log_ok() { echo -e "${GREEN}[OK]${NC} $1"; }
|
||||
log_warn() { echo -e "${YELLOW}[WARN]${NC} $1"; }
|
||||
log_error() { echo -e "${RED}[ERROR]${NC} $1"; }
|
||||
log_step() { echo -e "\n${BOLD}${CYAN}=== $1 ===${NC}\n"; }
|
||||
|
||||
gen_pass() { openssl rand -hex 16; }
|
||||
|
||||
usage() {
|
||||
cat <<'EOF'
|
||||
Usage: ./install.sh [OPTIONS]
|
||||
|
||||
Options:
|
||||
--non-interactive Skip all prompts, generate random passwords
|
||||
--skip-binaries Skip compiling PHP/ImageMagick (use if already built)
|
||||
--vanity <prefix> Generate a vanity .onion address with this prefix
|
||||
--vanity-threads <n> Number of threads for vanity generation (default: nproc)
|
||||
--db-pass <pass> Set hosting MySQL password
|
||||
--pma-pass <pass> Set phpMyAdmin MySQL password
|
||||
--admin-pass <pass> Set admin panel password
|
||||
-h, --help Show this help
|
||||
|
||||
Examples:
|
||||
./install.sh # Interactive install
|
||||
./install.sh --non-interactive # Fully automated with random passwords
|
||||
./install.sh --vanity mysite # Generate vanity onion starting with "mysite"
|
||||
EOF
|
||||
exit 0
|
||||
}
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
--non-interactive) NONINTERACTIVE=true; shift ;;
|
||||
--skip-binaries) SKIP_BINARIES=true; shift ;;
|
||||
--vanity) VANITY_PREFIX="$2"; shift 2 ;;
|
||||
--vanity-threads) VANITY_THREADS="$2"; shift 2 ;;
|
||||
--db-pass) DB_HOSTING_PASS="$2"; shift 2 ;;
|
||||
--pma-pass) DB_PMA_PASS="$2"; shift 2 ;;
|
||||
--admin-pass) ADMIN_PASS="$2"; shift 2 ;;
|
||||
-h|--help) usage ;;
|
||||
*) log_error "Unknown option: $1"; usage ;;
|
||||
esac
|
||||
done
|
||||
log_step "Pre-flight checks"
|
||||
|
||||
if [ "$(id -u)" -ne 0 ]; then
|
||||
log_error "This script must be run as root"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -f /etc/os-release ]; then
|
||||
. /etc/os-release
|
||||
fi
|
||||
|
||||
if [ -f /etc/debian_version ]; then
|
||||
DEBIAN_FULL=$(cat /etc/debian_version)
|
||||
DEBIAN_VERSION=$(echo "$DEBIAN_FULL" | cut -d. -f1)
|
||||
# Ubuntu 24.04 reports "trixie/sid", treat as compatible
|
||||
if echo "$DEBIAN_FULL" | grep -q "trixie"; then
|
||||
DEBIAN_VERSION=13
|
||||
fi
|
||||
if [ "$DEBIAN_VERSION" -ge 13 ] 2>/dev/null; then
|
||||
: # ok
|
||||
else
|
||||
log_error "Debian 13+ or Ubuntu 24.04+ required. You have: $DEBIAN_FULL"
|
||||
exit 1
|
||||
fi
|
||||
elif [ "$ID" = "ubuntu" ]; then
|
||||
UBUNTU_MAJOR=$(echo "$VERSION_ID" | cut -d. -f1)
|
||||
if [ "$UBUNTU_MAJOR" -lt 24 ]; then
|
||||
log_error "Ubuntu 24.04+ required. You have: $VERSION_ID"
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
log_error "This script requires Debian 13+ or Ubuntu 24.04+"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
log_ok "Running as root on ${PRETTY_NAME:-Debian $DEBIAN_FULL}"
|
||||
|
||||
# Auto-clone repo if not running from within it
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" && pwd)"
|
||||
if [ ! -f "$SCRIPT_DIR/install_binaries.sh" ]; then
|
||||
log_info "Repository not found locally. Cloning..."
|
||||
apt update -qq
|
||||
apt install -y -qq git 2>/dev/null
|
||||
SCRIPT_DIR="/root/hosting"
|
||||
if [ -d "$SCRIPT_DIR" ]; then
|
||||
cd "$SCRIPT_DIR" && git pull origin "$REPO_BRANCH" 2>/dev/null || true
|
||||
else
|
||||
git clone -b "$REPO_BRANCH" "$REPO_URL" "$SCRIPT_DIR"
|
||||
fi
|
||||
log_ok "Repository cloned to $SCRIPT_DIR"
|
||||
# Re-exec from the cloned copy, passing state via env vars
|
||||
export HOSTING_NONINTERACTIVE="$NONINTERACTIVE"
|
||||
export HOSTING_SKIP_BINARIES="$SKIP_BINARIES"
|
||||
export HOSTING_VANITY_PREFIX="$VANITY_PREFIX"
|
||||
export HOSTING_VANITY_THREADS="$VANITY_THREADS"
|
||||
export HOSTING_DB_PASS="$DB_HOSTING_PASS"
|
||||
export HOSTING_PMA_PASS="$DB_PMA_PASS"
|
||||
export HOSTING_ADMIN_PASS="$ADMIN_PASS"
|
||||
exec "$SCRIPT_DIR/install.sh" "${ORIGINAL_ARGS[@]}"
|
||||
fi
|
||||
|
||||
log_ok "Repository found at $SCRIPT_DIR"
|
||||
|
||||
# Interactive prompts (skipped with --non-interactive)
|
||||
|
||||
if [ "$NONINTERACTIVE" = false ]; then
|
||||
log_step "Configuration"
|
||||
|
||||
# --- Passwords ---
|
||||
echo -e "${BOLD}Password Configuration${NC}"
|
||||
echo "You can enter custom passwords or let the installer generate secure random ones."
|
||||
echo ""
|
||||
|
||||
if [ -z "$DB_HOSTING_PASS" ]; then
|
||||
read -p "Hosting MySQL password [leave empty to generate]: " DB_HOSTING_PASS
|
||||
fi
|
||||
if [ -z "$DB_PMA_PASS" ]; then
|
||||
read -p "phpMyAdmin MySQL password [leave empty to generate]: " DB_PMA_PASS
|
||||
fi
|
||||
if [ -z "$ADMIN_PASS" ]; then
|
||||
read -p "Admin panel password [leave empty to generate]: " ADMIN_PASS
|
||||
fi
|
||||
|
||||
# --- Vanity onion ---
|
||||
echo ""
|
||||
echo -e "${BOLD}Onion Address Configuration${NC}"
|
||||
echo "You can generate a vanity .onion address with a custom prefix."
|
||||
echo "Only characters a-z and 2-7 are valid (base32)."
|
||||
echo ""
|
||||
echo "Estimated generation times:"
|
||||
echo " 3 chars ~seconds"
|
||||
echo " 4 chars ~minutes"
|
||||
echo " 5 chars ~10-30 minutes"
|
||||
echo " 6 chars ~hours"
|
||||
echo " 7+ chars ~days (not recommended)"
|
||||
echo ""
|
||||
|
||||
if [ -z "$VANITY_PREFIX" ]; then
|
||||
read -p "Vanity onion prefix [leave empty for random]: " VANITY_PREFIX
|
||||
fi
|
||||
|
||||
if [ -n "$VANITY_PREFIX" ]; then
|
||||
# Validate base32
|
||||
if ! echo "$VANITY_PREFIX" | grep -qP '^[a-z2-7]+$'; then
|
||||
log_error "Invalid prefix. Only lowercase a-z and digits 2-7 are allowed."
|
||||
exit 1
|
||||
fi
|
||||
PREFIX_LEN=${#VANITY_PREFIX}
|
||||
if [ "$PREFIX_LEN" -gt 7 ]; then
|
||||
log_warn "Prefix '$VANITY_PREFIX' is $PREFIX_LEN characters. This could take days or weeks."
|
||||
read -p "Continue anyway? [y/N]: " CONFIRM
|
||||
if [ "$CONFIRM" != "y" ] && [ "$CONFIRM" != "Y" ]; then
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
[ -z "$DB_HOSTING_PASS" ] && DB_HOSTING_PASS=$(gen_pass)
|
||||
[ -z "$DB_PMA_PASS" ] && DB_PMA_PASS=$(gen_pass)
|
||||
[ -z "$ADMIN_PASS" ] && ADMIN_PASS=$(gen_pass)
|
||||
[ -z "$BLOWFISH_SECRET" ] && BLOWFISH_SECRET=$(gen_pass)
|
||||
[ -z "$ONION_ENC_KEY" ] && ONION_ENC_KEY=$(openssl rand -hex 32)
|
||||
|
||||
echo ""
|
||||
log_info "Installation will proceed with the following:"
|
||||
echo " Hosting DB password: $DB_HOSTING_PASS"
|
||||
echo " phpMyAdmin DB password: $DB_PMA_PASS"
|
||||
echo " Admin panel password: $ADMIN_PASS"
|
||||
echo " Vanity prefix: ${VANITY_PREFIX:-<random>}"
|
||||
echo ""
|
||||
|
||||
if [ "$NONINTERACTIVE" = false ]; then
|
||||
read -p "Proceed with installation? [Y/n]: " CONFIRM
|
||||
if [ "$CONFIRM" = "n" ] || [ "$CONFIRM" = "N" ]; then
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
CREDS_FILE="/root/hosting-credentials.txt"
|
||||
cat > "$CREDS_FILE" <<EOF
|
||||
=== Daniel's Hosting Credentials ===
|
||||
Generated: $(date)
|
||||
|
||||
Hosting MySQL User: hosting
|
||||
Hosting MySQL Password: $DB_HOSTING_PASS
|
||||
|
||||
phpMyAdmin MySQL User: phpmyadmin
|
||||
phpMyAdmin MySQL Password: $DB_PMA_PASS
|
||||
|
||||
Admin Panel Password: $ADMIN_PASS
|
||||
|
||||
Blowfish Secret: $BLOWFISH_SECRET
|
||||
Onion Key Encryption Key: $ONION_ENC_KEY
|
||||
EOF
|
||||
chmod 600 "$CREDS_FILE"
|
||||
log_ok "Credentials saved to $CREDS_FILE"
|
||||
log_step "Step 1: Purge conflicting packages"
|
||||
|
||||
DEBIAN_FRONTEND=noninteractive apt purge -y apache2* dnsmasq* eatmydata exim4* \
|
||||
imagemagick-6-common mysql-client* mysql-server* nginx* libnginx-mod* \
|
||||
php7* resolvconf 2>/dev/null || true
|
||||
|
||||
systemctl disable systemd-resolved.service 2>/dev/null || true
|
||||
systemctl stop systemd-resolved.service 2>/dev/null || true
|
||||
|
||||
echo "nameserver 1.1.1.1" > /etc/resolv.conf
|
||||
log_ok "DNS set to 1.1.1.1"
|
||||
log_step "Step 2: Add repositories"
|
||||
|
||||
apt update -qq
|
||||
apt install -y -qq git apt-transport-tor curl lsb-release
|
||||
|
||||
CODENAME=$(lsb_release -cs)
|
||||
IS_UBUNTU=false
|
||||
[ "${ID:-}" = "ubuntu" ] && IS_UBUNTU=true
|
||||
|
||||
curl -sSL https://deb.torproject.org/torproject.org/A3C4F0F979CAA22CDBA8F512EE8CBC9E886DDD89.asc \
|
||||
> /etc/apt/trusted.gpg.d/torproject.asc
|
||||
grep -q "torproject.org" /etc/apt/sources.list || \
|
||||
echo "deb tor://apow7mjfryruh65chtdydfmqfpj5btws7nbocgtaovhvezgccyjazpqd.onion/torproject.org/ $CODENAME main" >> /etc/apt/sources.list
|
||||
|
||||
# Sury nginx repo only needed on Debian (Ubuntu has nginx + brotli natively)
|
||||
if [ "$IS_UBUNTU" = false ]; then
|
||||
curl -sSL https://packages.sury.org/nginx/apt.gpg \
|
||||
> /etc/apt/trusted.gpg.d/sury.gpg
|
||||
grep -q "sury.org" /etc/apt/sources.list || \
|
||||
echo "deb https://packages.sury.org/nginx/ $CODENAME main" >> /etc/apt/sources.list
|
||||
fi
|
||||
|
||||
# Prevent Ubuntu from auto-rebooting during upgrade
|
||||
if [ "$IS_UBUNTU" = true ]; then
|
||||
systemctl mask needrestart.service 2>/dev/null || true
|
||||
export NEEDRESTART_SUSPEND=1
|
||||
export NEEDRESTART_MODE=l
|
||||
fi
|
||||
|
||||
apt update -qq
|
||||
DEBIAN_FRONTEND=noninteractive apt upgrade -y
|
||||
|
||||
if [ "$IS_UBUNTU" = true ]; then
|
||||
systemctl unmask needrestart.service 2>/dev/null || true
|
||||
fi
|
||||
log_ok "Repositories configured"
|
||||
if [ "$SKIP_BINARIES" = true ]; then
|
||||
log_step "Step 3: Skipping binary compilation (--skip-binaries)"
|
||||
else
|
||||
log_step "Step 3: Building binaries (this will take a while)"
|
||||
log_info "Compiling ImageMagick, PHP 8.5, 8.4, 8.3, 8.2, and web applications..."
|
||||
|
||||
cd "$SCRIPT_DIR"
|
||||
bash ./install_binaries.sh 2>&1 | tee /root/install_binaries.log
|
||||
|
||||
if [ ${PIPESTATUS[0]} -ne 0 ]; then
|
||||
log_error "install_binaries.sh failed. Check /root/install_binaries.log"
|
||||
exit 1
|
||||
fi
|
||||
log_ok "All binaries compiled and installed"
|
||||
fi
|
||||
if [ -n "$VANITY_PREFIX" ]; then
|
||||
log_step "Step 4: Generating vanity .onion address (prefix: $VANITY_PREFIX)"
|
||||
|
||||
if [ ! -d /tmp/mkp224o ]; then
|
||||
cd /tmp
|
||||
apt install -y -qq libsodium-dev autoconf make gcc
|
||||
git clone https://github.com/cathugger/mkp224o.git mkp224o
|
||||
cd mkp224o
|
||||
./autogen.sh
|
||||
./configure --enable-donna64
|
||||
make -j$(nproc)
|
||||
fi
|
||||
|
||||
VANITY_THREADS=${VANITY_THREADS:-$(nproc)}
|
||||
VANITY_OUT="/tmp/vanity-onion"
|
||||
mkdir -p "$VANITY_OUT"
|
||||
|
||||
log_info "Searching for prefix '$VANITY_PREFIX' with $VANITY_THREADS threads..."
|
||||
log_info "This may take a while depending on prefix length."
|
||||
|
||||
/tmp/mkp224o/mkp224o -t "$VANITY_THREADS" -n 1 -s -d "$VANITY_OUT" "$VANITY_PREFIX"
|
||||
|
||||
VANITY_DIR=$(ls -d "$VANITY_OUT"/*.onion 2>/dev/null | head -1)
|
||||
if [ -z "$VANITY_DIR" ]; then
|
||||
log_error "Vanity generation failed — no match found"
|
||||
VANITY_PREFIX=""
|
||||
else
|
||||
VANITY_HOSTNAME=$(cat "$VANITY_DIR/hostname" | tr -d '[:space:]')
|
||||
VANITY_SECRET=$(cat "$VANITY_DIR/hs_ed25519_secret_key" | base64 -w0)
|
||||
log_ok "Generated vanity address: ${GREEN}${VANITY_HOSTNAME}${NC}"
|
||||
fi
|
||||
else
|
||||
log_step "Step 4: Skipping vanity generation (random onion)"
|
||||
fi
|
||||
log_step "Step 5: Copy site and config files"
|
||||
|
||||
cp -a "$SCRIPT_DIR/var/www/"* /var/www/
|
||||
cp -a "$SCRIPT_DIR/etc/"* /etc/
|
||||
chown root:bind /etc/bind/ -R 2>/dev/null || true
|
||||
# Remove Ubuntu module-enabled symlinks that conflict with our nginx.conf
|
||||
rm -f /etc/nginx/modules-enabled/mod-http-brotli-*.conf /etc/nginx/modules-enabled/mod-stream.conf 2>/dev/null || true
|
||||
|
||||
log_ok "Files copied"
|
||||
log_step "Step 6: Create PHP-FPM systemd service files"
|
||||
|
||||
# 8.2 service files should exist from install_binaries.sh packages
|
||||
for ver in 8.3 8.4 8.5; do
|
||||
for tmpl in /etc/systemd/system/php8.2-fpm*.service; do
|
||||
[ -f "$tmpl" ] || continue
|
||||
newfile=$(echo "$tmpl" | sed "s/8.2/$ver/g")
|
||||
[ -f "$newfile" ] || sed "s/8.2/$ver/g" "$tmpl" > "$newfile"
|
||||
done
|
||||
done
|
||||
|
||||
systemctl daemon-reload
|
||||
log_ok "PHP-FPM service files created for 8.2, 8.3, 8.4, 8.5"
|
||||
log_step "Step 7: Configure Tor"
|
||||
|
||||
systemctl restart bind9.service 2>/dev/null || systemctl restart named.service 2>/dev/null || true
|
||||
systemctl restart tor@default.service
|
||||
sleep 3
|
||||
|
||||
ONION_ADDR=$(cat /var/lib/tor/hidden_service/hostname 2>/dev/null || echo "")
|
||||
if [ -z "$ONION_ADDR" ]; then
|
||||
log_error "Tor hidden service hostname not found. Waiting..."
|
||||
sleep 10
|
||||
ONION_ADDR=$(cat /var/lib/tor/hidden_service/hostname 2>/dev/null || echo "")
|
||||
fi
|
||||
|
||||
if [ -z "$ONION_ADDR" ]; then
|
||||
log_error "Could not get .onion address. Check tor configuration."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
log_ok "Onion address: ${GREEN}${ONION_ADDR}${NC}"
|
||||
log_step "Step 8: Configure hosting"
|
||||
|
||||
ADMIN_HASH=$(php8.2 -r "echo password_hash('$ADMIN_PASS', PASSWORD_DEFAULT);" 2>/dev/null || \
|
||||
php8.5 -r "echo password_hash('$ADMIN_PASS', PASSWORD_DEFAULT);")
|
||||
sed -i "s|const DBPASS='MY_PASSWORD'|const DBPASS='$DB_HOSTING_PASS'|" /var/www/common.php
|
||||
sed -i "s|const ADMIN_PASSWORD='MY_PASSWORD'|const ADMIN_PASSWORD='$ADMIN_HASH'|" /var/www/common.php
|
||||
sed -i "s|const ONION_KEY_ENCRYPTION_KEY=''|const ONION_KEY_ENCRYPTION_KEY='$ONION_ENC_KEY'|" /var/www/common.php
|
||||
sed -i "s|password = MY_PASSWORD|password = $DB_HOSTING_PASS|" /etc/postfix/sql/alias.cf
|
||||
sed -i "s|hosts = localhost|hosts = 127.0.0.1|" /etc/postfix/sql/alias.cf
|
||||
|
||||
# Replace default onion domain everywhere
|
||||
DEFAULT_ONION="dhosting4xxoydyaivckq7tsmtgi4wfs3flpeyitekkmqwu4v4r46syd.onion"
|
||||
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"
|
||||
|
||||
# Dovecot 2.4 in trixie has different config syntax
|
||||
# Comment out old conf.d include if it causes issues
|
||||
if ! doveconf 2>&1 | grep -q "^# OS:"; then
|
||||
log_warn "Dovecot config has errors, applying Debian 13 fix..."
|
||||
sed -i 's|^!include conf.d|#!include conf.d|' /etc/dovecot/dovecot.conf
|
||||
cat > /etc/dovecot/local.conf <<'DOVECOT'
|
||||
mail_driver = maildir
|
||||
mail_path = ~/Maildir
|
||||
protocols = imap pop3 lmtp
|
||||
listen = 127.0.0.1
|
||||
ssl = no
|
||||
auth_mechanisms = plain login
|
||||
passdb pam {
|
||||
driver = pam
|
||||
}
|
||||
userdb passwd {
|
||||
driver = passwd
|
||||
}
|
||||
service lmtp {
|
||||
unix_listener /var/spool/postfix/private/dovecot-lmtp {
|
||||
mode = 0600
|
||||
user = postfix
|
||||
group = postfix
|
||||
}
|
||||
}
|
||||
service auth {
|
||||
unix_listener /var/spool/postfix/private/auth {
|
||||
mode = 0660
|
||||
user = postfix
|
||||
group = postfix
|
||||
}
|
||||
}
|
||||
DOVECOT
|
||||
fi
|
||||
|
||||
systemctl restart dovecot
|
||||
log_ok "Dovecot configured"
|
||||
log_step "Step 10: Configure Postfix"
|
||||
|
||||
postalias /etc/aliases
|
||||
postmap /etc/postfix/canonical /etc/postfix/sender_login_maps /etc/postfix/transport
|
||||
|
||||
log_ok "Postfix maps created"
|
||||
log_step "Step 11: Configure fstab and quota"
|
||||
|
||||
grep -q "tmpfs /tmp" /etc/fstab || \
|
||||
echo "tmpfs /tmp tmpfs defaults,noatime 0 0" >> /etc/fstab
|
||||
grep -q "tmpfs /var/log/nginx" /etc/fstab || \
|
||||
echo "tmpfs /var/log/nginx tmpfs rw,user,noatime 0 0" >> /etc/fstab
|
||||
grep -q "hidepid" /etc/fstab || \
|
||||
echo "proc /proc proc defaults,hidepid=2 0 0" >> /etc/fstab
|
||||
|
||||
# Add quota options to root or /home mount
|
||||
if grep -q "/home" /etc/fstab && ! grep -q "usrjquota" /etc/fstab; then
|
||||
sed -i '/\/home/s/defaults/defaults,noatime,usrjquota=aquota.user,jqfmt=vfsv1/' /etc/fstab
|
||||
elif ! grep -q "usrjquota" /etc/fstab; then
|
||||
sed -i '/errors=remount-ro/s/errors=remount-ro/errors=remount-ro,noatime,usrjquota=aquota.user,jqfmt=vfsv1/' /etc/fstab
|
||||
fi
|
||||
|
||||
systemctl daemon-reload
|
||||
QUOTA_TARGET=$(findmnt -n -o TARGET --target /home 2>/dev/null || echo "/")
|
||||
mount -o remount "$QUOTA_TARGET" 2>/dev/null || true
|
||||
quotacheck -cMu "$QUOTA_TARGET" 2>/dev/null || true
|
||||
quotaon "$QUOTA_TARGET" 2>/dev/null || true
|
||||
|
||||
log_ok "Filesystem configured"
|
||||
log_step "Step 12: Install Composer dependencies"
|
||||
|
||||
echo "nameserver 1.1.1.1" > /etc/resolv.conf
|
||||
cd /var/www
|
||||
COMPOSER_ALLOW_SUPERUSER=1 composer install 2>&1 | tail -3
|
||||
|
||||
if [ ! -f /var/www/vendor/autoload.php ]; then
|
||||
log_warn "Composer install failed, retrying..."
|
||||
sleep 5
|
||||
COMPOSER_ALLOW_SUPERUSER=1 composer install 2>&1 | tail -3
|
||||
fi
|
||||
|
||||
if [ ! -f /var/www/vendor/autoload.php ]; then
|
||||
log_error "Composer install failed. Check DNS/network."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
log_ok "Composer dependencies installed"
|
||||
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
|
||||
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
|
||||
|
||||
log_ok "MySQL users and databases created"
|
||||
log_step "Step 14: Run setup.php"
|
||||
|
||||
php8.2 /var/www/setup.php 2>&1 || true
|
||||
mkdir -p /var/log/nginx /var/run/nginx
|
||||
for ver in 8.2 8.3 8.4 8.5; do
|
||||
systemctl enable "php$ver-fpm@default" 2>/dev/null || true
|
||||
systemctl start "php$ver-fpm@default" 2>/dev/null || true
|
||||
done
|
||||
systemctl restart nginx 2>/dev/null || true
|
||||
|
||||
log_ok "Setup complete"
|
||||
if [ -n "$VANITY_PREFIX" ] && [ -n "$VANITY_SECRET" ]; then
|
||||
log_step "Step 15: Import vanity onion address"
|
||||
|
||||
# Replace the auto-generated hidden service with our vanity one
|
||||
rm -rf /var/lib/tor/hidden_service/*
|
||||
cp "$VANITY_DIR/hostname" /var/lib/tor/hidden_service/hostname
|
||||
cp "$VANITY_DIR/hs_ed25519_secret_key" /var/lib/tor/hidden_service/hs_ed25519_secret_key
|
||||
cp "$VANITY_DIR/hs_ed25519_public_key" /var/lib/tor/hidden_service/hs_ed25519_public_key
|
||||
chown -R debian-tor:debian-tor /var/lib/tor/hidden_service/
|
||||
chmod 700 /var/lib/tor/hidden_service/
|
||||
chmod 600 /var/lib/tor/hidden_service/*
|
||||
|
||||
# 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" $ONION_CONFIG_FILES
|
||||
|
||||
# Rebuild postfix maps with new address
|
||||
postmap /etc/postfix/canonical /etc/postfix/sender_login_maps /etc/postfix/transport
|
||||
|
||||
ONION_ADDR="$NEW_ONION"
|
||||
systemctl restart tor@default.service
|
||||
|
||||
# Update credentials file
|
||||
echo "" >> "$CREDS_FILE"
|
||||
echo "Vanity Onion: $ONION_ADDR" >> "$CREDS_FILE"
|
||||
|
||||
log_ok "Vanity address imported: ${GREEN}${ONION_ADDR}${NC}"
|
||||
|
||||
# Cleanup
|
||||
rm -rf /tmp/vanity-onion /tmp/mkp224o
|
||||
else
|
||||
log_step "Step 15: Skipping vanity import"
|
||||
fi
|
||||
log_step "Step 16: Final configuration"
|
||||
|
||||
systemctl enable hosting-del.timer hosting.timer hosting-autoscale.timer
|
||||
systemctl start hosting-autoscale.timer
|
||||
sed -i 's/^Subsystem/#Subsystem/' /etc/ssh/sshd_config
|
||||
systemctl restart nginx postfix dovecot
|
||||
systemctl restart tor@default.service
|
||||
|
||||
log_ok "Timers enabled, services configured"
|
||||
log_step "Installation Complete"
|
||||
|
||||
echo -e "${BOLD}Onion Address:${NC} ${GREEN}http://${ONION_ADDR}${NC}"
|
||||
echo ""
|
||||
echo -e "${BOLD}Credentials:${NC}"
|
||||
echo " Hosting DB password: $DB_HOSTING_PASS"
|
||||
echo " phpMyAdmin DB password: $DB_PMA_PASS"
|
||||
echo " Admin panel password: $ADMIN_PASS"
|
||||
echo ""
|
||||
echo -e "${BOLD}Credentials saved to:${NC} $CREDS_FILE"
|
||||
echo ""
|
||||
echo -e "${BOLD}PHP Versions:${NC} 8.2, 8.3, 8.4, 8.5 (default: 8.5)"
|
||||
echo -e "${BOLD}Instances:${NC} auto-scaling (1 per ~250 accounts, checked hourly)"
|
||||
echo ""
|
||||
echo -e "${YELLOW}Recommended: Reboot the server now and wait ~5 minutes for all services to start.${NC}"
|
||||
echo ""
|
||||
|
||||
if [ "$NONINTERACTIVE" = false ]; then
|
||||
read -p "Reboot now? [Y/n]: " REBOOT
|
||||
if [ "$REBOOT" != "n" ] && [ "$REBOOT" != "N" ]; then
|
||||
log_info "Rebooting..."
|
||||
reboot
|
||||
fi
|
||||
else
|
||||
log_info "Non-interactive mode: skipping reboot. Run 'reboot' when ready."
|
||||
fi
|
||||
+39
-14
@@ -6,9 +6,28 @@ export LANG=C.UTF-8
|
||||
export PATH="/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin"
|
||||
# install all required packages
|
||||
DEBIAN_FRONTEND=noninteractive apt-get update
|
||||
DEBIAN_FRONTEND=noninteractive apt-get --no-install-recommends install -y apt-transport-tor bash-completion bind9 brotli bzip2 ca-certificates clamav-daemon clamav-freshclam curl dovecot-imapd dovecot-lmtpd dovecot-pop3d git hardlink haveged iptables jailkit libio-socket-ip-perl libnginx-mod-http-brotli libnginx-mod-stream libsasl2-modules locales locales-all logrotate lsb-release mariadb-server nano nginx postfix postfix-mysql quota quotatool redis rspamd rsync ssh tor unzip util-linux vim wget xz-utils zip zopfli
|
||||
DEBIAN_FRONTEND=noninteractive apt-get --no-install-recommends install -y apt-transport-tor bash-completion bind9 brotli bzip2 ca-certificates clamav-daemon clamav-freshclam curl dovecot-imapd dovecot-lmtpd dovecot-pop3d git hardlink haveged iptables jailkit libio-socket-ip-perl libnginx-mod-http-brotli-filter libnginx-mod-http-brotli-static libnginx-mod-stream libsasl2-modules locales locales-all logrotate lsb-release mariadb-server nano nginx postfix postfix-mysql quota quotatool redis rspamd rsync ssh tor unzip util-linux vim wget xz-utils zip zopfli
|
||||
# build dependencies
|
||||
DEBIAN_FRONTEND=noninteractive apt-get --no-install-recommends install -y autoconf automake bison g++ gcc ghostscript gnupg libaom-dev $(apt-cache search --names-only 'libargon2(-0)?-dev' | awk '{print $1;}' | head -n1) binutils-dev libbrotli-dev libbz2-dev libc-client2007e-dev libcurl4-openssl-dev libdjvulibre-dev libedit-dev $(apt-cache search --names-only 'libenchant(-2)?-dev' | awk '{print $1;}' | head -n1) libffi-dev $(apt-cache search --names-only libfreetype6?-dev | awk '{print $1;}' | head -n1) libfftw3-dev libfribidi-dev libgd-dev libgmp-dev libgpg-error-dev libgpgme-dev libgraphviz-dev libgs-dev libharfbuzz-dev libheif-dev libjbig-dev libjbig2dec0-dev libjxl-dev libkrb5-dev libldap2-dev liblmdb-dev liblqr-1-0-dev libmariadb-dev libonig-dev libopenexr-dev libopenjp2-7-dev libpango1.0-dev libpng-dev libpspell-dev libqdbm-dev libraqm-dev libraw-dev libreadline-dev librsvg2-dev libsasl2-dev libsodium-dev libssh2-1-dev libssl-dev libsqlite3-dev libsystemd-dev libtidy-dev libtool libwebp-dev libwmf-dev libxml2-dev libxpm-dev libxslt1-dev libzip-dev libzstd-dev make poppler-utils re2c zlib1g-dev
|
||||
DEBIAN_FRONTEND=noninteractive apt-get --no-install-recommends install -y autoconf automake bison g++ gcc ghostscript libpam0g-dev gnupg libaom-dev $(apt-cache search --names-only 'libargon2(-0)?-dev' | awk '{print $1;}' | head -n1) binutils-dev libbrotli-dev libbz2-dev libcurl4-openssl-dev libdjvulibre-dev libedit-dev $(apt-cache search --names-only 'libenchant(-2)?-dev' | awk '{print $1;}' | head -n1) libffi-dev $(apt-cache search --names-only libfreetype6?-dev | awk '{print $1;}' | head -n1) libfftw3-dev libfribidi-dev libgd-dev libgmp-dev libgpg-error-dev libgpgme-dev libgraphviz-dev libgs-dev libharfbuzz-dev libheif-dev libjbig-dev libjbig2dec0-dev libjxl-dev libkrb5-dev libldap2-dev liblmdb-dev liblqr-1-0-dev libmariadb-dev libonig-dev libopenexr-dev libopenjp2-7-dev libpango1.0-dev libpng-dev libpspell-dev libqdbm-dev libraqm-dev libraw-dev libreadline-dev librsvg2-dev libsasl2-dev libsodium-dev libssh2-1-dev libssl-dev libsqlite3-dev libsystemd-dev libtidy-dev libtool libwebp-dev libwmf-dev libxml2-dev libxpm-dev libxslt1-dev libzip-dev libzstd-dev make poppler-utils re2c zlib1g-dev
|
||||
|
||||
# build uw-imap c-client from source (removed from trixie, needed for PHP --with-imap / SquirrelMail)
|
||||
if [ ! -e /usr/local/lib/libc-client.a ]; then
|
||||
cd /tmp
|
||||
curl -sSL https://deb.debian.org/debian/pool/main/u/uw-imap/uw-imap_2007f~dfsg.orig.tar.gz | tar xz
|
||||
curl -sSL https://deb.debian.org/debian/pool/main/u/uw-imap/uw-imap_2007f~dfsg-7.debian.tar.xz | tar xJ -C imap-2007f~dfsg
|
||||
cd imap-2007f~dfsg
|
||||
for p in debian/patches/*.patch; do patch -p1 < "$p" 2>/dev/null; done
|
||||
# fix OpenSSL 3 include paths
|
||||
sed -i 's|#include <ssl.h>|#include <openssl/ssl.h>|; s|#include <err.h>|#include <openssl/err.h>|; s|#include <pem.h>|#include <openssl/pem.h>|; s|#include <buffer.h>|#include <openssl/buffer.h>|; s|#include <bio.h>|#include <openssl/bio.h>|; s|#include <crypto.h>|#include <openssl/crypto.h>|; s|#include <rand.h>|#include <openssl/rand.h>|; s|#include <x509v3.h>|#include <openssl/x509v3.h>|' src/osdep/unix/ssl_unix.c
|
||||
touch ip6
|
||||
echo y | make lnp EXTRACFLAGS="-fPIC -Wno-error=implicit-function-declaration -Wno-error=implicit-int -Wno-error=incompatible-pointer-types" SSLTYPE=unix
|
||||
cp c-client/c-client.a /usr/local/lib/libc-client.a
|
||||
mkdir -p /usr/local/include/c-client
|
||||
cp c-client/*.h /usr/local/include/c-client/
|
||||
ln -sf /usr/local/include/c-client /usr/include/c-client
|
||||
cd "$OLDPWD"
|
||||
rm -rf /tmp/imap-2007f~dfsg
|
||||
fi
|
||||
|
||||
# install nvm
|
||||
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
|
||||
@@ -68,8 +87,8 @@ ln -fs /usr/include/qdbm/depot.h /usr/include/depot.h
|
||||
cd php-src
|
||||
cd ext
|
||||
cd apcu && git fetch --all && git checkout v5.1.24 && cd ..
|
||||
cd php-ext-brotli && git fetch --all && git checkout 0.15.0 && cd ..
|
||||
cd imagick && git fetch --all && git checkout 3.7.0 && cd ..
|
||||
cd php-ext-brotli && git fetch --all && git checkout 0.18.3 && cd ..
|
||||
cd imagick && git fetch --all && git checkout 3.8.1 && cd ..
|
||||
cd php-gnupg && git fetch --all && git checkout master && cd ..
|
||||
cd php-rar && git fetch --all && git reset --hard && git checkout ab26d285759e4c917879967b09976a44829ed570
|
||||
cat <<EOF | git apply -
|
||||
@@ -170,32 +189,38 @@ index 5e680f6..cb5bdaa 100644
|
||||
EOF
|
||||
|
||||
cd ..
|
||||
cd igbinary && git fetch --all && git checkout 3.2.16 && cd ..
|
||||
cd igbinary && git fetch --all && git checkout master && cd ..
|
||||
cd msgpack-php && git fetch --all && git checkout msgpack-2.2.0 && cd ..
|
||||
rm -rf ssh2-*
|
||||
curl -sSf https://pecl.php.net/get/ssh2 | tar xzvf - --exclude package.xml
|
||||
cd ..
|
||||
git fetch --all
|
||||
git fetch --all --tags
|
||||
git checkout php-8.5.4
|
||||
./buildconf -f
|
||||
LIBS='-lgpg-error -lgomp' CXXFLAGS='-O3 -mtune=native -march=native -std=c++17' CFLAGS='-O3 -mtune=native -march=native' ./configure -C --enable-re2c-cgoto --prefix=/usr --with-config-file-scan-dir=/etc/php/8.5/fpm/conf.d --libdir=/usr/lib/php --libexecdir=/usr/lib/php --datadir=/usr/share/php/8.5 --program-suffix=8.5 --sysconfdir=/etc --localstatedir=/var --mandir=/usr/share/man --enable-fpm --enable-cli --disable-cgi --disable-phpdbg --with-fpm-systemd --with-fpm-user=www-data --with-fpm-group=www-data --with-layout=GNU --disable-dtrace --disable-short-tags --without-valgrind --disable-shared --disable-debug --disable-rpath --without-pear --with-openssl --enable-bcmath --with-bz2 --enable-calendar --with-curl --enable-dba --with-qdbm --with-lmdb --enable-exif --enable-ftp --enable-gd --with-external-gd --with-jpeg --with-webp --with-xpm --with-freetype --enable-gd-jis-conv --with-gettext --with-gmp --with-mhash --with-imap --with-imap-ssl --with-kerberos --enable-intl --with-ldap --with-ldap-sasl --enable-mbstring --with-mysqli --with-pdo-mysql --enable-mysqlnd --with-mysql-sock=/run/mysqld/mysqld.sock --with-zlib --with-libedit --with-readline --enable-shmop --enable-soap --enable-sockets --with-sodium --with-password-argon2 --with-tidy --with-xsl --with-enchant --with-pspell --with-zip --with-ffi --enable-apcu --enable-brotli --with-libbrotli --with-imagick --with-ssh2 --with-gnupg --enable-igbinary --with-msgpack --enable-sysvsem --enable-sysvmsg --enable-sysvshm
|
||||
make -j $PROC_LIMIT install
|
||||
make distclean
|
||||
git reset --hard
|
||||
git checkout php-8.4.19
|
||||
./buildconf -f
|
||||
LIBS='-lgpg-error -lgomp' CXXFLAGS='-O3 -mtune=native -march=native -std=c++17' CFLAGS='-O3 -mtune=native -march=native' ./configure -C --enable-re2c-cgoto --prefix=/usr --with-config-file-scan-dir=/etc/php/8.4/fpm/conf.d --libdir=/usr/lib/php --libexecdir=/usr/lib/php --datadir=/usr/share/php/8.4 --program-suffix=8.4 --sysconfdir=/etc --localstatedir=/var --mandir=/usr/share/man --enable-fpm --enable-cli --disable-cgi --disable-phpdbg --with-fpm-systemd --with-fpm-user=www-data --with-fpm-group=www-data --with-layout=GNU --disable-dtrace --disable-short-tags --without-valgrind --disable-shared --disable-debug --disable-rpath --without-pear --with-openssl --enable-bcmath --with-bz2 --enable-calendar --with-curl --enable-dba --with-qdbm --with-lmdb --enable-exif --enable-ftp --enable-gd --with-external-gd --with-jpeg --with-webp --with-xpm --with-freetype --enable-gd-jis-conv --with-gettext --with-gmp --with-mhash --with-imap --with-imap-ssl --with-kerberos --enable-intl --with-ldap --with-ldap-sasl --enable-mbstring --with-mysqli --with-pdo-mysql --enable-mysqlnd --with-mysql-sock=/run/mysqld/mysqld.sock --with-zlib --with-libedit --with-readline --enable-shmop --enable-soap --enable-sockets --with-sodium --with-password-argon2 --with-tidy --with-xsl --with-enchant --with-pspell --with-zip --with-ffi --enable-apcu --enable-brotli --with-libbrotli --with-imagick --with-ssh2 --with-gnupg --enable-igbinary --with-msgpack --enable-sysvsem --enable-sysvmsg --enable-sysvshm
|
||||
make -j $PROC_LIMIT install
|
||||
make distclean
|
||||
git reset --hard
|
||||
git checkout php-8.3.13
|
||||
./buildconf -f
|
||||
LIBS='-lgpg-error' CXXFLAGS='-O3 -mtune=native -march=native' CFLAGS='-O3 -mtune=native -march=native' ./configure -C --enable-re2c-cgoto --prefix=/usr --with-config-file-scan-dir=/etc/php/8.3/fpm/conf.d --libdir=/usr/lib/php --libexecdir=/usr/lib/php --datadir=/usr/share/php/8.3 --program-suffix=8.3 --sysconfdir=/etc --localstatedir=/var --mandir=/usr/share/man --enable-fpm --enable-cli --disable-cgi --disable-phpdbg --with-fpm-systemd --with-fpm-user=www-data --with-fpm-group=www-data --with-layout=GNU --disable-dtrace --disable-short-tags --without-valgrind --disable-shared --disable-debug --disable-rpath --without-pear --with-openssl --enable-bcmath --with-bz2 --enable-calendar --with-curl --enable-dba --with-qdbm --with-lmdb --enable-exif --enable-ftp --enable-gd --with-external-gd --with-jpeg --with-webp --with-xpm --with-freetype --enable-gd-jis-conv --with-gettext --with-gmp --with-mhash --with-imap --with-imap-ssl --with-kerberos --enable-intl --with-ldap --with-ldap-sasl --enable-mbstring --with-mysqli --with-pdo-mysql --enable-mysqlnd --with-mysql-sock=/run/mysqld/mysqld.sock --with-zlib --with-libedit --with-readline --enable-shmop --enable-soap --enable-sockets --with-sodium --with-password-argon2 --with-tidy --with-xsl --with-enchant --with-pspell --with-zip --with-ffi --enable-apcu --enable-brotli --with-libbrotli --with-imagick --with-ssh2 --with-gnupg --enable-rar --enable-igbinary --with-msgpack --enable-sysvsem --enable-sysvmsg --enable-sysvshm
|
||||
LIBS='-lgpg-error -lgomp' CXXFLAGS='-O3 -mtune=native -march=native -std=c++17' CFLAGS='-O3 -mtune=native -march=native' ./configure -C --enable-re2c-cgoto --prefix=/usr --with-config-file-scan-dir=/etc/php/8.3/fpm/conf.d --libdir=/usr/lib/php --libexecdir=/usr/lib/php --datadir=/usr/share/php/8.3 --program-suffix=8.3 --sysconfdir=/etc --localstatedir=/var --mandir=/usr/share/man --enable-fpm --enable-cli --disable-cgi --disable-phpdbg --with-fpm-systemd --with-fpm-user=www-data --with-fpm-group=www-data --with-layout=GNU --disable-dtrace --disable-short-tags --without-valgrind --disable-shared --disable-debug --disable-rpath --without-pear --with-openssl --enable-bcmath --with-bz2 --enable-calendar --with-curl --enable-dba --with-qdbm --with-lmdb --enable-exif --enable-ftp --enable-gd --with-external-gd --with-jpeg --with-webp --with-xpm --with-freetype --enable-gd-jis-conv --with-gettext --with-gmp --with-mhash --with-imap --with-imap-ssl --with-kerberos --enable-intl --with-ldap --with-ldap-sasl --enable-mbstring --with-mysqli --with-pdo-mysql --enable-mysqlnd --with-mysql-sock=/run/mysqld/mysqld.sock --with-zlib --with-libedit --with-readline --enable-shmop --enable-soap --enable-sockets --with-sodium --with-password-argon2 --with-tidy --with-xsl --with-enchant --with-pspell --with-zip --with-ffi --enable-apcu --enable-brotli --with-libbrotli --with-imagick --with-ssh2 --with-gnupg --enable-igbinary --with-msgpack --enable-sysvsem --enable-sysvmsg --enable-sysvshm
|
||||
make -j $PROC_LIMIT install
|
||||
make distclean
|
||||
git reset --hard
|
||||
git checkout php-8.2.25
|
||||
./buildconf -f
|
||||
LIBS='-lgpg-error' CXXFLAGS='-O3 -mtune=native -march=native' CFLAGS='-O3 -mtune=native -march=native' ./configure -C --enable-re2c-cgoto --prefix=/usr --with-config-file-scan-dir=/etc/php/8.2/fpm/conf.d --libdir=/usr/lib/php --libexecdir=/usr/lib/php --datadir=/usr/share/php/8.2 --program-suffix=8.2 --sysconfdir=/etc --localstatedir=/var --mandir=/usr/share/man --enable-fpm --enable-cli --disable-cgi --disable-phpdbg --with-fpm-systemd --with-fpm-user=www-data --with-fpm-group=www-data --with-layout=GNU --disable-dtrace --disable-short-tags --without-valgrind --disable-shared --disable-debug --disable-rpath --without-pear --with-openssl --enable-bcmath --with-bz2 --enable-calendar --with-curl --enable-dba --with-qdbm --with-lmdb --enable-exif --enable-ftp --enable-gd --with-external-gd --with-jpeg --with-webp --with-xpm --with-freetype --enable-gd-jis-conv --with-gettext --with-gmp --with-mhash --with-imap --with-imap-ssl --with-kerberos --enable-intl --with-ldap --with-ldap-sasl --enable-mbstring --with-mysqli --with-pdo-mysql --enable-mysqlnd --with-mysql-sock=/run/mysqld/mysqld.sock --with-zlib --with-libedit --with-readline --enable-shmop --enable-soap --enable-sockets --with-sodium --with-password-argon2 --with-tidy --with-xsl --with-enchant --with-pspell --with-zip --with-ffi --enable-apcu --enable-brotli --with-libbrotli --with-imagick --with-ssh2 --with-gnupg --enable-rar --enable-igbinary --with-msgpack --enable-sysvsem --enable-sysvmsg --enable-sysvshm
|
||||
LIBS='-lgpg-error -lgomp' CXXFLAGS='-O3 -mtune=native -march=native -std=c++17' CFLAGS='-O3 -mtune=native -march=native' ./configure -C --enable-re2c-cgoto --prefix=/usr --with-config-file-scan-dir=/etc/php/8.2/fpm/conf.d --libdir=/usr/lib/php --libexecdir=/usr/lib/php --datadir=/usr/share/php/8.2 --program-suffix=8.2 --sysconfdir=/etc --localstatedir=/var --mandir=/usr/share/man --enable-fpm --enable-cli --disable-cgi --disable-phpdbg --with-fpm-systemd --with-fpm-user=www-data --with-fpm-group=www-data --with-layout=GNU --disable-dtrace --disable-short-tags --without-valgrind --disable-shared --disable-debug --disable-rpath --without-pear --with-openssl --enable-bcmath --with-bz2 --enable-calendar --with-curl --enable-dba --with-qdbm --with-lmdb --enable-exif --enable-ftp --enable-gd --with-external-gd --with-jpeg --with-webp --with-xpm --with-freetype --enable-gd-jis-conv --with-gettext --with-gmp --with-mhash --with-imap --with-imap-ssl --with-kerberos --enable-intl --with-ldap --with-ldap-sasl --enable-mbstring --with-mysqli --with-pdo-mysql --enable-mysqlnd --with-mysql-sock=/run/mysqld/mysqld.sock --with-zlib --with-libedit --with-readline --enable-shmop --enable-soap --enable-sockets --with-sodium --with-password-argon2 --with-tidy --with-xsl --with-enchant --with-pspell --with-zip --with-ffi --enable-apcu --enable-brotli --with-libbrotli --with-imagick --with-ssh2 --with-gnupg --enable-igbinary --with-msgpack --enable-sysvsem --enable-sysvmsg --enable-sysvshm
|
||||
make -j $PROC_LIMIT install
|
||||
make distclean
|
||||
git reset --hard
|
||||
git checkout php-8.1.30
|
||||
./buildconf -f
|
||||
LIBS='-lgpg-error' CXXFLAGS='-O3 -mtune=native -march=native' CFLAGS='-O3 -mtune=native -march=native' ./configure -C --enable-re2c-cgoto --prefix=/usr --with-config-file-scan-dir=/etc/php/8.1/fpm/conf.d --libdir=/usr/lib/php --libexecdir=/usr/lib/php --datadir=/usr/share/php/8.1 --program-suffix=8.1 --sysconfdir=/etc --localstatedir=/var --mandir=/usr/share/man --enable-fpm --enable-cli --disable-cgi --disable-phpdbg --with-fpm-systemd --with-fpm-user=www-data --with-fpm-group=www-data --with-layout=GNU --disable-dtrace --disable-short-tags --without-valgrind --disable-shared --disable-debug --disable-rpath --without-pear --with-openssl --enable-bcmath --with-bz2 --enable-calendar --with-curl --enable-dba --with-qdbm --with-lmdb --enable-exif --enable-ftp --enable-gd --with-external-gd --with-jpeg --with-webp --with-xpm --with-freetype --enable-gd-jis-conv --with-gettext --with-gmp --with-mhash --with-imap --with-imap-ssl --with-kerberos --enable-intl --with-ldap --with-ldap-sasl --enable-mbstring --with-mysqli --with-pdo-mysql --enable-mysqlnd --with-mysql-sock=/run/mysqld/mysqld.sock --with-zlib --with-libedit --with-readline --enable-shmop --enable-soap --enable-sockets --with-sodium --with-password-argon2 --with-tidy --with-xsl --with-enchant --with-pspell --with-zip --with-ffi --enable-apcu --enable-brotli --with-libbrotli --with-imagick --with-ssh2 --with-gnupg --enable-rar --enable-igbinary --with-msgpack --enable-sysvsem --enable-sysvmsg --enable-sysvshm
|
||||
make -j $PROC_LIMIT install
|
||||
make distclean
|
||||
git reset --hard
|
||||
ln -fs /usr/bin/php8.3 /usr/bin/php
|
||||
ln -fs /usr/bin/php8.5 /usr/bin/php
|
||||
cd ..
|
||||
ldconfig
|
||||
|
||||
|
||||
@@ -0,0 +1,251 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
# Tor Hosting - Update Script
|
||||
# https://github.com/DanWin/hosting
|
||||
#
|
||||
# Updates the hosting platform without rebuilding binaries.
|
||||
# For full reinstall including PHP/ImageMagick, use install.sh instead.
|
||||
#
|
||||
# Usage:
|
||||
# ./update.sh # Update code + configs
|
||||
# ./update.sh --rebuild # Also rebuild PHP/ImageMagick
|
||||
# ./update.sh --php-only # Only rebuild PHP (skip ImageMagick)
|
||||
# ./update.sh --code-only # Only update PHP code, no config changes
|
||||
|
||||
REPO_URL="https://github.com/DanWin/hosting.git"
|
||||
REPO_BRANCH="master"
|
||||
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
CYAN='\033[0;36m'
|
||||
BOLD='\033[1m'
|
||||
NC='\033[0m'
|
||||
|
||||
REBUILD=false
|
||||
PHP_ONLY=false
|
||||
CODE_ONLY=false
|
||||
|
||||
log_info() { echo -e "${CYAN}[INFO]${NC} $1"; }
|
||||
log_ok() { echo -e "${GREEN}[OK]${NC} $1"; }
|
||||
log_warn() { echo -e "${YELLOW}[WARN]${NC} $1"; }
|
||||
log_error() { echo -e "${RED}[ERROR]${NC} $1"; }
|
||||
log_step() { echo -e "\n${BOLD}${CYAN}=== $1 ===${NC}\n"; }
|
||||
|
||||
usage() {
|
||||
cat <<'EOF'
|
||||
Usage: ./update.sh [OPTIONS]
|
||||
|
||||
Options:
|
||||
--rebuild Rebuild PHP and ImageMagick from source
|
||||
--php-only Only rebuild PHP (skip ImageMagick if already built)
|
||||
--code-only Only update PHP code files, skip config/service changes
|
||||
-h, --help Show this help
|
||||
|
||||
What this script does:
|
||||
1. Pulls latest code from the repository
|
||||
2. Updates PHP files in /var/www/
|
||||
3. Preserves your passwords, onion address, and encryption keys
|
||||
4. Restarts PHP-FPM and nginx
|
||||
5. Optionally rebuilds PHP/ImageMagick binaries
|
||||
EOF
|
||||
exit 0
|
||||
}
|
||||
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
--rebuild) REBUILD=true; shift ;;
|
||||
--php-only) PHP_ONLY=true; shift ;;
|
||||
--code-only) CODE_ONLY=true; shift ;;
|
||||
-h|--help) usage ;;
|
||||
*) log_error "Unknown option: $1"; usage ;;
|
||||
esac
|
||||
done
|
||||
log_step "Pre-flight checks"
|
||||
|
||||
if [ "$(id -u)" -ne 0 ]; then
|
||||
log_error "Must be run as root"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -d "/root/hosting" ]; then
|
||||
REPO_DIR="/root/hosting"
|
||||
elif [ -d "$(dirname "$0")/.git" ]; then
|
||||
REPO_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||
else
|
||||
log_error "Repository not found. Expected at /root/hosting"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
log_ok "Repository at $REPO_DIR"
|
||||
log_step "Backing up current configuration"
|
||||
|
||||
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"
|
||||
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."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -z "$DBPASS" ] || [ -z "$ADDRESS" ]; then
|
||||
log_error "Could not read current configuration. Aborting."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
log_ok "Backup saved to $BACKUP_DIR"
|
||||
log_step "Pulling latest code"
|
||||
|
||||
cd "$REPO_DIR"
|
||||
OLD_BINARIES_HASH=""
|
||||
if [ -f "$REPO_DIR/install_binaries.sh" ]; then
|
||||
OLD_BINARIES_HASH=$(md5sum "$REPO_DIR/install_binaries.sh" | cut -d' ' -f1)
|
||||
fi
|
||||
|
||||
git fetch origin "$REPO_BRANCH"
|
||||
git reset --hard "origin/$REPO_BRANCH"
|
||||
|
||||
NEW_BINARIES_HASH=$(md5sum "$REPO_DIR/install_binaries.sh" | cut -d' ' -f1)
|
||||
|
||||
log_ok "Code updated to latest"
|
||||
BINARIES_CHANGED=false
|
||||
if [ "$OLD_BINARIES_HASH" != "$NEW_BINARIES_HASH" ] && [ -n "$OLD_BINARIES_HASH" ]; then
|
||||
BINARIES_CHANGED=true
|
||||
log_warn "install_binaries.sh has changed since last update"
|
||||
|
||||
# Detect what changed
|
||||
CHANGES=""
|
||||
# Check for PHP version tag changes
|
||||
NEW_PHP_VERSIONS=$(grep -oP 'git checkout php-\K[0-9.]+' "$REPO_DIR/install_binaries.sh" | sort)
|
||||
for ver in $NEW_PHP_VERSIONS; do
|
||||
MAJOR_MINOR=$(echo "$ver" | cut -d. -f1-2)
|
||||
if [ ! -f "/usr/sbin/php-fpm$MAJOR_MINOR" ]; then
|
||||
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
|
||||
CHANGES="$CHANGES - PHP $MAJOR_MINOR: installed=$INSTALLED_VER, repo=$ver\n"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
# Check ImageMagick version
|
||||
NEW_IM_VER=$(grep -oP 'git checkout \K[0-9.]+[-0-9]*' "$REPO_DIR/install_binaries.sh" | head -1)
|
||||
CUR_IM_VER=$(magick --version 2>/dev/null | grep -oP 'ImageMagick \K[0-9.]+-[0-9]+' || echo "not installed")
|
||||
if [ "$NEW_IM_VER" != "$CUR_IM_VER" ]; then
|
||||
CHANGES="$CHANGES - ImageMagick: installed=$CUR_IM_VER, repo=$NEW_IM_VER\n"
|
||||
fi
|
||||
|
||||
# Check extension versions
|
||||
for ext_line in $(grep -oP '(igbinary|imagick|php-ext-brotli|msgpack-php|apcu).*checkout \K\S+' "$REPO_DIR/install_binaries.sh"); do
|
||||
CHANGES="$CHANGES - Extension update: $ext_line\n"
|
||||
done
|
||||
|
||||
if [ -n "$CHANGES" ]; then
|
||||
echo -e "${YELLOW}Binary changes detected:${NC}"
|
||||
echo -e "$CHANGES"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$REBUILD" = true ]; then
|
||||
log_step "Rebuilding all binaries (PHP + ImageMagick)"
|
||||
bash "$REPO_DIR/install_binaries.sh" 2>&1 | tee /root/rebuild.log
|
||||
log_ok "Binaries rebuilt"
|
||||
elif [ "$PHP_ONLY" = true ]; then
|
||||
log_step "Rebuilding PHP only"
|
||||
if [ ! -f /usr/local/lib/libMagickCore-7.Q16HDRI.so ]; then
|
||||
log_error "ImageMagick not found. Use --rebuild for full build."
|
||||
exit 1
|
||||
fi
|
||||
bash "$REPO_DIR/install_binaries.sh" 2>&1 | tee /root/rebuild.log
|
||||
log_ok "PHP rebuilt"
|
||||
elif [ "$BINARIES_CHANGED" = true ] && [ "$CODE_ONLY" != true ]; then
|
||||
log_warn "Binary build script changed. Run with --rebuild to apply."
|
||||
log_warn "Continuing with code-only update for now."
|
||||
fi
|
||||
|
||||
log_step "Updating code files"
|
||||
cp -a "$REPO_DIR/var/www/common.php" /var/www/common.php
|
||||
cp -a "$REPO_DIR/var/www/html/home.php" /var/www/html/home.php
|
||||
cp -a "$REPO_DIR/var/www/html/login.php" /var/www/html/login.php
|
||||
cp -a "$REPO_DIR/var/www/html/admin.php" /var/www/html/admin.php
|
||||
cp -a "$REPO_DIR/var/www/html/files.php" /var/www/html/files.php
|
||||
cp -a "$REPO_DIR/var/www/html/password.php" /var/www/html/password.php
|
||||
cp -a "$REPO_DIR/var/www/html/pgp.php" /var/www/html/pgp.php
|
||||
cp -a "$REPO_DIR/var/www/html/register.php" /var/www/html/register.php
|
||||
cp -a "$REPO_DIR/var/www/html/index.php" /var/www/html/index.php
|
||||
cp -a "$REPO_DIR/var/www/html/list.php" /var/www/html/list.php
|
||||
cp -a "$REPO_DIR/var/www/html/faq.php" /var/www/html/faq.php
|
||||
cp -a "$REPO_DIR/var/www/html/delete.php" /var/www/html/delete.php
|
||||
cp -a "$REPO_DIR/var/www/html/log.php" /var/www/html/log.php 2>/dev/null || true
|
||||
cp -a "$REPO_DIR/var/www/html/logout.php" /var/www/html/logout.php 2>/dev/null || true
|
||||
cp -a "$REPO_DIR/var/www/html/upgrade.php" /var/www/html/upgrade.php 2>/dev/null || true
|
||||
cp -a "$REPO_DIR/var/www/setup.php" /var/www/setup.php
|
||||
cp -a "$REPO_DIR/var/www/cron.php" /var/www/cron.php
|
||||
cp -a "$REPO_DIR/var/www/find_old.php" /var/www/find_old.php 2>/dev/null || true
|
||||
|
||||
log_ok "Code files updated"
|
||||
|
||||
log_step "Restoring configuration"
|
||||
|
||||
DEFAULT_ONION="dhosting4xxoydyaivckq7tsmtgi4wfs3flpeyitekkmqwu4v4r46syd.onion"
|
||||
sed -i "s|const DBHOST='127.0.0.1'|const DBHOST='$DBHOST'|" /var/www/common.php
|
||||
sed -i "s|const DBPASS='MY_PASSWORD'|const DBPASS='$DBPASS'|" /var/www/common.php
|
||||
sed -i "s|const ADMIN_PASSWORD='MY_PASSWORD'|const ADMIN_PASSWORD='$ADMIN_PASSWORD'|" /var/www/common.php
|
||||
sed -i "s|const ONION_KEY_ENCRYPTION_KEY=''|const ONION_KEY_ENCRYPTION_KEY='$ONION_KEY_ENCRYPTION_KEY'|" /var/www/common.php
|
||||
sed -i "s|$DEFAULT_ONION|$ADDRESS|g" /var/www/common.php
|
||||
sed -i "s|$DEFAULT_ONION|$ADDRESS|g" /var/www/skel/www/index.hosting.html 2>/dev/null || true
|
||||
chown root:www-data /var/www/common.php
|
||||
chmod 640 /var/www/common.php
|
||||
|
||||
log_ok "Configuration restored (onion: $ADDRESS)"
|
||||
|
||||
if [ "$CODE_ONLY" = true ]; then
|
||||
log_step "Code-only update complete"
|
||||
log_ok "Restart services manually if needed: systemctl restart nginx"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
log_step "Updating services"
|
||||
php8.2 /var/www/setup.php 2>&1 || true
|
||||
mkdir -p /var/log/nginx /var/run/nginx
|
||||
for ver in 8.2 8.3 8.4 8.5; do
|
||||
systemctl restart "php$ver-fpm@default" 2>/dev/null || true
|
||||
done
|
||||
systemctl restart nginx 2>/dev/null || true
|
||||
FAILS=0
|
||||
for svc in nginx php8.2-fpm@default php8.3-fpm@default php8.4-fpm@default php8.5-fpm@default; do
|
||||
if ! systemctl is-active --quiet "$svc"; then
|
||||
log_warn "$svc is not running"
|
||||
FAILS=$((FAILS + 1))
|
||||
fi
|
||||
done
|
||||
|
||||
if [ "$FAILS" -eq 0 ]; then
|
||||
log_ok "All services running"
|
||||
else
|
||||
log_warn "$FAILS service(s) need attention"
|
||||
fi
|
||||
|
||||
log_step "Update Complete"
|
||||
|
||||
echo -e "${BOLD}Onion:${NC} $ADDRESS"
|
||||
echo -e "${BOLD}Backup:${NC} $BACKUP_DIR"
|
||||
echo ""
|
||||
TITLE=$(curl -s --max-time 30 --socks5-hostname 127.0.0.1:9050 "http://$ADDRESS/" 2>/dev/null | grep -o "<title>[^<]*</title>")
|
||||
if [ -n "$TITLE" ]; then
|
||||
log_ok "Site responding: $TITLE"
|
||||
else
|
||||
log_warn "Site not responding via Tor (may need a moment)"
|
||||
fi
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
require(__DIR__ . '/common.php');
|
||||
$db = get_db_instance();
|
||||
|
||||
$accounts_per_instance = 250;
|
||||
|
||||
function next_instance_id(array $existing): string {
|
||||
// a-z, then aa, ab, ... az, ba, ...
|
||||
if(empty($existing)){
|
||||
return 'a';
|
||||
}
|
||||
$last = end($existing);
|
||||
$len = strlen($last);
|
||||
for($i = $len - 1; $i >= 0; $i--){
|
||||
if($last[$i] !== 'z'){
|
||||
$last[$i] = chr(ord($last[$i]) + 1);
|
||||
return $last;
|
||||
}
|
||||
$last[$i] = 'a';
|
||||
}
|
||||
return str_repeat('a', $len + 1);
|
||||
}
|
||||
|
||||
$stmt = $db->query('SELECT instance, COUNT(*) as cnt FROM onions WHERE enabled IN (1, -2) GROUP BY instance;');
|
||||
$loads = [];
|
||||
while($row = $stmt->fetch(PDO::FETCH_ASSOC)){
|
||||
$loads[$row['instance']] = (int)$row['cnt'];
|
||||
}
|
||||
|
||||
$current = SERVICE_INSTANCES;
|
||||
$total_accounts = array_sum($loads);
|
||||
$needed = max(1, (int)ceil($total_accounts / $accounts_per_instance));
|
||||
|
||||
if($needed <= count($current)){
|
||||
echo "OK: $total_accounts accounts across " . count($current) . " instance(s)\n";
|
||||
exit(0);
|
||||
}
|
||||
|
||||
$new_instances = $current;
|
||||
while(count($new_instances) < $needed){
|
||||
$new_instances[] = next_instance_id($new_instances);
|
||||
}
|
||||
|
||||
$old_str = "const SERVICE_INSTANCES=['" . implode("','", $current) . "']";
|
||||
$new_str = "const SERVICE_INSTANCES=['" . implode("','", $new_instances) . "']";
|
||||
|
||||
$common = file_get_contents('/var/www/common.php');
|
||||
if(strpos($common, $old_str) === false){
|
||||
echo "ERROR: could not find SERVICE_INSTANCES in common.php\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
file_put_contents('/var/www/common.php', str_replace($old_str, $new_str, $common));
|
||||
echo "SCALED: $total_accounts accounts, " . count($current) . " -> " . count($new_instances) . " instances\n";
|
||||
|
||||
require(__DIR__ . '/setup.php');
|
||||
+86
-28
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
require_once(__DIR__ . '/vendor/autoload.php');
|
||||
const DBHOST='localhost'; // Database host
|
||||
const DBHOST='127.0.0.1'; // Database host
|
||||
const DBUSER='hosting'; // Database user
|
||||
const DBPASS='MY_PASSWORD'; // Database password
|
||||
const DBNAME='hosting'; // Database
|
||||
@@ -26,11 +26,11 @@ const INDEX_MD5S=[ //MD5 sums of index.hosting.html files that should be conside
|
||||
];
|
||||
const REQUIRE_APPROVAL=false; //require admin approval of new sites? true/false
|
||||
const ENABLE_SHELL_ACCESS=true; //allows users to login via ssh, when disabled only sftp is allowed - run setup.php to migrate existing accounts
|
||||
const ADMIN_PASSWORD='MY_PASSWORD'; //password for admin interface
|
||||
const ADMIN_PASSWORD='MY_PASSWORD'; //password hash for admin interface - generate with: php -r "echo password_hash('yourpassword', PASSWORD_DEFAULT);"
|
||||
const SERVICE_INSTANCES=['a']; //one character per instance - run multiple tor+php-fpm instances for load balancing, remove all but one instance if you expect less than 200 accounts. If tor starts using 100% cpu and failing circuits every few hours after a restart, add more instances. In my experience this happens around 250 hidden services per instance - run setup.php after change
|
||||
const DISABLED_PHP_VERSIONS=[]; //php versions still installed on the system but no longer offered for new accounts
|
||||
const PHP_VERSIONS=[7 => '8.1', 8 => '8.2']; //currently active php versions
|
||||
const DEFAULT_PHP_VERSION='8.2'; //default php version
|
||||
const PHP_VERSIONS=[8 => '8.2', 9 => '8.3', 10 => '8.4', 11 => '8.5']; //currently active php versions
|
||||
const DEFAULT_PHP_VERSION='8.5'; //default php version
|
||||
const PHP_CONFIG='zend_extension=opcache.so
|
||||
memory_limit = 256M
|
||||
error_reporting = E_ALL
|
||||
@@ -86,6 +86,7 @@ const COINPAYMENTS_PRIVATE = 'COINPAYMENTS_PRIVATE'; //Coinpayments private API
|
||||
const COINPAYMENTS_PUBLIC = 'COINPAYMENTS_PUBLIC'; //Coinpayments public API key
|
||||
const COINPAYMENTS_MERCHANT_ID = 'COINPAYMENTS_MERCHANT_ID'; //Coinpayments merchant ID
|
||||
const COINPAYMENTS_IPN_SECRET = 'COINPAYMENTS_IPN_SECRET'; //Coinpayments IPN secret
|
||||
const ONION_KEY_ENCRYPTION_KEY=''; //32-byte hex key to encrypt onion private keys at rest - generate with: php -r "echo bin2hex(random_bytes(32));"
|
||||
const COINPAYMENTS_FAKE_BUYER_EMAIL = 'daniel@danwin1210.me'; //fixed email used for the required buyer email field
|
||||
const SITE_NAME = "Daniel's Hosting"; //globally changes the sites title
|
||||
const HOME_MOUNT_PATH = '/home'; //mount path of the home directory. Usually /home as own partition or / on a system with no extra home partition
|
||||
@@ -114,7 +115,7 @@ if(isset($_REQUEST['lang']) && isset(LANGUAGES[$_REQUEST['lang']])){
|
||||
$locale = LANGUAGES[$_REQUEST['lang']]['locale'];
|
||||
$language = $_REQUEST['lang'];
|
||||
$dir = LANGUAGES[$_REQUEST['lang']]['dir'];
|
||||
setcookie('language', $_REQUEST['lang'], ['expires' => 0, 'path' => '/', 'domain' => '', 'secure' => ($_SERVER['HTTPS'] ?? '' === 'on'), 'httponly' => true, 'samesite' => 'Strict']);
|
||||
setcookie('language', $_REQUEST['lang'], ['expires' => 0, 'path' => '/', 'domain' => '', 'secure' => (($_SERVER['HTTPS'] ?? '') === 'on'), 'httponly' => true, 'samesite' => 'Strict']);
|
||||
}elseif(isset($_COOKIE['language']) && isset(LANGUAGES[$_COOKIE['language']])){
|
||||
$locale = LANGUAGES[$_COOKIE['language']]['locale'];
|
||||
$language = $_COOKIE['language'];
|
||||
@@ -134,7 +135,7 @@ if(isset($_REQUEST['lang']) && isset(LANGUAGES[$_REQUEST['lang']])){
|
||||
$locale = LANGUAGES[$lang]['locale'];
|
||||
$language = $lang;
|
||||
$dir = LANGUAGES[$lang]['dir'];
|
||||
setcookie('language', $lang, ['expires' => 0, 'path' => '/', 'domain' => '', 'secure' => ($_SERVER['HTTPS'] ?? '' === 'on'), 'httponly' => true, 'samesite' => 'Strict']);
|
||||
setcookie('language', $lang, ['expires' => 0, 'path' => '/', 'domain' => '', 'secure' => (($_SERVER['HTTPS'] ?? '') === 'on'), 'httponly' => true, 'samesite' => 'Strict']);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -192,9 +193,9 @@ function send_captcha(): void
|
||||
$length = strlen($captchachars)-1;
|
||||
$code = '';
|
||||
for($i = 0; $i < 5; ++$i){
|
||||
$code .= $captchachars[mt_rand(0, $length)];
|
||||
$code .= $captchachars[random_int(0, $length)];
|
||||
}
|
||||
$randid = mt_rand();
|
||||
$randid = random_int(1, 2147483647);
|
||||
$time = time();
|
||||
$db = get_db_instance();
|
||||
$stmt = $db->prepare('INSERT INTO captcha (id, time, code) VALUES (?, ?, ?);');
|
||||
@@ -215,11 +216,11 @@ function send_captcha(): void
|
||||
imagestring($im, 5, 5, 5, $code, $fg);
|
||||
$line = imagecolorallocate($im, 255, 255, 255);
|
||||
for($i = 0; $i < 2; ++$i){
|
||||
imageline($im, 0, mt_rand(0, 24), 55, mt_rand(0, 24), $line);
|
||||
imageline($im, 0, random_int(0, 24), 55, random_int(0, 24), $line);
|
||||
}
|
||||
$dots = imagecolorallocate($im, 255, 255, 255);
|
||||
for($i = 0; $i < 100; ++$i){
|
||||
imagesetpixel($im, mt_rand(0, 55), mt_rand(0, 24), $dots);
|
||||
imagesetpixel($im, random_int(0, 55), random_int(0, 24), $dots);
|
||||
}
|
||||
echo '<img width="55" height="24" src="data:image/gif;base64,';
|
||||
}elseif(CAPTCHA === 3){
|
||||
@@ -230,15 +231,15 @@ function send_captcha(): void
|
||||
$cb = imagecolorallocatealpha($im, 0, 0, 0, 127);
|
||||
imagefill($im, 0, 0, $bg);
|
||||
$line = imagecolorallocate($im, 255, 255, 255);
|
||||
$deg = (mt_rand(0,1)*2-1)*mt_rand(10, 20);
|
||||
$deg = (random_int(0,1)*2-1)*random_int(10, 20);
|
||||
|
||||
$background = imagecreatetruecolor(120, 80);
|
||||
imagefill($background, 0, 0, $cb);
|
||||
|
||||
for ($i=0; $i<20; ++$i) {
|
||||
$char=imagecreatetruecolor(12, 16);
|
||||
imagestring($char, 5, 2, 2, $captchachars[mt_rand(0, $length)], $cc);
|
||||
$char = imagerotate($char, (mt_rand(0,1)*2-1)*mt_rand(10, 20), $cb);
|
||||
imagestring($char, 5, 2, 2, $captchachars[random_int(0, $length)], $cc);
|
||||
$char = imagerotate($char, (random_int(0,1)*2-1)*random_int(10, 20), $cb);
|
||||
$char = imagescale($char, 24, 32);
|
||||
imagefilter($char, IMG_FILTER_SMOOTH, 0.6);
|
||||
imagecopy($background, $char, rand(0, 100), rand(0, 60), 0, 0, 24, 32);
|
||||
@@ -255,9 +256,9 @@ function send_captcha(): void
|
||||
$im = $background;
|
||||
|
||||
for($i=0;$i<1000;++$i){
|
||||
$c = mt_rand(100,230);
|
||||
$c = random_int(100,230);
|
||||
$dots=imagecolorallocate($im, $c, $c, $c);
|
||||
imagesetpixel($im, mt_rand(0, 120), mt_rand(0, 80), $dots);
|
||||
imagesetpixel($im, random_int(0, 120), random_int(0, 80), $dots);
|
||||
}
|
||||
imagedestroy($char);
|
||||
echo '<img width="120" height="80" src="data:image/png;base64,';
|
||||
@@ -268,18 +269,18 @@ function send_captcha(): void
|
||||
imagefill($im, 0, 0, $bg);
|
||||
$line = imagecolorallocate($im, 100, 100, 100);
|
||||
for($i = 0; $i < 5; ++$i){
|
||||
imageline($im, 0, mt_rand(0, 200), 150, mt_rand(0, 200), $line);
|
||||
imageline($im, 0, random_int(0, 200), 150, random_int(0, 200), $line);
|
||||
}
|
||||
$dots = imagecolorallocate($im, 200, 200, 200);
|
||||
for($i = 0; $i < 1000; ++$i){
|
||||
imagesetpixel($im, mt_rand(0, 150), mt_rand(0, 200), $dots);
|
||||
imagesetpixel($im, random_int(0, 150), random_int(0, 200), $dots);
|
||||
}
|
||||
$chars = [];
|
||||
for($i = 0; $i < 10; ++$i){
|
||||
$found = false;
|
||||
while(!$found){
|
||||
$x = mt_rand(10, 140);
|
||||
$y = mt_rand(10, 180);
|
||||
$x = random_int(10, 140);
|
||||
$y = random_int(10, 180);
|
||||
$found = true;
|
||||
foreach($chars as $char){
|
||||
if($char['x'] >= $x && ($char['x'] - $x) < 25){
|
||||
@@ -302,7 +303,7 @@ function send_captcha(): void
|
||||
$chars[$i]['x'] = $x;
|
||||
$chars[$i]['y'] = $y;
|
||||
if($i < 5){
|
||||
imagechar($im, 5, $chars[$i]['x'], $chars[$i]['y'], $captchachars[mt_rand(0, $length)], $fg);
|
||||
imagechar($im, 5, $chars[$i]['x'], $chars[$i]['y'], $captchachars[random_int(0, $length)], $fg);
|
||||
}else{
|
||||
imagechar($im, 5, $chars[$i]['x'], $chars[$i]['y'], $code[$i-5], $fg);
|
||||
}
|
||||
@@ -324,7 +325,7 @@ function send_captcha(): void
|
||||
function check_login() : array {
|
||||
session_start();
|
||||
if(empty($_SESSION['csrf_token'])){
|
||||
$_SESSION['csrf_token']=sha1(uniqid());
|
||||
$_SESSION['csrf_token']=bin2hex(random_bytes(32));
|
||||
}
|
||||
if(empty($_SESSION['hosting_username']) || !empty($_SESSION['2fa_code'])){
|
||||
header('Location: login.php');
|
||||
@@ -401,9 +402,10 @@ NumPrimaryGuards '.NUM_GUARDS.'
|
||||
continue;
|
||||
}
|
||||
if(!file_exists("/var/lib/tor-instances/$instance/hidden_service_$tmp[onion].onion")){
|
||||
$decrypted_key = decrypt_private_key($tmp['private_key']);
|
||||
if($tmp['version']==2){
|
||||
//php openssl implementation has some issues, re-export using native openssl
|
||||
$pkey=openssl_pkey_get_private($tmp['private_key']);
|
||||
$pkey=openssl_pkey_get_private($decrypted_key);
|
||||
openssl_pkey_export($pkey, $exported);
|
||||
$priv_key=shell_exec('echo ' . escapeshellarg($exported) . ' | openssl rsa');
|
||||
//save hidden service
|
||||
@@ -414,9 +416,9 @@ NumPrimaryGuards '.NUM_GUARDS.'
|
||||
chown("/var/lib/tor-instances/$instance/hidden_service_$tmp[onion].onion/private_key", "_tor-$instance");
|
||||
chgrp("/var/lib/tor-instances/$instance/hidden_service_$tmp[onion].onion/", "_tor-$instance");
|
||||
chgrp("/var/lib/tor-instances/$instance/hidden_service_$tmp[onion].onion/private_key", "_tor-$instance");
|
||||
$update_onion->execute([$priv_key, $tmp['onion']]);
|
||||
$update_onion->execute([encrypt_private_key($priv_key), $tmp['onion']]);
|
||||
}elseif($tmp['version']==3){
|
||||
$priv_key=base64_decode($tmp['private_key']);
|
||||
$priv_key=base64_decode($decrypted_key);
|
||||
//save hidden service
|
||||
mkdir("/var/lib/tor-instances/$instance/hidden_service_$tmp[onion].onion", 0700);
|
||||
file_put_contents("/var/lib/tor-instances/$instance/hidden_service_$tmp[onion].onion/hs_ed25519_secret_key", $priv_key);
|
||||
@@ -500,8 +502,15 @@ function rewrite_nginx_config(): void
|
||||
$nginx='';
|
||||
$rewrites = [];
|
||||
// rewrite rules
|
||||
$valid_flags = ['', 'last', 'break', 'redirect', 'permanent'];
|
||||
$stmt = $db->query('SELECT user_id, regex, replacement, flag, ifnotexists FROM nginx_rewrites;');
|
||||
while($tmp = $stmt->fetch(PDO::FETCH_ASSOC)){
|
||||
// sanitize: reject values containing single quotes or semicolons to prevent nginx config injection
|
||||
if(str_contains($tmp['regex'], "'") || str_contains($tmp['regex'], ';') ||
|
||||
str_contains($tmp['replacement'], "'") || str_contains($tmp['replacement'], ';') ||
|
||||
!in_array($tmp['flag'], $valid_flags, true)){
|
||||
continue;
|
||||
}
|
||||
if(!isset($rewrites[$tmp['user_id']])){
|
||||
$rewrites[$tmp['user_id']] = '';
|
||||
}
|
||||
@@ -630,8 +639,18 @@ function rewrite_nginx_config(): void
|
||||
function rewrite_php_config(string $key): void
|
||||
{
|
||||
$db = get_db_instance();
|
||||
$all_versions = array_replace(PHP_VERSIONS, DISABLED_PHP_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);");
|
||||
foreach(array_replace(PHP_VERSIONS, DISABLED_PHP_VERSIONS) as $php_key => $version){
|
||||
$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]);
|
||||
while($row=$tmp_stmt->fetch(PDO::FETCH_ASSOC)){
|
||||
$sa = sanitize_system_account($row['system_account']);
|
||||
if($sa !== false){
|
||||
$all_accounts[] = $sa;
|
||||
}
|
||||
}
|
||||
foreach($all_versions as $php_key => $version){
|
||||
$stmt->execute([$key, $php_key]);
|
||||
$php = "[www]
|
||||
user = www-data
|
||||
@@ -672,7 +691,17 @@ env[HOME]=/
|
||||
mkdir("/etc/php/$version/fpm/pool.d/$key/", 0755, true);
|
||||
}
|
||||
file_put_contents("/etc/php/$version/fpm/pool.d/$key/www.conf", $php);
|
||||
exec('systemctl restart '.escapeshellarg("php$version-fpm@$key"));
|
||||
}
|
||||
// restart FPM: first stop all to release sockets, remove stale sockets, then start all
|
||||
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($all_versions as $php_key => $version){
|
||||
exec('systemctl start '.escapeshellarg("php$version-fpm@$key"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -747,7 +776,7 @@ function add_user_onion(int $user_id, string $onion, string $priv_key, int $onio
|
||||
$db = get_db_instance();
|
||||
$stmt=$db->prepare('INSERT INTO onions (user_id, onion, private_key, version, enabled, enable_smtp, instance) VALUES (?, ?, ?, ?, 1, 0, ?);');
|
||||
$instance = get_new_tor_instance();
|
||||
$stmt->execute([$user_id, $onion, $priv_key, $onion_version, $instance]);
|
||||
$stmt->execute([$user_id, $onion, encrypt_private_key($priv_key), $onion_version, $instance]);
|
||||
enqueue_instance_reload($instance);
|
||||
}
|
||||
|
||||
@@ -822,11 +851,36 @@ function enqueue_instance_reload($instance = null): void
|
||||
}
|
||||
}
|
||||
|
||||
function encrypt_private_key(string $key): string {
|
||||
if(empty(ONION_KEY_ENCRYPTION_KEY)){
|
||||
return $key;
|
||||
}
|
||||
$enc_key = hex2bin(ONION_KEY_ENCRYPTION_KEY);
|
||||
$nonce = random_bytes(SODIUM_CRYPTO_SECRETBOX_NONCEBYTES);
|
||||
$cipher = sodium_crypto_secretbox($key, $nonce, $enc_key);
|
||||
return 'enc:' . base64_encode($nonce . $cipher);
|
||||
}
|
||||
|
||||
function decrypt_private_key(string $data): string {
|
||||
if(!str_starts_with($data, 'enc:')){
|
||||
return $data; // not encrypted (legacy)
|
||||
}
|
||||
$enc_key = hex2bin(ONION_KEY_ENCRYPTION_KEY);
|
||||
$raw = base64_decode(substr($data, 4));
|
||||
$nonce = substr($raw, 0, SODIUM_CRYPTO_SECRETBOX_NONCEBYTES);
|
||||
$cipher = substr($raw, SODIUM_CRYPTO_SECRETBOX_NONCEBYTES);
|
||||
$plain = sodium_crypto_secretbox_open($cipher, $nonce, $enc_key);
|
||||
if($plain === false){
|
||||
return ''; // decryption failed
|
||||
}
|
||||
return $plain;
|
||||
}
|
||||
|
||||
function get_db_instance() : PDO {
|
||||
static $db = null;
|
||||
if($db === null){
|
||||
try{
|
||||
$db=new PDO('mysql:host=' . DBHOST . ';dbname=' . DBNAME, DBUSER, DBPASS, [PDO::ATTR_ERRMODE=>PDO::ERRMODE_WARNING, PDO::ATTR_PERSISTENT=>PERSISTENT]);
|
||||
$db=new PDO('mysql:host=' . DBHOST . ';dbname=' . DBNAME, DBUSER, DBPASS, [PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION, PDO::ATTR_PERSISTENT=>PERSISTENT]);
|
||||
}catch(PDOException $e){
|
||||
die(_('No Connection to MySQL database!'));
|
||||
}
|
||||
@@ -1098,6 +1152,10 @@ function dashboard_menu(array $user, string $current_site): void
|
||||
function print_header(string $sub_title, string $style = '', string $base_target = '_self'): void
|
||||
{
|
||||
global $language, $dir;
|
||||
header('X-Frame-Options: DENY');
|
||||
header('X-Content-Type-Options: nosniff');
|
||||
header('Referrer-Policy: no-referrer');
|
||||
header("Content-Security-Policy: default-src 'self'; script-src 'none'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; frame-ancestors 'none'");
|
||||
?>
|
||||
<!DOCTYPE html><html lang="<?php echo $language; ?>" dir="<?php echo $dir; ?>"><head>
|
||||
<title><?php echo htmlspecialchars(SITE_NAME) . ' - ' . htmlspecialchars($sub_title); ?></title>
|
||||
|
||||
+27
-7
@@ -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){
|
||||
$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']=sha1(uniqid());
|
||||
$_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
@@ -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
|
||||
|
||||
|
||||
+46
-17
@@ -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
|
||||
$description = trim($_POST['description'] ?? '');
|
||||
$description = mb_substr($description, 0, 50);
|
||||
|
||||
$stmt->execute([$_REQUEST['onion'], $user['id']]);
|
||||
$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);
|
||||
@@ -182,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;
|
||||
@@ -192,7 +208,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>';
|
||||
}
|
||||
@@ -204,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>';
|
||||
@@ -216,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' : '';
|
||||
@@ -286,6 +300,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
@@ -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']);
|
||||
|
||||
@@ -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{
|
||||
|
||||
@@ -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>
|
||||
|
||||
+5
-5
@@ -322,7 +322,7 @@ server {
|
||||
include snippets/fastcgi-php.conf;
|
||||
fastcgi_param DOCUMENT_ROOT /html;
|
||||
fastcgi_param SCRIPT_FILENAME /html$fastcgi_script_name;
|
||||
fastcgi_pass unix:/var/run/php/8.2-hosting;
|
||||
fastcgi_pass unix:/var/run/php/' . DEFAULT_PHP_VERSION . '-hosting;
|
||||
}
|
||||
}
|
||||
location /squirrelmail {
|
||||
@@ -330,7 +330,7 @@ server {
|
||||
include snippets/fastcgi-php.conf;
|
||||
fastcgi_param DOCUMENT_ROOT /html;
|
||||
fastcgi_param SCRIPT_FILENAME /html$fastcgi_script_name;
|
||||
fastcgi_pass unix:/var/run/php/8.2-squirrelmail;
|
||||
fastcgi_pass unix:/var/run/php/' . DEFAULT_PHP_VERSION . '-squirrelmail;
|
||||
}
|
||||
}
|
||||
location /phpmyadmin {
|
||||
@@ -338,7 +338,7 @@ server {
|
||||
include snippets/fastcgi-php.conf;
|
||||
fastcgi_param DOCUMENT_ROOT /html;
|
||||
fastcgi_param SCRIPT_FILENAME /html$fastcgi_script_name;
|
||||
fastcgi_pass unix:/run/php/8.2-phpmyadmin;
|
||||
fastcgi_pass unix:/run/php/' . DEFAULT_PHP_VERSION . '-phpmyadmin;
|
||||
}
|
||||
}
|
||||
location /adminer {
|
||||
@@ -347,7 +347,7 @@ server {
|
||||
include snippets/fastcgi-php.conf;
|
||||
fastcgi_param DOCUMENT_ROOT /html/adminer;
|
||||
fastcgi_param SCRIPT_FILENAME /html/adminer$fastcgi_script_name;
|
||||
fastcgi_pass unix:/run/php/8.2-adminer;
|
||||
fastcgi_pass unix:/run/php/' . DEFAULT_PHP_VERSION . '-adminer;
|
||||
}
|
||||
}
|
||||
location /externals/jush/ {
|
||||
@@ -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