From fbb8b63d11a8fecd0d0050681a5b21545a587605 Mon Sep 17 00:00:00 2001 From: David Morley Date: Mon, 13 Feb 2017 09:10:30 -0800 Subject: [PATCH] Develop (#108) * Nicely import $_GET and $_POST parameters, PHP7 style! Fix all SQL queries, to make sure they use pg_query_params for parameter injection. Simplify various `if` conditionals to 1-liners. * use adminemail from config.php file properly * fix my bad changes * remove get * use adminemail from config.php file properly * fix one more * bump bootstrap to a 6 * fix using the whois column for random location data * put n/a if location data is missing * Revert "bump bootstrap to a 6" * move n/a to view * Make pretty * sql cleanup * more tables * reorder the pull, put domain first to make future changes easier * add sql updates * cleanup a bit * terms manual for podmin. add click and checks rough * missed a few and was a bad kid on formating already * few more back to === * remove domain hardcode * sql cleanup * more tables * reorder the pull, put domain first to make future changes easier * add sql updates * cleanup a bit * terms manual for podmin. add click and checks rough * missed a few and was a bad kid on formating already * few more back to === * few bugs and cleanup api to be consistant * cleanup my SELECT statements * more fix * hrm fix my messup * Fixes (#69) * fix geo data and ratings show * fix the month check and date on view * remove testing item * changes * remove http and pingdom * few oopses * fixes * yup * cleanup * WordPress! * Fix forgotten date_updated column. (#71) Rename date column to date_created in rating_comments. * Some simplifications (#72) * Simplify arithmetics for $score. Use PHP7 random_int method for improved random int generation. * Simplify uptimerobot API calls by removing JSON callback. * Simplify user and admin ratings. * Smaller fixes and command simplifications. * Remove unnecessary pg_free_result and pg_close calls. (#76) ah, never knew you did not Have to have them! * 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. * Better forms and email sending (#73) * Improve HTML form output. Better email message sending. Various code fixes and simplifications. * Make email sending more logical. Fix wrong email field. * Move email headers up. Better email formatting when a new rating has been added. * Populate sslexpire, dnssec.. (#74) * merge * merge * populate the new db cols * clean * cleanup * Add missing tags. (#78) Remove alt properties from div. * add icon and sslexpire * ping! * Fixpullnbackup (#79) * fixes for issue 63 * example * add install note * quotes * Fixpullnbackup fixes (#81) * Fix a few warnings and correct data type for boolean variables. * Boolean data type for $dnssec, $signup and $ipv6. Use only $signup instead of also $registrations_open. Use only $outputssl instead of also $outputresults. * Weird PSQL requires boolean to be passed as int, else it gives an error: `invalid input syntax for type boolean: ""` * Remove unnecessary unsets. * Remove unnecessary foreach loop. * Fix alignment (visual only). [skip ci] * To determine if the request was successful, check for a valid JSON to parse instead of searching the response for a string. * Rename query result variables to prevent breaking the main loop. * Add a small debug function to make debug output cleaner and easier to use. * Add debug flag. Browser: `pull.php?debug`, CLI: `pull.php debug` * Remove old code that prevents markers from overlapping each other, as mapbox nicely separates them. * fix the IP issue and pretty map spiral * fix some pull issues * updates * without 'false' * fix boolean and more * fixes again * deal with cname and try less flaky dns * gather enough stats on our own for longterm use * cleanup * remove trim * php7 not php4 duh * old debug info from using pingdom, clean * fix map * Fix debug output for software versions. * Fix the regex to get the A value of a DNS entry. * Ownstats (#88) * rebase * features and work * Make software version pull easier to understand and extend. (#91) * Combine related conditions. (#90) * Add helper function for chart display. (#89) Simplify chart data generation. * PR updates * WIP - Nicer domain checks (#92) * Explicitly check passed domain name. * Make domain lowercase. * Use native PHP instead of system exec calls to get IPs. * remove key * few misses * need to call it redmatrix to stay consistant, idk what proper name is * some more * back to old ip lookup, use delv for both. * tr * bad copy n paste * Moarfix (#94) * fix bad pods getting other pods data * maybe easier to read this way * changes * xmpp * v1 api back to legacy (#95) * Terms (#96) * change terms to podmin_statement * use grep more david * fix labeling * some responsiveness cleanup & few features (#98) * some responsiveness cleanup * few sql ones * basic email ping on bad pod * cleanup * fix facebox * fix my mistakes * few issues on dev that needed working out * less zeros is more I think * make this more logical and work for pods * latent * bool and ca pull * dum * Add list groups for nav menus. * Use bootstrap alpha 6. * Update nav bar. * Update sidebar nav menus. * Update sidebar nav css. * Update main column and padding. * Make menu generation more dynamic. * Fix main home link location. * Add horizontal ruler to separate sidebar navigations. * Set z-index for sidebar and sort CSS properties. * Fluid layout for stats page. * Revamp podmin add form. * Revamp podmin edit form. * Only use responsive table container with actual tables. Use CSS class for tablesorter component. * Add complete col- classes. * More cleanup (#105) * dash * language tag * do better when no podname given. make tooltip cleaner. * kill ad, shorten tip, clean language * users/sign_up is a ruby path, we support all now * more time to try, go back to weightedscore (#106) * more time to try, go back to weightedscore * forgot one * damn bool --- README.md | 6 +- api-more.php | 1 - api.php | 34 +- bower.json | 5 +- cleanup.php | 67 ++-- config.php.example | 6 +- css/dashboard.css | 69 +---- css/newstyle.css | 24 +- db/add.php | 139 ++++----- db/api-more.php | 15 +- db/edit.php | 115 +++---- db/gettoken.php | 87 +++--- db/kill.php | 69 ++--- db/migration00001.sql | 60 ++++ db/pods_apiv1.sql | 27 ++ db/pull-masterversions.php | 31 ++ db/pull.php | 614 +++++++++++++------------------------ db/pull.sh | 33 +- db/saverating.php | 35 ++- db/tables.sql | 86 ++++-- db/version.md | 8 + go.php | 40 ++- index.php | 124 +++++--- js/podup.js | 12 +- podcrawler.php | 29 ++ podmin.php | 48 ++- podminedit.php | 28 +- rate.php | 19 +- show.php | 62 ++-- showfull.php | 105 +++---- showmap.php | 27 +- showstats.php | 52 ---- statsview.php | 13 + statsviewjs.php | 40 +++ 34 files changed, 1082 insertions(+), 1048 deletions(-) delete mode 120000 api-more.php create mode 100644 db/migration00001.sql create mode 100644 db/pods_apiv1.sql create mode 100644 db/pull-masterversions.php create mode 100644 db/version.md create mode 100644 podcrawler.php delete mode 100644 showstats.php create mode 100644 statsview.php create mode 100644 statsviewjs.php diff --git a/README.md b/README.md index 8991eac..3fd631e 100644 --- a/README.md +++ b/README.md @@ -4,12 +4,13 @@ Poduptime is software to get live stats and data on listed Diaspora Pods. Dependencies: ``` -php7.0 php7.0-curl php7.0-pgsql php-geoip php7.0-cli php7.0-common php7.0-json php7.0-readline +php7.0 php7.0-curl php7.0-pgsql php-geoip php7.0-cli php7.0-common php7.0-json php7.0-readline php-cgi git curl postgresql postgresql-contrib wget dnsutils +bind9 npm nodejs nodejs-legacy ``` @@ -42,10 +43,11 @@ psql -u podupuser podupdb < db/tables.sql Edit `config.php` to add your DB and file settings. touch add.log in location you configured in config.php +run db/pull.sh manually or with cron to update your data ============================ -Source for https://podupti.me +Source for Diaspora Pod Uptime Poduptime is software to get live stats and data on listed Diaspora Pods. Copyright (C) 2011 David Morley diff --git a/api-more.php b/api-more.php deleted file mode 120000 index a6b383f..0000000 --- a/api-more.php +++ /dev/null @@ -1 +0,0 @@ -db/api-more.php \ No newline at end of file diff --git a/api.php b/api.php index f81a6ad..a4ffcd0 100644 --- a/api.php +++ b/api.php @@ -1,22 +1,27 @@ Diaspora Pods -IP Locations of Diaspora pods on podupti.me - +IP Locations of Diaspora pods on {$_SERVER['HTTP_HOST']} + EOF; - $sql = "SELECT * FROM pods WHERE hidden <> 'yes'"; + $sql = "SELECT name,monthsmonitored,responsetimelast7,uptimelast7,dateupdated,score,domain,country,lat,long FROM pods_apiv1"; $result = pg_query($dbh, $sql); $result || die('Error in SQL query: ' . pg_last_error()); @@ -32,10 +37,9 @@ EOF; $row['dateupdated'], $row['score'] ); - $scheme = $row['secure'] === 'true' ? 'https://' : 'http://'; echo << - {$scheme}{$row['domain']} + https://{$row['domain']} urn:{$row['domain']} Pod Location is: {$row['country']} @@ -48,8 +52,8 @@ EOF; EOF; } echo ''; -} 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 ($_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_apiv1'; $result = pg_query($dbh, $sql); $result || die('Error in SQL query: ' . pg_last_error()); @@ -62,22 +66,19 @@ EOF; 'podcount' => $numrows, 'pods' => $rows, ]; - if ($_GET['method'] === 'jsonp') { - print $_GET['callback'] . '(' . json_encode($obj) . ')'; + if ($_method === 'jsonp') { + print $_callback . '(' . json_encode($obj) . ')'; } else { print json_encode($obj); } } else { $i = 0; - $sql = "SELECT * FROM pods WHERE hidden <> 'yes' ORDER BY uptimelast7 DESC"; + $sql = "SELECT domain,uptimelast7,country FROM pods_apiv1"; $result = pg_query($dbh, $sql); $result || die('Error in SQL query: ' . pg_last_error()); $numrows = pg_num_rows($result); while ($row = pg_fetch_array($result)) { -// $status = $row['status'] === 'up' ? 'Online' : 'Offline'; -// $scheme = $row['secure'] === 'true' ? 'https://' : 'http://'; -// $class = $row['secure'] === 'true' ? 'green' : 'red'; $i++ > 0 && print ','; printf( @@ -87,7 +88,4 @@ EOF; $row['country'] ); } - - pg_free_result($result); - pg_close($dbh); } diff --git a/bower.json b/bower.json index b2d3bdd..a55577f 100644 --- a/bower.json +++ b/bower.json @@ -19,11 +19,12 @@ "tests" ], "dependencies": { - "bootstrap": "v4.0.0-alpha.5", + "bootstrap": "v4.0.0-alpha.6", "jquery-ui": "^1.12.1", "tablesorter": "jquery.tablesorter#^2.28.3", "leaflet": "^1.0.2", "leaflet.markercluster": "^1.0.0", - "facebox": "*" + "facebox": "*", + "chart.js": "^2.4.0" } } diff --git a/cleanup.php b/cleanup.php index 4fdf2b4..f70126c 100644 --- a/cleanup.php +++ b/cleanup.php @@ -4,17 +4,17 @@ require_once __DIR__ . '/config.php'; $dbh = pg_connect("dbname=$pgdb user=$pguser password=$pgpass"); $dbh || die('Error in connection: ' . pg_last_error()); -$sql = "SELECT * FROM pods WHERE hidden <> 'no' AND score < 50 ORDER BY weightedscore"; +$sql = "SELECT domain,masterversion,shortversion,softwarename,monthsmonitored,score,signup,secure,name,country,city,state,lat,long,uptime_alltime,active_users_halfyear,active_users_monthly,service_facebook,service_twitter,service_tumblr,service_wordpress,service_xmpp,latency,date_updated,ipv6,total_users,local_posts,comment_counts,stats_apikey,userrating,sslvalid FROM pods WHERE score < 50 ORDER BY weightedscore"; $result = pg_query($dbh, $sql); $result || die('Error in SQL query: ' . pg_last_error()); - $numrows = pg_num_rows($result); ?> pods that are open for signup now. - +
+
@@ -27,9 +27,8 @@ $numrows = pg_num_rows($result); - - + + @@ -39,29 +38,20 @@ $numrows = pg_num_rows($result); $tt = 0; while ($row = pg_fetch_array($result)) { $tt++; - if ($row['secure'] === 'true') { - $scheme = 'https://'; - $class = 'green'; - $tip = 'This pod uses SSL encryption for traffic.'; - } else { - $scheme = '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', + $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 -20 to +20 this pod is a %6$s right now', $pod_name, $row['monthsmonitored'], - $row['responsetimelast7'], - $row['uptimelast7'], - $row['dateupdated'], + $row['latency'], + $row['uptime_alltime'], + $row['date_updated'], $row['score'] ); - echo ''; + echo ''; if (stristr($row['shortversion'], 'head')) { $version = '.dev'; @@ -74,45 +64,40 @@ $numrows = pg_num_rows($result); $pre = 'This pod runs production code'; } if ($row['shortversion'] === $row['masterversion'] && $row['shortversion'] !== '') { - $classver = 'green'; + $classver = 'text-success'; } elseif ($verdiff > 6) { - $classver = 'red'; + $classver = 'text-warning'; } else { $classver = 'black'; } echo ''; - echo ''; - echo ''; - echo ''; + echo ''; + echo ''; + echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; - if (strpos($row['pingdomurl'], 'pingdom.com')) { - $moreurl = $row['pingdomurl']; - } else { - $moreurl = 'https://api.uptimerobot.com/getMonitors?format=json&customUptimeRatio=7-30-60-90&apiKey=' . $row['pingdomurl']; - } - echo ''; + $moreurl = 'https://api.uptimerobot.com/getMonitors?format=json&noJsonCallback=1&customUptimeRatio=7-30-60-90&apiKey=' . $row['stats_apikey']; + echo ''; echo ''; - echo ''; + echo ''; ?> '; + echo ''; } - pg_free_result($result); - pg_close($dbh); ?>
Pod?Active 1? Posts? Comm?Month? - Sc?Month?Sc? conn? Delete??
' . $row['domain'] . '
?
' . $row['domain'] . '
?
' . $version . '
' . $row['uptimelast7'] . '' . $row['responsetimelast7'] . '' . ($row['signup'] === '1' ? 'Open' : 'Closed') . '' . $row['uptime_alltime'] . '' . $row['latency'] . '' . ($row['signup'] === 't' ? 'Open' : 'Closed') . '' . $row['total_users'] . '' . $row['active_users_halfyear'] . '' . $row['active_users_monthly'] . '' . $row['local_posts'] . '' . $row['comment_counts'] . '' . $row['score'] . '
con info
con info
- - - - warn - delete + + + + +
+ diff --git a/config.php.example b/config.php.example index 97116c4..090caed 100644 --- a/config.php.example +++ b/config.php.example @@ -16,5 +16,7 @@ $pgdb = ''; $adminemail = ''; //admin key for deleting pods, set this as a cookie on your own $adminkey = ''; -//apikey for public api calls -$apikey = ''; +//DNS server for dnssec testing +$dnsserver = ''; +//CA for curl to use - suggest wget http://curl.haxx.se/ca/cacert.pem as they pull from mozilla if you use a system CA then certs like wosign and startssl will be valid but users will be unable to connect to them +$cafullpath = ''; diff --git a/css/dashboard.css b/css/dashboard.css index 126afd9..f631dfe 100644 --- a/css/dashboard.css +++ b/css/dashboard.css @@ -2,9 +2,9 @@ * Base structure */ -/* Move down content because we have a fixed navbar that is 50px tall */ +/* Move down content because we have a fixed navbar that is 54px tall */ body { - padding-top: 50px; + padding-top: 54px; } @@ -13,59 +13,32 @@ body { */ .sub-header { - padding-bottom: 10px; border-bottom: 1px solid #eee; -} - -/* - * Top navigation - * Hide default border to remove 1px line. - */ -.navbar-fixed-top { - border: 0; + padding-bottom: 10px; } /* * Sidebar */ -/* Hide for mobile, show later */ .sidebar { - display: none; + background-color: #f5f5f5; + border-right: 1px solid #eee; + bottom: 0; + display: block; + overflow-x: hidden; + overflow-y: auto; /* Scrollable contents if viewport is shorter than content. */ + padding: 10px; + position: fixed; + top: 54px; + z-index: 1000; } -@media (min-width: 768px) { - .sidebar { - position: fixed; - top: 51px; - bottom: 0; - left: 0; - z-index: 1000; - display: block; - padding: 20px; - overflow-x: hidden; - overflow-y: auto; /* Scrollable contents if viewport is shorter than content. */ - background-color: #f5f5f5; - border-right: 1px solid #eee; - } -} - -/* Sidebar navigation */ -.nav-sidebar { - margin-right: -21px; /* 20px padding + 1px border */ +.sidebar .nav { margin-bottom: 20px; - margin-left: -20px; } -.nav-sidebar > li > a { - padding-right: 20px; - padding-left: 20px; +.sidebar .nav .nav-link { + padding: .3em .7em; } -.nav-sidebar > .active > a, -.nav-sidebar > .active > a:hover, -.nav-sidebar > .active > a:focus { - color: #fff; - background-color: #696969; -} - /* * Main content @@ -74,13 +47,6 @@ body { .main { padding: 20px; } -@media (min-width: 768px) { - .main { - padding-right: 40px; - padding-left: 40px; - } -} - /* * Placeholder dashboard ideas @@ -97,7 +63,6 @@ body { margin-bottom: 20px; } .placeholder img { - display: inline-block; border-radius: 50%; + display: inline-block; } - diff --git a/css/newstyle.css b/css/newstyle.css index 9ab06b3..d8dd01e 100644 --- a/css/newstyle.css +++ b/css/newstyle.css @@ -1,19 +1,9 @@ -.db-wrapper { -vertical-align: top; -} .rating { font-size:9px; } -.content { -margin-left: 2px !important; -width: 99%; -} .tfont { font-size:12px; } -#results { -width: 750px; -} .smlogo { width: 16px; height: 16px; @@ -39,10 +29,6 @@ background: none; .smlogo-xmpp img { vertical-align: unset; } -.morehover { -display: inline-block; -vertical-align: super; -} #map { height: 580px; } .mycluster { width: 35px; @@ -56,4 +42,12 @@ background-size: 25px 37px; .icon { color: red; } - +table { +empty-cells: show; +} +#facebox { +z-index: 1000 !important; +} +#facebox .content { +width: 800px !important; +} diff --git a/db/add.php b/db/add.php index c95fe52..5dbc26a 100644 --- a/db/add.php +++ b/db/add.php @@ -1,54 +1,67 @@ lfile(__DIR__ . $log_dir . '/add.log'); -if (!$_POST['url']) { - $log->lwrite('no url given ' . $_POST['domain']); - die('no url given'); -} -if (!$_POST['email']) { - $log->lwrite('no email given ' . $_POST['domain']); - die('no email given'); -} -if (!$_POST['domain']) { - $log->lwrite('no domain given ' . $_POST['domain']); +$log->lfile(__DIR__ . '/../' . $log_dir . '/add.log'); +if (!($_domain = $_GET['domain'] ?? null)) { + $log->lwrite('no domain given'); die('no pod domain given'); } -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']); - die('API key bad needs to be like m58978-80abdb799f6ccf15e3e3787ee'); -} -require_once __DIR__ . '/../config.php'; +$_email = $_GET['email'] ?? ''; +$_podmin_statement = $_GET['podmin_statement'] ?? ''; +$_podmin_notify = $_GET['podmin_notify'] ?? 0; + +$_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,pingdomurl FROM pods'; +$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'] == $_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']); - die('API key already exists'); + 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'] . '"'); + } } } -//curl the header of pod with and without https $chss = curl_init(); -curl_setopt($chss, CURLOPT_URL, 'https://' . $_POST['domain'] . '/nodeinfo/1.0'); +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); @@ -57,51 +70,35 @@ curl_setopt($chss, CURLOPT_NOBODY, 0); $outputssl = curl_exec($chss); curl_close($chss); -$ch = curl_init(); -curl_setopt($ch, CURLOPT_URL, 'http://' . $_POST['domain'] . '/nodeinfo/1.0'); -curl_setopt($ch, CURLOPT_POST, 0); -curl_setopt($ch, CURLOPT_HEADER, 0); -curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); -curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); -curl_setopt($ch, CURLOPT_NOBODY, 0); -$output = curl_exec($ch); -curl_close($ch); - -if (stristr($outputssl, 'nodeName')) { - $log->lwrite('Your pod has ssl and is valid ' . $_POST['domain']); +if (stristr($outputssl, 'openRegistrations')) { + $log->lwrite('Your pod has ssl and is valid ' . $_domain); echo 'Your pod has ssl and is valid
'; - $valid = 1; -} -if (stristr($output, 'nodeName')) { - $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
'; - $valid = 1; -} -if ($valid == '1') { - $sql = "INSERT INTO pods (domain, pingdomurl, email) VALUES($1, $2, $3)"; - $result = pg_query_params($dbh, $sql, [$_POST['domain'], $_POST['url'], $_POST['email']]); + + $publickey = md5(uniqid($domain, true)); + $sql = 'INSERT INTO pods (domain, email, podmin_statement, podmin_notify, publickey) VALUES ($1, $2, $3, $4, $5)'; + $result = pg_query_params($dbh, $sql, [$_domain, $_email, $_podmin_statement, $_podmin_notify, $publickey]); $result || die('Error in SQL query: ' . pg_last_error()); - $to = $adminemail; - $cc = $_POST['email']; - $subject = 'New pod added to podupti.me '; - $message = sprintf( - "%1\$s\n\nStats Url: %2\$s\n\nPod: %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!'; - $headers = 'From: ' . $_POST['email'] . "\r\nReply-To: " . $_POST['email'] . "\r\nCc: " . $_POST['email'] . "\r\n"; - @mail($to, $subject, $message, $headers); + if ($_email) { + $to = $adminemail; + $subject = 'New pod added to ' . $_SERVER['HTTP_HOST']; + $headers = ['From: ' . $_email, 'Reply-To: ' . $_email, 'Cc: ' . $_email]; - echo 'Data successfully inserted! Your pod will be reviewed and live on the list in a few hours!'; + $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!', + ]; - pg_free_result($result); + @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!'; - pg_close($dbh); } else { - $log->lwrite('Could not validate your pod on http or https, check your setup! ' . $_POST['domain']); - echo 'Could not validate your pod on http or https, check your setup!
Take a look at your /nodeinfo'; + $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(); diff --git a/db/api-more.php b/db/api-more.php index 5892734..3908c49 100644 --- a/db/api-more.php +++ b/db/api-more.php @@ -1,17 +1,24 @@ '; @@ -25,5 +32,3 @@ while ($row = pg_fetch_array($result)) { echo 'Longitude: ' . $row['long'] . '
'; } } -pg_free_result($result); -pg_close($dbh); diff --git a/db/edit.php b/db/edit.php index e2ad70b..b4035a8 100644 --- a/db/edit.php +++ b/db/edit.php @@ -1,73 +1,74 @@ 6 || die('bad token'); +// Required parameters. +($_domain = $_GET['domain'] ?? null) || die('no pod domain given'); +($_token = $_GET['token'] ?? null) || die('no token given'); +strlen($_token) > 6 || die('bad token'); -$domain = $_GET['domain']; +// Other parameters. +$_action = $_GET['action'] ?? ''; +$_weight = $_GET['weight'] ?? 10; +$_email = $_GET['email'] ?? ''; +$_podmin_statement = $_GET['podmin_statement'] ?? ''; +$_podmin_notify = $_GET['podmin_notify'] ?? 0; require_once __DIR__ . '/../config.php'; $dbh = pg_connect("dbname=$pgdb user=$pguser password=$pgpass"); $dbh || die('Error in connection: ' . pg_last_error()); -$sql = "SELECT domain,email,token,tokenexpire,pingdomurl,weight FROM pods WHERE domain = '$domain'"; -$result = pg_query($dbh, $sql); +$sql = 'SELECT domain,email,token,tokenexpire,weight,podmin_statement,podmin_notify FROM pods WHERE domain = $1'; +$result = pg_query_params($dbh, $sql, [$_domain]); $result || die('Error in SQL query: ' . pg_last_error()); 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())) { - die('token expired'); - } - //delete pod - 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 { - echo 'pod removed from DB'; - } + $row['token'] === $_token || die('token mismatch'); + $row['tokenexpire'] >= date('Y-m-d H:i:s') || die('token expired'); + + // Delete and exit. + if ('delete' === $_action) { + $sql = 'DELETE FROM pods WHERE domain = $1'; + $result = pg_query_params($dbh, $sql, [$_domain]); + $result || die('Error in SQL query: ' . pg_last_error()); + + die('pod removed from DB'); } - //save and exit - 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, [$_GET['email'], $_GET['pingdomurl'], $_GET['weight'], $_GET['domain']]); - if (!$result) { - die('Error in SQL query: ' . pg_last_error()); - } - $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); - pg_free_result($result); - pg_close($dbh); + + // Save and exit + if ('save' === $_action) { + $_weight <= 10 || die('10 is max weight'); + + $sql = 'UPDATE pods SET email = $1, weight = $2, podmin_statement = $3, podmin_notify = $4 WHERE domain = $5'; + $result = pg_query_params($dbh, $sql, [$_email, $_weight, $_podmin_statement, $_podmin_notify, $_domain]); + $result || die('Error in SQL query: ' . pg_last_error()); + + $to = $_email; + $headers = ['From: ' . $adminemail, 'Cc: ' . $row['email'], 'Bcc: ' . $adminemail]; + $subject = 'Edit notice from poduptime'; + $message = 'Data for ' . $_domain . ' updated. If it was not you reply and let me know!'; + @mail($to, $subject, $message, implode("\r\n", $headers)); + die('Data saved. Will go into effect on next hourly change'); } - //form - echo 'Authorized to edit ' . $domain . ' until ' . $row['tokenexpire'] . '
'; - echo '
'; - echo ''; - echo ''; - echo ''; - echo ''; - echo 'Stats Key Uptimerobot API key for this monitor
'; - echo 'Email
'; - echo 'Weight This lets you weight your pod lower on the list if you have too much trafic coming in, 10 is the norm use lower to move down the list.
'; - echo ''; - echo '



'; - - echo '
'; - echo ''; - echo ''; - echo ''; - echo 'WARNING: This can not be undone, you will need to add your pod again if you want back on list: '; - echo '



'; + // Forms. + ?> + Authorized to edit until
+
+ + +
+
+
+
+ +
+
+
+
+
+ + + WARNING: This can not be undone, you will need to add your pod again if you want back on list: +
+ 0 || die('domain not found'); + while ($row = pg_fetch_array($result)) { - if ($_POST['email']) { - if ($row['email'] <> $_POST['email']) { - die('email not a match'); - } - $uuid = md5(uniqid($domain, true)); - $expire = date('Y-m-d H:i:s', time() + 2700); - $sql = "UPDATE pods SET token=$1, tokenexpire=$2 WHERE domain = '$domain'"; - $result = pg_query_params($dbh, $sql, [$uuid, $expire]); - if (!$result) { - die('Error in SQL query: ' . pg_last_error()); - } - $to = $_POST['email']; - $subject = 'Temporary edit key for podupti.me'; - $message = 'Link: https://podupti.me/db/edit.php?domain=' . $_POST['domain'] . '&token=' . $uuid . ' Expires: ' . $expire . ' ' . $systemTimeZone . "\n\n"; - $headers = "From: support@diasp.org\r\nBcc: support@diasp.org\r\n"; - @mail($to, $subject, $message, $headers); - echo 'Link sent to your email'; - } elseif (!$_POST['email']) { - $uuid = md5(uniqid($domain, true)); - $expire = date('Y-m-d H:i:s', time() + 9700); - $sql = "UPDATE pods SET token=$1, tokenexpire=$2 WHERE domain = '$domain'"; - $result = pg_query_params($dbh, $sql, [$uuid, $expire]); - if (!$result) { - die('Error in SQL query: ' . pg_last_error()); - } - $to = 'support@diasp.org'; - $subject = 'FORWARD REQUEST: Temporary edit key for podupti.me'; - $message = 'User trying to edit pod without email address. Email found: ' . $row['email'] . ' Link: https://podupti.me/db/edit.php?domain=' . $_POST['domain'] . '&token=' . $uuid . ' Expires: ' . $expire . ' ' . $systemTimeZone . "\n\n"; - $headers = "From: support@diasp.org\r\nBcc: support@diasp.org\r\n"; - @mail($to, $subject, $message, $headers); - echo 'Link sent to administrator to review and verify, if approved they will forward the edit key to you.'; + // Set up common variables. + $uuid = md5(uniqid($_domain, true)); + $link = sprintf('https://%1$s/db/edit.php?domain=%2$s&token=%3$s', $_SERVER['HTTP_HOST'], $_domain, $uuid); + $headers = ['From: ' . $adminemail]; + $message_lines = []; + + if ($_email) { + $row['email'] === $_email || die('email mismatch'); + + $to = $_email; + $subject = 'Temporary edit key for ' . $_SERVER['HTTP_HOST']; + $headers[] = 'Bcc: ' . $adminemail; + $expire = time() + 2700; + $output = 'Link sent to your email'; + } elseif (!$row['email']) { + echo "domain is registered but no email associated, to add an email use the add a pod feature";die; + } else { + $to = $adminemail; + $subject = 'FORWARD REQUEST: Temporary edit key for ' . $_SERVER['HTTP_HOST']; + $message_lines[] = 'User trying to edit pod without email address.'; + $message_lines[] = 'Email found: ' . $row['email']; + $expire = time() + 9700; + $output = 'Link sent to administrator to review and verify, if approved they will forward the edit key to you.'; } - pg_free_result($result); - pg_close($dbh); + + $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()); + + $message_lines[] = 'Link: ' . $link; + $message_lines[] = 'Expires: ' . date('Y-m-d H:i:s T', $expire); + + @mail($to, $subject, implode("\r\n", $message_lines), implode("\r\n", $headers)); + + echo $output; } diff --git a/db/kill.php b/db/kill.php index 4117322..d4f7843 100644 --- a/db/kill.php +++ b/db/kill.php @@ -1,52 +1,47 @@ $_POST['adminkey']) { - die('admin key fail'); - } - //save and exit - if ($_POST['action'] == 'delete') { - $sql = "DELETE from pods WHERE domain = $1"; - $result = pg_query_params($dbh, $sql, [$domain]); - if (!$result) { - die('two Error in SQL query: ' . pg_last_error()); - } - if ($row['email']) { - $to = $row['email']; - $subject = 'Pod deleted from poduptime '; - $message = 'Pod ' . $_POST['domain'] . ' was deleted from podupti.me as it was dead on the list. ' . $_POST['comments'] . " Feel free to add back at any time. \n\n"; - $headers = "From: support@diasp.org\r\nCc:support@diasp.org," . $row['email'] . "\r\n"; - @mail($to, $subject, $message, $headers); + $email = $row['email'] ?? null; + + if ($_action === 'delete') { + $sql = 'DELETE FROM pods WHERE domain = $1'; + $res_delete = pg_query_params($dbh, $sql, [$_domain]); + $res_delete || die('two Error in SQL query: ' . pg_last_error()); + + if ($email) { + $to = $email; + $headers = ['From: ' . $adminemail, 'Cc: ' . $adminemail]; + $subject = 'Pod deleted from ' . $_SERVER['HTTP_HOST']; + $message = 'Pod ' . $_domain . ' was deleted from ' . $_SERVER['HTTP_HOST'] . ' as it was dead on the list. ' . $_comments . ' Feel free to add back at any time.'; + @mail($to, $subject, $message, implode("\r\n", $headers)); } - pg_free_result($result); - pg_close($dbh); - } elseif ($_POST['action'] == 'warn') { - if ($row['email']) { - $to = $row['email']; - $subject = 'Pod removal warning from poduptime '; - $message = 'Pod ' . $_POST['domain'] . ' is on the list to be deleted now because: ' . $_POST['comments'] . ". \n\n Please let me know if you need help fixing before it is removed. \n\n"; - $headers = "From: support@diasp.org\r\nCc:support@diasp.org," . $row['email'] . "\r\n"; - @mail($to, $subject, $message, $headers); + } elseif ($_action === 'warn') { + if ($email) { + $to = $email; + $headers = ['From: ' . $adminemail, 'Cc: ' . $adminemail]; + $subject = 'Pod removal warning from ' . $_SERVER['HTTP_HOST']; + $message = 'Pod ' . $_domain . ' is on the list to be deleted now because: ' . $_comments . ".\r\nPlease let me know if you need help fixing before it is removed."; + @mail($to, $subject, $message, implode("\r\n", $headers)); } } + echo $result; } diff --git a/db/migration00001.sql b/db/migration00001.sql new file mode 100644 index 0000000..07d7e3b --- /dev/null +++ b/db/migration00001.sql @@ -0,0 +1,60 @@ +ALTER TABLE pods ADD podmin_statement text, ADD sslexpire timestamp, ADD dnssec boolean, ADD masterversion text, ADD shortversion text, ADD publickey text, ADD podmin_notify boolean; +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 stats_apikey; +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 latency; + +ALTER TABLE pods RENAME COLUMN dateUpdated TO date_updated; +ALTER TABLE pods RENAME COLUMN dateLaststats TO date_laststats; +ALTER TABLE pods RENAME COLUMN dateCreated TO date_created; + +ALTER TABLE rating_comments RENAME COLUMN date TO date_created; + +ALTER TABLE pods ALTER COLUMN ipv6 TYPE boolean USING ipv6::boolean; +ALTER TABLE pods ALTER hidden DROP DEFAULT; +ALTER TABLE pods ALTER COLUMN hidden TYPE boolean USING hidden::boolean; +ALTER TABLE pods ALTER COLUMN secure TYPE boolean USING secure::boolean; +ALTER TABLE pods ALTER COLUMN signup TYPE boolean USING signup::boolean; +ALTER TABLE pods ALTER COLUMN latency TYPE smallint USING latency::int; + +ALTER TABLE pods ALTER weight SET DEFAULT 10; +ALTER TABLE pods ALTER score SET DEFAULT 50; +ALTER TABLE pods ALTER adminrating SET DEFAULT 0; +ALTER TABLE pods ALTER userrating SET DEFAULT 0; +ALTER TABLE pods ALTER weightedscore SET DEFAULT 0; + +DROP TABLE users; + +CREATE TABLE apikeys ( + key text, + email text, + usage int, + date_created timestamp DEFAULT current_timestamp +); + +CREATE TABLE clicks ( + domain text, + manualclick int, + autoclick int, + date_clicked timestamp DEFAULT current_timestamp +); + +CREATE TABLE checks ( + domain text, + online boolean, + error text, + latency numeric(8,6), + total_users int, + local_posts int, + comment_counts int, + shortversion text, + date_checked timestamp DEFAULT current_timestamp +); + +CREATE TABLE masterversions ( + software text, + version text, + date_checked timestamp DEFAULT current_timestamp +); diff --git a/db/pods_apiv1.sql b/db/pods_apiv1.sql new file mode 100644 index 0000000..457e7db --- /dev/null +++ b/db/pods_apiv1.sql @@ -0,0 +1,27 @@ +DROP TABLE pods_apiv1; +CREATE TABLE pods_apiv1 AS SELECT * FROM pods; + + +ALTER TABLE pods_apiv1 RENAME COLUMN stats_apikey TO pingdomurl; +ALTER TABLE pods_apiv1 RENAME COLUMN service_xmpp TO xmpp; +ALTER TABLE pods_apiv1 RENAME COLUMN uptime_alltime TO uptimelast7; +ALTER TABLE pods_apiv1 RENAME COLUMN latency TO responsetimelast7; + +ALTER TABLE pods_apiv1 RENAME COLUMN date_updated TO dateUpdated; +ALTER TABLE pods_apiv1 RENAME COLUMN date_laststats TO dateLaststats; +ALTER TABLE pods_apiv1 RENAME COLUMN date_created TO dateCreated; + + + +ALTER TABLE pods_apiv1 ALTER COLUMN ipv6 TYPE text USING ipv6::text; +ALTER TABLE pods_apiv1 ALTER hidden DROP DEFAULT; +ALTER TABLE pods_apiv1 ALTER COLUMN hidden TYPE text USING hidden::text; +ALTER TABLE pods_apiv1 ALTER COLUMN secure TYPE text USING secure::text; +ALTER TABLE pods_apiv1 ALTER COLUMN signup TYPE text USING signup::text; +ALTER TABLE pods_apiv1 ALTER COLUMN responsetimelast7 TYPE text USING responsetimelast7::smallint; + +ALTER TABLE pods_apiv1 ADD Hgitdate text, ADD Hgitref text, ADD Hruntime text, ADD Hencoding text, ADD longversion text, ADD ptr text, ADD whois text, ADD postalcode text, ADD connection text, ADD pingdomlast text; + +ALTER TABLE pods_apiv1 DROP podmin_statement, DROP sslexpire, DROP dnssec, DROP publickey, DROP podmin_notify; + +UPDATE pods_apiv1 SET hgitdate = 'unsupported'; diff --git a/db/pull-masterversions.php b/db/pull-masterversions.php new file mode 100644 index 0000000..40534f0 --- /dev/null +++ b/db/pull-masterversions.php @@ -0,0 +1,31 @@ + ['url' => 'https://raw.githubusercontent.com/diaspora/diaspora/master/config/defaults.yml', 'regex' => '/number:.*"(.*)"/'], + 'friendica' => ['url' => 'https://raw.githubusercontent.com/friendica/friendica/master/boot.php', 'regex' => '/define.*\'FRIENDICA_VERSION\'.*\'(.*)\'/'], + 'redmatrix' => ['url' => 'https://raw.githubusercontent.com/redmatrix/hubzilla/master/boot.php', 'regex' => '/define.*\'STD_VERSION\'.*\'(.*)\'/'], + 'socialhome' => ['url' => 'https://raw.githubusercontent.com/jaywink/socialhome/master/bower.json', 'regex' => '/version":.*"(.*)"/'], + 'social-relay' => ['url' => 'https://raw.githubusercontent.com/jaywink/social-relay/master/social_relay/config.py', 'regex' => '/VERSION.*"(.*)"/'], +]; + +foreach ($softwares as $software => $details) { + $mv = curl_init(); + curl_setopt($mv, CURLOPT_URL, $details['url']); + curl_setopt($mv, CURLOPT_CONNECTTIMEOUT, 5); + curl_setopt($mv, CURLOPT_RETURNTRANSFER, 1); + $outputmv = curl_exec($mv); + curl_close($mv); + + if ($masterversion = preg_match($details['regex'], $outputmv, $version) ? $version[1] : '') { + $sql = 'INSERT INTO masterversions (software,version) VALUES ($1,$2)'; + $result = pg_query_params($dbh, $sql, [$software, $masterversion]); + $result || die('Error in SQL query: ' . pg_last_error()); + } + + printf('%s:%s ', $software, $masterversion ?: 'n/a'); +} diff --git a/db/pull.php b/db/pull.php index fe0c73c..64e711d 100644 --- a/db/pull.php +++ b/db/pull.php @@ -1,419 +1,235 @@ '; -} +$debug = isset($_GET['debug']) || (isset($argv) && in_array('debug', $argv, true)); +$newline = PHP_SAPI === 'cli' ? "\n" : '
'; -//get master code version for freindica pods -$mv = curl_init(); -curl_setopt($mv, CURLOPT_URL, 'https://raw.githubusercontent.com/friendica/friendica/master/boot.php'); -curl_setopt($mv, CURLOPT_POST, 0); -curl_setopt($mv, CURLOPT_HEADER, 0); -curl_setopt($mv, CURLOPT_CONNECTTIMEOUT, 5); -curl_setopt($mv, CURLOPT_RETURNTRANSFER, 1); -curl_setopt($mv, CURLOPT_NOBODY, 0); -$outputmv = curl_exec($mv); -curl_close($mv); -preg_match('/FRIENDICA_VERSION\', \'(.*?)\'/', $outputmv, $version); -$fmasterversion = trim($version[1], '"'); -if ($debug) { - echo 'Frendica Masterversion: ' . $fmasterversion . '
'; -} -$dbh = pg_connect("dbname=$pgdb user=$pguser password=$pgpass"); -$dbh2 = pg_connect("dbname=$pgdb user=$pguser password=$pgpass"); -$dbh || die('Error in connection: ' . pg_last_error()); +$_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()); -//foreach pod check it and update db -$domain = isset($_GET['domain']) ? $_GET['domain'] : null; -if ($domain) { - $sql = "SELECT domain,pingdomurl,score,datecreated,weight FROM pods WHERE domain = $1"; - $sleep = '0'; - $result = pg_query_params($dbh, $sql, [$domain]); -} elseif (PHP_SAPI === "cli") { - $sql = 'SELECT domain,pingdomurl,score,datecreated,adminrating,weight FROM pods'; - $sleep = '1'; +if ($_domain) { + $sql = 'SELECT domain,score,date_created,adminrating,weight,hidden,podmin_notify,email FROM pods WHERE domain = $1'; + $result = pg_query_params($dbh, $sql, [$_domain]); +} elseif (PHP_SAPI === 'cli') { + $sql = 'SELECT domain,score,date_created,adminrating,weight,hidden,podmin_notify,email FROM pods'; $result = pg_query($dbh, $sql); } else { die('No valid input'); } $result || die('Error in SQL query1: ' . pg_last_error()); -while ($row = pg_fetch_all($result)) { - $numrows = pg_num_rows($result); - for ($i = 0; $i < $numrows; $i ++) { - $domain = $row[$i]['domain']; - $score = $row[$i]['score']; - $dateadded = $row[$i]['datecreated']; - $admindb = $row[$i]['adminrating']; - $weight = $row[$i]['weight']; - //get ratings - $userrate = 0; - $adminrate = 0; - $userratingavg = []; - $adminratingavg = []; - $userrating = []; - $adminrating = []; - $sqlforr = "SELECT * FROM rating_comments WHERE domain = $1"; - $ratings = pg_query_params($dbh, $sqlforr, [$domain]); - $ratings || die('Error in SQL query2: ' . pg_last_error()); +while ($row = pg_fetch_assoc($result)) { + $domain = $row['domain']; + $score = (int) $row['score']; + $dateadded = $row['date_created']; + $admindb = (int) $row['adminrating']; + $weight = $row['weight']; + $hiddennow = $row['hidden']; + $email = $row['email']; + $notify = $row['podmin_notify']; + $sqlforr = 'SELECT admin,rating FROM rating_comments WHERE domain = $1'; + $ratings = pg_query_params($dbh, $sqlforr, [$domain]); + $ratings || die('Error in SQL query2: ' . pg_last_error()); - $numratings = pg_num_rows($ratings); - while ($myrow = pg_fetch_assoc($ratings)) { - if ($myrow['admin'] == 0) { - $userratingavg[] = $myrow['rating']; - $userrate ++; - } elseif ($myrow['admin'] == 1) { - $adminratingavg[] = $myrow['rating']; - $adminrate ++; - } - } + _debug('Domain', $domain); - if ($userrate > 0) { - $userrating = round(array_sum($userratingavg) / $userrate, 2); - } - if ($adminrate > 0) { - $adminrating = round(array_sum($adminratingavg) / $adminrate, 2); - } - if ($debug) { - echo 'Domain: ' . $domain . '
'; - } - if (!$userrating) { - $userrating = 0; - } - if ($userrating > 10) { - $userrating = 10; - } - if (!$adminrating) { - $adminrating = 0; - } - if ($adminrating > 10) { - $adminrating = 10; - } - if ($admindb == - 1) { - $adminrating = - 1; + $user_ratings = []; + $admin_ratings = []; + while ($rating = pg_fetch_assoc($ratings)) { + if ($rating['admin'] == 0) { + $user_ratings[] = $rating['rating']; + } elseif ($rating['admin'] == 1) { + $admin_ratings[] = $rating['rating']; } - pg_free_result($ratings); - $userrate = 0; - $adminrate = 0; - unset($userratingavg); - unset($adminratingavg); - unset($name); - unset($total_users); - unset($active_users_halfyear); - unset($active_users_monthly); - unset($local_posts); - unset($registrations_open); - unset($comment_counts); - unset($service_facebook); - unset($service_twitter); - unset($service_tumblr); - unset($service_wordpess); - unset($dver); - unset($dverr); - unset($xdver); - unset($xmpp); - unset($softwarename); - unset($outputsslerror); - $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, 9); - curl_setopt($chss, CURLOPT_TIMEOUT, 9); - curl_setopt($chss, CURLOPT_RETURNTRANSFER, 1); - curl_setopt($chss, CURLOPT_NOBODY, 0); - $outputssl = curl_exec($chss); - $outputsslerror = curl_error($chss); - curl_close($chss); + } + $user_rating = empty($user_ratings) ? 0 : max(10, round(array_sum($user_ratings) / count($user_ratings), 2)); + $admin_rating = empty($admin_ratings) ? 0 : max(10, round(array_sum($admin_ratings) / count($admin_ratings), 2)); - $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, 'http://' . $domain . '/nodeinfo/1.0'); - curl_setopt($ch, CURLOPT_POST, 0); - curl_setopt($ch, CURLOPT_HEADER, 0); - curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 9); - curl_setopt($ch, CURLOPT_TIMEOUT, 9); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); - curl_setopt($ch, CURLOPT_NOBODY, 0); - $output = curl_exec($ch); - curl_close($ch); - if ($debug) { - echo 'not-e'; - print $output; - } - if ($debug) { - echo 'e'; - var_dump($outputssl); - } - if (!$output && !$outpulssl && !$domain) { - continue; - echo 'no connection to pod'; - } - if ($outputssl) { - $secure = 'true'; - $outputresults = $outputssl; - } elseif ($output) { - $secure = 'false'; - $outputresults = $output; - } - if (stristr($outputresults, 'openRegistrations')) { - $score = $score + 1; - if ($debug) { - echo 'Secure: ' . $secure . '
'; - } - //get new json from nodeinfo - $jsonssl = json_decode($outputresults); - var_dump($jsonssl); - if ($jsonssl->openRegistrations === true) { - $registrations_open = 1; - } - $xdver = isset($jsonssl->software->version) ? $jsonssl->software->version : 0; - $dverr = explode('-', trim($xdver)); - $dver = $dverr[0]; - if ($debug) { - echo '
Version code: ' . $dver . '
'; - } - if (!$dver) { - $score = $score - 2; - } - $softwarename = isset($jsonssl->software->name) ? $jsonssl->software->name : 'null'; - $name = isset($jsonssl->metadata->nodeName) ? $jsonssl->metadata->nodeName : 'null'; - $total_users = isset($jsonssl->usage->users->total) ? $jsonssl->usage->users->total : 0; - $active_users_halfyear = isset($jsonssl->usage->users->activeHalfyear) ? $jsonssl->usage->users->activeHalfyear : 0; - $active_users_monthly = isset($jsonssl->usage->users->activeMonth) ? $jsonssl->usage->users->activeMonth : 0; - $local_posts = isset($jsonssl->usage->localPosts) ? $jsonssl->usage->localPosts : 0; - $comment_counts = isset($jsonssl->usage->localComments) ? $jsonssl->usage->localComments : 0; - if (array_search('facebook', $jsonssl->services->outbound) !== false) { - $service_facebook = 'true'; - } else { - $service_facebook = 'false'; - } - if (array_search('twitter', $jsonssl->services->outbound) !== false) { - $service_twitter = 'true'; - } else { - $service_twitter = 'false'; - } - if (array_search('tumblr', $jsonssl->services->outbound) !== false) { - $service_tumblr = 'true'; - } else { - $service_tumblr = 'false'; - } - if (array_search('wordpress', $jsonssl->services->outbound) !== false) { - $service_wordpress = 'true'; - } else { - $service_wordpress = 'false'; - } - if ($jsonssl->metadata->xmppChat === true) { - $xmpp = 'true'; - } else { - $xmpp = 'false'; - } - } else { - $secure = 'false'; - $score = $score - 1; - $dver = '.connect error'; - $dverr = 0; - //no diaspora cookie on either, lets set this one as hidden and notify someone its not really a pod - //could also be a ssl pod with a bad cert, I think its ok to call that a dead pod now - } - $signup = $registrations_open; - if ($debug) { - echo '
Signup Open: ' . $signup . '
'; - } - $ip6 = escapeshellcmd('dig +nocmd ' . $domain . ' aaaa +noall +short'); - $ip = escapeshellcmd('dig +nocmd ' . $domain . ' a +noall +short'); - $ip6num = exec($ip6); - $ipnum = exec($ip); - $test = strpos($ip6num, ':'); - if ($test === false) { - $ipv6 = 'no'; - } else { - $ipv6 = 'yes'; - } - if ($debug) { - echo 'IP: ' . $ipnum . '
'; - } - $location = geoip_record_by_name($ipnum); - if ($debug) { - echo ' Location: '; - var_dump($location); - echo '
'; - } - if ($location) { - $ipdata = 'Country: ' . $location['country_name'] . "\n"; - $whois = 'Country: ' . $location['country_name'] . "\n Lat:" . $location['latitude'] . ' Long:' . $location['longitude']; - $country = $location['country_code']; - $city = isset($location->city) ? iconv('UTF-8', 'UTF-8//IGNORE', $location->city) : null; - $state = ''; - $months = 0; - $uptime = 0; - $lat = $location['latitude']; - $long = $location['longitude']; - //if lat and long are just a generic country with no detail lets make some tail up or openmap just stacks them all on top another - if (strlen($lat) < 4) { - $lat = $lat + (rand(1, 15) / 10); - } - if (strlen($long) < 4) { - $long = $long + (rand(1, 15) / 10); - } - } - echo '
'; - $connection = ''; - $pingdomdate = date('Y-m-d H:i:s'); - if (strpos($row[$i]['pingdomurl'], 'pingdom.com')) { - //curl the pingdom page - $ping = curl_init(); - $thismonth = '/' . date('Y') . '/' . date('m'); - curl_setopt($ping, CURLOPT_URL, $row[$i]['pingdomurl'] . $thismonth); - if ($debug) { - echo $row[$i]['pingdomurl'] . $thismonth; - } - curl_setopt($ping, CURLOPT_POST, 0); - curl_setopt($ping, CURLOPT_HEADER, 1); - curl_setopt($ping, CURLOPT_RETURNTRANSFER, 1); - curl_setopt($ping, CURLOPT_CONNECTTIMEOUT, 8); - curl_setopt($ping, CURLOPT_NOBODY, 0); - curl_setopt($ping, CURLOPT_MAXCONNECTS, 5); - curl_setopt($ping, CURLOPT_FOLLOWLOCATION, true); - $pingdom = curl_exec($ping); - $info = curl_getinfo($ping); - curl_close($ping); - if ($debug) { - echo '
Pingdom code: ' . $info['http_code'] . '
'; - } - if ($info['http_code'] == 200) { - //response time - preg_match_all('/

Avg. resp. time this month<\/h3> -

(.*?)\s*(.*?)\s*<\/select/is', $pingdom, $matchhistory); - $implodemonths = implode(' ', $matchhistory[1]); - preg_match_all('/Uptime this month<\/h3>\s*

(.*?)% 200 so stats are gone, lower score - $score = $score - 2; - } - } else { - //do uptimerobot API instead - $ping = curl_init(); - curl_setopt($ping, CURLOPT_URL, 'https://api.uptimerobot.com/getMonitors?format=json&customUptimeRatio=7-30-60-90&responseTimes=1&responseTimesAverage=86400&apiKey=' . $row[$i]['pingdomurl']); - curl_setopt($ping, CURLOPT_POST, 0); - curl_setopt($ping, CURLOPT_HEADER, 0); - curl_setopt($ping, CURLOPT_RETURNTRANSFER, 1); - curl_setopt($ping, CURLOPT_CONNECTTIMEOUT, 8); - curl_setopt($ping, CURLOPT_NOBODY, 0); - curl_setopt($ping, CURLOPT_MAXCONNECTS, 5); - curl_setopt($ping, CURLOPT_FOLLOWLOCATION, true); - $uptimerobot = curl_exec($ping); - curl_close($ping); - $json_encap = 'jsonUptimeRobotApi()'; - $up2 = substr($uptimerobot, strlen($json_encap) - 1, strlen($uptimerobot) - strlen($json_encap)); - $uptr = json_decode($up2); - if ($debug) { - print_r($uptr); - echo '
'; - } - if (!$uptr) { - $score = $score - 2; - } - $responsetime = $uptr->monitors->monitor{'0'}->responsetime{'0'}->value; - $uptimerobotstat = $uptr->stat; - $uptime = $uptr->monitors->monitor{'0'}->alltimeuptimeratio; - $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'; - } - if ($uptr->monitors->monitor{'0'}->status == 0) { - $live = 'Paused'; - } - if ($uptr->monitors->monitor{'0'}->status == 1) { - $live = 'Not Checked Yet'; - } - if ($uptr->monitors->monitor{'0'}->status == 8) { - $live = 'Seems Down'; - } - if ($uptr->monitors->monitor{'0'}->status == 9) { - $live = 'Down'; - } - $pingdomdate = date('Y-m-d H:i:s'); - if ($uptimerobotstat == 'fail' || $live <> 'Up') { - $score = $score - 2; - } - } - if ($softwarename == 'diaspora') { - $masterversion = $dmasterversion; - } elseif ($softwarename == 'friendica') { - $masterversion = $fmasterversion; - } - if ($score > 70) { - $hidden = 'no'; - } else { - $hidden = 'yes'; - } - if ($debug) { - echo 'Hidden: ' . $hidden . '
'; - } - // lets cap the scores or you can go too high or too low to never be effected by them - if ($score > 100) { - $score = 100; - } elseif ($score < 0) { - $score = 0; - } - $weightedscore = ($uptime + $score + ($active_users_monthly / 19999) - ((10 - $weight) * .12)); - //sql it + if ($admindb == -1) { + $admin_rating = -1; + } - $timenow = date('Y-m-d H:i:s'); - $sql = "UPDATE pods SET Hgitdate=$1, Hencoding=$2, secure=$3, hidden=$4, Hruntime=$5, Hgitref=$6, ip=$7, ipv6=$8, monthsmonitored=$9, - uptimelast7=$10, status=$11, dateLaststats=$12, dateUpdated=$13, responsetimelast7=$14, score=$15, adminrating=$16, country=$17, city=$18, - state=$19, lat=$20, long=$21, postalcode='', connection=$22, whois=$23, userrating=$24, longversion=$25, shortversion=$26, - masterversion=$27, signup=$28, total_users=$29, active_users_halfyear=$30, active_users_monthly=$31, local_posts=$32, name=$33, - comment_counts=$35, service_facebook=$36, service_tumblr=$37, service_twitter=$38, service_wordpress=$39, weightedscore=$40, xmpp=$41, softwarename=$42, sslvalid=$43 - WHERE domain=$34"; - $result = pg_query_params($dbh, $sql, [$gitdate, $encoding, $secure, $hidden, $runtime, $gitrev, $ipnum, $ipv6, $months, $uptime, $live, $pingdomdate, $timenow, $responsetime, $score, $adminrating, $country, $city, $state, $lat, $long, $dver, $whois, $userrating, $xdver, $dver, $masterversion, $signup, $total_users, $active_users_halfyear, $active_users_monthly, $local_posts, $name, $domain, $comment_counts, $service_facebook, $service_tumblr, $service_twitter, $service_wordpress, $weightedscore, $xmpp, $softwarename, $outputsslerror]); - $result || die('Error in SQL query3: ' . pg_last_error()); + $chss = curl_init(); + curl_setopt($chss, CURLOPT_URL, 'https://' . $domain . '/nodeinfo/1.0'); + curl_setopt($chss, CURLOPT_CONNECTTIMEOUT, 10); + curl_setopt($chss, CURLOPT_TIMEOUT, 30); + curl_setopt($chss, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($chss, CURLOPT_CERTINFO, 1); + curl_setopt($chss, CURLOPT_CAINFO, $cafullpath); + $outputssl = curl_exec($chss); + $outputsslerror = curl_error($chss); + $info = curl_getinfo($chss, CURLINFO_CERTINFO); + $latency = curl_getinfo($chss, CURLINFO_TOTAL_TIME); + $sslexpire = $info[0]['Expire date'] ?? null; + curl_close($chss); - if ($debug) { - echo '
Score out of 100: ' . $score . '
'; - } - if (!$debug) { - echo 'Success'; - } - //end foreach + _debug('Nodeinfo output', $outputssl, true); + _debug('Nodeinfo output error', $outputsslerror, true); + _debug('Cert expire date', $sslexpire); + _debug('Latency', $latency); + + $jsonssl = json_decode($outputssl); + + $xdver = $jsonssl->software->version ?? 0; + $dverr = explode('-', trim($xdver)); + $shortversion = $dverr[0]; + $signup = ($jsonssl->openRegistrations ?? false) === true; + $softwarename = $jsonssl->software->name ?? 'unknown'; + $name = $jsonssl->metadata->nodeName ?? $softwarename; + $total_users = $jsonssl->usage->users->total ?? 0; + $active_users_halfyear = $jsonssl->usage->users->activeHalfyear ?? 0; + $active_users_monthly = $jsonssl->usage->users->activeMonth ?? 0; + $local_posts = $jsonssl->usage->localPosts ?? 0; + $comment_counts = $jsonssl->usage->localComments ?? 0; + $service_xmpp = ($jsonssl->metadata->xmppChat ?? false) === true; + $service_facebook = false; + $service_twitter = false; + $service_tumblr = false; + $service_wordpress = false; + if (json_last_error() === 0) { + (!$jsonssl->software->version) || $score += 1; + $service_facebook = in_array('facebook', $jsonssl->services->outbound, true); + $service_twitter = in_array('twitter', $jsonssl->services->outbound, true); + $service_tumblr = in_array('tumblr', $jsonssl->services->outbound, true); + $service_wordpress = in_array('wordpress', $jsonssl->services->outbound, true); + } + + if ($jsonssl !== null) { + $status = 'Up'; + $sql_checks = 'INSERT INTO checks (domain, online, latency, total_users, local_posts, comment_counts, shortversion) VALUES ($1, $2, $3, $4, $5, $6, $7)'; + $result_checks = pg_query_params($dbh, $sql_checks, [$domain, 1, $latency, $total_users, $local_posts, $comment_counts, $shortversion]); + $result_checks || die('Error in SQL query: ' . pg_last_error()); + } + + if (!$jsonssl) { + _debug('Connection', 'Can not connect to pod'); + $sql_errors = 'INSERT INTO checks (domain, online, error, latency) VALUES ($1, $2, $3, $4)'; + $result_errors = pg_query_params($dbh, $sql_errors, [$domain, 0, $outputsslerror, $latency]); + $result_errors || die('Error in SQL query: ' . pg_last_error()); + $score -= 1; + $shortversion = '0.error'; + $status = 'Down'; + } + + _debug('Version code', $shortversion); + _debug('Signup Open', $signup); + + $iplookupv4 = []; + $ip = ''; + exec(escapeshellcmd('delv @' . $dnsserver . ' ' . $domain . ' 2>&1'), $iplookupv4); + $dnssec = in_array('; fully validated', $iplookupv4, true) ?? false; + $getaonly = array_values(preg_grep('/\s+IN\s+A\s+.*/', $iplookupv4)); + if ($getaonly) { + preg_match('/A\s(.*)/', $getaonly[0], $aversion); + $ip = trim($aversion[1]) ?? ''; + } + $iplookupv6 = []; + $ipv6 = null; + exec(escapeshellcmd('delv @' . $dnsserver . ' ' . $domain . ' AAAA 2>&1'), $iplookupv6); + $getaaaaonly = array_values(preg_grep('/\s+IN\s+AAAA\s+.*/', $iplookupv6)); + if ($getaaaaonly) { + preg_match('/AAAA\s(.*)/', $getaaaaonly[0], $aaaaversion); + $ipv6 = trim($aaaaversion[1]) ?? ''; + } + $ip || $score -= 2; + + _debug('IPv4', $ip); + _debug('Iplookupv4', $iplookupv4, true); + _debug('IPv6', $ipv6); + _debug('Iplookupv6', $iplookupv6, true); + + $location = geoip_record_by_name($ip); + _debug('Location', $location, true); + $country = !empty($location['country_code']) ? iconv('UTF-8', 'UTF-8//IGNORE', $location['country_code']) : null; + $city = !empty($location['city']) ? iconv('UTF-8', 'UTF-8//IGNORE', $location['city']) : null; + $state = !empty($location['region']) ? iconv('UTF-8', 'UTF-8//IGNORE', $location['region']) : null; + $lat = !empty($location['latitude']) ? $location['latitude'] : 0; + $long = !empty($location['longitude']) ? $location['longitude'] : 0; + + echo $newline; + $statslastdate = date('Y-m-d H:i:s'); + + $diff = (new DateTime())->diff(new DateTime($dateadded)); + $months = $diff->m + ($diff->y * 12); + + $avglatency = 0; + $sqllatency = 'SELECT round(avg(latency) * 1000) AS latency FROM checks WHERE domain = $1'; + $resultlatency = pg_query_params($dbh, $sqllatency, [$domain]); + $resultlatency || die('Error in SQL query resultchecks: ' . pg_last_error()); + $avglatency = pg_fetch_result($resultlatency, 0); + + $uptime = 0; + $sqlonline = 'SELECT avg(online::int) * 100 AS online FROM checks WHERE domain = $1'; + $resultonline = pg_query_params($dbh, $sqlonline, [$domain]); + $resultonline || die('Error in SQL query resultchecks: ' . pg_last_error()); + $uptime = round(pg_fetch_result($resultonline, 0),2); + + _debug('Uptime', $uptime); + + $sqlmasters = 'SELECT version FROM masterversions WHERE software = $1 ORDER BY date_checked LIMIT 1'; + $resultmasters = pg_query_params($dbh, $sqlmasters, [$softwarename]); + $resultmasters || die('Error in SQL query: ' . pg_last_error()); + $masterversion = pg_fetch_result($resultmasters, 0); + + _debug('Masterversion', $masterversion); + + $hidden = $score <= 70; + _debug('Hidden', $hidden ? 'yes' : 'no'); + + if ($hiddennow === 'f' && $hidden && $notify === 't') { + $to = $email; + $headers = ['From: ' . $adminemail, 'Bcc: ' . $adminemail]; + $subject = 'Monitoring notice from poduptime'; + $message = 'Notice for ' . $domain . '. Your score fell to ' . $score . ' and your pod is now marked as hidden.'; + @mail($to, $subject, $message, implode("\r\n", $headers)); + _debug('Mail Notice', 'sent to '.$email); + } + if ($score > 100) { + $score = 100; + } elseif ($score < 0) { + $score = 0; + } + $weightedscore = ($uptime + $score - (10 - $weight)) / 2; + _debug('Weighted Score', $weightedscore); + + $timenow = date('Y-m-d H:i:s'); + $sql_set = 'UPDATE pods SET secure = $2, hidden = $3, ip = $4, ipv6 = $5, monthsmonitored = $6, uptime_alltime = $7, status = $8, date_laststats = $9, date_updated = $10, latency = $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, dnssec = $37, sslexpire = $38 WHERE domain = $1'; + $result_set = pg_query_params($dbh, $sql_set, [$domain, 1, (int) $hidden, $ip, (int) ($ipv6 !== null), $months, $uptime, $status, $statslastdate, $timenow, $avglatency, $score, $admin_rating, $country, $city, $state, $lat, $long, $user_rating, $shortversion, $masterversion, (int) $signup, $total_users, $active_users_halfyear, $active_users_monthly, $local_posts, $name, $comment_counts, (int) $service_facebook, (int) $service_tumblr, (int) $service_twitter, (int) $service_wordpress, $weightedscore, (int) $service_xmpp, $softwarename, $outputsslerror, (int) $dnssec, $sslexpire]); + $result_set || die('Error in SQL query3: ' . pg_last_error()); + + _debug('Score out of 100', $score); + + echo 'Success '.$domain; + + echo $newline; + echo $newline; +} + +/** + * Output a debug message and variable value + * + * @param string $label + * @param mixed $var + * @param bool $dump + */ +function _debug($label, $var = null, $dump = false) { + global $debug, $newline; + + if (!$debug) { + return; + } + + if ($dump || is_array($var)) { + $output = print_r($var, true); + } elseif (is_bool($var)) { + $output = $var ? 'true' : 'false'; + } else { + $output = (string) $var; } + + printf('%s: %s%s', $label, $output, $newline); } -pg_free_result($result); -pg_close($dbh); diff --git a/db/pull.sh b/db/pull.sh index 502887c..7e8c2e5 100755 --- a/db/pull.sh +++ b/db/pull.sh @@ -1,24 +1,31 @@ -WGET="/usr/bin/wget" +SCRIPT_DIR="$( cd "$( dirname "$0" )" && pwd )" +TIME=`date +%k` + if [ -s /tmp/index.google ];then - echo "already running die" + echo "already running die" exit; else - echo "Checking for internet"; + echo "Checking for internet"; fi -$WGET -q --tries=10 --timeout=15 http://www.google.com -O /tmp/index.google -# &> /dev/null +wget -q --tries=2 --timeout=15 http://www.google.com -O /tmp/index.google sleep 2 if [ ! -s /tmp/index.google ];then - echo "could not update pods as no internet" - rm /tmp/index.google + echo "could not update pods as no internet" + rm /tmp/index.google exit; else - echo "Pulling in new pod data"; - cd /var/www/poduptime/db - php pull.php debug=1 - touch last.data - php backup.php - rm /tmp/index.google + cd "$SCRIPT_DIR" + if [ $TIME = 6 ];then + echo "Pulling in master versions"; + php pull-masterversions.php + echo "Update CA" + wget https://curl.haxx.se/ca/cacert.pem -O ../cacert.pem + fi + echo "Pulling in new pod data"; + php pull.php + touch last.data + php backup.php + rm /tmp/index.google fi diff --git a/db/saverating.php b/db/saverating.php index 37c3123..b498f52 100644 --- a/db/saverating.php +++ b/db/saverating.php @@ -1,24 +1,35 @@ 90 AND masterversion = shortversion AND signup = 1 ORDER BY RANDOM() LIMIT 1"; + $sql = 'SELECT domain FROM pods WHERE score > 90 AND masterversion = shortversion AND signup ORDER BY RANDOM() LIMIT 1'; $result = pg_query($dbh, $sql); $result || die('Error in SQL query: ' . pg_last_error()); - $row = pg_fetch_all($result); - $scheme = $row[0]['secure'] === 'true' ? 'https://' : 'http://'; - header('Location:' . $scheme . $row[0]['domain'] . '/users/sign_up'); + + $row = pg_fetch_all($result); + + $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: https://' . $row[0]['domain']); } diff --git a/index.php b/index.php index 8568ed9..60ab996 100644 --- a/index.php +++ b/index.php @@ -1,80 +1,115 @@ - + - Diaspora Pod Uptime Status - Find your new social home on a hosted pod - + Open Source Social Network Pod Uptime Status + - - + + -