Verified Commit f095b907 authored by Armando Lüscher's avatar Armando Lüscher

Merge branch 'develop' into contrib

parents 9c1fa59d 09481a05
# Changelog
The format is based on [Keep a Changelog] and this project adheres to [Semantic Versioning].
## [Unreleased]
### Added
- Added bootstrapping to simplify initialisation of config and database
- Config syntax has changed to array style (#155)
- Added `pghost` config to set database port
### Changed
- Introduce proper changelog format (#189)
- Moved DB migration scripts into `db` folder
### Deprecated
### Removed
### Fixed
### Security
## [2.3.1] - 2018-08-05
### Added
- Podmins can link directly to their pod via `https://podupti.me/domain.name` for stats and to allow users to rate easier
- Wizard to help you filter the columns to what you need (#145)
### Changed
- Now one table with a basic default view you can customize (#171)
## [2.3.0] - 2018-07-19
:exclamation: DB migrations required! (see [SQL migration script][2.2.0-sql-migration])
### Added
- Language is detected based on your homepage, edit your homepage to non-en if that is what you use
- Add development and release dates to `masterversions` table (#143)
- Store full country name, store days monitored each pod (#150)
- Store detectedlanguage (#144)
- Show version and update in full view cleaner (#143)
- Filter and search on the columns of data (#147)
- Paginate the results so they fit per page (#147)
### Changed
- Podmins can no longer access `db/pull.php` to test their pod, they can however get to a debug screen from the edit pod area
- Edit will send to email on file and be less delay, runner of site does not really have any way to verify email address
- Default new pods to `UP` to be checked
- Use the git API for release versions, check development releases on pods (#143)
- Move from [bower to yarn](https://bower.io/blog/2017/how-to-migrate-away-from-bower/) for packages
- Move to PHP 7.2 with strict typing
- Move to [Eslint compliance](https://eslint.org/docs/rules/)
- Move to [PSR-2 compliance](https://www.php-fig.org/psr/psr-2/)
- NOTE `config.php.example` change to full paths for 2 items!
- Show time as human readable everywhere (#150)
### Removed
- Unused `hidden` and `secure` columns (#140, #141)
### Fixed
- Rename table `rating_comments` to `ratingcomments` for redbean support (#146)
### Security
- Forbid access to files that should be CLI only (#152)
## [2.2.0] - 2018-05-12
:exclamation: DB migrations required! (see [SQL migration script][2.2.0-sql-migration])
### Added
- Podmins can now pause/unpause or delete from podmin area
- Graph on user growth on the network
- Add monthly stats table
### Changed
- `go.php` auto select picks a more stable pod than before
- Make map prettier
- Use lines on tables to make them more readable
- Don't delete dead pods, keep them and data for history hide them for users
- Put daily tasks in the `pull.sh` and run each day
- Update status to 1-5 rather than text
### Fixed
- Fix ipv6
[2.2.0-sql-migration]: https://git.feneas.org/diasporg/Poduptime/blob/master/db/migrations/2.1.4-2.2.0.sql
[2.3.0-sql-migration]: https://git.feneas.org/diasporg/Poduptime/blob/master/db/migrations/2.2.0-2.3.0.sql
[Unreleased]: https://git.feneas.org/diasporg/Poduptime/compare/master...develop
[2.3.1]: https://git.feneas.org/diasporg/Poduptime/compare/2.3.0...2.3.1
[2.3.0]: https://git.feneas.org/diasporg/Poduptime/compare/v2.2.0...2.3.0
[2.2.0]: https://git.feneas.org/diasporg/Poduptime/compare/2.1.3...v2.2.0
[Keep a Changelog]: https://keepachangelog.com/
[Semantic Versioning]: https://semver.org/
# 2.3.x
## End Users
* Now one table with a basic default view you can customize https://git.feneas.org/diasporg/Poduptime/issues/171
* Wizard to help you filter the columns to what you need https://git.feneas.org/diasporg/Poduptime/issues/145
## Podmins
* Can link directly to your pod via https://podupti.me/domain.name for stats and to allow users to rate easier
# 2.3.0
## Podmins
* Can no longer access db/pull.php to test their pod, they can however get to a debug screen from the edit pod area
* Language is detected based on your homepage, edit your homepage to non-en if that is what you use
* Edit will send to email on file and be less delay, runner of site does not really have anyway to verify email address
## DB
* Add development and release dates to masterversions table https://git.feneas.org/diasporg/Poduptime/issues/143
* Store full country name, store days monitored each pod https://git.feneas.org/diasporg/Poduptime/issues/150
* Store detectedlanguage https://git.feneas.org/diasporg/Poduptime/issues/144
* DB migrations see db/version.md
* rename table rating_comments to ratingcomments for redbean support https://git.feneas.org/diasporg/Poduptime/issues/146
* Default new pods to UP to be checked
* Remove unused hidden and secure columns https://git.feneas.org/diasporg/Poduptime/issues/141 https://git.feneas.org/diasporg/Poduptime/issues/140
## Cleanup
* Use the git API for release versions, check development releases on pods https://git.feneas.org/diasporg/Poduptime/issues/143
* Forbid access to files that should be cli only https://git.feneas.org/diasporg/Poduptime/issues/152
* Move from bower to yarn for packages https://bower.io/blog/2017/how-to-migrate-away-from-bower/
* Move to PHP 7.2 with declare(strict_types=1);
* Move to Eslint compliance https://eslint.org/docs/rules/
* Move to PSR-2 compliance https://www.php-fig.org/psr/psr-2/
* NOTE config.php.example change to full paths for 2 items!
## End Users
* Show version and update in full view cleaner https://git.feneas.org/diasporg/Poduptime/issues/143
* Filter and search on the columns of data https://git.feneas.org/diasporg/Poduptime/issues/147
* Paginate the results so they fit per page https://git.feneas.org/diasporg/Poduptime/issues/147
* Show time as human readable everywhere https://git.feneas.org/diasporg/Poduptime/issues/150
# 2.2.0
## Podmins
* Can now pause/unpause or delete from podmin area
## End Users
* go.php auto select picks a more stable pod than before
* Graph on user growth on the network
* Make map prettier
* Use lines on tables to make them more readable
## Cleanup
* Don't delete dead pods, keep them and data for history hide them for users
* Put daily tasks in the pull.sh and run each day
* Fix ipv6
## DB
* Add monthly stats table
* Update status to 1-5 rather than text
* Two migrations for this version update see db/version.md
......@@ -15,15 +15,7 @@ $_format = $_GET['format'] ?? '';
$_method = $_GET['method'] ?? '';
$_callback = $_GET['callback'] ?? '';
require_once __DIR__ . '/vendor/autoload.php';
require_once __DIR__ . '/config.php';
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);
require_once __DIR__ . '/boot.php';
if ($_format === 'georss') {
echo <<<EOF
......
<?php
/**
* Boot the application, loading config and database connection.
*/
declare(strict_types=1);
use RedBeanPHP\R;
/**
* Helper to get config values.
*
* @param null|string $param
* @param null|mixed $default
*
* @return mixed|null
*/
function c(string $param = null, $default = null)
{
static $config;
if ($config === null) {
$config = require __DIR__ . '/config.php';
is_array($config) || die('Invalid config format.');
}
if ($param === null) {
return $config;
}
if (array_key_exists($param, $config)) {
return $config[$param];
}
return $default;
}
define('PODUPTIME', microtime(true));
require_once __DIR__ . '/vendor/autoload.php';
// Set up global DB connection.
R::setup(
sprintf(
'pgsql:host=%s;port=%d;dbname=%s',
c('pghost'),
c('pgport', 5432),
c('pgdb')
),
c('pguser'),
c('pgpass'),
true
);
R::testConnection() || die('Error in DB connection');
R::usePartialBeans(true);
......@@ -4,38 +4,43 @@
* Config for Poduptime.
*/
//backup directory - full dir path
$backup_dir = __DIR__ . '/backup';
return [
//backup directory - full dir path
'backup_dir' => __DIR__ . '/backup',
//log directory - full dir path
$log_dir = __DIR__ . '/log';
//log directory - full dir path
'log_dir' => __DIR__ . '/log',
//location of pg dump - full dir path
$pg_dump_dir = '/usr/bin';
//location of pg dump - full dir path
'pg_dump_dir' => '/usr/bin',
//db host
$pghost = 'localhost';
//db host
'pghost' => 'localhost',
//db username
$pguser = '';
//db port
'pgport' => 5432,
//db password
$pgpass = '';
//db username
'pguser' => '',
//db name
$pgdb = '';
//db password
'pgpass' => '',
//admin email for forms
$adminemail = '';
//db name
'pgdb' => '',
//DNS server for dnssec testing. 1.1.1.1 tests the best
$dnsserver = '';
//admin email for forms
'adminemail' => '',
//CA for curl to use - full file path (pull.sh will update this monthly)
$cafullpath = '';
//DNS server for dnssec testing. 1.1.1.1 tests the best
'dnsserver' => '',
//Mapbox.com API key. https://www.mapbox.com/help/how-access-tokens-work/
$mapboxkey = '';
//CA for curl to use - full file path (pull.sh will update this monthly)
'cafullpath' => '',
//Geolite2-city database file in mmdb format - full file path (pull.sh will update this monthly)
$geoip2db = '';
//Mapbox.com API key. https://www.mapbox.com/help/how-access-tokens-work/
'mapboxkey' => '',
//Geolite2-city database file in mmdb format - full file path (pull.sh will update this monthly)
'geoip2db' => '',
];
......@@ -8,21 +8,9 @@ declare(strict_types=1);
use RedBeanPHP\R;
require_once __DIR__ . '/../vendor/autoload.php';
require_once __DIR__ . '/../config.php';
require_once __DIR__ . '/../boot.php';
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 (!($_domain = $_GET['domain'] ?? null)) {
die('no pod domain given');
}
($_domain = $_GET['domain'] ?? null) || die('no pod domain given');
// Other parameters.
$_email = $_GET['email'] ?? '';
......@@ -43,6 +31,7 @@ try {
die('Error in SQL query: ' . $e->getMessage());
}
$stop = false;
foreach ($pods as $pod) {
if ($pod['domain'] === $_domain) {
if ($pod['email']) {
......@@ -85,12 +74,11 @@ foreach ($pods as $pod) {
</form>
EOF;
$stop = 1;
$stop = true;
}
}
if (!$stop) {
$link = 'https://' . $_domain . '/nodeinfo/1.0';
if ($infos = file_get_contents('https://' . $_domain . '/.well-known/nodeinfo')) {
$info = json_decode($infos, true);
......@@ -113,12 +101,12 @@ if (!$stop) {
$publickey = md5(uniqid($_domain, true));
try {
$p = R::dispense('pods');
$p['domain'] = $_domain;
$p['email'] = $_email;
$p = R::dispense('pods');
$p['domain'] = $_domain;
$p['email'] = $_email;
$p['podmin_statement'] = $_podmin_statement;
$p['podmin_notify'] = $_podmin_notify;
$p['publickey'] = $publickey;
$p['podmin_notify'] = $_podmin_notify;
$p['publickey'] = $publickey;
R::store($p);
} catch (\RedBeanPHP\RedException $e) {
......@@ -126,7 +114,7 @@ if (!$stop) {
}
if ($_email) {
$to = $adminemail;
$to = c('adminemail');
$subject = 'New pod added to ' . $_SERVER['HTTP_HOST'];
$headers = ['From: ' . $_email, 'Reply-To: ' . $_email, 'Cc: ' . $_email];
......@@ -144,4 +132,4 @@ if (!$stop) {
} else {
echo 'Could not validate your pod, check your setup!<br>Take a look at <a href="' . $link . '">your /nodeinfo</a>';
}
}
\ No newline at end of file
}
......@@ -15,15 +15,7 @@ use RedBeanPHP\R;
// Other parameters.
$_format = $_GET['format'] ?? '';
require_once __DIR__ . '/../vendor/autoload.php';
require_once __DIR__ . '/../config.php';
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);
require_once __DIR__ . '/../boot.php';
try {
$pod = R::getRow('
......
......@@ -11,19 +11,19 @@ if (PHP_SAPI !== 'cli') {
exit;
}
require_once __DIR__ . '/../config.php';
$c = require __DIR__ . '/../config.php';
$keep = (60 * 60 * 6) * 1;
$dump_date = date('Ymd_Hs');
$file_name = $backup_dir . '/dump_' . $dump_date . '.sql';
system("export PGPASSWORD=$pgpass && $pg_dump_dir/pg_dump --clean --format=tar --username=$pguser $pgdb >> $file_name");
echo "pg backup of $pgdb made";
$dirh = dir($backup_dir);
$file_name = "{$c['backup_dir']}/dump_{$dump_date}.sql";
system("export PGPASSWORD={$c['pgpass']} && {$c['pg_dump_dir']}/pg_dump --clean --format=tar --username={$c['pguser']} {$c['pgdb']} >> {$file_name}");
echo "pg backup of {$c['pgdb']} made";
$dirh = dir($c['backup_dir']);
while ($entry = $dirh->read()) {
$old_file_time = (date('U') - $keep);
$file_created = filectime("$backup_dir/$entry");
$old_file_time = date('U') - $keep;
$file_created = filectime("{$c['backup_dir']}/{$entry}");
if ($file_created < $old_file_time && !is_dir($entry)) {
if (unlink("$backup_dir/$entry")) {
if (unlink("{$c['backup_dir']}/{$entry}")) {
echo 'Cleaned up old backups';
}
}
......
......@@ -22,13 +22,7 @@ $_email = $_GET['email'] ?? '';
$_podmin_statement = $_GET['podmin_statement'] ?? '';
$_podmin_notify = $_GET['podmin_notify'] ?? 0;
require_once __DIR__ . '/../vendor/autoload.php';
require_once __DIR__ . '/../config.php';
// 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);
require_once __DIR__ . '/../boot.php';
try {
$pod = R::findOne('pods', 'domain = ?', [$_domain]);
......@@ -89,7 +83,7 @@ if ('save' === $_action) {
}
$to = $_email;
$headers = ['From: ' . $adminemail, 'Cc: ' . $pod['email'], 'Bcc: ' . $adminemail];
$headers = ['From: ' . c('adminemail'), 'Cc: ' . $pod['email'], 'Bcc: ' . c('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));
......@@ -149,4 +143,4 @@ Authorized to edit <b><?php echo $_domain; ?></b> for <?php echo (new Carbon($po
<input value="debug" type="button" aria-describedby="debug" data-featherlight="/db/pull.php?debug=1&nowrite=1&domain=<?php echo $_domain; ?>"/>
<small id="debug" class="form-text text-muted">
Do a debug pull of your pod. Won't update the database just show what it would look like on a pass.
</small>
\ No newline at end of file
</small>
......@@ -14,14 +14,7 @@ use RedBeanPHP\R;
// Other parameters.
$_email = $_GET['email'] ?? '';
require_once __DIR__ . '/../vendor/autoload.php';
require_once __DIR__ . '/../config.php';
// 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);
require_once __DIR__ . '/../boot.php';
try {
$pod = R::findOne('pods', 'domain = ?', [$_domain]);
......@@ -33,7 +26,7 @@ try {
// Set up common variables.
$uuid = md5(uniqid($_domain, true));
$link = sprintf('https://%1$s/?edit&domain=%2$s&token=%3$s', $_SERVER['HTTP_HOST'], $_domain, $uuid);
$headers = ['From: ' . $adminemail];
$headers = ['From: ' . c('adminemail')];
$message_lines = [];
if ($_email) {
......@@ -41,7 +34,7 @@ if ($_email) {
$to = $_email;
$subject = 'Temporary edit key for ' . $_SERVER['HTTP_HOST'];
$headers[] = 'Bcc: ' . $adminemail;
$headers[] = 'Bcc: ' . c('adminemail');
$expire = time() + 8700;
$output = 'Link sent to your email.';
} elseif (!$pod['email']) {
......@@ -49,7 +42,7 @@ if ($_email) {
} else {
$to = $pod['email'];
$subject = 'Temporary edit key for ' . $_SERVER['HTTP_HOST'];
$headers[] = 'Bcc: ' . $adminemail;
$headers[] = 'Bcc: ' . c('adminemail');
$message_lines[] = 'Looks like you did not enter your email address, be sure to update it if you forgot the one we have for you.';
$message_lines[] = 'Email found: ' . $pod['email'];
$expire = time() + 8700;
......
# Migrations
## New install
When setting up a new install, import [`db/tables.sql`][tables.sql] and do not perform any migrations!
## Migrating
If you are upgrading your existing installation, execute the necessary migrations scripts found in [`db/migrations`][migrations].
## API v1
To support the original API v1 you should import [`db/pods_apiv1.sql`][pods_apiv1.sql] into your DB as often as you want your API updated.
[tables.sql] https://git.feneas.org/diasporg/Poduptime/blob/master/db/tables.sql
[migrations] https://git.feneas.org/diasporg/Poduptime/tree/master/db/migrations
[pods_apiv1.sql] https://git.feneas.org/diasporg/Poduptime/blob/master/db/pods_apiv1.sql
......@@ -13,15 +13,7 @@ if (PHP_SAPI !== 'cli') {
use RedBeanPHP\R;
require_once __DIR__ . '/../vendor/autoload.php';
require_once __DIR__ . '/../config.php';
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);
require_once __DIR__ . '/../boot.php';
try {
$monthly_totals = R::getAll("
......@@ -39,8 +31,8 @@ try {
} catch (\RedBeanPHP\RedException $e) {
die('Error in SQL query: ' . $e->getMessage());
}
foreach ($monthly_totals as $monthly) {
foreach ($monthly_totals as $monthly) {
// Format date to timestamp.
$timestamp = $monthly['yymm'] . '-01 01:01:01-01';
......
......@@ -13,15 +13,7 @@ if (PHP_SAPI !== 'cli') {
use RedBeanPHP\R;
require_once __DIR__ . '/../vendor/autoload.php';
require_once __DIR__ . '/../config.php';
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);
require_once __DIR__ . '/../boot.php';
try {
$sql = '
......
......@@ -13,15 +13,7 @@ if (PHP_SAPI !== 'cli') {
use RedBeanPHP\R;
require_once __DIR__ . '/../vendor/autoload.php';
require_once __DIR__ . '/../config.php';
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);
require_once __DIR__ . '/../boot.php';
$softwares = [
'diaspora' => ['repo' => 'diaspora/diaspora', 'gitsite' => 'api.github.com', 'gittype' => 'github', 'devbranch' => 'develop'],
......@@ -39,11 +31,11 @@ $opts = [
];
foreach ($softwares as $software => $details) {
if ($details['gittype'] == 'github') {
if ($details['gittype'] === 'github') {
$context = stream_context_create($opts);
$releasejson = json_decode(file_get_contents('https://' . $details["gitsite"] . '/repos/' . $details["repo"] . '/releases/latest', false, $context));
if ($details["devbranch"]) {
$commitjson = json_decode(file_get_contents('https://' . $details["gitsite"] . '/repos/' . $details["repo"] . '/commits/' . $details["devbranch"], false, $context));
$releasejson = json_decode(file_get_contents('https://' . $details['gitsite'] . '/repos/' . $details['repo'] . '/releases/latest', false, $context));
if ($details['devbranch']) {
$commitjson = json_decode(file_get_contents('https://' . $details['gitsite'] . '/repos/' . $details['repo'] . '/commits/' . $details['devbranch'], false, $context));
} else {
$commitjson = '';
}
......@@ -63,11 +55,11 @@ foreach ($softwares as $software => $details) {
die('Error in SQL query: ' . $e->getMessage());
}
}
} elseif ($details['gittype'] == 'gitlab') {
} elseif ($details['gittype'] === 'gitlab') {
$context = stream_context_create($opts);
$releasejson = json_decode(file_get_contents('https://' . $details["gitsite"] . '/api/v4/projects/' . $details["repo"] . '/repository/tags', false, $context));
if ($details["devbranch"]) {
$commitjson = json_decode(file_get_contents('https://' . $details["gitsite"] . '/api/v4/projects/' . $details["repo"] . '/repository/commits/' . $details["devbranch"], false, $context));
$releasejson = json_decode(file_get_contents('https://' . $details['gitsite'] . '/api/v4/projects/' . $details['repo'] . '/repository/tags', false, $context));
if ($details['devbranch']) {
$commitjson = json_decode(file_get_contents('https://' . $details['gitsite'] . '/api/v4/projects/' . $details['repo'] . '/repository/commits/' . $details['devbranch'], false, $context));
} else {
$commitjson = '';
}
......@@ -89,6 +81,5 @@ foreach ($softwares as $software => $details) {
}
}
printf('%s:%s:%s ', $software, $masterversion, $devlastcommit ?: 'n/a');
}
......@@ -30,20 +30,13 @@ $_domain = $_GET['domain'] ?? null;
// Must have a domain, except if called from CLI.
$_domain || PHP_SAPI === 'cli' || die('No valid input');
require_once __DIR__ . '/../vendor/autoload.php';
require_once __DIR__ . '/../config.php';
require_once __DIR__ . '/../boot.php';
define('PODUPTIME', microtime(true));
// Set up global DB connection.
R::setup("pgsql:host={$pghost};dbname={$pgdb}", $pguser, $pgpass, true);
$sqldebug && R::debug(true);
R::testConnection() || die('Error in DB connection');
R::usePartialBeans(true);
$sqldebug && R::fancyDebug(true);
try {
// Setup GeoIP Database
$reader = new Reader($geoip2db);
$reader = new Reader(c('geoip2db'));
$sql = '
SELECT domain, score, date_created, weight, podmin_notify, email, masterversion, shortversion, status
......@@ -101,28 +94,24 @@ foreach ($pods as $pod) {
// Default link to fetch node info.
$link = "https://{$domain}/nodeinfo/1.0";
if (($infos = @file_get_contents("https://{$domain}/.well-known/nodeinfo")) !== false) {
$info = json_decode($infos, true);
extract(_curl("https://{$domain}/.well-known/nodeinfo"));
$outputwellknown = $curl_body;
if ($outputwellknown !== false) {
$info = json_decode($outputwellknown, true);
$link = max($info['links'])['href'];
}
_debug('Nodeinfo link', $link);
extract(_curl($link));
$chss = curl_init();
curl_setopt($chss, CURLOPT_URL, $link);
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);
$conntime = curl_getinfo($chss, CURLINFO_CONNECT_TIME);
$nstime = curl_getinfo($chss, CURLINFO_NAMELOOKUP_TIME);
$outputssl = $curl_body;
$outputsslerror = $curl_error;
$info = $curl_info;
$conntime = $curl_conntime;
$nstime = $curl_nstime;
$latency = $conntime - $nstime;
$sslexpire = $info[0]['Expire date'] ?? null;
curl_close($chss);
_debug('Nodeinfo output', $outputssl, true);
_debug('Nodeinfo output error', $outputsslerror, true);
......@@ -259,12 +248,14 @@ foreach ($pods as $pod) {
$d = new DOMDocument;
libxml_use_internal_errors(true);
$d->loadHTMLFile('https://' . $domain);
extract(_curl("https://{$domain}/"));
$outputbody = $curl_body;
($outputbody ? $d->loadHTML($outputbody) : $d->loadHTML('<html></html>'));
$body = $d->getElementsByTagName('html')->item(0);
if ($body) {
$ld = new Language;
$detectedlanguage = strtoupper(key($ld->detect($body->nodeValue)->bestResults()->close()));
$detectedlanguage = key($ld->detect($body->nodeValue)->bestResults()->close());
} else {
$score -= 1;
$detectedlanguage = null;
......@@ -297,7 +288,7 @@ foreach ($pods as $pod) {
_debug('Signup Open', $signup);
$dnsserver = !empty($dnsserver) ? $dnsserver : '1.1.1.1';
$dnsserver = c('dnsserver') ?: '1.1.1.1';
$delv = new NPM\Xec\Command("delv @{$dnsserver} {$domain}");
$delv->throwExceptionOnError(false);
......@@ -355,7 +346,7 @@ foreach ($pods as $pod) {
if ($score == 49 && $notify && !$develop && $dbscore == 50) {
$to = $email;
$headers = ['From: ' . $adminemail, 'Bcc: ' . $adminemail];
$headers = ['From: ' . c('adminemail'), 'Bcc: ' . c('adminemail')];
$subject = 'Monitoring notice from poduptime';
$message = 'Notice for ' . $domain . '. Your score is ' . $score . ' and your pod will fall off the list soon.';
@mail($to, $subject, $message, implode("\r\n", $headers));
......@@ -455,3 +446,24 @@ function _debug($label, $var = null, $dump = false)
printf('%s: %s%s', $label, $output, $newline);
}
function _curl($url)
{
global $cafullpath;
$chss = curl_init();
curl_setopt($chss, CURLOPT_URL, $url);
curl_setopt($chss, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($chss, CURLOPT_TIMEOUT, 20);
curl_setopt($chss, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($chss, CURLOPT_CERTINFO, 1);
curl_setopt($chss, CURLOPT_CAINFO, $cafullpath);
return [