Commit 21953d9f authored by David Morley's avatar David Morley

Random cleanups

parent ce06e864
......@@ -6,7 +6,6 @@
declare(strict_types=1);
use Poduptime\Logging;
use RedBeanPHP\R;
require_once __DIR__ . '/../vendor/autoload.php';
......@@ -21,10 +20,7 @@ if (PHP_SAPI === 'cli' || PHP_SAPI === 'cgi-fcgi') {
R::usePartialBeans(true);
}
$log = new Logging();
$log->lfile($log_dir . '/add.log');
if (!($_domain = $_GET['domain'] ?? null)) {
$log->lwrite('no domain given');
die('no pod domain given');
}
......@@ -50,13 +46,11 @@ try {
foreach ($pods as $pod) {
if ($pod['domain'] === $_domain) {
if ($pod['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, $pod['publickey']) === false) {
$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<br><b> ' . $_domain . ' IN TXT "' . $pod['publickey'] . '"</b>');
}
......@@ -107,7 +101,6 @@ $outputssl = curl_exec($chss);
curl_close($chss);
if ($outputssl && stripos($outputssl, 'openRegistrations') !== false) {
$log->lwrite('Your pod has ssl and is valid ' . $_domain);
echo 'Your pod has ssl and is valid<br>';
$publickey = md5(uniqid($_domain, true));
......@@ -142,7 +135,5 @@ if ($outputssl && stripos($outputssl, 'openRegistrations') !== false) {
echo 'Data successfully inserted! Your pod will be checked and live on the list in a few hours!';
} else {
$log->lwrite('Could not validate your pod, check your setup! ' . $_domain);
echo 'Could not validate your pod, check your setup!<br>Take a look at <a href="' . $link . '">your /nodeinfo</a>';
}
$log->lclose();
......@@ -16,7 +16,7 @@ require_once __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 --username=$pguser $pgdb >> $file_name");
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);
while ($entry = $dirh->read()) {
......
......@@ -356,7 +356,7 @@ foreach ($pods as $pod) {
$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 not showing on the site.';
$message = 'Notice for ' . $domain . '. Your score fell to ' . $score . ' and your pod will fall off the list soon.';
@mail($to, $subject, $message, implode("\r\n", $headers));
_debug('Mail Notice', 'sent to ' . $email);
......
......@@ -68,7 +68,7 @@ $navs = [
['text' => 'Contact', 'href' => 'https://dia.so/support', 'active' => false],
['text' => 'Wiki', 'href' => 'https://git.feneas.org/diasporg/Poduptime/wikis/home', 'active' => false],
['text' => 'API', 'href' => 'https://git.feneas.org/diasporg/Poduptime/wikis/API', 'active' => false],
['text' => 'How to host a pod', 'href' => 'https://diasporafoundation.org/', 'active' => false],
['text' => 'How to host a pod', 'href' => 'https://fediverse.party/', 'active' => false],
],
];
?>
......
<?php
/**
* Logging class:
* - contains lfile, lwrite and lclose public methods
* - lfile sets path and name of log file
* - lwrite writes message to the log file (and implicitly opens log file)
* - lclose closes log file
* - first call of lwrite method will open log file implicitly
* - message is written with the following format: [d/M/Y:H:i:s] (script name) message
* - http://www.redips.net/php/write-to-log-file/
*/
declare(strict_types=1);
namespace Poduptime;
class Logging
{
private $handle;
private $log_file;
public function lfile($path): void
{
$this->log_file = $path;
}
public function lwrite($message): void
{
if (!\is_resource($this->handle)) {
$this->lopen();
}
$script_name = pathinfo($_SERVER['PHP_SELF'], PATHINFO_FILENAME);
$time = @date('[d/M/Y:H:i:s]');
fwrite($this->handle, "$time ($script_name) $message" . PHP_EOL);
}
public function lclose(): void
{
fclose($this->handle);
}
private function lopen(): void
{
$log_file_default = '/tmp/logfile.txt';
if (0 === stripos(PHP_OS, 'WIN')) {
$log_file_default = 'c:/php/logfile.txt';
}
$lfile = $this->log_file ?: $log_file_default;
$this->handle = fopen($lfile, 'ab') or exit("Can't open {$lfile}!");
}
}
User-agent: *
Allow: /
User-agent: *
Disallow: /podstat.php
User-agent: SemrushBot
Disallow: /podstat.php
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment