From bef733240f0dc9038f915c24f704c8a7aa2e6f6f Mon Sep 17 00:00:00 2001 From: Daniel Winzen Date: Thu, 6 Jun 2024 16:38:45 +0200 Subject: [PATCH] Add primary domain in setup.php --- README.md | 2 ++ common_config.php | 1 - etc/rc.local | 2 +- setup.php | 10 ++++++++++ tools/create_admin.php | 2 -- www/manage_account.php | 2 +- www/register.php | 2 +- 7 files changed, 15 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index f51ca15..83c5722 100644 --- a/README.md +++ b/README.md @@ -160,6 +160,8 @@ nano /var/www/mail/tools/create_admin.php php /var/www/mail/tools/create_admin.php ``` +Copy the file `/etc/postfix/danwin1210-mail.crt` from your main server to the same location on the proxy server. + Final step is to reboot the server and check that everything is working. ### General Domain settings diff --git a/common_config.php b/common_config.php index 07bcff5..18ab453 100644 --- a/common_config.php +++ b/common_config.php @@ -27,7 +27,6 @@ const DBUSER_PROSODY = 'prosody'; // Database user const DBPASS_PROSODY = 'YOUR_PASSWORD'; // Database password const DBNAME_PROSODY = 'prosody'; // Database const REGISTRATION_ENABLED = true; // Whether registration is enabled -const PRIMARY_DOMAIN='danwin1210.de'; // Primary domain to use when a username without domain part was specified const LANGUAGES = [ 'cs' => ['name' => 'čeština', 'locale' => 'cs_CZ', 'flag' => '🇨🇿', 'show_in_menu' => true, 'dir' => 'ltr'], diff --git a/etc/rc.local b/etc/rc.local index 098917f..d9c5cd8 100755 --- a/etc/rc.local +++ b/etc/rc.local @@ -36,7 +36,7 @@ ip6tables -A OUTPUT -o lo -j ACCEPT iptables -A INPUT -i lo -j ACCEPT ip6tables -A INPUT -i lo -j ACCEPT #unrestricted access to these IPs -for clearnet in 127.0.0.0/8; do( +for clearnet in 127.0.0.0/8 10.9.0.0/24; do( iptables -t nat -A OUTPUT -d $clearnet -j RETURN iptables -A OUTPUT -d $clearnet -j ACCEPT ) done diff --git a/setup.php b/setup.php index 3200494..ea0fa2e 100644 --- a/setup.php +++ b/setup.php @@ -60,3 +60,13 @@ try{ echo $e->getMessage() . PHP_EOL; } } +try { + $stmt = $db->prepare( 'INSERT IGNORE INTO domain (domain, created, modified) VALUES (?, NOW(), NOW())' ); + $stmt->execute( [ CLEARNET_SERVER ] ); + $stmt->execute( [ ONION_SERVER ] ); + $stmt = $db->prepare( 'INSERT IGNORE INTO alias_domain (alias_domain, target_domain, created, modified) VALUES (?, ?, NOW(), NOW())' ); + $stmt->execute( [ ONION_SERVER, CLEARNET_SERVER ] ); +} catch( PDOException $e ) { + echo _('Error adding primary domain:') . PHP_EOL; + echo $e->getMessage() . PHP_EOL; +} diff --git a/tools/create_admin.php b/tools/create_admin.php index abeff1b..5af9fe1 100644 --- a/tools/create_admin.php +++ b/tools/create_admin.php @@ -7,5 +7,3 @@ $db = get_db_instance(); $hash = password_hash( ADMIN_PASS, PASSWORD_ARGON2ID ); $stmt = $db->prepare( 'INSERT INTO admin (password_hash_type, password, superadmin, username, created, modified) VALUES ("{ARGON2ID}", ?, 1, ?, NOW(), NOW());' ); $stmt->execute( [ $hash, ADMIN_USER ] ); -$stmt = $db->prepare( 'INSERT IGNORE INTO domain (domain, created, modified) VALUES (?, NOW(), NOW())' ); -$stmt->execute( [ PRIMARY_DOMAIN ] ); \ No newline at end of file diff --git a/www/manage_account.php b/www/manage_account.php index 26fc177..2278d7a 100644 --- a/www/manage_account.php +++ b/www/manage_account.php @@ -49,7 +49,7 @@ if ( $_SERVER[ 'REQUEST_METHOD' ] === 'POST' ) { if ( $ok ) { $db = get_db_instance(); $user = $match[ 1 ]; - $domain = $match[ 3 ] ?? PRIMARY_DOMAIN; + $domain = $match[ 3 ] ?? CLEARNET_SERVER; $stmt = $db->prepare( 'SELECT target_domain FROM alias_domain WHERE alias_domain = ? AND active=1;' ); $stmt->execute( [ $domain ] ); if ( $tmp = $stmt->fetch( PDO::FETCH_ASSOC ) ) { diff --git a/www/register.php b/www/register.php index 05a57e5..880ae34 100644 --- a/www/register.php +++ b/www/register.php @@ -31,7 +31,7 @@ if ( isset( $_POST[ 'user' ] ) ) { $msg .= ''; } $user = mb_strtolower( $match[ 1 ] ?? '' ); - $domain = $match[ 3 ] ?? PRIMARY_DOMAIN; + $domain = $match[ 3 ] ?? CLEARNET_SERVER; if ( $ok && ( empty( $_POST[ 'pwd' ] ) || empty( $_POST[ 'pwd2' ] ) || $_POST[ 'pwd' ] !== $_POST[ 'pwd2' ] ) ) { $ok = false; $msg .= '';