lfile(__DIR__ . '/../' . $log_dir . '/add.log'); if (!($_domain = $_GET['domain'] ?? null)) { $log->lwrite('no domain given'); die('no pod domain given'); } $_domain = strtolower($_domain); if (!filter_var(gethostbyname($_domain), FILTER_VALIDATE_IP)) { die('Could not validate the domain name, be sure to enter it as "domain.com" (no caps, no slashes, no extras)'); } $dbh = pg_connect("dbname=$pgdb user=$pguser password=$pgpass"); $dbh || die('Error in connection: ' . pg_last_error()); $sql = 'SELECT domain, stats_apikey, publickey, email FROM pods'; $result = pg_query($dbh, $sql); $result || die('Error in SQL query: ' . pg_last_error()); while ($row = pg_fetch_array($result)) { if ($row['domain'] === $_domain ) { if ($row['email']) { $log->lwrite('domain already exists and is registered to an owner' . $_domain); die('domain already exists and is registered to an owner, use the edit function to modify'); } $digtxt = exec(escapeshellcmd('dig ' . $_domain . ' TXT +short')); if (strpos($digtxt, $row['publickey']) !== false) { echo 'domain validated, you can now add details '; $uuid = md5(uniqid($_domain, true)); $expire = time() + 2700; $sql = 'UPDATE pods SET token = $1, tokenexpire = $2 WHERE domain = $3'; $result = pg_query_params($dbh, $sql, [$uuid, date('Y-m-d H:i:s', $expire), $_domain]); $result || die('Error in SQL query: ' . pg_last_error()); echo <<


EOF; die; } else { $log->lwrite('domain already exists and can be registered' . $_domain); die('domain already exists, you can claim the domain by adding a DNS TXT record that states
' . $_domain . ' IN TXT "' . $row['publickey'] . '"'); } } } $chss = curl_init(); curl_setopt($chss, CURLOPT_URL, 'https://' . $_domain . '/nodeinfo/1.0'); curl_setopt($chss, CURLOPT_POST, 0); curl_setopt($chss, CURLOPT_HEADER, 0); curl_setopt($chss, CURLOPT_CONNECTTIMEOUT, 5); curl_setopt($chss, CURLOPT_RETURNTRANSFER, 1); curl_setopt($chss, CURLOPT_NOBODY, 0); $outputssl = curl_exec($chss); curl_close($chss); if (stristr($outputssl, 'openRegistrations')) { $log->lwrite('Your pod has ssl and is valid ' . $_domain); echo 'Your pod has ssl and is valid
'; $publickey = md5(uniqid($domain, true)); $sql = 'INSERT INTO pods (domain, email, terms, publickey) VALUES ($1, $2, $3, $4)'; $result = pg_query_params($dbh, $sql, [$_domain, $_email, $_terms, $publickey]); $result || die('Error in SQL query: ' . pg_last_error()); if ($_email) { $to = $adminemail; $subject = 'New pod added to ' . $_SERVER['HTTP_HOST']; $headers = ['From: ' . $_email, 'Reply-To: ' . $_email, 'Cc: ' . $_email]; $message_lines = [ 'https://' . $_SERVER['HTTP_HOST'], 'Pod: https://' . $_SERVER['HTTP_HOST'] . '/db/pull.php?debug=1&domain=' . $_domain, '', 'Your pod will not show up right away, as it needs to pass a few checks first.', 'Give it a few hours!', ]; @mail($to, $subject, implode("\r\n", $message_lines), implode("\r\n", $headers)); } echo 'Data successfully inserted! Your pod will be reviewed and live on the list in a few hours!'; } else { $log->lwrite('Could not validate your pod, check your setup! ' . $_domain); echo 'Could not validate your pod, check your setup!
Take a look at your /nodeinfo'; } $log->lclose();