Skip to content

Commit c26cbf3

Browse files
committed
WIP backup before adding a new Controller class
1 parent 0deef8e commit c26cbf3

22 files changed

+1220
-874
lines changed

public/index.php

+9-146
Original file line numberDiff line numberDiff line change
@@ -1,158 +1,21 @@
11
<?php
22

33
declare(strict_types=1);
4-
// Creared: 20150101 - Updated: 20250202
4+
// Created: 20150101 - Updated: 20250203
55
// Copyright (C) 2015-2025 Mark Constable <markc@renta.net> (AGPL-3.0)
66

7+
namespace HCP;
8+
79
const DBG = true;
810

911
require_once __DIR__ . '/../vendor/autoload.php';
1012

11-
use HCP\Init;
12-
13-
echo new Init(new class()
14-
{
15-
public $cfg = [
16-
'email' => 'admin@example.com',
17-
'admpw' => 'admin123',
18-
'file' => '../src/.ht_conf.php', // settings override
19-
'hash' => 'SHA512-CRYPT',
20-
'host' => '',
21-
'perp' => 25,
22-
'self' => '/',
23-
];
24-
25-
public $in = [
26-
'a' => '', // API (apiusr:apikey)
27-
'd' => '', // Domain (current)
28-
'g' => null, // Group/Category
29-
'f' => 'html', // Rendering Format
30-
'i' => null, // Item or ID
31-
'l' => '', // Log (alert message)
32-
'm' => 'list', // Method (or action)
33-
'o' => 'Home', // Object (or plugin)
34-
'r' => 'local', // Remotes (local)
35-
't' => 'TopNav', // Theme (Default)
36-
'x' => '', // XHR (request)
37-
];
38-
39-
public $out = [
40-
'doc' => 'NetServa HCP',
41-
'css' => '',
42-
'log' => '',
43-
'nav1' => '',
44-
'nav2' => '',
45-
'nav3' => '',
46-
'head' => 'NetServa',
47-
'main' => 'Error: missing page!',
48-
'foot' => 'Copyright (C) 2015-2025 Mark Constable (AGPL-3.0)',
49-
'js' => '',
50-
];
51-
52-
public $t;
53-
54-
public $db = [
55-
'host' => '127.0.0.1', // DB site
56-
'name' => 'sysadm', // DB name
57-
'pass' => '../src/.ht_pw', // MySQL password override
58-
'path' => '../sysadm/sysadm.db', // SQLite DB
59-
'port' => '3306', // DB port
60-
'sock' => '', // '/run/mysqld/mysqld.sock',
61-
'type' => 'sqlite', // mysql | sqlite
62-
'user' => 'sysadm', // DB user
63-
];
64-
65-
public $nav1 = [
66-
'non' => [
67-
['Webmail', 'webmail/', 'bi bi-envelope'],
68-
['Phpmyadmin', 'phpmyadmin/', 'bi bi-globe'],
69-
],
70-
'usr' => [
71-
['Webmail', 'webmail/', 'bi bi-envelope'],
72-
['Phpmyadmin', 'phpmyadmin/', 'bi bi-globe'],
73-
],
74-
'adm' => [
75-
['Menu', [
76-
['Webmail', 'webmail/', 'bi bi-envelope'],
77-
['Phpmyadmin', 'phpmyadmin/', 'bi bi-globe'],
78-
], 'bi bi-list'],
79-
['Admin', [
80-
['Accounts', '?o=Accounts', 'bi bi-people'],
81-
['Vhosts', '?o=Vhosts', 'bi bi-globe'],
82-
['Mailboxes', '?o=Vmails', 'bi bi-envelope'],
83-
['Aliases', '?o=Valias', 'bi bi-envelope-fill'],
84-
['DKIM', '?o=Dkim', 'bi bi-person-vcard'],
85-
['Domains', '?o=Domains', 'bi bi-server'],
86-
], 'bi bi-gear-fill'],
87-
['Stats', [
88-
['Sys Info', '?o=InfoSys', 'bi bi-speedometer'],
89-
['Processes', '?o=Processes', 'bi bi-diagram-2'],
90-
['Mail Info', '?o=Infomail', 'bi bi-envelope-fill'],
91-
['Mail Graph', '?o=Mailgraph', 'bi bi-envelope'],
92-
], 'bi bi-graph-up'],
93-
],
94-
];
95-
96-
public $nav2 = [];
97-
98-
public $nav3 = [];
99-
100-
public $dns = [
101-
'a' => '127.0.0.1',
102-
'mx' => '',
103-
'ns1' => 'ns1.',
104-
'ns2' => 'ns2.',
105-
'prio' => 0,
106-
'ttl' => 300,
107-
'soa' => [
108-
'primary' => 'ns1.',
109-
'email' => 'admin.',
110-
'refresh' => 7200,
111-
'retry' => 540,
112-
'expire' => 604800,
113-
'ttl' => 3600,
114-
],
115-
'db' => [
116-
'host' => '127.0.0.1', // Alt DNS DB site
117-
'name' => 'pdns', // Alt DNS DB name
118-
'pass' => '../src/.ht_dns_pw', // MySQL DNS password override
119-
'path' => '../sysadm/pdns.db', // DNS SQLite DB
120-
'port' => '3306', // Alt DNS DB port
121-
'sock' => '', // '/run/mysqld/mysqld.sock',
122-
'type' => 'sqlite', // mysql | sqlite | '' to disable
123-
'user' => 'pdns', // Alt DNS DB user
124-
],
125-
];
126-
127-
public $acl = [
128-
0 => 'SuperAdmin',
129-
1 => 'Administrator',
130-
2 => 'User',
131-
3 => 'Suspended',
132-
9 => 'Anonymous',
133-
];
134-
});
135-
136-
function elog(string $content): void
137-
{
138-
if (DBG)
139-
{
140-
error_log($content);
141-
}
142-
}
13+
// Initialize with correct self path and hostname
14+
$self = str_replace('index.php', '', $_SERVER['PHP_SELF']);
15+
$host = getenv('HOSTNAME') ?: '';
16+
echo new Init(new Config($self, $host));
14317

144-
function dbg($var = null): void
18+
function dbg(mixed $var = null): void
14519
{
146-
if (is_object($var))
147-
{
148-
$refobj = new \ReflectionObject($var);
149-
// get all public and protected properties
150-
$var = $refobj->getProperties(\ReflectionProperty::IS_PUBLIC);
151-
$var = \array_merge($var, $refobj->getProperties(\ReflectionProperty::IS_PROTECTED));
152-
}
153-
ob_start();
154-
print_r($var);
155-
$ob = ob_get_contents();
156-
ob_end_clean();
157-
error_log($ob);
20+
error_log(var_export($var, true));
15821
}

src/Config.php

+123
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
// Created: 20150101 - Updated: 20250203
5+
// Copyright (C) 2015-2025 Mark Constable <markc@renta.net> (AGPL-3.0)
6+
7+
namespace HCP;
8+
9+
use HCP\Util;
10+
11+
enum ACL: int
12+
{
13+
case SuperAdmin = 0;
14+
case Administrator = 1;
15+
case User = 2;
16+
case Suspended = 3;
17+
case Anonymous = 9;
18+
}
19+
20+
readonly class Config
21+
{
22+
public string $email;
23+
public string $admpw;
24+
public string $file;
25+
public string $hash;
26+
public string $host;
27+
public int $perp;
28+
public string $self;
29+
public array $db;
30+
public array $nav1;
31+
public array $nav2;
32+
public array $nav3;
33+
public array $dns;
34+
public string $acl;
35+
36+
public function __construct(
37+
string $self = '/',
38+
string $host = ''
39+
)
40+
{
41+
Util::elog(__METHOD__);
42+
43+
$this->email = 'admin@example.com';
44+
$this->admpw = 'admin123';
45+
$this->file = '../src/.ht_conf.php';
46+
$this->hash = 'SHA512-CRYPT';
47+
$this->host = $host;
48+
$this->perp = 25;
49+
$this->self = $self;
50+
$this->db = [
51+
'host' => '127.0.0.1',
52+
'name' => 'sysadm',
53+
'pass' => '../src/.ht_pw',
54+
'path' => '../sysadm/sysadm.db',
55+
'port' => '3306',
56+
'sock' => '',
57+
'type' => 'sqlite',
58+
'user' => 'sysadm',
59+
];
60+
$this->nav1 = [
61+
'non' => [
62+
['Webmail', 'webmail/', 'bi bi-envelope'],
63+
['Phpmyadmin', 'phpmyadmin/', 'bi bi-globe'],
64+
],
65+
'usr' => [
66+
['Webmail', 'webmail/', 'bi bi-envelope'],
67+
['Phpmyadmin', 'phpmyadmin/', 'bi bi-globe'],
68+
],
69+
'adm' => [
70+
['Menu', [
71+
['Webmail', 'webmail/', 'bi bi-envelope'],
72+
['Phpmyadmin', 'phpmyadmin/', 'bi bi-globe'],
73+
], 'bi bi-list'],
74+
['Admin', [
75+
['Accounts', '?o=Accounts', 'bi bi-people'],
76+
['Vhosts', '?o=Vhosts', 'bi bi-globe'],
77+
['Mailboxes', '?o=Vmails', 'bi bi-envelope'],
78+
['Aliases', '?o=Valias', 'bi bi-envelope-fill'],
79+
['DKIM', '?o=Dkim', 'bi bi-person-vcard'],
80+
['Domains', '?o=Domains', 'bi bi-server'],
81+
], 'bi bi-gear-fill'],
82+
['Stats', [
83+
['Sys Info', '?o=InfoSys', 'bi bi-speedometer'],
84+
['Processes', '?o=Processes', 'bi bi-diagram-2'],
85+
['Mail Info', '?o=Infomail', 'bi bi-envelope-fill'],
86+
['Mail Graph', '?o=Mailgraph', 'bi bi-envelope'],
87+
], 'bi bi-graph-up'],
88+
],
89+
];
90+
$this->nav2 = [
91+
['TopNav', '?t=TopNav', 'bi bi-list'],
92+
['SideBar', '?t=SideBar', 'bi bi-layout-sidebar']
93+
];
94+
$this->nav3 = [];
95+
$this->dns = [
96+
'a' => '127.0.0.1',
97+
'mx' => '',
98+
'ns1' => 'ns1.',
99+
'ns2' => 'ns2.',
100+
'prio' => 0,
101+
'ttl' => 300,
102+
'soa' => [
103+
'primary' => 'ns1.',
104+
'email' => 'admin.',
105+
'refresh' => 7200,
106+
'retry' => 540,
107+
'expire' => 604800,
108+
'ttl' => 3600,
109+
],
110+
'db' => [
111+
'host' => '127.0.0.1',
112+
'name' => 'pdns',
113+
'pass' => '../src/.ht_dns_pw',
114+
'path' => '../sysadm/pdns.db',
115+
'port' => '3306',
116+
'sock' => '',
117+
'type' => 'sqlite',
118+
'user' => 'pdns',
119+
],
120+
];
121+
$this->acl = ACL::class;
122+
}
123+
}

0 commit comments

Comments
 (0)