From 5d63bcda7edf9ecdb0652aa6b169713bb7a21242 Mon Sep 17 00:00:00 2001 From: David Morley Date: Mon, 26 Mar 2018 08:24:51 -0700 Subject: [PATCH] WIP better delete (#127) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * better delete * enum q * enum * Delete updated (#134) * fix for some really old and incompatable pods - this should be done a… (#131) * fix for some really old and incompatable pods - this should be done at some point also using the data from the checks table * socialhome not pulling version code properly, update location for that * some cleanup and fix the stats that just grind (#133) * some cleanup and fix the stats that just grind * limit the full page for now, so much dead pods * add ganggo version pull * remove unused item * oops * Remove temporary RedBean assignment fix, as corrected upstream by using partial beans. see https://github.com/gabordemooij/redbean/issues/547 * Use enum for pod status. --- api.php | 1 + composer.json | 8 +++-- composer.lock | 66 +++++++++++++++++++++++++++-------- db/add.php | 11 +----- db/api-more.php | 8 ++++- db/edit.php | 70 +++++++++++++++++++++++++++----------- db/gettoken.php | 8 ++--- db/kill.php | 1 + db/migration00003.sql | 11 ++++++ db/pull-masterversions.php | 4 ++- db/pull.php | 25 +++++++++----- db/saverating.php | 1 + db/tables.sql | 2 +- go.php | 1 + index.php | 4 +++ lib/PodStatus.php | 13 +++++++ podstat.php | 38 ++------------------- rate.php | 1 + robots.txt | 7 ++++ show.php | 8 ++--- showfull.php | 7 ++-- showmap.php | 3 +- statsviewjs.php | 1 + 23 files changed, 193 insertions(+), 106 deletions(-) create mode 100644 lib/PodStatus.php diff --git a/api.php b/api.php index 5cde5df..fa31aac 100644 --- a/api.php +++ b/api.php @@ -18,6 +18,7 @@ define('PODUPTIME', microtime(true)); // Set up global DB connection. R::setup("pgsql:host={$pghost};dbname={$pgdb}", $pguser, $pgpass, true); R::testConnection() || die('Error in DB connection'); +R::usePartialBeans(true); if ($_format === 'georss') { echo <<=5.4.0" + }, + "require-dev": { + "phpunit/phpunit": "~4.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "CommerceGuys\\Enum\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Bojan Zivanovic" + } + ], + "description": "A PHP 5.4+ enumeration library.", + "time": "2015-02-27T21:36:56+00:00" + }, { "name": "gabordemooij/redbean", - "version": "v4.3.3", + "version": "v5.0", "source": { "type": "git", "url": "https://github.com/gabordemooij/redbean.git", - "reference": "1c7ec69850e9f7966ff7feb87b01d8f43a9753d3" + "reference": "44229acdf493e2229c1e33e3add211f23c05ee4d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/gabordemooij/redbean/zipball/1c7ec69850e9f7966ff7feb87b01d8f43a9753d3", - "reference": "1c7ec69850e9f7966ff7feb87b01d8f43a9753d3", + "url": "https://api.github.com/repos/gabordemooij/redbean/zipball/44229acdf493e2229c1e33e3add211f23c05ee4d", + "reference": "44229acdf493e2229c1e33e3add211f23c05ee4d", "shasum": "" }, "require": { @@ -46,27 +83,28 @@ "keywords": [ "orm" ], - "time": "2016-10-03 21:25:17" + "time": "2017-10-19T21:38:38+00:00" }, { "name": "jaybizzle/crawler-detect", - "version": "v1.2.36", + "version": "v1.2.61", "source": { "type": "git", "url": "https://github.com/JayBizzle/Crawler-Detect.git", - "reference": "186cdc021f972a7e06963a84ef692d75f5b325c6" + "reference": "9f22764fa72f6a30211fe16cf28a1f43642136de" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/JayBizzle/Crawler-Detect/zipball/186cdc021f972a7e06963a84ef692d75f5b325c6", - "reference": "186cdc021f972a7e06963a84ef692d75f5b325c6", + "url": "https://api.github.com/repos/JayBizzle/Crawler-Detect/zipball/9f22764fa72f6a30211fe16cf28a1f43642136de", + "reference": "9f22764fa72f6a30211fe16cf28a1f43642136de", "shasum": "" }, "require": { "php": ">=5.3.0" }, "require-dev": { - "phpunit/phpunit": "4.*" + "phpunit/phpunit": "4.8.*", + "satooshi/php-coveralls": "1.*" }, "type": "library", "autoload": { @@ -94,7 +132,7 @@ "crawlerdetect", "php crawler detect" ], - "time": "2017-03-03 21:13:00" + "time": "2018-03-19T20:27:17+00:00" }, { "name": "noplanman/xec", @@ -146,7 +184,7 @@ "shell", "timeout" ], - "time": "2017-03-12 19:16:23" + "time": "2017-03-12T19:16:23+00:00" } ], "packages-dev": [], diff --git a/db/add.php b/db/add.php index 6bb5f22..5dd4ee0 100644 --- a/db/add.php +++ b/db/add.php @@ -29,6 +29,7 @@ if (!filter_var(gethostbyname($_domain), FILTER_VALIDATE_IP)) { // Set up global DB connection. R::setup("pgsql:host={$pghost};dbname={$pgdb}", $pguser, $pgpass, true); R::testConnection() || die('Error in DB connection'); +R::usePartialBeans(true); try { $pods = R::getAll(' @@ -57,11 +58,6 @@ foreach ($pods as $pod) { $p['token'] = $uuid; $p['tokenexpire'] = date('Y-m-d H:i:s', $expire); - // @todo Temporary fix! https://github.com/gabordemooij/redbean/issues/547 - foreach ($p->getProperties() as $key => $value) { - $p[$key] = $value; - } - R::store($p); } catch (\RedBeanPHP\RedException $e) { die('Error in SQL query: ' . $e->getMessage()); @@ -110,11 +106,6 @@ if (stristr($outputssl, 'openRegistrations')) { $p['podmin_notify'] = $_podmin_notify; $p['publickey'] = $publickey; - // @todo Temporary fix! https://github.com/gabordemooij/redbean/issues/547 - foreach ($p->getProperties() as $key => $value) { - $p[$key] = $value; - } - R::store($p); } catch (\RedBeanPHP\RedException $e) { die('Error in SQL query: ' . $e->getMessage()); diff --git a/db/api-more.php b/db/api-more.php index f175000..9f79012 100644 --- a/db/api-more.php +++ b/db/api-more.php @@ -18,6 +18,7 @@ define('PODUPTIME', microtime(true)); // Set up global DB connection. R::setup("pgsql:host={$pghost};dbname={$pgdb}", $pguser, $pgpass, true); R::testConnection() || die('Error in DB connection'); +R::usePartialBeans(true); try { $pod = R::getRow(' @@ -32,7 +33,12 @@ try { if ($_format === 'json') { echo json_encode($pod); } else { - echo 'Status: ' . $pod['status'] . '
'; + if ($pod['status'] === PodStatus::Up) { + echo 'Status: Up
'; + } + if ($pod['status'] === PodStatus::Down) { + echo 'Status: Down
'; + } echo 'Last Git Pull: ' . $pod['hgitdate'] . '
'; echo 'Uptime This Month ' . $pod['uptimelast7'] . '
'; echo 'Months Monitored: ' . $pod['monthsmonitored'] . '
'; diff --git a/db/edit.php b/db/edit.php index 5b21f2d..e305c73 100644 --- a/db/edit.php +++ b/db/edit.php @@ -1,6 +1,7 @@ = date('Y-m-d H:i:s') || die('token expired'); // Delete and exit. if ('delete' === $_action) { - R::trash($pod); - die('pod removed from DB'); + try { + $pod['status'] = PodStatus::User_Deleted; + R::store($pod); + } catch (\RedBeanPHP\RedException $e) { + die('Error in SQL query: ' . $e->getMessage()); + } + die('pod deleted'); +} + +// Pause and exit. +if ('pause' === $_action) { + try { + $pod['status'] = PodStatus::Paused; + R::store($pod); + } catch (\RedBeanPHP\RedException $e) { + die('Error in SQL query: ' . $e->getMessage()); + } + die('pod paused'); +} + +// Un-Pause and exit. +if ('unpause' === $_action) { + try { + $pod['status'] = PodStatus::Recheck; + R::store($pod); + } catch (\RedBeanPHP\RedException $e) { + die('Error in SQL query: ' . $e->getMessage()); + } + die('pod unpaused'); } // Save and exit. @@ -49,11 +71,6 @@ if ('save' === $_action) { $pod['podmin_statement'] = $_podmin_statement; $pod['podmin_notify'] = $_podmin_notify; - // @todo Temporary fix for RedBean property handling, hope this gets fixed soon! - foreach ($pod->getProperties() as $key => $value) { - $pod[$key] = $value; - } - R::store($pod); } catch (\RedBeanPHP\RedException $e) { die('Error in SQL query: ' . $e->getMessage()); @@ -69,23 +86,38 @@ if ('save' === $_action) { } // Forms. + ?> Authorized to edit until
-
+ + -
-
+
+



+
Your pod status is currently:
-
-
+ + + + + +
+
+ + + + +
+
+ - WARNING: This can not be undone, you will need to add your pod again if you want back on list: +
getProperties() as $key => $value) { - $pod[$key] = $value; - } - R::store($pod); } catch (\RedBeanPHP\RedException $e) { die('Error in SQL query: ' . $e->getMessage()); diff --git a/db/kill.php b/db/kill.php index 7d75209..8ac8611 100644 --- a/db/kill.php +++ b/db/kill.php @@ -20,6 +20,7 @@ define('PODUPTIME', microtime(true)); // Set up global DB connection. R::setup("pgsql:host={$pghost};dbname={$pgdb}", $pguser, $pgpass, true); R::testConnection() || die('Error in DB connection'); +R::usePartialBeans(true); try { $pod = R::getRow('SELECT id, email FROM pods WHERE domain = ?', [$_domain]); diff --git a/db/migration00003.sql b/db/migration00003.sql index 248a61d..8a36c02 100644 --- a/db/migration00003.sql +++ b/db/migration00003.sql @@ -1,2 +1,13 @@ CREATE INDEX idx_clicks ON clicks (domain); +UPDATE pods SET status=0 WHERE status = 'Down'; +UPDATE pods SET status=1 WHERE status = 'Up'; +/* +0 = Down +1 = Up +2 = Recheck +3 = Paused +4 = System Deleted +5 = User Deleted +*/ +ALTER TABLE pods ALTER COLUMN status TYPE smallint USING status::smallint; diff --git a/db/pull-masterversions.php b/db/pull-masterversions.php index e8181b3..662edc3 100644 --- a/db/pull-masterversions.php +++ b/db/pull-masterversions.php @@ -11,13 +11,15 @@ define('PODUPTIME', microtime(true)); // Set up global DB connection. R::setup("pgsql:host={$pghost};dbname={$pgdb}", $pguser, $pgpass, true); R::testConnection() || die('Error in DB connection'); +R::usePartialBeans(true); $softwares = [ 'diaspora' => ['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":.*"(.*)"/'], + 'socialhome' => ['url' => 'https://raw.githubusercontent.com/jaywink/socialhome/master/socialhome/__init__.py', 'regex' => '/__version__ =.*"(.*)"/'], 'social-relay' => ['url' => 'https://raw.githubusercontent.com/jaywink/social-relay/master/social_relay/config.py', 'regex' => '/VERSION.*"(.*)"/'], + 'ganggo' => ['url' => 'https://raw.githubusercontent.com/ganggo/ganggo/master/package.json', 'regex' => '/"version": "(.*)"/'], ]; foreach ($softwares as $software => $details) { diff --git a/db/pull.php b/db/pull.php index 035fb82..01b0266 100644 --- a/db/pull.php +++ b/db/pull.php @@ -19,10 +19,11 @@ define('PODUPTIME', microtime(true)); // Set up global DB connection. R::setup("pgsql:host={$pghost};dbname={$pgdb}", $pguser, $pgpass, true); R::testConnection() || die('Error in DB connection'); +R::usePartialBeans(true); try { $sql = ' - SELECT domain, score, date_created, adminrating, weight, hidden, podmin_notify, email + SELECT domain, score, date_created, adminrating, weight, hidden, podmin_notify, email, masterversion, shortversion FROM pods '; @@ -31,7 +32,8 @@ try { $sql .= ' WHERE domain = ?'; $pods = R::getAll($sql, [$_domain]); } elseif (PHP_SAPI === 'cli') { - $pods = R::getAll($sql); + $sql .= ' WHERE status < ?'; + $pods = R::getAll($sql, [PodStatus::Paused]); } } catch (\RedBeanPHP\RedException $e) { die('Error in SQL query: ' . $e->getMessage()); @@ -46,6 +48,8 @@ foreach ($pods as $pod) { $hiddennow = $pod['hidden']; $email = $pod['email']; $notify = $pod['podmin_notify']; + $masterv = $pod['masterversion']; + $shortv = $pod['shortversion']; try { $ratings = R::getAll(' @@ -125,7 +129,7 @@ foreach ($pods as $pod) { } if ($jsonssl !== null) { - $status = 'Up'; + $status = PodStatus::Up; try { $c = R::dispense('checks'); @@ -158,7 +162,7 @@ foreach ($pods as $pod) { $score -= 1; $shortversion = '0.error'; - $status = 'Down'; + $status = PodStatus::Down; } _debug('Version code', $shortversion); @@ -228,6 +232,11 @@ foreach ($pods as $pod) { } _debug('Masterversion', $masterversion); + $masterversioncheck = explode('.',$masterversion); + $shortversioncheck = explode('.',$shortversion); + if (($masterversioncheck[1] - $shortversioncheck[1]) > 1) { + _debug('Outdated', 'Yes');$score -= 2; + } $hidden = $score <= 70; _debug('Hidden', $hidden ? 'yes' : 'no'); @@ -244,6 +253,9 @@ foreach ($pods as $pod) { $score = 100; } elseif ($score < 0) { $score = 0; + if ($masterv <> $shortv) { + $status = PodStatus::System_Deleted; + } } _debug('Score', $score); $weightedscore = ($uptime + $score - (10 - $weight)) / 2; @@ -288,11 +300,6 @@ foreach ($pods as $pod) { $p['sslvalid'] = $outputsslerror; $p['dnssec'] = $dnssec; $p['sslexpire'] = $sslexpire; - - // @todo Temporary fix! https://github.com/gabordemooij/redbean/issues/547 - foreach ($p->getProperties() as $key => $value) { - $p[$key] = $value; - } R::store($p); } catch (\RedBeanPHP\RedException $e) { diff --git a/db/saverating.php b/db/saverating.php index 785f33f..9610db6 100644 --- a/db/saverating.php +++ b/db/saverating.php @@ -20,6 +20,7 @@ define('PODUPTIME', microtime(true)); // Set up global DB connection. R::setup("pgsql:host={$pghost};dbname={$pgdb}", $pguser, $pgpass, true); R::testConnection() || die('Error in DB connection'); +R::usePartialBeans(true); try { $r = R::dispense('rating_comments'); diff --git a/db/tables.sql b/db/tables.sql index fbc8438..59c72da 100644 --- a/db/tables.sql +++ b/db/tables.sql @@ -27,7 +27,7 @@ CREATE TABLE pods ( active_users_monthly int, local_posts int, uptime_alltime numeric(5,2), - status text, + status smallint, latency smallint, service_facebook boolean, service_twitter boolean, diff --git a/go.php b/go.php index db56d5f..d998d3d 100644 --- a/go.php +++ b/go.php @@ -14,6 +14,7 @@ define('PODUPTIME', microtime(true)); // Set up global DB connection. R::setup("pgsql:host={$pghost};dbname={$pgdb}", $pguser, $pgpass, true); R::testConnection() || die('Error in DB connection'); +R::usePartialBeans(true); try { if ($_domain) { diff --git a/index.php b/index.php index 2971366..4a40fcb 100644 --- a/index.php +++ b/index.php @@ -10,6 +10,7 @@ define('PODUPTIME', microtime(true)); // Set up global DB connection. R::setup("pgsql:host={$pghost};dbname={$pgdb}", $pguser, $pgpass, true); R::testConnection() || die('Error in DB connection'); +R::usePartialBeans(true); // CloudFlare country code pull. $country_code = $_SERVER['HTTP_CF_IPCOUNTRY'] ?? ''; @@ -21,6 +22,7 @@ $cleanup = isset($_GET['cleanup']); $statsview = isset($_GET['statsview']); $podmin = isset($_GET['podmin']); $podminedit = isset($_GET['podminedit']); +$edit = isset($_GET['edit']); $simpleview = !($detailedview || $mapview || $cleanup || $podmin || $podminedit || $statsview); ?> @@ -129,6 +131,8 @@ $navs = [ include_once __DIR__ . '/podmin.php'; } elseif ($podminedit) { include_once __DIR__ . '/podminedit.php'; + } elseif ($edit) { + include_once __DIR__ . '/db/edit.php'; } elseif ($cleanup) { include_once __DIR__ . '/cleanup.php'; } else { diff --git a/lib/PodStatus.php b/lib/PodStatus.php new file mode 100644 index 0000000..2a23562 --- /dev/null +++ b/lib/PodStatus.php @@ -0,0 +1,13 @@ +, - label: 'Manual Clicks', - fill: false, - yAxisID: "r2", - borderColor: "#8A2BE2", - backgroundColor: "#8A2BE2", - borderWidth: 4, - pointHoverRadius: 6, - pointStyle: 'rect', - }, - { - data: , - label: 'Auto Clicks', - fill: false, - yAxisID: "r2", - borderColor: "#FFA07A", - backgroundColor: "#FFA07A", - borderWidth: 4, - pointHoverRadius: 6, - pointStyle: 'rect', } ] }, diff --git a/rate.php b/rate.php index 24485fa..4af1f47 100644 --- a/rate.php +++ b/rate.php @@ -12,6 +12,7 @@ define('PODUPTIME', microtime(true)); // Set up global DB connection. R::setup("pgsql:host={$pghost};dbname={$pgdb}", $pguser, $pgpass, true); R::testConnection() || die('Error in DB connection'); +R::usePartialBeans(true); ?> diff --git a/robots.txt b/robots.txt index c2a49f4..e484d47 100644 --- a/robots.txt +++ b/robots.txt @@ -1,2 +1,9 @@ User-agent: * Allow: / + +User-agent: * +Disallow: /podstat.php + +User-agent: SemrushBot +Disallow: /podstat.php + diff --git a/show.php b/show.php index 3c6e702..9ed97da 100644 --- a/show.php +++ b/show.php @@ -9,9 +9,10 @@ try { SELECT domain, masterversion, shortversion, softwarename, monthsmonitored, podmin_statement, score, signup, name, country, city, state, uptime_alltime, active_users_halfyear, active_users_monthly, service_facebook, service_twitter, service_tumblr, service_wordpress, service_xmpp FROM pods WHERE NOT hidden + AND status = ? AND signup ORDER BY weightedscore DESC - '); + ', [PodStatus::Up]); } catch (\RedBeanPHP\RedException $e) { die('Error in SQL query: ' . $e->getMessage()); } @@ -39,10 +40,9 @@ try { $verdiff = str_replace('.', '', $pod['masterversion']) - str_replace('.', '', $pod['shortversion']); $pod_name = htmlentities($pod['name'], ENT_QUOTES); $tip = sprintf( - 'Uptime %2$s%% over %1$s months, score is %3$s out of 100.', + 'Uptime %2$s%% over %1$s months.', $pod['monthsmonitored'], - $pod['uptime_alltime'], - $pod['score'] + $pod['uptime_alltime'] ); echo '
' . $pod['domain'] . '
'; diff --git a/showfull.php b/showfull.php index 7b3c9a8..f87eae6 100644 --- a/showfull.php +++ b/showfull.php @@ -6,8 +6,9 @@ defined('PODUPTIME') || die(); try { $pods = R::getAll(' - SELECT domain, dnssec, podmin_statement, sslexpire, masterversion, shortversion, softwarename, monthsmonitored, score, signup, 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 + SELECT domain, dnssec, podmin_statement, sslexpire, masterversion, shortversion, softwarename, monthsmonitored, score, signup, 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, status FROM pods + WHERE uptime_alltime > 50 ORDER BY weightedscore DESC '); } catch (\RedBeanPHP\RedException $e) { @@ -46,9 +47,9 @@ try { ' . $pod['domain'] . ' 🔒'; + echo '' . $pod['domain'] . ''; if ($pod['shortversion'] > $pod['masterversion']) { $version = $pod['shortversion']; diff --git a/showmap.php b/showmap.php index 6ad73ca..bb19682 100644 --- a/showmap.php +++ b/showmap.php @@ -11,7 +11,8 @@ try { WHERE NOT hidden AND lat != '' AND long != '' - "); + AND status < ? + ", [PodStatus::Recheck]); } catch (\RedBeanPHP\RedException $e) { die('Error in SQL query: ' . $e->getMessage()); } diff --git a/statsviewjs.php b/statsviewjs.php index 17188c5..4b23b0e 100644 --- a/statsviewjs.php +++ b/statsviewjs.php @@ -12,6 +12,7 @@ try { sum(total_users) AS users, round(avg(uptime_alltime),2) AS uptime FROM pods + WHERE NOT hidden GROUP BY softwarename '); } catch (\RedBeanPHP\RedException $e) { -- GitLab