-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First cut at PHP 8.2 and bootstrap5 using vscode
- Loading branch information
Showing
27 changed files
with
406 additions
and
402 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,37 +5,41 @@ | |
// Copyright (C) 2015-2023 Mark Constable <[email protected]> (AGPL-3.0) | ||
|
||
const DS = DIRECTORY_SEPARATOR; | ||
const INC = __DIR__.DS.'lib'.DS.'php'.DS; | ||
const DBG = false; | ||
const INC = __DIR__ . DS . 'lib' . DS . 'php' . DS; | ||
const DBG = true; | ||
|
||
spl_autoload_register(function ($c): void { | ||
$f = INC.str_replace(['\\', '_'], [DS, DS], strtolower($c)).'.php'; | ||
$f = INC . str_replace(['\\', '_'], [DS, DS], strtolower($c)) . '.php'; | ||
if (file_exists($f)) { | ||
include $f; | ||
if (DBG) { | ||
error_log("include $f"); | ||
} | ||
} else { | ||
error_log("!!! {$f} does not exist"); | ||
} | ||
}); | ||
|
||
echo new Init(new class() { | ||
echo new Init(new class() | ||
{ | ||
public $cfg = [ | ||
'email' => '[email protected]', | ||
'file' => __DIR__.DS.'lib'.DS.'.ht_conf.php', // settings override | ||
'file' => __DIR__ . DS . 'lib' . DS . '.ht_conf.php', // settings override | ||
'hash' => 'SHA512-CRYPT', | ||
'host' => '', | ||
'perp' => 25, | ||
'self' => '/hcp/', | ||
]; | ||
public $in = [ | ||
'a' => '', // API (apiusr:apikey) | ||
'd' => '', // Domain (current) | ||
'g' => null, // Group/Category | ||
'i' => null, // Item or ID | ||
'l' => '', // Log (message) | ||
'm' => 'list', // Method (action) | ||
'o' => 'home', // Object (content) | ||
't' => 'bootstrap5',// Theme | ||
'x' => '', // XHR (request) | ||
'a' => '', // API (apiusr:apikey) | ||
'd' => '', // Domain (current) | ||
'g' => null, // Group/Category | ||
'i' => null, // Item or ID | ||
'l' => '', // Log (message) | ||
'm' => 'list', // Method (action) | ||
'o' => 'home', // Object (content) | ||
't' => 'bootstrap5', // Theme | ||
'x' => '', // XHR (request) | ||
]; | ||
public $out = [ | ||
'doc' => 'NetServa', | ||
|
@@ -53,7 +57,7 @@ | |
public $db = [ | ||
'host' => '127.0.0.1', // DB site | ||
'name' => 'sysadm', // DB name | ||
'pass' => 'lib'.DS.'.ht_pw', // MySQL password override | ||
'pass' => 'lib' . DS . '.ht_pw', // MySQL password override | ||
'path' => '/var/lib/sqlite/sysadm/sysadm.db', // SQLite DB | ||
'port' => '3306', // DB port | ||
'sock' => '', // '/run/mysqld/mysqld.sock', | ||
|
@@ -90,8 +94,7 @@ | |
], 'fas fa-chart-line fa-fw'], | ||
], | ||
]; | ||
public $nav2 = [ | ||
]; | ||
public $nav2 = []; | ||
public $dns = [ | ||
'a' => '127.0.0.1', | ||
'mx' => '', | ||
|
@@ -110,7 +113,7 @@ | |
'db' => [ | ||
'host' => '127.0.0.1', // Alt DNS DB site | ||
'name' => 'pdns', // Alt DNS DB name | ||
'pass' => 'lib'.DS.'.ht_dns_pw', // MySQL DNS password override | ||
'pass' => 'lib' . DS . '.ht_dns_pw', // MySQL DNS password override | ||
'path' => '/var/lib/sqlite/sysadm/pdns.db', // DNS SQLite DB | ||
'port' => '3306', // Alt DNS DB port | ||
'sock' => '', // '/run/mysqld/mysqld.sock', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
// lib/php/plugin.php 20150101 - 20200414 | ||
// Copyright (C) 2015-2020 Mark Constable <[email protected]> (AGPL-3.0) | ||
// lib/php/plugin.php 20150101 - 20230604 | ||
// Copyright (C) 2015-2023 Mark Constable <[email protected]> (AGPL-3.0) | ||
|
||
class Plugin | ||
{ | ||
|
@@ -18,13 +18,15 @@ public function __construct(public Theme $t) | |
|
||
$o = $t->g->in['o']; | ||
$m = $t->g->in['m']; | ||
|
||
if (!util::is_usr() && ('auth' !== $o || ('list' !== $m && 'create' !== $m && 'resetpw' !== $m))) { | ||
util::redirect($t->g->cfg['self'].'?o=auth'); | ||
util::redirect($t->g->cfg['self'] . '?o=auth'); | ||
} | ||
|
||
$this->t = $t; | ||
$this->g = $t->g; | ||
$this->in = util::esc($this->in); | ||
|
||
if ($this->tbl) { | ||
if (!is_null($this->dbh)) { | ||
db::$dbh = $this->dbh; | ||
|
@@ -46,9 +48,9 @@ public function __toString(): string | |
|
||
public function __call(string $name, array $args): string | ||
{ | ||
elog(__METHOD__.'() name = '.$name.', args = '.var_export($args, true)); | ||
elog(__METHOD__ . '() name = ' . $name . ', args = ' . var_export($args, true)); | ||
|
||
return 'Plugin::'.$name.'() not implemented'; | ||
return 'Plugin::' . $name . '() not implemented'; | ||
} | ||
|
||
protected function create(): string | ||
|
@@ -59,7 +61,7 @@ protected function create(): string | |
$this->in['updated'] = date('Y-m-d H:i:s'); | ||
$this->in['created'] = date('Y-m-d H:i:s'); | ||
$lid = db::create($this->in); | ||
util::log('Item number '.$lid.' created', 'success'); | ||
util::log('Item number ' . $lid . ' created', 'success'); | ||
util::relist(); | ||
} else { | ||
return $this->t->create($this->in); | ||
|
@@ -80,7 +82,7 @@ protected function update(): string | |
if (util::is_post()) { | ||
$this->in['updated'] = date('Y-m-d H:i:s'); | ||
if (db::update($this->in, [['id', '=', $this->g->in['i']]])) { | ||
util::log('Item number '.$this->g->in['i'].' updated', 'success'); | ||
util::log('Item number ' . $this->g->in['i'] . ' updated', 'success'); | ||
util::relist(); | ||
} else { | ||
util::log('Error updating item.'); | ||
|
@@ -90,14 +92,14 @@ protected function update(): string | |
return $this->read(); | ||
} | ||
|
||
protected function delete(): string | ||
protected function delete(): void | ||
{ | ||
elog(__METHOD__); | ||
|
||
if (util::is_post()) { | ||
if ($this->g->in['i']) { | ||
$res = db::delete([['id', '=', $this->g->in['i']]]); | ||
util::log('Item number '.$this->g->in['i'].' removed', 'success'); | ||
util::log('Item number ' . $this->g->in['i'] . ' removed', 'success'); | ||
util::relist(); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
// lib/php/plugins/auth.php 20150101 - 20200414 | ||
// Copyright (C) 2015-2020 Mark Constable <[email protected]> (AGPL-3.0) | ||
// lib/php/plugins/auth.php 20150101 - 20230604 | ||
// Copyright (C) 2015-2023 Mark Constable <[email protected]> (AGPL-3.0) | ||
|
||
class Plugins_Auth extends Plugin | ||
{ | ||
|
@@ -34,16 +34,16 @@ public function create(): string | |
if ($usr = db::read('id,acl', 'login', $u, '', 'one')) { | ||
if (9 != $usr['acl']) { | ||
$newpass = util::genpw(self::OTP_LENGTH); | ||
if ($this->mail_forgotpw($u, $newpass, 'From: '.$this->g->cfg['email'])) { | ||
if ($this->mail_forgotpw($u, $newpass, 'From: ' . $this->g->cfg['email'])) { | ||
db::update([ | ||
'otp' => $newpass, | ||
'otpttl' => time(), | ||
], [['id', '=', $usr['id']]]); | ||
util::log('Sent reset password key for "'.$u.'" so please check your mailbox and click on the supplied link.', 'success'); | ||
util::log('Sent reset password key for "' . $u . '" so please check your mailbox and click on the supplied link.', 'success'); | ||
} else { | ||
util::log('Problem sending message to '.$u, 'danger'); | ||
util::log('Problem sending message to ' . $u, 'danger'); | ||
} | ||
util::redirect($this->cfg['self'].'?o='.$this->g->in['o'].'&m=list'); | ||
util::redirect($this->g->cfg['self'] . '?o=' . $this->g->in['o'] . '&m=list'); | ||
} else { | ||
util::log('Account is disabled, contact your System Administrator'); | ||
} | ||
|
@@ -77,7 +77,7 @@ public function list(): string | |
util::put_cookie('remember', $uniq, self::REMEMBER_ME_EXP); | ||
} | ||
$_SESSION['usr'] = $usr; | ||
util::log($login.' is now logged in', 'success'); | ||
util::log($login . ' is now logged in', 'success'); | ||
if (0 === (int) $acl) { | ||
$_SESSION['adm'] = $id; | ||
} | ||
|
@@ -123,7 +123,7 @@ public function update(): string | |
'otpttl' => 0, | ||
'updated' => date('Y-m-d H:i:s'), | ||
], [['id', '=', $i]])) { | ||
util::log('Password reset for '.$usr['login'], 'success'); | ||
util::log('Password reset for ' . $usr['login'], 'success'); | ||
if (util::is_usr()) { | ||
util::redirect($this->g->cfg['self']); | ||
} else { | ||
|
@@ -134,7 +134,7 @@ public function update(): string | |
util::log('Problem updating database'); | ||
} | ||
} else { | ||
util::log($usr['login'].' is not allowed access'); | ||
util::log($usr['login'] . ' is not allowed access'); | ||
} | ||
} else { | ||
util::log('Your one time password key has expired'); | ||
|
@@ -163,7 +163,7 @@ public function delete(): void | |
db::update(['cookie' => ''], [['id', '=', $id]]); | ||
$this->setcookie('remember', '', strtotime('-1 hour', 0)); | ||
} | ||
util::log($u.' is now logged out', 'success'); | ||
util::log($u . ' is now logged out', 'success'); | ||
} | ||
util::redirect($this->g->cfg['self']); | ||
} | ||
|
@@ -184,7 +184,7 @@ public function resetpw(): string | |
|
||
return $this->t->update(['id' => $id, 'login' => $login]); | ||
} | ||
util::log($login.' is not allowed access'); | ||
util::log($login . ' is not allowed access'); | ||
} else { | ||
util::log('Your one time password key has expired'); | ||
} | ||
|
@@ -201,20 +201,20 @@ private function mail_forgotpw(string $email, string $newpass, string $headers = | |
{ | ||
elog(__METHOD__); | ||
|
||
$host = $_SERVER['REQUEST_SCHEME'].'://' | ||
.$this->g->cfg['host'] | ||
.$this->g->cfg['self']; | ||
$host = $_SERVER['REQUEST_SCHEME'] . '://' | ||
. $this->g->cfg['host'] | ||
. $this->g->cfg['self']; | ||
|
||
return mail( | ||
"{$email}", | ||
'Reset password for '.$this->g->cfg['host'], | ||
'Reset password for ' . $this->g->cfg['host'], | ||
'Here is your new OTP (one time password) key that is valid for one hour. | ||
Please click on the link below and continue with reseting your password. | ||
If you did not request this action then please ignore this message. | ||
'.$host.'?o=auth&m=resetpw&otp='.$newpass, | ||
' . $host . '?o=auth&m=resetpw&otp=' . $newpass, | ||
$headers | ||
); | ||
} | ||
|
Oops, something went wrong.