Make only enabled onions clickable in admin + equal instance usage

This commit is contained in:
Daniel Winzen
2019-07-20 14:19:35 +02:00
parent 287eedf318
commit 2f97e826d4
5 changed files with 17 additions and 7 deletions

View File

@ -117,6 +117,7 @@ Once installed create a mysql user for phpmyadmin and cofigure it in `/var/www/h
```
mysql
CREATE USER 'phpmyadmin'@'%' IDENTIFIED BY 'MY_PASSWORD';
CREATE DATABASE phpmyadmin;
GRANT ALL PRIVILEGES ON phpmyadmin.* TO 'phpmyadmin'@'%';
FLUSH PRIVILEGES;
quit

View File

@ -600,9 +600,14 @@ function del_user_db(PDO $db, int $user_id, string $mysql_db) {
}
}
function get_new_tor_instance(PDO $db){
$stmt = $db->query('SELECT s.ID FROM service_instances AS s LEFT JOIN onions AS o ON (s.ID = o.instance) GROUP BY s.ID ORDER BY count(s.ID) LIMIT 1;');
return $stmt->fetch(PDO::FETCH_NUM)[0];
}
function add_user_onion(PDO $db, int $user_id, string $onion, string $priv_key, int $onion_version) {
$stmt=$db->prepare('INSERT INTO onions (user_id, onion, private_key, version, enabled, instance) VALUES (?, ?, ?, ?, 2, ?);');
$stmt->execute([$user_id, $onion, $priv_key, $onion_version, SERVICE_INSTANCES[array_rand(SERVICE_INSTANCES)]]);
$stmt->execute([$user_id, $onion, $priv_key, $onion_version, get_new_tor_instance($db)]);
}
function del_user_onion(PDO $db, int $user_id, string $onion) {

View File

@ -55,10 +55,10 @@ if(empty($_SESSION['logged_in'])){
echo '<form action="' . $_SERVER['SCRIPT_NAME'] . "\" method=\"POST\"><input type=\"hidden\" name=\"csrf_token\" value=\"$_SESSION[csrf_token]\">";
echo '<table border="1">';
echo '<tr><th>Username</th><th>Onion link</th><th>Action</th></tr>';
$stmt=$db->query('SELECT users.username, onions.onion FROM users INNER JOIN onions ON (onions.user_id=users.id) ORDER BY users.username;');
$stmt=$db->query('SELECT users.username, onions.onion, onions.enabled FROM users INNER JOIN onions ON (onions.user_id=users.id) ORDER BY users.username;');
$sccounts = [];
while($tmp=$stmt->fetch(PDO::FETCH_NUM)){
$accounts[$tmp[0]] []= $tmp[1];
$accounts[$tmp[0]] []= [$tmp[1], $tmp[2]];
}
foreach($accounts as $account => $onions){
echo "<tr><td>$account</td><td>";
@ -69,9 +69,13 @@ if(empty($_SESSION['logged_in'])){
}else{
echo '<br>';
}
echo "<a href=\"http://$onion.onion\" target=\"_blank\">$onion.onion</a>";
if($onion[1]=='1'){
echo "<a href=\"http://$onion[0].onion\" target=\"_blank\">$onion[0].onion</a>";
}else{
echo "$onion[0].onion";
}
}
echo "</td><td><button type=\"submit\" name=\"action\" value=\"edit_$onions[0]\">Edit</button><button type=\"submit\" name=\"action\" value=\"delete_$onions[0]\">Delete</button><button type=\"submit\" name=\"action\" value=\"suspend_$onions[0]\">Suspend</button></td></tr>";
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>";
}
echo '</table></form>';
}elseif(substr($_REQUEST['action'], 0, 7) === 'approve'){

View File

@ -45,6 +45,6 @@ header('Content-Type: text/html; charset=UTF-8');
<li>No proxy scripts! (You are already using TOR and this will just burden the network)</li>
<li>No IP logger or similar de-anonymizer sites!</li>
<li>I preserve the right to delete any site for violating these rules and adding new rules at any time.</li>
<li>Should you not honor these rules, I will (have to) work together with Law Enfocements!</li>
<li>Should you not honor these rules, I will (have to) work together with Law Enforcement!</li>
</ul>
</body></html>

View File

@ -108,7 +108,7 @@ if($_SERVER['REQUEST_METHOD']==='POST'){
}elseif($ok){
$mysql_user = add_mysql_user($db, $_POST['pass']);
$stmt=$db->prepare('INSERT INTO users (username, system_account, password, dateadded, public, php, autoindex, mysql_user, instance) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?);');
$stmt->execute([$_POST['username'], substr("$onion.onion", 0, 32), $hash, time(), $public_list, $php, $autoindex, $mysql_user, SERVICE_INSTANCES[array_rand(SERVICE_INSTANCES)]]);
$stmt->execute([$_POST['username'], substr("$onion.onion", 0, 32), $hash, time(), $public_list, $php, $autoindex, $mysql_user, get_new_tor_instance($db)]);
$user_id = $db->lastInsertId();
$stmt = $db->prepare('INSERT INTO disk_quota (user_id, quota_size, quota_files) VALUES (?, ?, ?);');
$stmt->execute([$user_id, DEFAULT_QUOTA_SIZE, DEFAULT_QUOTA_FILES]);