From 65dff3838dbd4ff2f3e5bd3d57fe35966399a563 Mon Sep 17 00:00:00 2001 From: dmorley Date: Thu, 12 Jan 2017 06:26:20 -0500 Subject: [PATCH] cleanup a bit --- cleanup.php | 2 +- db/migration00001.sql | 4 ++-- db/pull.php | 25 +++++++++++++------------ db/tables.sql | 6 +++--- go.php | 12 +++++++++++- show.php | 2 +- showfull.php | 4 ++-- 7 files changed, 33 insertions(+), 22 deletions(-) diff --git a/cleanup.php b/cleanup.php index 080d6c8..7a5e336 100644 --- a/cleanup.php +++ b/cleanup.php @@ -83,7 +83,7 @@ $numrows = pg_num_rows($result); echo '
' . $version . '
'; echo '' . $row['uptime_alltime'] . ''; echo '' . $row['responsetimems'] . ''; - echo ''; echo $row['signup'] ? 'Open' : 'Closed'; echo ''; + echo '' . ($row['signup'] ? 'Open' : 'Closed') . ''; echo '' . $row['total_users'] . ''; echo '' . $row['active_users_halfyear'] . ''; echo '' . $row['active_users_monthly'] . ''; diff --git a/db/migration00001.sql b/db/migration00001.sql index cb04506..573c046 100644 --- a/db/migration00001.sql +++ b/db/migration00001.sql @@ -1,10 +1,10 @@ -ALTER TABLE pods ADD terms text, ADD sslexpire timestamp, ADD uptime_custom text, ADD dnssec boolean, ADD masterversion text, ADD shortversion text; +ALTER TABLE pods ADD terms text DEFAULT '/terms', ADD sslexpire timestamp, ADD uptime_custom text, ADD dnssec boolean, ADD masterversion text, ADD shortversion text; ALTER TABLE pods DROP Hgitdate, DROP Hgitref, DROP Hruntime, DROP Hencoding, DROP longversion, DROP ptr, DROP whois, DROP postalcode, DROP connection, DROP pingdomlast; ALTER TABLE pods RENAME COLUMN pingdomurl TO statsurl; ALTER TABLE pods RENAME COLUMN xmpp TO service_xmpp; ALTER TABLE pods RENAME COLUMN uptimelast7 TO uptime_alltime; -ALTER TABLE pods RENAME COLUMN responsetimelast7 TO responsetimems; +ALTER TABLE pods RENAME COLUMN responsetimelast7 TO responsetime; ALTER TABLE pods ALTER COLUMN ipv6 TYPE boolean USING ipv6::boolean; ALTER TABLE pods ALTER hidden DROP DEFAULT; diff --git a/db/pull.php b/db/pull.php index c82521c..3032cc4 100644 --- a/db/pull.php +++ b/db/pull.php @@ -291,13 +291,13 @@ while ($row = pg_fetch_all($result)) { $uptime = isset($matchper[1][0]) ? preg_replace('/,/', '.', $matchper[1][0]) : 0; $statslastdate = date('Y-m-d H:i:s'); if (strpos($pingdom, "class=\"up\"")) { - $live = 'up'; + $status = 'up'; } elseif (strpos($pingdom, "class=\"down\"")) { - $live = 'down'; + $status = 'down'; } elseif (strpos($pingdom, "class=\"paused\"")) { - $live = 'paused'; + $status = 'paused'; } else { - $live = 'error'; + $status = 'error'; $score = $score - 2; } } else { @@ -330,25 +330,26 @@ while ($row = pg_fetch_all($result)) { $responsetime = $uptr->monitors->monitor{'0'}->responsetime{'0'}->value; $uptimerobotstat = $uptr->stat; $uptime = $uptr->monitors->monitor{'0'}->alltimeuptimeratio; + $uptime_custom = $uptr->monitors->monitor{'0'}->customuptimeratio; $diff = abs(strtotime(date('Y-m-d H:i:s')) - strtotime($dateadded)); $months = floor(($diff - $years * 365 * 60 * 60 * 24) / (30 * 60 * 60 * 24)); if ($uptr->monitors->monitor{'0'}->status == 2) { - $live = 'Up'; + $status = 'Up'; } if ($uptr->monitors->monitor{'0'}->status == 0) { - $live = 'Paused'; + $status = 'Paused'; } if ($uptr->monitors->monitor{'0'}->status == 1) { - $live = 'Not Checked Yet'; + $status = 'Not Checked Yet'; } if ($uptr->monitors->monitor{'0'}->status == 8) { - $live = 'Seems Down'; + $status = 'Seems Down'; } if ($uptr->monitors->monitor{'0'}->status == 9) { - $live = 'Down'; + $status = 'Down'; } $pingdomdate = date('Y-m-d H:i:s'); - if ($uptimerobotstat == 'fail' || $live <> 'Up') { + if ($uptimerobotstat == 'fail' || $status <> 'Up') { $score = $score - 2; } } @@ -375,9 +376,9 @@ while ($row = pg_fetch_all($result)) { //sql it $timenow = date('Y-m-d H:i:s'); - $sql = 'UPDATE pods SET secure = $2, hidden = $3, ip = $4, ipv6 = $5, monthsmonitored = $6, uptime_alltime = $7, status = $8, dateLaststats = $9, dateUpdated = $10, responsetimems = $11, score = $12, adminrating = $13, country = $14, city = $15, state = $16, lat = $17, long = $18, userrating = $19, shortversion = $20, masterversion = $21, signup = $22, total_users = $23, active_users_halfyear = $24, active_users_monthly = $25, local_posts = $26, name = $27, comment_counts = $28, service_facebook = $29, service_tumblr = $30, service_twitter = $31, service_wordpress = $32, weightedscore = $33, service_xmpp = $34, softwarename = $35, sslvalid = $36 + $sql = 'UPDATE pods SET secure = $2, hidden = $3, ip = $4, ipv6 = $5, monthsmonitored = $6, uptime_alltime = $7, status = $8, dateLaststats = $9, dateUpdated = $10, responsetime = $11, score = $12, adminrating = $13, country = $14, city = $15, state = $16, lat = $17, long = $18, userrating = $19, shortversion = $20, masterversion = $21, signup = $22, total_users = $23, active_users_halfyear = $24, active_users_monthly = $25, local_posts = $26, name = $27, comment_counts = $28, service_facebook = $29, service_tumblr = $30, service_twitter = $31, service_wordpress = $32, weightedscore = $33, service_xmpp = $34, softwarename = $35, sslvalid = $36, uptime_custom = $37 WHERE domain = $1'; - $result = pg_query_params($dbh, $sql, [$domain, $secure, $hidden, $ip, $ipv6, $months, $uptime, $live, $statslastdate, $timenow, $responsetime, $score, $adminrating, $country, $city, $state, $lat, $long, $userrating, $shortversion, $masterversion, $signup, $total_users, $active_users_halfyear, $active_users_monthly, $local_posts, $name, $comment_counts, $service_facebook, $service_tumblr, $service_twitter, $service_wordpress, $weightedscore, $service_xmpp, $softwarename, $outputsslerror]); + $result = pg_query_params($dbh, $sql, [$domain, $secure, $hidden, $ip, $ipv6, $months, $uptime, $status, $statslastdate, $timenow, $responsetime, $score, $adminrating, $country, $city, $state, $lat, $long, $userrating, $shortversion, $masterversion, $signup, $total_users, $active_users_halfyear, $active_users_monthly, $local_posts, $name, $comment_counts, $service_facebook, $service_tumblr, $service_twitter, $service_wordpress, $weightedscore, $service_xmpp, $softwarename, $outputsslerror, $uptime_custom]); $result || die('Error in SQL query3: ' . pg_last_error()); if ($debug) { diff --git a/db/tables.sql b/db/tables.sql index 512bd07..f3f8271 100644 --- a/db/tables.sql +++ b/db/tables.sql @@ -9,7 +9,7 @@ CREATE TABLE pods ( weightedscore numeric(5,2) DEFAULT 10, adminrating decimal DEFAULT 10, userrating decimal DEFAULT 10, - hidden boolean DEFAULT 'yes', + hidden boolean DEFAULT true, ip text, country text, city text, @@ -30,7 +30,7 @@ CREATE TABLE pods ( uptime_alltime numeric(5,2), uptime_custom text, status text, - responsetimems text, + responsetime text, service_facebook boolean, service_twitter boolean, service_tumblr boolean, @@ -38,7 +38,7 @@ CREATE TABLE pods ( service_xmpp boolean, token text, tokenexpire timestamp, - terms text, + terms text DEFAULT '/terms', sslexpire timestamp, dnssec boolean, comment_counts int, diff --git a/go.php b/go.php index e67231b..83a52f8 100644 --- a/go.php +++ b/go.php @@ -17,7 +17,10 @@ if ($_url) { $row = pg_fetch_all($result); $row || die('unknown url'); - //Add click counter +1 for $row[0]['domain'] clicks in future, separate click table + $sql = 'INSERT INTO clicks (domain, manualclick) VALUES ($1, $2)'; + $result = pg_query_params($dbh, $sql, [$host, '1']); + $result || die('Error in SQL query: ' . pg_last_error()); + header('Location:' . $_url); } else { $sql = 'SELECT secure,domain FROM pods WHERE score > 90 AND masterversion = shortversion AND signup ORDER BY RANDOM() LIMIT 1'; @@ -26,5 +29,12 @@ if ($_url) { $row = pg_fetch_all($result); $scheme = $row[0]['secure'] ? 'https://' : 'http://'; + + $sql = 'INSERT INTO clicks (domain, autoclick) VALUES ($1, $2)'; + $result = pg_query_params($dbh, $sql, [$row[0]['domain'], '1']); + $result || die('Error in SQL query: ' . pg_last_error()); + header('Location:' . $scheme . $row[0]['domain'] . '/users/sign_up'); } + pg_free_result($result); + pg_close($dbh); diff --git a/show.php b/show.php index ec41509..30dda22 100644 --- a/show.php +++ b/show.php @@ -8,7 +8,7 @@ $country_code = $_SERVER['HTTP_CF_IPCOUNTRY'] ?? ''; $dbh = pg_connect("dbname=$pgdb user=$pguser password=$pgpass"); $dbh || die('Error in connection: ' . pg_last_error()); -$sql = "SELECT * FROM pods WHERE adminrating <> -1 AND NOT hidden AND signup ORDER BY uptime_alltime DESC"; +$sql = "SELECT * FROM pods WHERE NOT hidden AND signup ORDER BY uptime_alltime DESC"; $result = pg_query($dbh, $sql); $result || die('Error in SQL query: ' . pg_last_error()); diff --git a/showfull.php b/showfull.php index 3f23efd..96ac11f 100644 --- a/showfull.php +++ b/showfull.php @@ -76,9 +76,9 @@ $numrows = pg_num_rows($result); } echo '
' . $version . '
'; echo '' . $row['uptime_alltime'] . '%'; - echo ''; echo $row['ipv6'] ? 'Yes' : 'No'; echo ''; + echo '' . ($row['ipv6'] ? 'Yes' : 'No') . ''; echo '' . $row['responsetimems'] . ''; - echo ''; echo $row['signup'] ? 'Open' : 'Closed'; echo ''; + echo '' . ($row['signup'] ? 'Open' : 'Closed') . ''; echo '' . $row['total_users'] . ''; echo '' . $row['active_users_halfyear'] . ''; echo '' . $row['active_users_monthly'] . ''; -- 2.22.0