diff --git a/README.md b/README.md
index a24e4dd..e686d9a 100644
--- a/README.md
+++ b/README.md
@@ -1,54 +1,59 @@
# Boz's Libre Hosting Panel
This projects was started to create another _keep it simple and stupid_ libre web hosting control panel suitable for providers of everyday shared hosting services.
## Disclaimer
Do not try to become a system administrator if you do not like responsibilities, if you do not want to understand your infrastructure, if you do not want to have information security paranoia, etc.
## Preamble
An hosting panel is just the iceberg summit of a lot of technologies and protocols involved. Do not try to implement such project in production if you do not know what you are doing. You must gain confidence with the technologies involved.
Papers:
* RFC 5321 - Simple Mail Transfer Protocol
* RFC 7208 - Sender Policy Framework (SPF)
* RFC 6376 - DomainKeys Identified Mail (DKIM) Signatures
* RFC 7489 - Domain-based Message Authentication, Reporting, and Conformance (DMARC)
Software involved:
* Debian GNU/Linux stable
* MariaDB / MySQL
* Postfix
* Dovecot
* PureFTPd
* OpenDKIM
* Apache HTTP server / nginx
* PHP
## Features
Let me say that I love listening to the whishlist of my costumers. Here are the most important features/TODOs:
-- administration of own mailboxes
+- administration of own mailboxes (thanks to Postfix and Dovecot over MariaDB)
+ - [X] list
- [X] password reset
- - [ ] add
+ - [X] add
- [ ] remove
- [ ] view quota
- administration of own mail aliases (thanks to Postfix and Dovecot over MariaDB)
+ - [X] list
- [X] change forward destination(s)
- [X] add
- [X] remove
-- [ ] administration of own FTP accounts (thanks to Pure-FTPd over MariaDB)
+- administration of own FTP accounts (thanks to Pure-FTPd over MariaDB)
+ - [X] list
+ - [ ] add
+ - [ ] remove
- [ ] administration of own MariaDB databases
## License
Copyright (C) 2018 [Valerio Bozzolan](https://boz.reyboz.it/) - _Boz Libre Hosting Panel_
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License along with this program. If not, see .
diff --git a/include/class-Breadcrumb.php b/include/class-Breadcrumb.php
index 80a326d..5105877 100644
--- a/include/class-Breadcrumb.php
+++ b/include/class-Breadcrumb.php
@@ -1,71 +1,79 @@
.
/**
* Handle a breadcrumb with the related microdata
*
* @url https://schema.org/BreadcrumbList
* @url https://developers.google.com/search/docs/data-types/breadcrumb
*/
class Breadcrumb {
/**
* Spawn the breadcrumb
*
* @param $uid string|null Starting menu uid
* @param $title string|null Starting title
* @param $parent_uid string|null Parent menu uid
*/
public static function spawn( $breadcrumbs ) {
?>
-
+ = self::menuEntryLink( ++$i, $crumb ) ?>
url ? $entry->getSitePage() : null;
return self::link( $i, $url, $entry->name );
}
/**
- * Spawn a link with microdata
+ * Get a link with microdata
+ *
+ * @param int $i
+ * @param string $url
+ * @param string $title
+ * @return string
*/
public static function link( $i, $url, $title ) {
- echo '';
+ $s = '';
if( $url ) {
- echo '';
- echo '' . esc_html( $title ) . '';
- echo '';
+ $s .= '';
+ $s .= '' . esc_html( $title ) . '';
+ $s .= '';
} else {
- echo '' . _esc_html( $title ) . '';
+ $s .= '' . esc_html( $title ) . '';
}
- echo '';
- echo "\n";
+ $s .= '';
+ $s .= "\n";
+
+ return $s;
}
}
diff --git a/include/class-Header.php b/include/class-Header.php
index e4e81aa..9f6bce7 100644
--- a/include/class-Header.php
+++ b/include/class-Header.php
@@ -1,91 +1,91 @@
.
/**
* The header of the web page
*/
class Header {
/**
* Header arguments
*
* It's public because the Footer reads it.
*
* @var array
*/
public static $args;
/**
* Spawn the header to standard output
*
* @param $args mixed Can be the page UID, or arguments where:
* uid: menu UID like 'home'
* title: document title
*/
public static function spawn( $args = [] ) {
// store arguments for future reads
self::$args = & $args;
// shortcut
if( is_string( $args ) ) {
$args = [ 'uid' => $args ];
}
// eventually retrieve actual page UID
if( ! isset( $args[ 'uid' ] ) ) {
$args[ 'uid' ] = self::actualPageUID();
}
// retrieve page informations
$page = isset( $args[ 'uid' ] )
- ? get_menu_entry( $args[ 'uid' ] )
+ ? menu_entry( $args[ 'uid' ] )
: null;
// populate the page informations
if( $page ) {
$args = array_replace( [
'title' => $page->name,
], $args );
} else {
$args[ 'uid' ] = null;
}
// populate default arguments
$args = array_replace( [
'container' => true,
'sidebar' => true,
'breadcrumb' => [],
], $args );
// charset is usually UTF-8
header( 'Content-Type: text/html; charset=' . CHARSET );
// spawn header template
template( 'header', [ 'args' => $args ] );
}
/**
* Get the default page UID
*
* @return string
*/
public static function actualPageUID() {
$page = basename( $_SERVER[ 'SCRIPT_NAME' ] );
return str_replace( '.php', '', $page );
}
}
diff --git a/include/functions.php b/include/functions.php
index c7c81a0..ffb00a4 100644
--- a/include/functions.php
+++ b/include/functions.php
@@ -1,205 +1,195 @@
.
/**
* Require a certain page from the template directory
*
* @param $name string page name (to be sanitized)
* @param $args mixed arguments to be passed to the page scope
*/
function template( $template_name, $template_args = [] ) {
extract( $template_args, EXTR_SKIP );
return require TEMPLATE_PATH . __ . "$template_name.php";
}
/**
* Get the returned text from a template
*
* @param $name string page name (to be sanitized)
* @param $args mixed arguments to be passed to the page scope
* @see template()
* @return string
*/
function template_content( $name, $args = [] ) {
ob_start();
template( $name, $args );
$text = ob_get_contents();
ob_end_clean();
return $text;
}
/**
* Print an e-mail (safe for bots)
*
* @param $email string
*/
function email_blur( $email ) {
$dot = strip_tags( __( " dot " ) );
$at = strip_tags( __( " at " ) );
$email = esc_html( $email );
echo str_replace( [ '.', '@' ], [ $dot, $at ], $email );
}
/**
* Send an e-mail to someone
*
* @param $subject string E-mail subject
* @param $message string E-mail message
* @param $to string E-mail recipient (from current logged-in user as default)
*/
function send_email( $subject, $message, $to = false ) {
if( ! $to ) {
if( ! is_logged() ) {
die( "can't retrieve e-mail address from anon user" );
}
$to = get_user( 'user_email' );
}
return SMTPMail::instance()
->to( $to )
->message( $subject, $message )
->disconnect();
}
/**
* Require a certain permission
*
* @param $permission string An internal permission like 'edit-all-user'
* @param $redirect boolean Enable or disable the redirect
*/
function require_permission( $permission, $redirect = true ) {
if( ! has_permission( $permission ) ) {
if( is_logged() ) {
Header::spawn( [
'title' => __( "Permission denied" ),
] );
Footer::spawn();
exit;
} else {
- $login = get_menu_entry( 'login' );
+ $login = menu_entry( 'login' );
$url = $login->getSitePage( URL );
if( $redirect && isset( $_SERVER[ 'REQUEST_URI' ] ) ) {
$url = http_build_get_query( $url, [
'redirect' => $_SERVER[ 'REQUEST_URI' ],
] );
}
http_redirect( $url, 307 );
}
}
}
-/**
- * Check the POST action
- *
- * @param $action string e.g. 'save-domain'
- * @return bool
- */
-function is_action( $action ) {
- return isset( $_POST[ 'action' ] ) && $_POST[ 'action' ] === $action;
-}
-
/**
* Get URL parts from the PATH_INFO
*
* It spawn a "bad request" page if something goes wrong.
*
* @param $max int If $min is specified, this is the maximum number of parameters. When unspecified, this is the exact number of parameters.
* @param $min int Mininum number of parameters.
* @return array
* @see https://httpd.apache.org/docs/2.4/mod/core.html#acceptpathinfo
*/
function url_parts( $max, $min = false ) {
if( $min === false ) {
$min = $max;
}
// split the PATH_INFO parts
$parts = explode( _, $_SERVER[ 'PATH_INFO' ] );
array_shift( $parts );
// eventually spawn the "bad request"
$n = count( $parts );
if( $n > $max || $n < $min ) {
BadRequest::spawn( __( "unexpected URL" ) );
}
// eventually fill expected fields
for( $i = $n; $i < $max; $i++ ) {
$parts[] = null;
}
return $parts;
}
/**
* Link to an existing page from the menu
*
* @param $uid string E.g. 'index'
* @param $args mixed Arguments
*/
function the_menu_link( $uid, $args = [] ) {
- $page = get_menu_entry( $uid );
+ $page = menu_entry( $uid );
the_link( $page->getSitePage(), $page->name, $args );
}
/**
* Link to a whatever page
*
* P.S. link() is a reserved function
*
* @param $url string
* @param $title string
* @param $args mixed Arguments
*/
function the_link( $url, $title, $args = [] ) {
template( 'link', [
'title' => $title,
'url' => $url,
'args' => $args,
] );
}
/**
* Generate a password
*
* @param $bytes int
*/
function generate_password( $bytes = 8 ) {
return rtrim( base64_encode( bin2hex( openssl_random_pseudo_bytes( $bytes ) ) ), '=' );
}
/**
* Validate a mailbox username
*
* @param $mailbox string
* @return bool
*/
function validate_mailbox_username( $mailbox ) {
return 1 === preg_match( '/^[a-z][a-z0-9-_.]+$/', $mailbox );
}
/**
* A certain value must be an e-mail
*
* @param $email string
* @return string filtered e-mail
*/
function require_email( $email ) {
$email = luser_input( $email, 128 );
if( filter_var( $email, FILTER_VALIDATE_EMAIL ) === false ) {
BadRequest::spawn( __( "fail e-mail validation" ) );
}
return $email;
}
diff --git a/load-example.php b/load-example.php
index 4ca5128..c828a0d 100644
--- a/load-example.php
+++ b/load-example.php
@@ -1,52 +1,52 @@
.
/*
* This is an example configuration file
*
* Please fill this file and save as 'load.php'!
*/
// database credentials
$username = 'insert here database username';
$password = 'insert here database password';
$database = 'insert here database name';
$location = 'localhost';
// database prefix (if any)
$prefix = '';
// your contact e-mail
define( 'CONTACT_EMAIL', 'services@example.org' );
// your SMTP credentials
define( 'MAIL_FROM', 'noreply@example.org' );
define( 'SMTP_USERNAME', 'noreply@example.org' );
define( 'SMTP_PASSWORD', 'insert here smtp password' );
define( 'SMTP_AUTH', 'PLAIN' );
define( 'SMTP_TLS', true );
define( 'SMTP_SERVER', 'mail.example.org' );
define( 'SMTP_PORT', 465 );
// absolute path to the project directory without trailing slash
define( 'ABSPATH', __DIR__ );
// absolute web directory without trailing slash
define( 'ROOT', '' );
// path to the boz-php framework
-require '/usr/share/php/boz-php/load.php';
+require '/usr/share/php/suckless-php/load.php';
diff --git a/template/404.php b/template/404.php
index abcba2a..4162bf3 100644
--- a/template/404.php
+++ b/template/404.php
@@ -1,30 +1,30 @@
.
/*
* This is the template for a bad request
*
* Called from:
* include/class-PageNotFound.php
*/
// unuseful when load directly
defined( 'BOZ_PHP' ) or die;
?>
-
-
+ = __( "Oh no! A page not found error!" ) ?>
+ = __( "The page you was looking for is wrong or was deleted or you have not enough permissions to see it, etc. you know." ) ?>
diff --git a/template/bad-request.php b/template/bad-request.php
index f96a376..2189716 100644
--- a/template/bad-request.php
+++ b/template/bad-request.php
@@ -1,39 +1,39 @@
.
/*
* This is the template for a bad request
*
* Called from:
* include/class-BadRequest.php
*
* Available variables:
* $message string
*/
// unuseful when load directly
defined( 'BOZ_PHP' ) or die;
?>
-
+ = __( "Your request cannot be processed." ) ?>
-
+ = __( "If you think that it's not your fault, contact us. Thanks!" ) ?>
diff --git a/template/breadcrumb.php b/template/breadcrumb.php
index 1213c18..177e79d 100644
--- a/template/breadcrumb.php
+++ b/template/breadcrumb.php
@@ -1,36 +1,36 @@
.
/*
* This is the template for the website breadcrumb navigation menu
*
* Called from:
* template/header.php
*/
// unuseful when load directly
defined( 'BOZ_PHP' ) or die;
// add home to the breadcrumb
-array_unshift( $args[ 'breadcrumb' ], get_menu_entry( 'index' ) );
+array_unshift( $args[ 'breadcrumb' ], menu_entry( 'index' ) );
// add "this page" to the breadcrumb
if( $args[ 'uid' ] !== 'index' ) {
$args[ 'breadcrumb' ][] = new MenuEntry( null, null, $args[ 'title' ] );
}
Breadcrumb::spawn( $args[ 'breadcrumb' ] );
diff --git a/template/domain-create.php b/template/domain-create.php
index 9d1a80f..2626d8a 100644
--- a/template/domain-create.php
+++ b/template/domain-create.php
@@ -1,33 +1,33 @@
.
/*
* This is the template for the create domain form
*
* Called from:
* domain.php
*/
// unuseful when load directly
defined( 'BOZ_PHP' ) or die;
?>
diff --git a/template/footer.php b/template/footer.php
index d0a3fac..6e06c17 100644
--- a/template/footer.php
+++ b/template/footer.php
@@ -1,80 +1,80 @@
.
/*
* This is the template for the website footer
*
* Called from:
* include/class-Footer.php
*
* Available variables:
* $args array
*/
// unuseful when load directly
defined( 'BOZ_PHP' ) or die;
load_module( 'footer' );
?>
-
+ = __( "Help:" ) ?>
-
-
+ = __( "Contribute:" ) ?>
+