Commit 62961183 authored by noplanman's avatar noplanman Committed by David Morley

Unify parameters (#77)

* Use `stats_apikey` instead of `url` for stats API key.

* Use `domain` instead of `url` for go.php.

* Fix error messages for adminkey.
parent 41f234fd
......@@ -8,9 +8,13 @@ if (!($_domain = $_POST['domain'] ?? null)) {
$log->lwrite('no domain given');
die('no pod domain given');
}
if (!($_url = $_POST['url'] ?? null)) {
$log->lwrite('no url given ' . $_domain);
die('no url given');
if (!($_stats_apikey = $_POST['stats_apikey'] ?? null)) {
$log->lwrite('no api given ' . $_domain);
die('no API key for your stats');
}
if (strlen($_stats_apikey) < 14) {
$log->lwrite('api key too short ' . $_domain);
die('API key bad needs to be like m58978-80abdb799f6ccf15e3e3787ee');
}
if (!($_email = $_POST['email'] ?? null)) {
$log->lwrite('no email given ' . $_domain);
......@@ -20,14 +24,6 @@ if (!($_terms = $_POST['terms'] ?? null)) {
$log->lwrite('terms link required ' . $_domain);
die('no terms link');
}
if (!$_url) {
$log->lwrite('no api given ' . $_domain);
die('no API key for your stats');
}
if (strlen($_url) < 14) {
$log->lwrite('api key too short ' . $_domain);
die('API key bad needs to be like m58978-80abdb799f6ccf15e3e3787ee');
}
$dbh = pg_connect("dbname=$pgdb user=$pguser password=$pgpass");
$dbh || die('Error in connection: ' . pg_last_error());
......@@ -41,7 +37,7 @@ while ($row = pg_fetch_array($result)) {
$log->lwrite('domain already exists ' . $_domain);
die('domain already exists');
}
if ($row['stats_apikey'] === $_url) {
if ($row['stats_apikey'] === $_stats_apikey) {
$log->lwrite('API key already exists ' . $_domain);
die('API key already exists');
}
......@@ -62,7 +58,7 @@ if (stristr($outputssl, 'nodeName')) {
echo 'Your pod has ssl and is valid<br>';
$sql = 'INSERT INTO pods (domain, stats_apikey, email, terms) VALUES ($1, $2, $3, $4)';
$result = pg_query_params($dbh, $sql, [$_domain, $_url, $_email, $_terms]);
$result = pg_query_params($dbh, $sql, [$_domain, $_stats_apikey, $_email, $_terms]);
$result || die('Error in SQL query: ' . pg_last_error());
$to = $adminemail;
......@@ -71,7 +67,7 @@ if (stristr($outputssl, 'nodeName')) {
$message = sprintf(
"%1\$s\n\nStats Url: %2\$s\n\nPod: %3\$s\n\n",
'https://' . $_SERVER['HTTP_HOST'],
'https://api.uptimerobot.com/getMonitors?format=json&noJsonCallback=1&customUptimeRatio=7-30-60-90&apiKey=' . $_url,
'https://api.uptimerobot.com/getMonitors?format=json&noJsonCallback=1&customUptimeRatio=7-30-60-90&apiKey=' . $_stats_apikey,
'https://' . $_SERVER['HTTP_HOST'] . '/db/pull.php?debug=1&domain=' . $_domain
);
$message .= 'Your pod will not show right away, needs to pass a few checks, Give it a few hours!';
......
......@@ -2,7 +2,7 @@
// Required parameters.
($_domain = $_POST['domain'] ?? null) || die('no pod domain given');
($_adminkey = $_POST['adminkey'] ?? null) || die('no token given');
($_adminkey = $_POST['adminkey'] ?? null) || die('no admin key given');
($_action = $_POST['action'] ?? null) || die('no action selected');
// Other parameters.
......@@ -18,7 +18,7 @@ $result = pg_query_params($dbh, $sql, [$_domain]);
$result || die('one Error in SQL query: ' . pg_last_error());
while ($row = pg_fetch_array($result)) {
$adminkey === $_adminkey || die('admin key fail');
$adminkey === $_adminkey || die('admin key mismatch');
//save and exit
if ($_action === 'delete') {
......
<?php
// Other parameters.
$_url = $_GET['url'] ?? '';
$_domain = $_GET['domain'] ?? '';
require_once __DIR__ . '/config.php';
$dbh = pg_connect("dbname=$pgdb user=$pguser password=$pgpass");
$dbh || die('Error in connection: ' . pg_last_error());
if ($_url) {
$host = parse_url($_url, PHP_URL_HOST);
if ($_domain) {
$sql = 'SELECT domain FROM pods WHERE domain LIKE $1';
$result = pg_query_params($dbh, $sql, [$host]);
$result = pg_query_params($dbh, $sql, [$_domain]);
$result || die('Error in SQL query: ' . pg_last_error());
$row = pg_fetch_all($result);
$row || die('unknown url');
$row || die('unknown domain');
$sql = 'INSERT INTO clicks (domain, manualclick) VALUES ($1, $2)';
$result = pg_query_params($dbh, $sql, [$host, '1']);
$result = pg_query_params($dbh, $sql, [$_domain, '1']);
$result || die('Error in SQL query: ' . pg_last_error());
header('Location:' . $_url);
header('Location: https://' . $_domain);
} else {
$sql = 'SELECT domain FROM pods WHERE score > 90 AND masterversion = shortversion AND signup ORDER BY RANDOM() LIMIT 1';
$result = pg_query($dbh, $sql);
......@@ -33,5 +32,5 @@ if ($_url) {
$result = pg_query_params($dbh, $sql, [$row[0]['domain'], '1']);
$result || die('Error in SQL query: ' . pg_last_error());
header('Location:https://' . $row[0]['domain'] . '/users/sign_up');
header('Location: https://' . $row[0]['domain'] . '/users/sign_up');
}
......@@ -4,7 +4,7 @@ Its easy start monitoring on your pod with a free <a href="https://uptimerobot.c
Create a monitor for your pod, then in "My Settings" create a monitor-specific API key and paste below.<br>
<br>
<form action="https://<?php echo $_SERVER['HTTP_HOST'] ?>/db/add.php" method="post">
<label>Monitor API Key: <input type="text" name="url" class="xlarge span8" placeholder="m58978-80abdb799f6ccf15e3e4ttwe"> (don't copy the period on the end)</label><br>
<label>Monitor API Key: <input type="text" name="stats_apikey" class="xlarge span8" placeholder="m58978-80abdb799f6ccf15e3e4ttwe"> (don't copy the period on the end)</label><br>
<label>Pod Domain Name: <input type="text" name="domain" class="xlarge span4" placeholder="domain.com"></label><br>
<label>Pod Terms Link: <input type="text" name="terms" class="xlarge span4" value="/terms" placeholder="/terms"></label><br>
<label>Your Email: <input type="text" name="email" class="xlarge span4" placeholder="user@domain.com"></label><br>
......
......@@ -42,7 +42,7 @@ $numrows = pg_num_rows($result);
$row['uptime_alltime'],
$row['score']
);
echo '<tr><td><div title="' . $tip . '" data-toggle="tooltip" data-placement="bottom"><a class="text-success url" target="_self" href="/go.php?url=https://' . $row['domain'] . '">' . $row['domain'] . '</a></div></td>';
echo '<tr><td><div title="' . $tip . '" data-toggle="tooltip" data-placement="bottom"><a class="text-success url" target="_self" href="/go.php?domain=' . $row['domain'] . '">' . $row['domain'] . '</a></div></td>';
echo '<td>' . $row['uptime_alltime'] . '%</td>';
echo '<td data-toggle="tooltip" data-placement="bottom" title="Active users six months: ' . $row['active_users_halfyear'] . ', Active users one month: ' . $row['active_users_monthly'] . '">' . $row['active_users_halfyear'] . '</td>';
......
......@@ -46,7 +46,7 @@ $numrows = pg_num_rows($result);
$tip = "\n This {$row['softwarename']} pod {$pod_name} has been watched for {$row['monthsmonitored']} months with an overall uptime of {$row['uptime_alltime']}% and a response time average today of {$row['responsetime']}ms was last checked on {$row['date_updated']}. ";
$tip .= "On a scale of 100 this pod is a {$row['score']} right now";
echo '<tr><td><a title="' . $tip . '" data-toggle="tooltip" data-placement="bottom" class="text-success" target="_self" href="/go.php?url=https://' . $row['domain'] . '">' . $row['domain'] . '</a></td>';
echo '<tr><td><a title="' . $tip . '" data-toggle="tooltip" data-placement="bottom" class="text-success" target="_self" href="/go.php?domain=' . $row['domain'] . '">' . $row['domain'] . '</a></td>';
if ($row['shortversion'] > $row['masterversion']) {
$version = $row['shortversion'];
......
......@@ -53,7 +53,7 @@ foreach ($csv as $cords) {
'type': 'Feature',
'id': '1',
'properties' : {
'html': '{$pod_name}<br><a href="/go.php?url=https://{$row['domain']}">Visit</a><br> Open Signup: {$signup}<br> Users: {$row['active_users_halfyear']}<br> Uptime: {$row['uptime_alltime']}%<br> Services:{$feat}'
'html': '{$pod_name}<br><a href="/go.php?domain={$row['domain']}">Visit</a><br> Open Signup: {$signup}<br> Users: {$row['active_users_halfyear']}<br> Uptime: {$row['uptime_alltime']}%<br> Services:{$feat}'
},
'geometry': {
'type': 'Point',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment