From 78ba449fa3ef76c044336fb8e16d3b9094eed88d Mon Sep 17 00:00:00 2001
From: Daniel Winzen
Date: Sun, 22 Jan 2023 20:00:49 +0100
Subject: [PATCH] Make scripts translatable
---
.gitignore | 3 +
README.md | 8 +
update-translation.sh | 3 +
var/www/common.php | 156 ++--
var/www/composer.json | 6 +-
var/www/cron.php | 12 +-
var/www/find_old.php | 6 +-
var/www/html/admin.php | 109 ++-
var/www/html/coinpayments_ipn.php | 14 +-
var/www/html/delete.php | 12 +-
var/www/html/faq.php | 23 +-
var/www/html/files.php | 78 +-
var/www/html/home.php | 112 +--
var/www/html/index.php | 69 +-
var/www/html/list.php | 9 +-
var/www/html/login.php | 34 +-
var/www/html/password.php | 34 +-
var/www/html/pgp.php | 22 +-
var/www/html/register.php | 54 +-
var/www/html/upgrade.php | 24 +-
var/www/locale/hosting.pot | 1195 +++++++++++++++++++++++++++++
var/www/setup.php | 87 ++-
22 files changed, 1652 insertions(+), 418 deletions(-)
create mode 100644 .gitignore
create mode 100755 update-translation.sh
create mode 100644 var/www/locale/hosting.pot
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..d7c7170
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
+var/www/vendor/
+var/www/composer.lock
+*~
diff --git a/README.md b/README.md
index 9da38ff..aa87427 100644
--- a/README.md
+++ b/README.md
@@ -3,6 +3,14 @@ General Information:
This is a setup for a Tor based shared hosting server. It is provided as is and before putting it into production you should make changes according to your needs. This is a work in progress and you should carefully check the commit history for changes before updating.
+Translation:
+--------------------------
+
+Translations are managed in [Weblate](https://weblate.danwin1210.de/projects/DanWin/hosting).
+If you prefer manually submitting translations, the script `update-translations.sh` can be used to update the language template and translation files from source.
+It will generate the file `var/www/locale/hosting.pot` which you can then use as basis to create a new language file in `var/www/YOUR_LANG_CODE/LC_MESSAGES/hosting.po` and edit it with a translation program, such as [Poedit](https://poedit.net/).
+Once you are done, you can open a pull request, or [email me](mailto:daniel@danwin1210.de), to include the translation.
+
Installation Instructions:
--------------------------
diff --git a/update-translation.sh b/update-translation.sh
new file mode 100755
index 0000000..3723e24
--- /dev/null
+++ b/update-translation.sh
@@ -0,0 +1,3 @@
+#!/bin/bash
+xgettext --from-code UTF-8 -o var/www/locale/hosting.pot `find var/www/ -iname '*.php'`
+for translation in `find var/www/locale -iname '*.po'`; do msgmerge -U "$translation" var/www/locale/hosting.pot; msgfmt -o ${translation:0:-2}mo "$translation"; done
diff --git a/var/www/common.php b/var/www/common.php
index dd33675..1a2e1b3 100644
--- a/var/www/common.php
+++ b/var/www/common.php
@@ -63,62 +63,6 @@ session.use_strict_mode = 1
session.serialize_handler=igbinary
apc.serializer=igbinary
';
-const NGINX_DEFAULT = 'server {
- listen unix:/var/run/nginx/suspended backlog=4096 proxy_protocol;
- add_header Content-Type text/html;
- location / {
- return 200 \'SuspendedThis domain has been suspended due to violation of our hosting rules.\';
- }
-}
-server {
- listen [::]:80 ipv6only=off fastopen=100 backlog=4096 default_server;
- listen unix:/var/run/nginx.sock backlog=4096 default_server;
- root /var/www/html;
- index index.php;
- server_name ' . ADDRESS . ' *.' . ADDRESS . ';
- location / {
- try_files $uri $uri/ =404;
- location ~ \.php$ {
- 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;
- }
- }
- location /squirrelmail {
- location ~ \.php$ {
- 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;
- }
- }
- location /phpmyadmin {
- location ~ \.php$ {
- 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;
- }
- }
- location /adminer {
- root /var/www/html/adminer;
- location ~ \.php$ {
- 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;
- }
- }
- location /externals/jush/ {
- root /var/www/html/adminer;
- }
- location /nginx/ {
- root /var/log/;
- internal;
- }
-}
-';
const MAX_NUM_USER_DBS = 5; //maximum number of databases a user may have
const MAX_NUM_USER_ONIONS = 3; //maximum number of onion domains a user may have
const MAX_NUM_USER_DOMAINS = 3; //maximum number of clearnet domains a user may have
@@ -143,6 +87,57 @@ const COINPAYMENTS_IPN_SECRET = 'COINPAYMENTS_IPN_SECRET'; //Coinpayments IPN se
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
+const CONTACT_URL = 'https://danwin1210.de/contact.php'; //url to contact form
+const PRIVACY_URL = 'https://danwin1210.de/privacy.php'; //url to privacy policy
+const CLEARNET_A = '116.202.17.147'; // IPv4 Address of your clearnet gateway
+const CLEARNET_AAAA = '2a01:4f8:c010:d56::1'; // IPv6 Address of your clearnet gateway
+const CLEARNET_ADDRESS = 'hosting.danwin1210.me'; //Domain under which the service is reachable in clearnet
+const CLEARNET_SUBDOMAINS = 'danwin1210.me'; //domain of which all subdomains are mapped to this server
+const DEFAULT_LANG = 'en'; //default language
+const LANGUAGES = [ //available languages
+ 'en' => ['name' => 'English', 'locale' => 'en_GB', 'dir' => 'ltr'],
+];
+
+
+$language = DEFAULT_LANG;
+$locale = LANGUAGES[DEFAULT_LANG]['locale'];
+$dir = LANGUAGES[DEFAULT_LANG]['dir'];
+
+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']);
+}elseif(isset($_COOKIE['language']) && isset(LANGUAGES[$_COOKIE['language']])){
+ $locale = LANGUAGES[$_COOKIE['language']]['locale'];
+ $language = $_COOKIE['language'];
+ $dir = LANGUAGES[$_COOKIE['language']]['dir'];
+}elseif(!empty($_SERVER['HTTP_ACCEPT_LANGUAGE'])){
+ $prefLocales = array_reduce(
+ explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']),
+ function (array $res, string $el) {
+ list($l, $q) = array_merge(explode(';q=', $el), [1]);
+ $res[$l] = (float) $q;
+ return $res;
+ }, []);
+ arsort($prefLocales);
+ foreach($prefLocales as $l => $q){
+ $lang = locale_lookup(array_keys(LANGUAGES), $l);
+ if(!empty($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']);
+ break;
+ }
+ }
+}
+putenv('LC_ALL='.$locale);
+setlocale(LC_ALL, $locale);
+
+bindtextdomain('hosting', __DIR__.'/locale');
+bind_textdomain_codeset('hosting', 'UTF-8');
+textdomain('hosting');
function get_onion_v2($pkey) : string {
$keyData = openssl_pkey_get_details($pkey);
@@ -205,7 +200,7 @@ function send_captcha(): void
$db = get_db_instance();
$stmt = $db->prepare('INSERT INTO captcha (id, time, code) VALUES (?, ?, ?);');
$stmt->execute([$randid, $time, $code]);
- echo "Copy: ";
+ echo ' |
'._('Copy:').' ';
if(CAPTCHA === 1){
$im = imagecreatetruecolor(55, 24);
$bg = imagecolorallocate($im, 0, 0, 0);
@@ -285,7 +280,7 @@ function send_captcha(): void
imagegif($im);
imagedestroy($im);
echo base64_encode(ob_get_clean()).'"> | ';
- echo " |
";
+ echo ' | ';
}
function check_login() : array {
@@ -364,7 +359,7 @@ NumPrimaryGuards '.NUM_GUARDS.'
while($tmp=$stmt->fetch(PDO::FETCH_ASSOC)){
$system_account = sanitize_system_account($tmp['system_account']);
if($system_account === false){
- echo "ERROR: Account $tmp[system_account] looks strange\n";
+ printf(_('ERROR: Account %s looks strange').PHP_EOL, $tmp['system_account']);
continue;
}
if(!file_exists("/var/lib/tor-instances/$instance/hidden_service_$tmp[onion].onion")){
@@ -532,7 +527,7 @@ function rewrite_nginx_config(): void
while($tmp=$stmt->fetch(PDO::FETCH_ASSOC)){
$system_account = sanitize_system_account($tmp['system_account']);
if($system_account === false){
- echo "ERROR: Account $tmp[system_account] looks strange\n";
+ printf(_('ERROR: Account %s looks strange').PHP_EOL, $tmp['system_account']);
continue;
}
if($tmp['php']>0){
@@ -570,7 +565,7 @@ function rewrite_nginx_config(): void
while($tmp=$stmt->fetch(PDO::FETCH_ASSOC)){
$system_account = sanitize_system_account($tmp['system_account']);
if($system_account === false){
- echo "ERROR: Account $tmp[system_account] looks strange\n";
+ printf(_('ERROR: Account %s looks strange').PHP_EOL, $tmp['system_account']);
continue;
}
if($tmp['php']>0){
@@ -611,7 +606,7 @@ function rewrite_nginx_config(): void
while($tmp=$stmt->fetch(PDO::FETCH_ASSOC)){
$system_account = sanitize_system_account($tmp['system_account']);
if($system_account === false){
- echo "ERROR: Account $tmp[system_account] looks strange\n";
+ printf(_('ERROR: Account %s looks strange').PHP_EOL, $tmp['system_account']);
continue;
}
$nginx_mysql.="server {
@@ -655,7 +650,7 @@ pm.max_children = 8
while($tmp=$stmt->fetch(PDO::FETCH_ASSOC)){
$system_account = sanitize_system_account($tmp['system_account']);
if($system_account === false){
- echo "ERROR: Account $tmp[system_account] looks strange\n";
+ printf(_('ERROR: Account %s looks strange').PHP_EOL, $tmp['system_account']);
continue;
}
$php.='['.$tmp['system_account']."]
@@ -816,7 +811,7 @@ function del_user_domain(int $user_id, string $domain): void
function check_csrf_error(): false|string
{
if(empty($_POST['csrf_token']) || $_POST['csrf_token'] !== $_SESSION['csrf_token']){
- return 'Invalid CSRF token, please try again.';
+ return _('Invalid CSRF token, please try again.');
}
return false;
}
@@ -838,7 +833,7 @@ function get_db_instance() : PDO {
try{
$db=new PDO('mysql:host=' . DBHOST . ';dbname=' . DBNAME, DBUSER, DBPASS, [PDO::ATTR_ERRMODE=>PDO::ERRMODE_WARNING, PDO::ATTR_PERSISTENT=>PERSISTENT]);
}catch(PDOException $e){
- die('No Connection to MySQL database!');
+ die(_('No Connection to MySQL database!'));
}
}
return $db;
@@ -973,7 +968,7 @@ function setup_chroot(string $account, string $last_account): void
{
$system_account = sanitize_system_account($account);
if($system_account === false){
- echo "ERROR: Account $account looks strange\n";
+ printf(_('ERROR: Account %s looks strange').PHP_EOL, $account);
return;
}
$last_account = sanitize_system_account($last_account);
@@ -1016,7 +1011,7 @@ function update_system_user_password(string $user, string $password): void
{
$system_account = sanitize_system_account($user);
if($system_account === false){
- echo "ERROR: Account $user looks strange\n";
+ printf(_('ERROR: Account %s looks strange').PHP_EOL, $user);
return;
}
$fp = fopen("/etc/shadow", "r+");
@@ -1058,11 +1053,11 @@ function main_menu(string $current_site): void
{
echo '';
$sites = [
- 'index.php' => 'Info',
- 'register.php' => 'Register',
- 'login.php' => 'Login',
- 'list.php' => 'List of hosted sites',
- 'faq.php' => 'FAQ',
+ 'index.php' => _('Info'),
+ 'register.php' => _('Register'),
+ 'login.php' => _('Login'),
+ 'list.php' => _('List of hosted sites'),
+ 'faq.php' => _('FAQ'),
];
$first = true;
foreach($sites as $link => $name){
@@ -1086,14 +1081,14 @@ function main_menu(string $current_site): void
function dashboard_menu(array $user, string $current_site): void
{
- echo '
Logged in as ' . htmlspecialchars($user['username']);
+ echo '
'.sprintf(_('Logged in as %s'), htmlspecialchars($user['username']));
$sites = [
- 'logout.php' => 'Logout',
- 'home.php' => 'Dashboard',
- 'pgp.php' => 'PGP 2FA',
- 'password.php' => 'Change password',
- 'files.php' => 'FileManager',
- 'delete.php' => 'Delete account',
+ 'logout.php' => _('Logout'),
+ 'home.php' => _('Dashboard'),
+ 'pgp.php' => _('PGP 2FA'),
+ 'password.php' => _('Change password'),
+ 'files.php' => _('FileManager'),
+ 'delete.php' => _('Delete account'),
];
foreach($sites as $link => $name){
if($link===$current_site){
@@ -1107,8 +1102,9 @@ 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;
?>
-
+
diff --git a/var/www/composer.json b/var/www/composer.json
index 25b1f33..abe7d7a 100644
--- a/var/www/composer.json
+++ b/var/www/composer.json
@@ -9,6 +9,8 @@
"ext-posix": "*",
"ext-gnupg": "*",
"ext-ssh2": "*",
- "ext-fileinfo": "*"
- }
+ "ext-fileinfo": "*",
+ "ext-gettext": "*",
+ "ext-intl": "*"
+ }
}
diff --git a/var/www/cron.php b/var/www/cron.php
index aa9aba0..2334dbb 100644
--- a/var/www/cron.php
+++ b/var/www/cron.php
@@ -26,11 +26,11 @@ $stmt=$db->query("SELECT users.system_account, new_account.password, users.id, u
while($account=$stmt->fetch(PDO::FETCH_ASSOC)){
$system_account = basename($account['system_account']);
if($system_account !== $account['system_account']){
- echo "ERROR: Account $account[system_account] looks strange\n";
+ printf(_("ERROR: Account %s looks strange").PHP_EOL, $account['system_account']);
continue;
}
if(posix_getpwnam($system_account) !== false){
- echo "ERROR: Account $account[system_account] already exists\n";
+ printf(_("ERROR: Account %s already exists").PHP_EOL, $account['system_account']);
continue;
}
$reload[$account['instance']] = true;
@@ -52,7 +52,7 @@ $mark_onions=$db->prepare('UPDATE onions SET enabled=-1 WHERE user_id=? AND enab
foreach($accounts as $account){
$system_account = sanitize_system_account($account['system_account']);
if($system_account === false){
- echo "ERROR: Account $account[system_account] looks strange\n";
+ printf(_("ERROR: Account %s looks strange").PHP_EOL, $account['system_account']);
continue;
}
$reload[$account['instance']]=true;
@@ -95,7 +95,7 @@ $drop_user=$db->prepare("DROP USER ?@'%';");
foreach($accounts as $account){
$system_account = sanitize_system_account($account['system_account']);
if($system_account === false){
- echo "ERROR: Account $account[system_account] looks strange\n";
+ printf(_("ERROR: Account %s looks strange").PHP_EOL, $account['system_account']);
continue;
}
//kill processes of the user to allow deleting system users
@@ -131,7 +131,7 @@ $del=$db->prepare("DELETE FROM pass_change WHERE user_id=?;");
while($account=$stmt->fetch(PDO::FETCH_ASSOC)){
$system_account = sanitize_system_account($account['system_account']);
if($system_account === false){
- echo "ERROR: Account $account[system_account] looks strange\n";
+ printf(_("ERROR: Account %s looks strange").PHP_EOL, $account['system_account']);
continue;
}
update_system_user_password($system_account, $account['password']);
@@ -144,7 +144,7 @@ $updated=$db->prepare("UPDATE disk_quota SET updated = 0 WHERE user_id=?;");
while($account=$stmt->fetch(PDO::FETCH_ASSOC)){
$system_account = sanitize_system_account($account['system_account']);
if($system_account === false){
- echo "ERROR: Account $account[system_account] looks strange\n";
+ printf(_("ERROR: Account %s looks strange").PHP_EOL, $account['system_account']);
continue;
}
exec('quotatool -u '. escapeshellarg($system_account) . ' -i -q ' . escapeshellarg($account['quota_files']) . ' -l ' . escapeshellarg($account['quota_files']) . ' ' . HOME_MOUNT_PATH);
diff --git a/var/www/find_old.php b/var/www/find_old.php
index 2ded764..56b7f58 100644
--- a/var/www/find_old.php
+++ b/var/www/find_old.php
@@ -9,7 +9,7 @@ $update=$db->prepare('UPDATE disk_quota SET quota_size_used = ?, quota_files_use
foreach($all_accounts as $tmp){
$system_account = sanitize_system_account($tmp['system_account']);
if($system_account === false){
- echo "ERROR: Account $tmp[system_account] looks strange\n";
+ printf(_("ERROR: Account %s looks strange").PHP_EOL, $tmp['system_account']);
continue;
}
$quota = shell_exec('quota -pu ' . escapeshellarg($tmp['system_account']));
@@ -25,7 +25,7 @@ foreach($all_accounts as $tmp){
foreach($all_accounts as $tmp){
$system_account = sanitize_system_account($tmp['system_account']);
if($system_account === false){
- echo "ERROR: Account $tmp[system_account] looks strange\n";
+ printf(_("ERROR: Account %s looks strange").PHP_EOL, $tmp['system_account']);
continue;
}
exec('find '.escapeshellarg("/home/$tmp[system_account]/tmp").' -path '.escapeshellarg("/home/$tmp[system_account]/tmp/*").' -cmin +1440 -delete');
@@ -41,7 +41,7 @@ $all=$stmt->fetchAll(PDO::FETCH_ASSOC);
foreach($all as $tmp){
$system_account = sanitize_system_account($tmp['system_account']);
if($system_account === false){
- echo "ERROR: Account $tmp[system_account] looks strange\n";
+ printf(_("ERROR: Account %s looks strange").PHP_EOL, $tmp['system_account']);
continue;
}
//check modification times
diff --git a/var/www/html/admin.php b/var/www/html/admin.php
index ec3dfe9..8055e38 100644
--- a/var/www/html/admin.php
+++ b/var/www/html/admin.php
@@ -6,9 +6,9 @@ session_start(['name'=>'hosting_admin']);
if($_SERVER['REQUEST_METHOD']==='HEAD'){
exit; // headers sent, no further processing needed
}
-print_header('Admin panel', 'td{padding:5px;}', '_blank');
+print_header(_('Admin panel'), 'td{padding:5px;}', '_blank');
?>
-Hosting - Admin panel
+
';
if($error){
- echo "$error
";
+ echo ''.$error.'
';
}elseif(isset($_POST['pass'])){
- echo "Wrong password!
";
+ echo ''._('Wrong password!').'
';
}
- echo 'If you disabled cookies, please re-enable them. You can\'t log in without!
';
+ echo ''._("If you disabled cookies, please re-enable them. You can't log in without!").'
';
}else{
echo '';
if(REQUIRE_APPROVAL){
$stmt=$db->query('SELECT COUNT(*) FROM new_account WHERE approved=0;');
$cnt=$stmt->fetch(PDO::FETCH_NUM)[0];
- echo 'Approve pending sites ($cnt) | ";
+ echo ''.sprintf(_('Approve pending sites (%s)'), $cnt).' | ';
}
- echo 'List of accounts | Delete accounts | Suspend hidden services | Edit hidden services | Logout
';
+ echo ''._('List of accounts').' | '._('Delete accounts').' | '._('Suspend hidden services').' | '._('Edit hidden services').' | '._('Logout').'
';
if(empty($_REQUEST['action']) || $_REQUEST['action']==='login'){
- echo 'Welcome to the admin panel!
';
+ echo ''._('Welcome to the admin panel!').'
';
}elseif($_REQUEST['action'] === 'logout'){
session_destroy();
header('Location: ' . $_SERVER['SCRIPT_NAME']);
@@ -47,9 +47,9 @@ if(empty($_SESSION['logged_in'])){
echo '';
- }elseif(substr($_REQUEST['action'], 0, 7) === 'approve'){
+ }elseif( str_starts_with( $_REQUEST[ 'action' ], 'approve' ) ){
$onion = substr($_REQUEST['action'], 8);
if(!empty($onion)){
if($error=check_csrf_error()){
- echo ''.$error.'
';
+ echo ''.$error.'
';
}else{
$stmt=$db->prepare('UPDATE new_account INNER JOIN onions ON (onions.user_id=new_account.user_id) SET new_account.approved=1 WHERE onions.onion=?;');
$stmt->execute([$onion]);
- echo 'Successfully approved
';
+ echo ''._('Successfully approved').'
';
}
}
echo '';
- }elseif(substr($_REQUEST['action'], 0, 6) === 'delete'){
- $onion = '';
- if(isset($_POST['onion'])){
- $onion = $_POST['onion'];
- }else{
- $onion = substr($_REQUEST['action'], 7);
- }
- echo 'Delete accouts:
';
+ }elseif( str_starts_with( $_REQUEST[ 'action' ], 'delete' ) ){
+ $onion = $_POST[ 'onion' ] ?? substr( $_REQUEST[ 'action' ], 7 );
+ echo ''._('Delete accounts:').'
';
echo '
';
+ echo '
';
if(!empty($onion)){
if($error=check_csrf_error()){
echo ''.$error.'
';
@@ -114,63 +109,53 @@ if(empty($_SESSION['logged_in'])){
if($user_id=$stmt->fetch(PDO::FETCH_NUM)){
$stmt=$db->prepare('UPDATE users SET todelete=1 WHERE id=?;');
$stmt->execute($user_id);
- echo "Successfully queued for deletion!
";
+ echo ''._('Successfully queued for deletion!').'
';
}else{
- echo "Onion address not hosted by us!
";
+ echo ''._('Onion address not hosted by us!').'
';
}
}else{
- echo "Invalid onion address!
";
+ echo ''._('Invalid onion address!').'
';
}
}
- }elseif(substr($_REQUEST['action'], 0, 7) === 'suspend'){
- $onion = '';
- if(isset($_POST['onion'])){
- $onion = $_POST['onion'];
- }else{
- $onion = substr($_REQUEST['action'], 8);
- }
- echo 'Suspend hidden service:
';
+ }elseif( str_starts_with( $_REQUEST[ 'action' ], 'suspend' ) ){
+ $onion = $_POST[ 'onion' ] ?? substr( $_REQUEST[ 'action' ], 8 );
+ echo ''._('Suspend hidden service:').'
';
echo '
';
+ echo '
';
if(!empty($onion)){
if($error=check_csrf_error()){
- echo ''.$error.'
';
+ echo ''.$error.'
';
}elseif(preg_match('~^([a-z2-7]{16}|[a-z2-7]{56})(\.onion)?$~', $onion, $match)){
$stmt=$db->prepare('SELECT instance FROM onions WHERE onion=?;');
$stmt->execute([$match[1]]);
if($instance=$stmt->fetch(PDO::FETCH_NUM)){
$stmt=$db->prepare('UPDATE onions SET enabled=-2 WHERE onion=?;');
$stmt->execute([$match[1]]);
- echo "Successfully queued for suspension!
";
+ echo ''._('Successfully queued for suspension!').'
';
enqueue_instance_reload($instance[0]);
}else{
- echo "Onion address not hosted by us!
";
+ echo ''._('Onion address not hosted by us!').'
';
}
}else{
- echo "Invalid onion address!
";
+ echo ''._('Invalid onion address!').'
';
}
}
- }elseif(substr($_REQUEST['action'], 0, 4) === 'edit'){
- $onion = '';
- if(isset($_POST['onion'])){
- $onion = $_POST['onion'];
- }else{
- $onion = substr($_REQUEST['action'], 5);
- }
- echo 'Edit hidden service:
';
+ }elseif( str_starts_with( $_REQUEST[ 'action' ], 'edit' ) ){
+ $onion = $_POST[ 'onion' ] ?? substr( $_REQUEST[ 'action' ], 5 );
+ echo ''._('Edit hidden service:').'
';
echo '
';
if(!empty($onion)){
if($error=check_csrf_error()){
- echo ''.$error.'
';
+ echo ''.$error.'
';
}elseif(preg_match('~^([a-z2-7]{16}|[a-z2-7]{56})(\.onion)?$~', $onion, $match)){
if(isset($_POST['num_intros'])){
$stmt=$db->prepare('SELECT version, instance FROM onions WHERE onion=?;');
@@ -195,7 +180,7 @@ if(empty($_SESSION['logged_in'])){
}
$stmt->execute([$enabled, $enable_smtp, $num_intros, $max_streams, $match[1]]);
enqueue_instance_reload($onion[1]);
- echo "Changes successfully saved!
";
+ echo ''._('Changes successfully saved!').'
';
}
}
$stmt=$db->prepare('SELECT onion, enabled, enable_smtp, num_intros, max_streams, version FROM onions WHERE onion=?;');
@@ -203,22 +188,22 @@ if(empty($_SESSION['logged_in'])){
if($onion=$stmt->fetch(PDO::FETCH_NUM)){
echo '