Skip to content

Commit 034cb6f

Browse files
committed
Prepare for PHP 8.4 compatibility
0 parents  commit 034cb6f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+20607
-0
lines changed

.gitignore

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
.ht*
2+
*kate-swp
3+
netserva.php
4+
adminer*
5+
phpinfo.php
6+
status/
7+
phpmyadmin/
8+
webmail/
9+
lib/uploads/*.jpg
10+
whmcs/
11+
.well-known/
12+
rspamd/
13+
phpliteadmin.*
14+
.php-cs-fixer.cache
15+
sysadm/

LICENSE

+662
Large diffs are not rendered by default.

README.md

+236
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,236 @@
1+
# NetServa HCP (RC1)
2+
3+
This is an ultra simple PHP based **Hosting Control Panel** for a lightweight
4+
Mail, Web and DNS server on an uptodate Ubuntu Server. It depends on the
5+
[NetServa SH] shell scripts being installed first.
6+
7+
## Hosting Control Panel
8+
9+
This project is ideal for [LXD containers] or cheap 256MB to 512MB VPS plans.
10+
11+
- [NetServa SH/HCP] does not reqire Python or Ruby, just PHP and Bash
12+
- Fully functional IMAP/SMTP mailserver with personalised Spam filtering
13+
- [LetsEncrypt] SSL enabled [nginx] web server with [PHP FPM 7+]
14+
- Optional [PowerDNS] installation for local LAN or real-world DNS service
15+
- Always based and tested on the latest release of [Ubuntu Server]
16+
- It can use either [SQLite] or [MySQL] as database backends
17+
- A fresh SQLite based install uses about 70MB ram (without Wordpress)
18+
- The "compiled" single file PHP script is less than 200KB in size
19+
- Built from the ground up using [Bootstrap 4] and [DataTables]
20+
- Developed and tested using LXD containers on the latest [Plasma Desktop]
21+
22+
## Usage
23+
24+
The PHP web interface relies on the [NetServa SH] scripts being installed
25+
on the primary and target hosts so the first thing to do, as root...
26+
27+
wget https://raw.githubusercontent.com/netserva/sh/master/bin/setup-sh ; . setup-sh
28+
29+
_Please first review the very simple script with "cat setup-sh"._
30+
31+
This installs the `SH` (Shell Helper) aliases and scripts into a `/root/.sh`
32+
directory and activates the environment variables and special aliases. See
33+
the [NetServa SH] repo for more information about how to use these aliases
34+
and scripts directly. This `HCP` project is just a web based frontend for
35+
the `SH` system which does all the real provisioning and management work.
36+
37+
The first step, after installing the `SH` scripts, is to make sure the
38+
current host has a hostname and a domainname. The domainname needs to be
39+
valid if using a publically accessible server and that needs the assistence
40+
of a real DNS service. Otherwise, if using a local LAN with private IPs
41+
(like 192.168.\*, 10.\* or 172.\*) then you can make up any domainname as
42+
long as your are consistent within your local LAN. Using something like
43+
`netserva.lan` is a good candidate unless you prefer something else. The
44+
hostname of your current host computer is usually determined when the OS is
45+
installed but can be changed by editing `/etc/hostname` and making sure
46+
`/etc/resolv.conf` has a reference like `search netserva.lan`. Once you get
47+
results like this...
48+
49+
~ hostname
50+
myhost
51+
~ hostname -d
52+
netserva.lan
53+
~ hostname -f
54+
myhost.netserva.lan
55+
56+
(where `myhost` and `netserva.lan` are your real or made up names) then
57+
continue on with the next step.
58+
59+
Now we "normalize" the host by using `setup-host` which updates the primary
60+
hosting **Desktop** or **Server** system to Bionic 18.04 (unless `os release`
61+
is defined.) using the current `hostname -f` unless a **hostname.domainname**
62+
is passed in as the first `[domain]` argument...
63+
64+
Usage: setup-host [domain] [(mysql)|sqlite] [admin(sysadm)] [os release(bionic)] [os mirror(archive.ubuntu.com)]
65+
66+
Assuming a LXD container is to be used for the actual server side
67+
(recommended for initial testing anyway) then use `setup-lxd` to install
68+
and setup the basic LXD container system...
69+
70+
Usage: setup-lxd [pool size (25) GB] [passwd] [IP]
71+
72+
We can now setup the actual NetServa SH/HCP system for testing so, for
73+
example, if we use something like `c1.netserva.lan`,
74+
where `c1` will be the container label and `netserva.lan` can either be a
75+
real domainname (if the server has a public IP) or whatever internal
76+
LAN-wide domainname you care to use...
77+
78+
Usage: newlxd FQDN [(small)|medium|large] [distro(bionic)] [(mysql)|sqlite]
79+
80+
If the installation procedure can detect an externally available public IP
81+
then it will attempt to install a LetsEncrypt SSL certificate so that the
82+
web server can be accessed via `https` and the mail server will be SSL enabled
83+
and ready for real-world deployment. Otherwise a self-signed certificate will
84+
be installed (which can be a problem for Firefox.) The mail, web, sftp and HCP
85+
login credentials will be available in `cat ~/.vhosts/$(hostname -f).conf`.
86+
87+
The essential configuration settings for the default server will be inside
88+
the container (example only for a local LAN domain called `netserva.lan`)...
89+
90+
lxc exec c1 bash
91+
cat ~/.vhosts/$(hostname -f)
92+
93+
Or, if you already have a containter or remote server ready to use after a
94+
fresh Ubuntu install then you could install the entire NetServa SH and HCP
95+
system by ssh'ing into the system (or for example, "lxc exec c1 bash" for a
96+
local LXD container) and...
97+
98+
wget https://raw.githubusercontent.com/netserva/sh/master/bin/setup-sh
99+
# cat setup-sh
100+
. setup-sh
101+
setup-all
102+
103+
This may take 5 to 15 mintes to complete depending on the bandwidth
104+
available to the target server. Once finished you should be able to go to
105+
`https://c1.netserva.lan/hcp` and login to the HCP web interface using the
106+
simple sitewide HTTP `sysadm/1234` authentication first then the real admin
107+
username and password available with `cat ~/.vhosts/$(hostname -f).conf`.
108+
109+
## Config Override
110+
111+
The main `index.php` file is actually the configuration for the entire
112+
program so that the rest of the PHP files could actually be included from
113+
anywhere else on the system (not just from `lib/php`) if the `INC` const
114+
is changed. To override the default settings (so sensitive information is
115+
not committed to some Git repo) a config override file can be put anywhere
116+
(the default being `lib/.ht_conf.php`) in which an array is returned where
117+
any of the top level property array values can be overridden. First review
118+
the main [index.php] file top level properties then compare below as an
119+
example of how to override these property values...
120+
121+
<?php
122+
return [
123+
'cfg' => ['email' => 'YOUR@EMAIL_ADDRESS'],
124+
'db' => ['type' => 'mysql', 'pass' => 'YOUR_MYSQL_PW'],
125+
'out' => [
126+
'doc' => 'YOUR_SITE_LABEL',
127+
'head' => 'YOUR_SITE_LABEL',
128+
'foot' => 'Copyright (C) 2018 YOUR_SITE_LABEL',
129+
],
130+
];
131+
132+
which would change the default email address (for forgotten password etc)
133+
to your email address, set the database to use MySQL with it's password
134+
and change the site titles and footer copyright notice. The SH/HCP system
135+
will use MySQL by default so if you use...
136+
137+
setup-all $(hostname -f) sqlite
138+
139+
for an extremely lightweight system (minus Wordpress) then use a
140+
`lib/.ht_conf.php` override file like...
141+
142+
<?php
143+
return [
144+
'cfg' => ['email' => 'YOUR@EMAIL_ADDRESS'],
145+
'db' => ['type' => 'sqlite'],
146+
'out' => [
147+
'doc' => 'YOUR_SITE_LABEL',
148+
'head' => 'YOUR_SITE_LABEL',
149+
'foot' => 'Copyright (C) 2018 YOUR_SITE_LABEL',
150+
],
151+
];
152+
153+
Another alternate option for a MySQL password is to create a simple plain
154+
text file called `lib/.ht_pw` and put ONLY the MySQL password in that file
155+
but of course using `lib/.ht_conf.php` instead allows you to modify or
156+
extend any of the top level properties in `index.php`.
157+
158+
The point of the config override is so you can keep doing a `git pull`and
159+
update the HCP web area (either from the NetServa repo or your own fork)
160+
without interference from locally updated files, and `git push` (to your
161+
own git repo) will not upload passwords to a possible public git repo.
162+
163+
## Athentication
164+
165+
During installation five random passwords will be auto-created in
166+
`/root/.vhosts/$(hostname -f)` along with a `/root/.my.cnf` with `DPASS`
167+
if MySQL is being used. Example...
168+
169+
~ grep PASS ~/.vhosts/$(hostname -f)
170+
APASS='LheTZOT8eYCrlAk8' # Admin HCP password
171+
DPASS='axVps7OIXb7VY4uT' # Database password, if using MySQL
172+
EPASS='a5cBBxXL59uAyJkc' # SMTP/IMAP password for admin@$VHOST
173+
UPASS='D8G3RgpBgSetyG4o' # SFTP password
174+
WPASS='LheTZOT8eYCrlAk8' # Wordpress admin password, if using MySQL
175+
176+
The initial `sysadm` user has access to most of the server with SUDO
177+
permissions to the provisioning scripts in `/root/.sh/bin/*`. This user
178+
also "owns" the default `YOUR_DOMAIN/adm` web area with the NetServa HCP
179+
web interface. All extra virtual hosts will be owned by `u1000 u1001 u1002
180+
etc` system users which will be chrooted, or locked into, their respective
181+
VHOST web area. For instance...
182+
183+
~ shhost all
184+
sysadm c1.netserva.org /home/u/c1.netserva.org
185+
u1001 netserva.org /home/u/netserva.org
186+
u1002 netserva.com /home/u/netserva.com
187+
u1003 netserva.net /home/u/netserva.net
188+
189+
where the above resulted from...
190+
191+
~ newlxd c1.netserva.org
192+
# then SSH/exec into the container and...
193+
~ addvhost netserva.org
194+
~ addvhost netserva.com
195+
~ addvhost netserva.net
196+
197+
The authentication point being that using SSH or SFTP (ie; from Dolphin) to
198+
this server as...
199+
200+
~ ssh -p9 sysadm@netserva.org
201+
# or for KDE kio
202+
sftp://sysadm@netserva.org:9/
203+
204+
would result in access to the whole (non-root) file system whereas...
205+
206+
~ ssh -p9 u1001@netserva.org
207+
# or for KDE kio
208+
sftp://u1001@netserva.org:9/
209+
210+
would chroot or lock access to the `/home/u/netserva.org` area with no
211+
possibility of using SUDO so folks only interested in working on a web site
212+
have reasonably safe access to only that web area.
213+
214+
`setup-ssh` can be used on the host to manage local SSH keys making logging
215+
in to a container or remote server much easier...
216+
217+
Usage: setup-ssh domain [targethost] [user] [port] [sshkeyname]
218+
219+
_All scripts and documentation are Copyright (C) 1995-2018 Mark Constable
220+
and Licensed [AGPL-3.0]_
221+
222+
[NetServa SH]: https://github.com/netserva/sh/
223+
[NetServa SH/HCP]: https://github.com/netserva/
224+
[AGPL-3.0]: http://www.gnu.org/licenses/agpl-3.0.html
225+
[Bootstrap 4]: https://getbootstrap.com/
226+
[DataTables]: https://datatables.net/examples/styling/bootstrap4/
227+
[index.php]: https://github.com/netserva/www/blob/master/index.php
228+
[nginx]: http://nginx.org/
229+
[PHP FPM 7+]: http://www.php.net/manual/en/install.fpm.php
230+
[Plasma Desktop]: https://kubuntu.org/
231+
[LXD containers]: https://linuxcontainers.org/lxd/introduction/
232+
[LetsEncrypt]: https://letsencrypt.org/
233+
[PowerDNS]: https://powerdns.com/
234+
[SQLite]: https://sqlite.org/features.html
235+
[MySQL]: https://mariadb.org/
236+
[Ubuntu Server]: https://ubuntu.com/download/server/

build.sh

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env bash
2+
# ~/.sh/build.sh 20170301 - 20180501
3+
# Copyright (C) 2015-2018 Mark Constable <markc@renta.net> (AGPL-3.0)
4+
5+
[[ $1 =~ '-h' ]] && echo "Usage: [bash] buildall.sh [path(pwd)]
6+
7+
Example:
8+
9+
su - sysadm
10+
cd var/www/adm
11+
bash build.sh .
12+
" && exit 1
13+
14+
[[ $1 ]] && cd $1
15+
16+
echo "<?php declare(strict_types = 1);
17+
// netserva.php $(date -u +'%Y-%m-%d %H:%M:%S') UTC
18+
// Copyright (C) 2015-2018 Mark Constable <markc@renta.net> (AGPL-3.0)
19+
// This is single script concatenation of all PHP files in lib/php at
20+
// https://github.com/netserva/hcp
21+
" > netserva.php
22+
23+
(
24+
find lib/php -name "*.php" -exec cat {} +
25+
cat index.php
26+
) | sed \
27+
-e '/^?>/d' \
28+
-e '/^<?php/d' \
29+
-e '/^\/\/ Copyright.*/d' \
30+
-e '/^error_log.*/,+1 d' >> netserva.php
31+
32+
chmod 640 netserva.php

0 commit comments

Comments
 (0)