1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- <?php declare(strict_types=1);
- if (dirsStatuses('onion')[$_POST['dir']] !== false)
- output(403, 'Wrong value for <code>dir</code>.');
- rateLimit();
- // Add Tor config
- $torConfFile = CONF['ht']['tor_config_path'] . '/' . $_SESSION['id'] . '/' . $_POST['dir'];
- $torConf = 'HiddenServiceDir ' . CONF['ht']['tor_keys_path'] . '/' . $_SESSION['id'] . '/' . $_POST['dir'] . '/
- HiddenServicePort 80 ' . CONF['ht']['onion_internal_host'] . LF;
- if (file_put_contents($torConfFile, $torConf) === false)
- output(500, 'Failed to write new Tor configuration file.');
- if (chmod($torConfFile, 0644) !== true)
- output(500, 'Failed to give correct permissions to new Tor configuration file.');
- // Reload Tor
- reloadTor();
- usleep(10000);
- // Get the hostname generated by Tor
- exescape([
- CONF['ht']['sudo_path'],
- '-u',
- CONF['ht']['tor_user'],
- '--',
- CONF['ht']['cat_path'],
- '--',
- CONF['ht']['tor_keys_path'] . '/' . $_SESSION['id'] . '/' . $_POST['dir'] . '/hostname',
- ], $output, $code);
- if ($code !== 0)
- output(500, 'Unable to read hostname file.');
- $onion = $output[0];
- if (preg_match('/^[0-9a-z]{56}\.onion$/D', $onion) !== 1)
- output(500, 'No onion address found.');
- // Store it in the database
- addSite($_SESSION['id'], $_POST['dir'], $onion, 'onion');
- htRelativeSymlink('../fs/' . $_SESSION['id'] . '/' . $_POST['dir'], CONF['ht']['ht_path'] . '/uri/' . $onion);
- // Tell the user their site address
- output(200, sprintf(_('%s added on this directory.'), PAGE_METADATA['title']) . ' ' . sprintf(_('Its address is: %s'), '<a href="http://' . $onion . '/"><code>http://' . $onion . '/</code></a>'));
|