Merge branch 'master' into patch-5
This commit is contained in:
@@ -93,6 +93,7 @@ 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 SOFTWARE_URL = 'https://github.com/DanWin/hosting';
|
||||
const CLEARNET = '0'; // clearnet enabled = 1 or 0 disabled
|
||||
const PUB_ONION_DESC = '0'; //enable public onion description, 0 = disabled, 1 = enabled
|
||||
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
|
||||
|
||||
@@ -36,7 +36,36 @@ while($account=$stmt->fetch(PDO::FETCH_ASSOC)){
|
||||
$reload[$account['instance']] = true;
|
||||
//add and manage rights of system user
|
||||
$shell = ENABLE_SHELL_ACCESS ? '/bin/bash' : '/usr/sbin/nologin';
|
||||
exec('useradd -l -g www-data -k /var/www/skel -m -s ' . escapeshellarg($shell) . ' ' . escapeshellarg($system_account));
|
||||
exec('useradd -l -g www-data -m -s ' . escapeshellarg($shell) . ' ' . escapeshellarg($system_account));
|
||||
//generate default hosting page
|
||||
$home = "/home/$system_account";
|
||||
$dir = "$home/www";
|
||||
$file = "$dir/index.hosting.html";
|
||||
if (!is_dir($dir)) {
|
||||
mkdir($dir, 0755, true);
|
||||
}
|
||||
$content = sprintf(
|
||||
'<!DOCTYPE html>
|
||||
<html lang="en" dir="ltr">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Site hosted by %s service</title>
|
||||
<meta name="robots" content="noindex">
|
||||
</head>
|
||||
<body>
|
||||
<p>This site is hosted by <a href="http://%s" target="_blank" rel="noopener">%s service</a>.</p>
|
||||
</body>
|
||||
</html>',
|
||||
htmlspecialchars(SITE_NAME, ENT_QUOTES, 'UTF-8'),
|
||||
htmlspecialchars(ADDRESS, ENT_QUOTES, 'UTF-8'),
|
||||
htmlspecialchars(SITE_NAME, ENT_QUOTES, 'UTF-8')
|
||||
);
|
||||
file_put_contents($file, $content);
|
||||
chown($dir, $system_account);
|
||||
chgrp($dir, 'www-data');
|
||||
chown($file, $system_account);
|
||||
chgrp($file, 'www-data');
|
||||
////////
|
||||
update_system_user_password($system_account, $account['password']);
|
||||
setup_chroot($system_account, $last_account);
|
||||
$last_account = $system_account;
|
||||
|
||||
@@ -131,10 +131,15 @@ if(isset($_REQUEST['action']) && isset($_REQUEST['onion']) && $_REQUEST['action'
|
||||
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 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
|
||||
|
||||
$stmt->execute([$_REQUEST['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 = ? 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']);
|
||||
@@ -151,7 +156,8 @@ if(isset($_REQUEST['action']) && isset($_REQUEST['onion']) && $_REQUEST['action'
|
||||
}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, $_REQUEST['onion']]);
|
||||
$stmt->execute([$enabled,$enable_smtp,$num_intros,$max_streams,$description,$_REQUEST['onion']]);
|
||||
enqueue_instance_reload($onion['instance']);
|
||||
}
|
||||
}
|
||||
@@ -176,8 +182,10 @@ 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>';
|
||||
$stmt=$db->prepare('SELECT onion, private_key, enabled, enable_smtp, num_intros, max_streams FROM onions WHERE user_id = ?;');
|
||||
//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;
|
||||
while($onion=$stmt->fetch(PDO::FETCH_ASSOC)){
|
||||
@@ -196,6 +204,8 @@ 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>';
|
||||
echo '<button type="submit" name="action" value="del_onion">'._('Delete').'</button></td>';
|
||||
@@ -206,7 +216,8 @@ 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="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' : '';
|
||||
echo '>'._('Random v3 Address').'</label>';
|
||||
@@ -219,6 +230,7 @@ if($count_onions<MAX_NUM_USER_ONIONS){
|
||||
echo '</label></td><td><button type="submit" name="action" value="add_onion">'._('Add onion').'</button></td></tr></form>';
|
||||
}
|
||||
echo '</table>';
|
||||
if (defined('CLEARNET') && CLEARNET !== '0'):
|
||||
if(MAX_NUM_USER_DOMAINS>0){
|
||||
echo '<h3>'._('Clearnet domains').'</h3>';
|
||||
echo '<table border="1">';
|
||||
@@ -251,6 +263,7 @@ if(MAX_NUM_USER_DOMAINS>0){
|
||||
echo '</table>';
|
||||
echo '<p>'.sprintf(_('To enable your clearnet domain, edit your DNS settings and enter %1$s as your A record and %2$s as your AAAA record. Once you have modified your DNS settings, <a href="%3$s" target="_blank">contact me</a> to configure the SSL certificate. You may also use any subdomain of %4$s'), CLEARNET_A, CLEARNET_AAAA, CONTACT_URL, CLEARNET_SUBDOMAINS).'</p>';
|
||||
}
|
||||
endif;
|
||||
echo '<h3>'._('MySQL Database').'</h3>';
|
||||
echo '<table border="1">';
|
||||
echo '<tr><th>'._('Database').'</th><th>'._('Host').'</th><th>'._('User').'</th><th>'._('Action').'</th></tr>';
|
||||
|
||||
@@ -54,4 +54,5 @@ print_header(_('Info'));
|
||||
<li><?php echo _('I preserve the right to delete any site for violating these rules and adding new rules at any time.'); ?></li>
|
||||
<li><?php echo _('Should you not honor these rules, I will (have to) work together with Law Enforcement!'); ?></li>
|
||||
</ul>
|
||||
<?php printf(_('<a href="%s" target="_blank" rel="noopener noreferrer">Based on Daniels Hosting</a>'), SOFTWARE_URL); ?>
|
||||
</body></html>
|
||||
|
||||
@@ -3,6 +3,7 @@ require_once('../common.php');
|
||||
header('Content-Type: text/html; charset=UTF-8');
|
||||
$db = get_db_instance();
|
||||
print_header(_('List of hosted sites'), 'td{padding:5px;}', '_blank');
|
||||
$show_desc = (defined('PUB_ONION_DESC') && (string)PUB_ONION_DESC === '1');
|
||||
?>
|
||||
<h1><?php echo _('Hosting - List of hosted sites'); ?></h1>
|
||||
<?php
|
||||
@@ -13,11 +14,26 @@ $stmt=$db->query('SELECT COUNT(*) FROM users WHERE public=0;');
|
||||
$hidden=$stmt->fetch(PDO::FETCH_NUM);
|
||||
echo '<p>'.sprintf(_('Here is a list of %1$d public hosted sites (%2$d sites hidden):'), $count[0], $hidden[0]).'</p>';
|
||||
echo '<table border="1">';
|
||||
echo '<tr><td>'._('Onion link').'</td></tr>';
|
||||
$stmt=$db->query('SELECT onions.onion FROM users INNER JOIN onions ON (onions.user_id=users.id) WHERE users.public=1 ORDER BY onions.onion;');
|
||||
while($tmp=$stmt->fetch(PDO::FETCH_NUM)){
|
||||
echo "<tr><td><a href=\"http://$tmp[0].onion\">$tmp[0].onion</a></td></tr>";
|
||||
echo '<tr><td>'._('Onion link').'</td>';
|
||||
if ($show_desc) {
|
||||
echo '<td>'._('Description').'</td>';
|
||||
}
|
||||
echo '</tr>';
|
||||
// description only when PUB_ONION_DESC = 1 in common.php
|
||||
if ($show_desc) {
|
||||
$stmt=$db->query('SELECT onions.onion, onions.description FROM users INNER JOIN onions ON (onions.user_id=users.id) WHERE users.public=1 ORDER BY onions.onion;');
|
||||
while($row=$stmt->fetch(PDO::FETCH_ASSOC)){
|
||||
$onion = $row['onion'];
|
||||
$desc = htmlspecialchars($row['description'] ?? '', ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
|
||||
echo "<tr><td><a href=\"http://$onion.onion\">$onion.onion</a></td><td>$desc</td></tr>";
|
||||
}
|
||||
} else {
|
||||
$stmt=$db->query('SELECT onions.onion FROM users INNER JOIN onions ON (onions.user_id=users.id) WHERE users.public=1 ORDER BY onions.onion;');
|
||||
while($row=$stmt->fetch(PDO::FETCH_NUM)){
|
||||
$onion = $row[0];
|
||||
echo "<tr><td><a href=\"http://$onion.onion\">$onion.onion</a></td></tr>";
|
||||
}
|
||||
}
|
||||
echo '</table>';
|
||||
?>
|
||||
</table>
|
||||
</body></html>
|
||||
|
||||
@@ -25,7 +25,7 @@ if(!$version){
|
||||
$db->exec("CREATE TABLE new_account (user_id int(11) NOT NULL PRIMARY KEY, password varchar(255) COLLATE latin1_bin NOT NULL, approved tinyint(1) UNSIGNED NOT NULL DEFAULT '0', CONSTRAINT new_account_ibfk_1 FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE ON UPDATE CASCADE) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_bin;");
|
||||
$db->exec('CREATE TABLE pass_change (user_id int(11) NOT NULL PRIMARY KEY, password varchar(255) COLLATE latin1_bin NOT NULL, CONSTRAINT pass_change_ibfk_1 FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE ON UPDATE CASCADE) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_bin;');
|
||||
$db->exec('CREATE TABLE mysql_databases (user_id int(11) NOT NULL, mysql_database varchar(64) COLLATE latin1_bin NOT NULL, KEY user_id (user_id), CONSTRAINT mysql_database_ibfk_1 FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE ON UPDATE CASCADE) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_bin;');
|
||||
$db->exec("CREATE TABLE onions (user_id int(11) NULL, onion varchar(56) COLLATE latin1_bin NOT NULL PRIMARY KEY, private_key varchar(1000) COLLATE latin1_bin NOT NULL, version tinyint(1) NOT NULL, enabled tinyint(1) NOT NULL DEFAULT '1', num_intros tinyint(3) NOT NULL DEFAULT '3', enable_smtp tinyint(1) NOT NULL DEFAULT '1', max_streams tinyint(3) unsigned NOT NULL DEFAULT '6', instance char(1) NOT NULL DEFAULT '2', KEY user_id (user_id), KEY enabled (enabled), KEY instance(instance), CONSTRAINT onions_ibfk_1 FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE SET NULL ON UPDATE CASCADE, CONSTRAINT instance_ibfk_1 FOREIGN KEY (instance) REFERENCES service_instances (id) ON DELETE RESTRICT ON UPDATE RESTRICT) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_bin;");
|
||||
$db->exec("CREATE TABLE onions (user_id int(11) NULL, onion varchar(56) COLLATE latin1_bin NOT NULL PRIMARY KEY, description varchar(100) COLLATE latin1_bin NULL, private_key varchar(1000) COLLATE latin1_bin NOT NULL, version tinyint(1) NOT NULL, enabled tinyint(1) NOT NULL DEFAULT '1', num_intros tinyint(3) NOT NULL DEFAULT '3', enable_smtp tinyint(1) NOT NULL DEFAULT '1', max_streams tinyint(3) unsigned NOT NULL DEFAULT '6', instance char(1) NOT NULL DEFAULT '2', KEY user_id (user_id), KEY enabled (enabled), KEY instance(instance), CONSTRAINT onions_ibfk_1 FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE SET NULL ON UPDATE CASCADE, CONSTRAINT instance_ibfk_1 FOREIGN KEY (instance) REFERENCES service_instances (id) ON DELETE RESTRICT ON UPDATE RESTRICT) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_bin;");
|
||||
$db->exec("CREATE TABLE domains (user_id int(11) NULL, domain varchar(255) COLLATE latin1_bin NOT NULL PRIMARY KEY, enabled tinyint(1) NOT NULL DEFAULT '1', KEY user_id (user_id), KEY enabled (enabled), CONSTRAINT domains_ibfk_1 FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE ON UPDATE CASCADE) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_bin;");
|
||||
$db->exec("CREATE TABLE disk_quota (user_id int(11) NOT NULL, quota_size int(10) unsigned NOT NULL, quota_files int(10) unsigned NOT NULL, updated tinyint(1) NOT NULL DEFAULT 1, quota_size_used int(10) unsigned NOT NULL DEFAULT '0', quota_files_used int(10) unsigned NOT NULL DEFAULT '0', KEY user_id (user_id), KEY updated (updated), CONSTRAINT disk_quota_ibfk_2 FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE ON UPDATE CASCADE) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_bin;");
|
||||
$db->exec('CREATE TABLE nginx_rewrites (id int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, user_id int(11) NOT NULL, `regex` varchar(255) NOT NULL, replacement varchar(255) NOT NULL, `flag` varchar(9) NOT NULL, ifnotexists tinyint(1) NOT NULL, CONSTRAINT nginx_rewrites_ibfk_2 FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE ON UPDATE CASCADE) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;');
|
||||
|
||||
Reference in New Issue
Block a user