Currently we have some license issues. We are working on it.

Unverified Commit 3f63e29d authored by David Morley's avatar David Morley
Browse files

Merge branch 'noplanman-code_structure'

parents d9b0a90d b2dd66f7
<?php
//Copyright (c) 2011, David Morley. This file is licensed under the Affero General Public License version 3 or later. See the COPYRIGHT file.
if ($_GET['key'] != '4r45tg') {die;}
if ($_GET['key'] != '4r45tg') {
die;
}
require_once __DIR__ . '/config.php';
......@@ -8,6 +10,7 @@ $dbh = pg_connect("dbname=$pgdb user=$pguser password=$pgpass");
if (!$dbh) {
die('Error in connection: ' . pg_last_error());
}
if ($_GET['format'] == 'georss') {
echo <<<EOF
<?xml version="1.0" encoding="utf-8"?>
......@@ -18,15 +21,15 @@ xmlns:georss="http://www.georss.org/georss">
<link href="http://podupti.me/"/>
EOF;
$sql = "SELECT * FROM pods WHERE hidden <> 'yes'";
$sql = "SELECT * FROM pods WHERE hidden <> 'yes'";
$result = pg_query($dbh, $sql);
if (!$result) {
die('Error in SQL query: ' . pg_last_error());
}
die('Error in SQL query: ' . pg_last_error());
}
$numrows = pg_num_rows($result);
while ($row = pg_fetch_array($result)) {
$pod_name = htmlentities($row['name'], ENT_QUOTES);
$tip = sprintf(
$tip = sprintf(
'This pod %1$s has been watched for %2$s months and its average ping time is %3$s with uptime of %4$s%% this month and was last checked on %5$s. On a score of 100 this pod is a %6$s right now',
$pod_name,
$row['monthsmonitored'],
......@@ -35,8 +38,12 @@ EOF;
$row['dateupdated'],
$row['score']
);
if ($row['secure'] == 'true') {$method = 'https://';} else {$method = 'http://';}
echo <<<EOF
if ($row['secure'] == 'true') {
$method = 'https://';
} else {
$method = 'http://';
}
echo <<<EOF
<entry>
<title>{$method}{$row['domain']}</title>
<link href="{$method}{$row['domain']}"/>
......@@ -51,9 +58,8 @@ EOF;
EOF;
}
echo '</feed>';
}
elseif ($_GET['format'] == 'json') {
$sql = 'SELECT id,domain,status,secure,score,userrating,adminrating,city,state,country,lat,long,ip,ipv6,pingdomurl,monthsmonitored,uptimelast7,responsetimelast7,local_posts,comment_counts,dateCreated,dateUpdated,dateLaststats,hidden FROM pods';
} elseif ($_GET['format'] == 'json') {
$sql = 'SELECT id,domain,status,secure,score,userrating,adminrating,city,state,country,lat,long,ip,ipv6,pingdomurl,monthsmonitored,uptimelast7,responsetimelast7,local_posts,comment_counts,dateCreated,dateUpdated,dateLaststats,hidden FROM pods';
$result = pg_query($dbh, $sql);
if (!$result) {
die('Error in SQL query: ' . pg_last_error());
......@@ -61,34 +67,42 @@ elseif ($_GET['format'] == 'json') {
$numrows = pg_num_rows($result);
//json output, thx Vipul A M for fixing this
header('Content-type: application/json');
$rows=array_values(pg_fetch_all($result));
$obj->podcount = $numrows;
$obj->pods = $rows;
$rows = array_values(pg_fetch_all($result));
$obj->podcount = $numrows;
$obj->pods = $rows;
if ($_GET['method'] == 'jsonp') {
print $_GET['callback'] . '(' . json_encode($obj) . ')';
} else {
print json_encode($obj);
}
}
else {
$i=0;
$sql = "SELECT * FROM pods WHERE hidden <> 'yes' ORDER BY uptimelast7 DESC";
} else {
$i = 0;
$sql = "SELECT * FROM pods WHERE hidden <> 'yes' ORDER BY uptimelast7 DESC";
$result = pg_query($dbh, $sql);
if (!$result) {
die('Error in SQL query: ' . pg_last_error());
}
$numrows = pg_num_rows($result);
while ($row = pg_fetch_array($result)) {
if ($row['status'] == 'up'){$status = 'Online';} else {$status = 'Offline';}
if ($row['secure'] == 'true') {$method = 'https://';$class = 'green';} else {$method = 'http://';$class = 'red';}
if ($row['status'] == 'up') {
$status = 'Online';
} else {
$status = 'Offline';
}
if ($row['secure'] == 'true') {
$method = 'https://';
$class = 'green';
} else {
$method = 'http://';
$class = 'red';
}
echo $row['domain'] . ' Up ' . $row['uptimelast7'] . '% This Month - Located in: ' . $row['country'];
if ($i < ($numrows -1)) {
if ($i < ($numrows - 1)) {
echo ',';
}
$i++;
}
$i ++;
}
pg_free_result($result);
pg_close($dbh);
pg_free_result($result);
pg_close($dbh);
}
<?php
$tt=0;
$tt = 0;
require_once __DIR__ . '/config.php';
$dbh = pg_connect("dbname=$pgdb user=$pguser password=$pgpass");
if (!$dbh) {
die('Error in connection: ' . pg_last_error());
}
$sql = "SELECT * FROM pods WHERE hidden <> 'no' AND score < 50 ORDER BY weightedscore";
$result = pg_query($dbh, $sql);
if (!$result) {
die('Error in SQL query: ' . pg_last_error());
}
$dbh = pg_connect("dbname=$pgdb user=$pguser password=$pgpass");
if (!$dbh) {
die('Error in connection: ' . pg_last_error());
}
$sql = "SELECT * FROM pods WHERE hidden <> 'no' AND score < 50 ORDER BY weightedscore";
$result = pg_query($dbh, $sql);
if (!$result) {
die('Error in SQL query: ' . pg_last_error());
}
$numrows = pg_num_rows($result);
?>
<meta property="og:title" content="<?php echo $numrows; ?> #Diaspora Pods listed, Come see the privacy aware social network." /><?php echo $numrows; ?> pods that are open for signup now.
<meta property="og:title" content="<?php echo $numrows; ?> #Diaspora Pods listed, Come see the privacy aware social network."/><?php echo $numrows; ?> pods that are open for signup now.
<meta charset="utf-8">
<!-- /* Copyright (c) 2011, David Morley. This file is licensed under the Affero General Public License version 3 or later. See the COPYRIGHT file. */ -->
<table id="myTable" class="table table-striped table-sm tablesorter table-hover tfont">
<thead>
<tr>
<th>Pod<a class="tipsy" title="A pod is a site for you to set up your account.">?</a></th>
<th>Version<a class="tipsy" title="Version of Diaspora this pod runs">?</a></th>
<th>Uptime<a class="tipsy" title="Percent of the time the pod is online for <?php echo date('F') ?>.">?</a></th>
<th>ms</th>
<th>Signups</th>
<th>Total<a class="tipsy" title="Number of total users on this pod.">?</a></th>
<th>Active 6<a class="tipsy" title="Number of users active last 6 months on this pod.">?</a></th>
<th>Active 1<a class="tipsy" title="Number of users active last 1 month on this pod.">?</a></th>
<th>Posts<a class="tipsy" title="Number of total posts on this pod.">?</a></th>
<th>Comm<a class="tipsy" title="Number of total comments on this pod.">?</a></th>
<th>Month<a class="tipsy" title="How many months has this pod been online? Click number for more history.">?</a></th>
<th>Sc<a class="tipsy" title="System Score on a 100 scale">?</a></th>
<th>conn<a class="tipsy" title="">?</a></th>
<th>Delete?<a class="tipsy" title="Delete this pod from DB?">?</a></th>
</tr>
</thead>
<tbody>
<?php
while ($row = pg_fetch_array($result)) {
$tt=$tt+1;
if ($row['secure'] == 'true') {
$method = 'https://';
$class= 'green';
$tip= 'This pod uses SSL encryption for traffic.';}
else {
$method = 'http://';
$class= 'red';
$tip= 'This pod does not offer SSL';
}
$verdiff = str_replace('.', '', $row['masterversion']) - str_replace('.', '', $row['shortversion']);
<thead>
<tr>
<th>Pod<a class="tipsy" title="A pod is a site for you to set up your account.">?</a></th>
<th>Version<a class="tipsy" title="Version of Diaspora this pod runs">?</a></th>
<th>Uptime<a class="tipsy" title="Percent of the time the pod is online for <?php echo date('F') ?>.">?</a></th>
<th>ms</th>
<th>Signups</th>
<th>Total<a class="tipsy" title="Number of total users on this pod.">?</a></th>
<th>Active 6<a class="tipsy" title="Number of users active last 6 months on this pod.">?</a></th>
<th>Active 1<a class="tipsy" title="Number of users active last 1 month on this pod.">?</a></th>
<th>Posts<a class="tipsy" title="Number of total posts on this pod.">?</a></th>
<th>Comm<a class="tipsy" title="Number of total comments on this pod.">?</a></th>
<th>Month<a class="tipsy" title="How many months has this pod been online? Click number for more history.">?</a>
</th>
<th>Sc<a class="tipsy" title="System Score on a 100 scale">?</a></th>
<th>conn<a class="tipsy" title="">?</a></th>
<th>Delete?<a class="tipsy" title="Delete this pod from DB?">?</a></th>
</tr>
</thead>
<tbody>
<?php
while ($row = pg_fetch_array($result)) {
$tt = $tt + 1;
if ($row['secure'] == 'true') {
$method = 'https://';
$class = 'green';
$tip = 'This pod uses SSL encryption for traffic.';
} else {
$method = 'http://';
$class = 'red';
$tip = 'This pod does not offer SSL';
}
$verdiff = str_replace('.', '', $row['masterversion']) - str_replace('.', '', $row['shortversion']);
$pod_name = htmlentities($row['name'], ENT_QUOTES);
$tip .= sprintf(
"\n" . 'This pod %1$s has been watched for %2$s months and its average ping time is %3$s with uptime of %4$s%% this month and was last checked on %5$s. On a score of -20 to +20 this pod is a %6$s right now',
$pod_name,
$row['monthsmonitored'],
$row['responsetimelast7'],
$row['uptimelast7'],
$row['dateupdated'],
$row['score']
);
$pod_name = htmlentities($row['name'], ENT_QUOTES);
$tip .= sprintf(
"\n" . 'This pod %1$s has been watched for %2$s months and its average ping time is %3$s with uptime of %4$s%% this month and was last checked on %5$s. On a score of -20 to +20 this pod is a %6$s right now',
$pod_name,
$row['monthsmonitored'],
$row['responsetimelast7'],
$row['uptimelast7'],
$row['dateupdated'],
$row['score']
);
echo '<tr><td><a class="' . $class . '" target="_self" href="' . $method . $row['domain'] . '">' . $row['domain'] . '<div title="' . $tip . '" class="tipsy" style="display: inline-block">?</div></a></td>';
echo '<tr><td><a class="' . $class . '" target="_self" href="' . $method . $row['domain'] . '">' . $row['domain'] . '<div title="' . $tip . '" class="tipsy" style="display: inline-block">?</div></a></td>';
if (stristr($row['shortversion'],'head'))
{$version = '.dev';$pre = 'This pod runs pre release
development code';} elseif (!$row['shortversion'])
{$version = '0';$pre = 'This pod runs
unknown code';}
else
{$version =$row['shortversion'];$pre = 'This pod runs production code';}
if ($row['shortversion'] == $row['masterversion'] && $row['shortversion'] != '') {$classver = 'green';} elseif ($verdiff > 6) {$classver = 'red';} else {$classver = 'black';}
echo '<td class="' . $classver . '"><div title="' . $pre . ' codename: ' . $row['longversion'] . ' master version is: ' . $row['masterversion'] . '" class="tipsy">' . $version . '</div></td>';
echo '<td>' . $row['uptimelast7'] . '</td>';
echo '<td>' . $row['responsetimelast7'] . '</td>';
if ($row['signup'] == 1) {$signup = 'Open';} else {$signup = 'Closed';}
echo '<td>' . $signup . '</td>';
echo '<td>' . $row['total_users'] . '</td>';
echo '<td>' . $row['active_users_halfyear'] . '</td>';
echo '<td>' . $row['active_users_monthly'] . '</td>';
echo '<td>' . $row['local_posts'] . '</td>';
echo '<td>' . $row['comment_counts'] . '</td>';
if (strpos($row['pingdomurl'],
'pingdom.com')) {$moreurl = $row['pingdomurl'];} else {$moreurl = 'http://api.uptimerobot.com/getMonitors?format=json&customUptimeRatio=7-30-60-90&apiKey=' . $row['pingdomurl'];}
echo '<td><div title="Last Check ' . $row['dateupdated'] . '" class="tipsy"><a target="_self" href="' . $moreurl . '">' . $row['monthsmonitored'] . '</a></div></td>';
echo '<td>' . $row['score'] . '</td>';
echo '<td><div class="tipsy" title="' . $row['sslvalid'] . '">con info </td>';
?>
<td>
<form method="post" action="db/kill.php" target="_blank">
<input name="comments" value="<?php echo $row['sslvalid']; ?>" size=10>
<input name="domain" value="<?php echo $row['domain']; ?>" type="hidden">
<input name="adminkey" value="<?php echo $_COOKIE['adminkey']; ?>" type="hidden">
<input name="action" type="radio" value="warn">warn
<input name="action" type="radio" value="delete">delete
<input type="submit" value="Process">
</form>
</td>
<?php
echo '</td></tr>';
}
pg_free_result($result);
pg_close($dbh);
?>
</tbody>
if (stristr($row['shortversion'], 'head')) {
$version = '.dev';
$pre = 'This pod runs pre release development code';
} elseif (!$row['shortversion']) {
$version = '0';
$pre = 'This pod runs unknown code';
} else {
$version = $row['shortversion'];
$pre = 'This pod runs production code';
}
if ($row['shortversion'] == $row['masterversion'] && $row['shortversion'] != '') {
$classver = 'green';
} elseif ($verdiff > 6) {
$classver = 'red';
} else {
$classver = 'black';
}
echo '<td class="' . $classver . '"><div title="' . $pre . ' codename: ' . $row['longversion'] . ' master version is: ' . $row['masterversion'] . '" class="tipsy">' . $version . '</div></td>';
echo '<td>' . $row['uptimelast7'] . '</td>';
echo '<td>' . $row['responsetimelast7'] . '</td>';
if ($row['signup'] == 1) {
$signup = 'Open';
} else {
$signup = 'Closed';
}
echo '<td>' . $signup . '</td>';
echo '<td>' . $row['total_users'] . '</td>';
echo '<td>' . $row['active_users_halfyear'] . '</td>';
echo '<td>' . $row['active_users_monthly'] . '</td>';
echo '<td>' . $row['local_posts'] . '</td>';
echo '<td>' . $row['comment_counts'] . '</td>';
if (strpos($row['pingdomurl'],
'pingdom.com')) {
$moreurl = $row['pingdomurl'];
} else {
$moreurl = 'http://api.uptimerobot.com/getMonitors?format=json&customUptimeRatio=7-30-60-90&apiKey=' . $row['pingdomurl'];
}
echo '<td><div title="Last Check ' . $row['dateupdated'] . '" class="tipsy"><a target="_self" href="' . $moreurl . '">' . $row['monthsmonitored'] . '</a></div></td>';
echo '<td>' . $row['score'] . '</td>';
echo '<td><div class="tipsy" title="' . $row['sslvalid'] . '">con info </td>';
?>
<td>
<form method="post" action="db/kill.php" target="_blank">
<input name="comments" value="<?php echo $row['sslvalid']; ?>" size=10>
<input name="domain" value="<?php echo $row['domain']; ?>" type="hidden">
<input name="adminkey" value="<?php echo $_COOKIE['adminkey']; ?>" type="hidden">
<input name="action" type="radio" value="warn">warn
<input name="action" type="radio" value="delete">delete
<input type="submit" value="Process">
</form>
</td>
<?php
echo '</td></tr>';
}
pg_free_result($result);
pg_close($dbh);
?>
</tbody>
</table>
......@@ -17,4 +17,4 @@ $adminemail = '';
//admin key for deleting pods, set this as a cookie on your own
$adminkey = '';
//apikey for public api calls
$apikey= '';
$apikey = '';
<!-- /* Copyright (c) 2011, David Morley. This file is licensed under the Affero General Public License version 3 or later. See the COPYRIGHT file. */ -->
<?php
$valid=0;
$valid = 0;
require_once __DIR__ . '/../logging.php';
$log = new Logging();
$log->lfile($log_dir . '/add.php.log');
if (!$_POST['url']){
$log->lwrite('no url given '.$_POST['domain']);
if (!$_POST['url']) {
$log->lwrite('no url given ' . $_POST['domain']);
die('no url given');
}
if (!$_POST['email']){
$log->lwrite('no email given '.$_POST['domain']);
if (!$_POST['email']) {
$log->lwrite('no email given ' . $_POST['domain']);
die('no email given');
}
if (!$_POST['domain']){
$log->lwrite('no domain given '.$_POST['domain']);
if (!$_POST['domain']) {
$log->lwrite('no domain given ' . $_POST['domain']);
die('no pod domain given');
}
if (!$_POST['url']){
$log->lwrite('no api given '.$_POST['domain']);
if (!$_POST['url']) {
$log->lwrite('no api given ' . $_POST['domain']);
die('no API key for your stats');
}
if (strlen($_POST['url']) < 14){
$log->lwrite('api key too short '.$_POST['domain']);
if (strlen($_POST['url']) < 14) {
$log->lwrite('api key too short ' . $_POST['domain']);
die('API key bad needs to be like m58978-80abdb799f6ccf15e3e3787ee');
}
......@@ -32,18 +32,18 @@ $dbh = pg_connect("dbname=$pgdb user=$pguser password=$pgpass");
if (!$dbh) {
die('Error in connection: ' . pg_last_error());
}
$sql = 'SELECT domain,pingdomurl FROM pods';
$sql = 'SELECT domain,pingdomurl FROM pods';
$result = pg_query($dbh, $sql);
if (!$result) {
die('Error in SQL query: ' . pg_last_error());
}
while ($row = pg_fetch_array($result)) {
if ($row['domain'] == $_POST['domain']) {
$log->lwrite('domain already exists '.$_POST['domain']);
$log->lwrite('domain already exists ' . $_POST['domain']);
die('domain already exists');
}
if ($row['pingdomurl'] == $_POST['url']) {
$log->lwrite('API key already exists '.$_POST['domain']);
$log->lwrite('API key already exists ' . $_POST['domain']);
die('API key already exists');
}
}
......@@ -70,38 +70,38 @@ $output = curl_exec($ch);
curl_close($ch);
if (stristr($outputssl, 'nodeName')) {
$log->lwrite('Your pod has ssl and is valid '.$_POST['domain']);
$log->lwrite('Your pod has ssl and is valid ' . $_POST['domain']);
echo 'Your pod has ssl and is valid<br>';
$valid=1;
$valid = 1;
}
if (stristr($output, 'nodeName')) {
$log->lwrite('Your pod does not have ssl but is a valid pod '.$_POST['domain']);
$log->lwrite('Your pod does not have ssl but is a valid pod ' . $_POST['domain']);
echo 'Your pod does not have ssl but is a valid pod<br>';
$valid=1;
$valid = 1;
}
if ($valid == '1') {
$sql = "INSERT INTO pods (domain, pingdomurl, email) VALUES($1, $2, $3)";
$result = pg_query_params($dbh, $sql, array($_POST['domain'], $_POST['url'], $_POST['email']));
$sql = "INSERT INTO pods (domain, pingdomurl, email) VALUES($1, $2, $3)";
$result = pg_query_params($dbh, $sql, [$_POST['domain'], $_POST['url'], $_POST['email']]);
if (!$result) {
die('Error in SQL query: ' . pg_last_error());
}
$to = $adminemail;
$cc = $_POST['email'];
$to = $adminemail;
$cc = $_POST['email'];
$subject = 'New pod added to podupti.me ';
$message.= sprintf(
$message .= sprintf(
"%1$s\n\n Stats Url: %2$s\n\n Pod: %3$s\n\n",
'https://podupti.me',
'https://api.uptimerobot.com/getMonitors?format=json&customUptimeRatio=7-30-60-90&apiKey=' . $_POST['url'],
'https://podupti.me/db/pull.php?debug=1&domain=' . $_POST['domain']
);
$message.= 'Your pod will not show right away, needs to pass a few checks, Give it a few hours!';
$message .= 'Your pod will not show right away, needs to pass a few checks, Give it a few hours!';
$headers = 'From: ' . $_POST['email'] . "\r\nReply-To: " . $_POST['email'] . "\r\nCc: " . $_POST['email'] . "\r\n";
@mail( $to, $subject, $message, $headers );
@mail($to, $subject, $message, $headers);
echo 'Data successfully inserted! Your pod will be reviewed and live on the list in a few hours!';
pg_free_result($result);
pg_close($dbh);
} else {
$log->lwrite('Could not validate your pod on http or https, check your setup! ' . $_POST['domain']);
......
......@@ -6,26 +6,26 @@ require_once __DIR__ . '/../config.php';
$dbh = pg_connect("dbname=$pgdb user=$pguser password=$pgpass");
if (!$dbh) {
die('Error in connection: ' . pg_last_error());
}
$sql = "SELECT id,domain,status,secure,score,userrating,adminrating,city,state,country,lat,long,ip,ipv6,pingdomurl,monthsmonitored,uptimelast7,responsetimelast7,local_posts,comment_counts,dateCreated,dateUpdated,dateLaststats,hidden FROM pods WHERE domain = $1";
$result = pg_query_params($dbh, $sql, array($_GET['url']));
}
$sql = "SELECT id,domain,status,secure,score,userrating,adminrating,city,state,country,lat,long,ip,ipv6,pingdomurl,monthsmonitored,uptimelast7,responsetimelast7,local_posts,comment_counts,dateCreated,dateUpdated,dateLaststats,hidden FROM pods WHERE domain = $1";
$result = pg_query_params($dbh, $sql, [$_GET['url']]);
if (!$result) {
die('Error in SQL query: ' . pg_last_error());
}
}
while ($row = pg_fetch_array($result)) {
if ($_GET['format'] == 'json') {
echo json_encode($row);
} else {
echo 'Status: ' . $row['status'] . '<br>';
echo 'Last Git Pull: ' . $row['hgitdate'] . '<br>';
echo 'Uptime This Month ' . $row['uptimelast7'] . '<br>';
echo 'Months Monitored: ' . $row['monthsmonitored'] . '<br>';
echo 'Response Time: ' . $row['responsetimelast7'] . '<br>';
echo 'User Rating: ' . $row['userrating'] . '<br>';
echo 'Server Location: ' . $row['country'] . '<br>';
echo 'Latitude: ' . $row['lat'] . '<br>';
echo 'Longitude: ' . $row['long'] . '<br>';
echo 'Status: ' . $row['status'] . '<br>';
echo 'Last Git Pull: ' . $row['hgitdate'] . '<br>';
echo 'Uptime This Month ' . $row['uptimelast7'] . '<br>';
echo 'Months Monitored: ' . $row['monthsmonitored'] . '<br>';
echo 'Response Time: ' . $row['responsetimelast7'] . '<br>';
echo 'User Rating: ' . $row['userrating'] . '<br>';
echo 'Server Location: ' . $row['country'] . '<br>';
echo 'Latitude: ' . $row['lat'] . '<br>';
echo 'Longitude: ' . $row['long'] . '<br>';
}
}
pg_free_result($result);
pg_free_result($result);
pg_close($dbh);
<?php
require_once __DIR__ . '/../config.php';
$keep = (60 * 60 * 6) * 1;
$keep = (60 * 60 * 6) * 1;
$dump_date = date('Ymd_Hs');
$file_name = $backup_dir . '/dump_' . $dump_date . '.sql';
system("export PGPASSWORD=$pgpass && $pg_dump_dir/pg_dump --username=$pguser $pgdb >> $file_name");
echo "pg backup of $pgdb made";
$dirh = dir($backup_dir);
while($entry = $dirh->read()) {
while ($entry = $dirh->read()) {
$old_file_time = (date('U') - $keep);
$file_created = filectime("$backup_dir/$entry");
$file_created = filectime("$backup_dir/$entry");
if ($file_created < $old_file_time && !is_dir($entry)) {
if(unlink("$backup_dir/$entry")) {
if (unlink("$backup_dir/$entry")) {
echo 'Cleaned up old backups';
}
}
......
<?php
if (!$_GET['domain']){
if (!$_GET['domain']) {
die('no pod domain given');
}
if (!$_GET['token']){
if (!$_GET['token']) {
die('no token given');
}
if (strlen($_GET['token']) < 6){
if (strlen($_GET['token']) < 6) {
die('bad token');
}
$domain = $_GET['domain'];
......@@ -16,7 +16,7 @@ $dbh = pg_connect("dbname=$pgdb user=$pguser password=$pgpass");
if (!$dbh) {
die('Error in connection: ' . pg_last_error());
}
$sql = "SELECT domain,email,token,tokenexpire,pingdomurl,weight FROM pods WHERE domain = '$domain'";
$sql = "SELECT domain,email,token,tokenexpire,pingdomurl,weight FROM pods WHERE domain = '$domain'";
$result = pg_query($dbh, $sql);
if (!$result) {
die('Error in SQL query: ' . pg_last_error());
......@@ -25,13 +25,13 @@ while ($row = pg_fetch_array($result)) {
if ($row['token'] <> $_GET['token']) {
die('token not a match');
}
if ($row['tokenexpire'] < date('Y-m-d H:i:s', time())) {
if ($row['tokenexpire'] < date('Y-m-d H:i:s', time())) {
die('token expired');
}
//delete pod
if ($_GET['delete'] == $row['token']){
$sql = "DELETE FROM pods WHERE domain = $1";
$result = pg_query_params($dbh, $sql, array($_GET['domain']));
if ($_GET['delete'] == $row['token']) {
$sql = "DELETE FROM pods WHERE domain = $1";
$result = pg_query_params($dbh, $sql, [$_GET['domain']]);
if (!$result) {
die('Error in SQL query: ' . pg_last_error());
} else {
......@@ -39,20 +39,20 @@ while ($row = pg_fetch_array($result)) {
}
}
//save and exit
if ($_GET['save'] == $row['token']){
if ($_GET['save'] == $row['token']) {
if ($_GET['weight'] > 10) {
die('10 is max weight');
}
$sql = "UPDATE pods SET email=$1, pingdomurl=$2, weight=$3 WHERE domain = $4";
$result = pg_query_params($dbh, $sql, array($_GET['email'],$_GET['pingdomurl'],$_GET['weight'],$_GET['domain']));
$sql = "UPDATE pods SET email=$1, pingdomurl=$2, weight=$3 WHERE domain = $4";
$result = pg_query_params($dbh, $sql, [$_GET['email'], $_GET['pingdomurl'], $_GET['weight'], $_GET['domain']]);
if (!$result) {
die('Error in SQL query: ' . pg_last_error());
}
$to = $_GET['email'];
$to = $_GET['email'];
$subject = 'Edit notice from poduptime ';
$message = 'Data for ' . $_GET['domain'] . " Updated. If it was not you reply and let me know! \n\n";
$headers = "From: support@diasp.org\r\nCc:support@diasp.org,". $_GET['oldemail'] ."\r\n";
@mail( $to, $subject, $message, $headers );
$headers = "From: support@diasp.org\r\nCc:support@diasp.org," . $_GET['oldemail'] . "\r\n";
@mail($to, $subject, $message, $headers);
pg_free_result($result);
pg_close($dbh);
die('Data saved. Will go into effect on next hourly change');
......