Skip to content

Commit 48ff9ec

Browse files
committed
First cut at PHP 8.2 and bootstrap5 using vscode
1 parent 875b823 commit 48ff9ec

27 files changed

+406
-402
lines changed

index.php

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,37 +5,41 @@
55
// Copyright (C) 2015-2023 Mark Constable <markc@renta.net> (AGPL-3.0)
66

77
const DS = DIRECTORY_SEPARATOR;
8-
const INC = __DIR__.DS.'lib'.DS.'php'.DS;
9-
const DBG = false;
8+
const INC = __DIR__ . DS . 'lib' . DS . 'php' . DS;
9+
const DBG = true;
1010

1111
spl_autoload_register(function ($c): void {
12-
$f = INC.str_replace(['\\', '_'], [DS, DS], strtolower($c)).'.php';
12+
$f = INC . str_replace(['\\', '_'], [DS, DS], strtolower($c)) . '.php';
1313
if (file_exists($f)) {
1414
include $f;
15+
if (DBG) {
16+
error_log("include $f");
17+
}
1518
} else {
1619
error_log("!!! {$f} does not exist");
1720
}
1821
});
1922

20-
echo new Init(new class() {
23+
echo new Init(new class()
24+
{
2125
public $cfg = [
2226
'email' => 'markc@renta.net',
23-
'file' => __DIR__.DS.'lib'.DS.'.ht_conf.php', // settings override
27+
'file' => __DIR__ . DS . 'lib' . DS . '.ht_conf.php', // settings override
2428
'hash' => 'SHA512-CRYPT',
2529
'host' => '',
2630
'perp' => 25,
2731
'self' => '/hcp/',
2832
];
2933
public $in = [
30-
'a' => '', // API (apiusr:apikey)
31-
'd' => '', // Domain (current)
32-
'g' => null, // Group/Category
33-
'i' => null, // Item or ID
34-
'l' => '', // Log (message)
35-
'm' => 'list', // Method (action)
36-
'o' => 'home', // Object (content)
37-
't' => 'bootstrap5',// Theme
38-
'x' => '', // XHR (request)
34+
'a' => '', // API (apiusr:apikey)
35+
'd' => '', // Domain (current)
36+
'g' => null, // Group/Category
37+
'i' => null, // Item or ID
38+
'l' => '', // Log (message)
39+
'm' => 'list', // Method (action)
40+
'o' => 'home', // Object (content)
41+
't' => 'bootstrap5', // Theme
42+
'x' => '', // XHR (request)
3943
];
4044
public $out = [
4145
'doc' => 'NetServa',
@@ -53,7 +57,7 @@
5357
public $db = [
5458
'host' => '127.0.0.1', // DB site
5559
'name' => 'sysadm', // DB name
56-
'pass' => 'lib'.DS.'.ht_pw', // MySQL password override
60+
'pass' => 'lib' . DS . '.ht_pw', // MySQL password override
5761
'path' => '/var/lib/sqlite/sysadm/sysadm.db', // SQLite DB
5862
'port' => '3306', // DB port
5963
'sock' => '', // '/run/mysqld/mysqld.sock',
@@ -90,8 +94,7 @@
9094
], 'fas fa-chart-line fa-fw'],
9195
],
9296
];
93-
public $nav2 = [
94-
];
97+
public $nav2 = [];
9598
public $dns = [
9699
'a' => '127.0.0.1',
97100
'mx' => '',
@@ -110,7 +113,7 @@
110113
'db' => [
111114
'host' => '127.0.0.1', // Alt DNS DB site
112115
'name' => 'pdns', // Alt DNS DB name
113-
'pass' => 'lib'.DS.'.ht_dns_pw', // MySQL DNS password override
116+
'pass' => 'lib' . DS . '.ht_dns_pw', // MySQL DNS password override
114117
'path' => '/var/lib/sqlite/sysadm/pdns.db', // DNS SQLite DB
115118
'port' => '3306', // Alt DNS DB port
116119
'sock' => '', // '/run/mysqld/mysqld.sock',

lib/php/init.php

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,11 @@ class Init
1111
public function __construct(object $g)
1212
{
1313
elog(__METHOD__);
14-
1514
session_start();
1615

17-
elog('GET='.var_export($_GET, true));
18-
elog('POST='.var_export($_POST, true));
19-
elog('SESSION='.var_export($_SESSION, true));
16+
elog('GET=' . var_export($_GET, true));
17+
elog('POST=' . var_export($_POST, true));
18+
elog('SESSION=' . var_export($_SESSION, true));
2019

2120
//$_SESSION = []; // to reset session for testing
2221

@@ -32,15 +31,17 @@ public function __construct(object $g)
3231
util::ses('o');
3332
util::ses('m');
3433
util::ses('l');
35-
$t = util::ses('t', '', $g->in['t']);
3634

37-
$t1 = 'themes_'.$t.'_'.$g->in['o'];
38-
$t2 = 'themes_'.$t.'_theme';
35+
$t = util::ses('t', '', $g->in['t']);
36+
$t1 = 'themes_' . $t . '_' . $g->in['o'];
37+
$t2 = 'themes_' . $t . '_theme';
3938

40-
$this->t = $thm = class_exists($t1) ? new $t1($g)
39+
$this->t = $thm = class_exists($t1)
40+
? new $t1($g)
4141
: (class_exists($t2) ? new $t2($g) : new Theme($g));
4242

43-
$p = 'plugins_'.$g->in['o'];
43+
$p = 'plugins_' . $g->in['o'];
44+
4445
if (class_exists($p)) {
4546
$g->in['a'] ? util::chkapi($g) : util::remember($g);
4647
$g->out['main'] = (string) new $p($thm);
@@ -58,7 +59,7 @@ public function __construct(object $g)
5859
public function __destruct()
5960
{
6061
//error_log('SESSION=' . var_export($_SESSION, true));
61-
elog(__FILE__.' '.$_SERVER['REMOTE_ADDR'].' '.round((microtime(true) - $_SERVER['REQUEST_TIME_FLOAT']), 4)."\n");
62+
elog(__FILE__ . ' ' . $_SERVER['REMOTE_ADDR'] . ' ' . round((microtime(true) - $_SERVER['REQUEST_TIME_FLOAT']), 4) . "\n");
6263
}
6364

6465
public function __toString(): string
@@ -91,7 +92,10 @@ public function __toString(): string
9192
function dbg($var = null): void
9293
{
9394
if (is_object($var)) {
94-
error_log(ReflectionObject::export($var, true));
95+
$refobj = new \ReflectionObject($var);
96+
// get all public and protected properties
97+
$var = $refobj->getProperties(\ReflectionProperty::IS_PUBLIC);
98+
$var = \array_merge($var, $refobj->getProperties(\ReflectionProperty::IS_PROTECTED));
9599
}
96100
ob_start();
97101
print_r($var);

lib/php/plugin.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?php
22

33
declare(strict_types=1);
4-
// lib/php/plugin.php 20150101 - 20200414
5-
// Copyright (C) 2015-2020 Mark Constable <markc@renta.net> (AGPL-3.0)
4+
// lib/php/plugin.php 20150101 - 20230604
5+
// Copyright (C) 2015-2023 Mark Constable <markc@renta.net> (AGPL-3.0)
66

77
class Plugin
88
{
@@ -18,13 +18,15 @@ public function __construct(public Theme $t)
1818

1919
$o = $t->g->in['o'];
2020
$m = $t->g->in['m'];
21+
2122
if (!util::is_usr() && ('auth' !== $o || ('list' !== $m && 'create' !== $m && 'resetpw' !== $m))) {
22-
util::redirect($t->g->cfg['self'].'?o=auth');
23+
util::redirect($t->g->cfg['self'] . '?o=auth');
2324
}
2425

2526
$this->t = $t;
2627
$this->g = $t->g;
2728
$this->in = util::esc($this->in);
29+
2830
if ($this->tbl) {
2931
if (!is_null($this->dbh)) {
3032
db::$dbh = $this->dbh;
@@ -46,9 +48,9 @@ public function __toString(): string
4648

4749
public function __call(string $name, array $args): string
4850
{
49-
elog(__METHOD__.'() name = '.$name.', args = '.var_export($args, true));
51+
elog(__METHOD__ . '() name = ' . $name . ', args = ' . var_export($args, true));
5052

51-
return 'Plugin::'.$name.'() not implemented';
53+
return 'Plugin::' . $name . '() not implemented';
5254
}
5355

5456
protected function create(): string
@@ -59,7 +61,7 @@ protected function create(): string
5961
$this->in['updated'] = date('Y-m-d H:i:s');
6062
$this->in['created'] = date('Y-m-d H:i:s');
6163
$lid = db::create($this->in);
62-
util::log('Item number '.$lid.' created', 'success');
64+
util::log('Item number ' . $lid . ' created', 'success');
6365
util::relist();
6466
} else {
6567
return $this->t->create($this->in);
@@ -80,7 +82,7 @@ protected function update(): string
8082
if (util::is_post()) {
8183
$this->in['updated'] = date('Y-m-d H:i:s');
8284
if (db::update($this->in, [['id', '=', $this->g->in['i']]])) {
83-
util::log('Item number '.$this->g->in['i'].' updated', 'success');
85+
util::log('Item number ' . $this->g->in['i'] . ' updated', 'success');
8486
util::relist();
8587
} else {
8688
util::log('Error updating item.');
@@ -90,14 +92,14 @@ protected function update(): string
9092
return $this->read();
9193
}
9294

93-
protected function delete(): string
95+
protected function delete(): void
9496
{
9597
elog(__METHOD__);
9698

9799
if (util::is_post()) {
98100
if ($this->g->in['i']) {
99101
$res = db::delete([['id', '=', $this->g->in['i']]]);
100-
util::log('Item number '.$this->g->in['i'].' removed', 'success');
102+
util::log('Item number ' . $this->g->in['i'] . ' removed', 'success');
101103
util::relist();
102104
}
103105
}

lib/php/plugins/accounts.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ protected function list(): string
7171
['dt' => null, 'db' => 'id'],
7272
['dt' => 0, 'db' => 'login', 'formatter' => function ($d, $row) {
7373
return '
74-
<b><a href="?o=accounts&m=read&i='.$row['id'].'">'.$d.'</a></b>';
74+
<b><a href="?o=accounts&m=read&i=' . $row['id'] . '">' . $d . '</a></b>';
7575
}],
7676
['dt' => 1, 'db' => 'fname'],
7777
['dt' => 2, 'db' => 'lname'],
@@ -92,7 +92,7 @@ protected function switch_user(): void
9292

9393
if (util::is_adm() and !is_null($this->g->in['i'])) {
9494
$_SESSION['usr'] = db::read('id,acl,grp,login,fname,lname,webpw,cookie', 'id', $this->g->in['i'], '', 'one');
95-
util::log('Switch to user: '.$_SESSION['usr']['login'], 'success');
95+
util::log('Switch to user: ' . $_SESSION['usr']['login'], 'success');
9696
} else {
9797
util::log('Not authorized to switch users');
9898
}

lib/php/plugins/auth.php

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?php
22

33
declare(strict_types=1);
4-
// lib/php/plugins/auth.php 20150101 - 20200414
5-
// Copyright (C) 2015-2020 Mark Constable <markc@renta.net> (AGPL-3.0)
4+
// lib/php/plugins/auth.php 20150101 - 20230604
5+
// Copyright (C) 2015-2023 Mark Constable <markc@renta.net> (AGPL-3.0)
66

77
class Plugins_Auth extends Plugin
88
{
@@ -34,16 +34,16 @@ public function create(): string
3434
if ($usr = db::read('id,acl', 'login', $u, '', 'one')) {
3535
if (9 != $usr['acl']) {
3636
$newpass = util::genpw(self::OTP_LENGTH);
37-
if ($this->mail_forgotpw($u, $newpass, 'From: '.$this->g->cfg['email'])) {
37+
if ($this->mail_forgotpw($u, $newpass, 'From: ' . $this->g->cfg['email'])) {
3838
db::update([
3939
'otp' => $newpass,
4040
'otpttl' => time(),
4141
], [['id', '=', $usr['id']]]);
42-
util::log('Sent reset password key for "'.$u.'" so please check your mailbox and click on the supplied link.', 'success');
42+
util::log('Sent reset password key for "' . $u . '" so please check your mailbox and click on the supplied link.', 'success');
4343
} else {
44-
util::log('Problem sending message to '.$u, 'danger');
44+
util::log('Problem sending message to ' . $u, 'danger');
4545
}
46-
util::redirect($this->cfg['self'].'?o='.$this->g->in['o'].'&m=list');
46+
util::redirect($this->g->cfg['self'] . '?o=' . $this->g->in['o'] . '&m=list');
4747
} else {
4848
util::log('Account is disabled, contact your System Administrator');
4949
}
@@ -77,7 +77,7 @@ public function list(): string
7777
util::put_cookie('remember', $uniq, self::REMEMBER_ME_EXP);
7878
}
7979
$_SESSION['usr'] = $usr;
80-
util::log($login.' is now logged in', 'success');
80+
util::log($login . ' is now logged in', 'success');
8181
if (0 === (int) $acl) {
8282
$_SESSION['adm'] = $id;
8383
}
@@ -123,7 +123,7 @@ public function update(): string
123123
'otpttl' => 0,
124124
'updated' => date('Y-m-d H:i:s'),
125125
], [['id', '=', $i]])) {
126-
util::log('Password reset for '.$usr['login'], 'success');
126+
util::log('Password reset for ' . $usr['login'], 'success');
127127
if (util::is_usr()) {
128128
util::redirect($this->g->cfg['self']);
129129
} else {
@@ -134,7 +134,7 @@ public function update(): string
134134
util::log('Problem updating database');
135135
}
136136
} else {
137-
util::log($usr['login'].' is not allowed access');
137+
util::log($usr['login'] . ' is not allowed access');
138138
}
139139
} else {
140140
util::log('Your one time password key has expired');
@@ -163,7 +163,7 @@ public function delete(): void
163163
db::update(['cookie' => ''], [['id', '=', $id]]);
164164
$this->setcookie('remember', '', strtotime('-1 hour', 0));
165165
}
166-
util::log($u.' is now logged out', 'success');
166+
util::log($u . ' is now logged out', 'success');
167167
}
168168
util::redirect($this->g->cfg['self']);
169169
}
@@ -184,7 +184,7 @@ public function resetpw(): string
184184

185185
return $this->t->update(['id' => $id, 'login' => $login]);
186186
}
187-
util::log($login.' is not allowed access');
187+
util::log($login . ' is not allowed access');
188188
} else {
189189
util::log('Your one time password key has expired');
190190
}
@@ -201,20 +201,20 @@ private function mail_forgotpw(string $email, string $newpass, string $headers =
201201
{
202202
elog(__METHOD__);
203203

204-
$host = $_SERVER['REQUEST_SCHEME'].'://'
205-
.$this->g->cfg['host']
206-
.$this->g->cfg['self'];
204+
$host = $_SERVER['REQUEST_SCHEME'] . '://'
205+
. $this->g->cfg['host']
206+
. $this->g->cfg['self'];
207207

208208
return mail(
209209
"{$email}",
210-
'Reset password for '.$this->g->cfg['host'],
210+
'Reset password for ' . $this->g->cfg['host'],
211211
'Here is your new OTP (one time password) key that is valid for one hour.
212212
213213
Please click on the link below and continue with reseting your password.
214214
215215
If you did not request this action then please ignore this message.
216216
217-
'.$host.'?o=auth&m=resetpw&otp='.$newpass,
217+
' . $host . '?o=auth&m=resetpw&otp=' . $newpass,
218218
$headers
219219
);
220220
}

0 commit comments

Comments
 (0)