diff --git a/template/dashboard.php b/404.php
similarity index 73%
copy from template/dashboard.php
copy to 404.php
index ca408a8..a117860 100644
--- a/template/dashboard.php
+++ b/404.php
@@ -1,29 +1,25 @@
.
/*
- * This is the template for the website dashboard
+ * This is the page not found
*/
-// unuseful when load directly
-defined( 'BOZ_PHP' ) or die;
-?>
+// load framework
+require 'load.php';
-
+PageNotFound::spawn();
diff --git a/content/logo/logo-64.png b/content/logo/logo-64.png
new file mode 100644
index 0000000..72fa02d
Binary files /dev/null and b/content/logo/logo-64.png differ
diff --git a/domain.php b/domain.php
new file mode 100644
index 0000000..b6e5132
--- /dev/null
+++ b/domain.php
@@ -0,0 +1,77 @@
+.
+
+/*
+ * This is the domain edit page
+ */
+
+// load framework
+require 'load.php';
+
+// wanted domain
+list( $domain_name ) = url_parts( 1 );
+
+// retrieve domain
+$domain = ( new DomainAPI )
+ ->whereStr( 'domain_name', $domain_name )
+ ->whereDomainIsEditable()
+ ->queryRow();
+
+// 404?
+$domain or PageNotFound::spawn();
+
+// domain mailboxes
+$mailboxes = ( new MailboxFullAPI() )
+ ->select( [
+ 'domain_name',
+ 'mailbox_username',
+ 'mailbox_receive',
+ ] )
+ ->whereMailboxDomainID( $domain->get( 'domain_ID' ) )
+ ->queryGenerator();
+
+// spawn header
+Header::spawn( [
+ 'title' => sprintf(
+ __( "Domain: %s" ),
+ "" . esc_html( $domain_name ) . ""
+ ),
+] );
+?>
+
+ valid() ): ?>
+
+
+
+ -
+
+ getMailboxPermalink(),
+ $mailbox->getMailboxAddress()
+ ) ?>
+
+
+
+
+
+
+.
-/**
- * The footer of the web page
- */
-class Footer {
+class BadRequest {
- /**
- * Spawn the footer to standard output
- *
- * @param $args array arguments
- */
public static function spawn() {
- template( 'footer', Header::$args );
+ http_response_code( 400 );
+ Header::spawn( [
+ 'title' => __( "Bad request" )
+ ] );
+ template( 'bad-request' );
+ Footer::spawn();
+ exit;
}
+
}
diff --git a/include/class-Footer.php b/include/class-Domain.php
similarity index 60%
copy from include/class-Footer.php
copy to include/class-Domain.php
index 0c73c38..cf391e8 100644
--- a/include/class-Footer.php
+++ b/include/class-Domain.php
@@ -1,31 +1,41 @@
.
/**
- * The footer of the web page
+ * A domain handled by the user
*/
-class Footer {
+class Domain extends Queried {
+
+ const T = 'domain';
+ const UID = 'domain_name';
+
+ public function __construct() {
+ $this->integers( 'domain_ID' );
+ $this->booleans( 'domain_active' );
+ $this->dates( 'domain_born', 'domain_expiration' );
+ }
/**
- * Spawn the footer to standard output
+ * Get the domain edit URl
*
- * @param $args array arguments
+ * @return string
*/
- public static function spawn() {
- template( 'footer', Header::$args );
+ public function getDomainPermalink( $absolute = false ) {
+ return ROOT . '/domain.php/' . $this->get( 'domain_name' );
}
+
}
diff --git a/include/class-DomainAPI.php b/include/class-DomainAPI.php
new file mode 100644
index 0000000..5e51ece
--- /dev/null
+++ b/include/class-DomainAPI.php
@@ -0,0 +1,69 @@
+.
+
+/**
+ * Domain API
+ */
+class DomainAPI extends Query {
+
+ public function __construct() {
+ parent::__construct();
+ $this->from( Domain::T );
+ $this->defaultClass( 'Domain' );
+ }
+
+ /**
+ * Join domain and users (once)
+ *
+ * @return self
+ */
+ public function joinDomainUser() {
+ if( empty( $this->joinedDomainUser ) ) {
+ $this->from( 'domain_user' );
+ $this->equals( 'domain_user.domain_ID', 'domain.domain_ID' );
+ $this->joinedDomainUser = true;
+ }
+ return $this;
+ }
+
+ /**
+ * Where the domains are editable by me
+ *
+ * @return self
+ */
+ public function whereDomainIsEditable() {
+ if( ! has_permission( 'edit-domain-all' ) ) {
+ $this->whereDomainUser();
+ }
+ return $this;
+ }
+
+ /**
+ * Limit to a certain user (or yourself)
+ *
+ * @param $user_ID int
+ * @return self
+ */
+ public function whereDomainUser( $user_ID = false ) {
+ if( ! $user_ID ) {
+ $user_ID = get_user( 'user_ID' );
+ }
+ $this->joinDomainUser();
+ return $this->whereInt( 'domain_user.user_ID', $user_ID );
+ }
+
+}
diff --git a/include/class-Footer.php b/include/class-Footer.php
index 0c73c38..a78d6cb 100644
--- a/include/class-Footer.php
+++ b/include/class-Footer.php
@@ -1,31 +1,31 @@
.
/**
* The footer of the web page
*/
class Footer {
/**
* Spawn the footer to standard output
*
* @param $args array arguments
*/
public static function spawn() {
template( 'footer', Header::$args );
}
}
diff --git a/include/class-Header.php b/include/class-Header.php
index 3cb9c58..ef67282 100644
--- a/include/class-Header.php
+++ b/include/class-Header.php
@@ -1,61 +1,88 @@
.
/**
* 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 array arguments where:
+ * @param $args mixed Can be the page UID, or arguments where:
+ * uid: menu UID like 'home'
* title: document title
- * h1: site title (as default, it's the document title)
*/
public static function spawn( $args = [] ) {
// store arguments for future reads
self::$args = & $args;
- // set default arguments
+ // 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' ] )
+ : null;
+
+ // populate the page informations
+ if( $page ) {
+ $args = array_replace( [
+ 'title' => $page->name,
+ ], $args );
+ }
+
+ // populate default arguments
$args = array_replace( [
- 'h1' => $args[ 'title' ],
'container' => true,
+ 'sidebar' => true,
], $args );
- // load Bootstrap stuff
- enqueue_js( 'jquery' );
- enqueue_js( 'bootstrap' );
- enqueue_css( 'bootstrap' );
-
// charset is usually UTF-8
header( 'Content-Type: text/html; charset=' . CHARSET );
// spawn header template
template( 'header', $args );
}
+
+ /**
+ * Get the default page UID
+ *
+ * @return string
+ */
+ public static function actualPageUID() {
+ $page = basename( $_SERVER[ 'PHP_SELF' ] );
+ return str_replace( '.php', '', $page );
+ }
}
diff --git a/include/class-Mailbox.php b/include/class-Mailbox.php
new file mode 100644
index 0000000..bf34607
--- /dev/null
+++ b/include/class-Mailbox.php
@@ -0,0 +1,106 @@
+.
+
+/**
+ * A mailbox
+ */
+class Mailbox extends Domain {
+
+ const T = 'mailbox';
+
+ public function __construct() {
+ $this->booleans( 'mailbox_receive' );
+ }
+
+ /**
+ * Get the mailbox address
+ *
+ * @return string E-mail
+ */
+ public function getMailboxAddress() {
+ return sprintf( "%s@%s",
+ $this->get( 'mailbox_username' ),
+ $this->get( 'domain_name' )
+ );
+ }
+
+ /**
+ * Get the mailbox permalink
+ *
+ * @return string
+ */
+ public function getMailboxPermalink( $absolute = false ) {
+ return Mailbox::permalink(
+ $this->get( 'domain_name' ),
+ $this->get( 'mailbox_username' )
+ );
+ }
+
+ /**
+ * Update this mailbox password
+ *
+ * @param $password string
+ * @return string
+ */
+ public function updateMailboxPassword( $password = null ) {
+ if( ! $password ) {
+ $password = Mailbox::generatePassword();
+ }
+ $enc_password = Mailbox::encryptPassword( $password );
+ query_update( 'mailbox', [
+ new DBCol( 'mailbox_password', $enc_password, 's' ),
+ ], sprintf(
+ "domain_ID = %d AND mailbox_username = '%s'",
+ esc_sql( $this->get( 'domain_ID' ) ),
+ esc_sql( $this->get( 'mailbox_username' ) )
+ ) );
+ return $password;
+ }
+
+ /**
+ * Get the mailbox permalink
+ *
+ * @return string
+ */
+ public static function permalink( $domain, $mailbox ) {
+ return sprintf(
+ '%s/%s/%s',
+ ROOT . '/mailbox.php',
+ $domain,
+ $mailbox
+ );
+ }
+
+ /**
+ * Encrypt a password
+ *
+ * TODO: do not hardcode to my Dovecot configuration
+ */
+ public static function encryptPassword( $password ) {
+ $salt = bin2hex( openssl_random_pseudo_bytes( 3 ) );
+ return '{SHA512-CRYPT}' . crypt( $password, "$6$$salt" );
+ }
+
+ /**
+ * Generate a password
+ *
+ * TODO: do not hardcode to a certain way
+ */
+ public static function generatePassword() {
+ return rtrim( base64_encode( bin2hex( openssl_random_pseudo_bytes( 8 ) ) ), '=' );
+ }
+}
diff --git a/include/class-Footer.php b/include/class-MailboxAPI.php
similarity index 51%
copy from include/class-Footer.php
copy to include/class-MailboxAPI.php
index 0c73c38..b180af0 100644
--- a/include/class-Footer.php
+++ b/include/class-MailboxAPI.php
@@ -1,31 +1,52 @@
.
/**
- * The footer of the web page
+ * Mailbox API
*/
-class Footer {
+class MailboxAPI extends DomainAPI {
+
+ public function __construct() {
+ Query::__construct();
+ $this->from( Mailbox::T );
+ $this->defaultClass( 'Mailbox' );
+ }
+
+ /**
+ * Limit to a certain domain
+ *
+ * @param $domain_ID int
+ */
+ public function whereMailboxDomainID( $domain_ID ) {
+ return $this->whereInt( 'mailbox.domain_ID', $domain_ID );
+ }
/**
- * Spawn the footer to standard output
+ * Join mailboxes and domain (once)
*
- * @param $args array arguments
+ * @return self
*/
- public static function spawn() {
- template( 'footer', Header::$args );
+ public function joinMailboxDomain() {
+ if( empty( $this->joinedMailboxDomain ) ) {
+ $this->joinedMailboxDomain = true;
+ $this->from( 'domain' );
+ $this->equals( 'domain.domain_ID', 'mailbox.domain_ID' );
+ }
+ return $this;
}
+
}
diff --git a/template/dashboard.php b/include/class-MailboxFullAPI.php
similarity index 73%
copy from template/dashboard.php
copy to include/class-MailboxFullAPI.php
index ca408a8..e42330a 100644
--- a/template/dashboard.php
+++ b/include/class-MailboxFullAPI.php
@@ -1,29 +1,28 @@
.
-/*
- * This is the template for the website dashboard
+/**
+ * Mailbox API (retrieve a full mailbox address)
*/
+class MailboxFullAPI extends MailboxAPI {
-// unuseful when load directly
-defined( 'BOZ_PHP' ) or die;
-?>
+ public function __construct() {
+ parent::__construct();
+ $this->joinMailboxDomain();
+ }
-
+}
diff --git a/include/class-Footer.php b/include/class-MenuTree.php
similarity index 55%
copy from include/class-Footer.php
copy to include/class-MenuTree.php
index 0c73c38..65537d2 100644
--- a/include/class-Footer.php
+++ b/include/class-MenuTree.php
@@ -1,31 +1,52 @@
.
/**
- * The footer of the web page
+ * Handle a menu
*/
-class Footer {
+class MenuTree {
/**
- * Spawn the footer to standard output
+ * Spawn the menu
*
- * @param $args array arguments
+ * @param $args array Menu arguments where:
+ * uid:
*/
- public static function spawn() {
- template( 'footer', Header::$args );
+ public static function spawn( $args = [] ) {
+
+ // default arguments
+ $args = array_replace( [
+ 'uid' => null,
+ 'level' => 0,
+ 'max-level' => 99,
+ ], $args );
+
+ // end if level reached
+ if( $args[ 'level' ] > $args['max-level'] ) {
+ return;
+ }
+
+ $args[ 'entries' ] = get_children_menu_entries( $args[ 'uid' ] );
+ if( ! $args[ 'entries' ] ) {
+ return;
+ }
+
+ // spawn the related template
+ template( 'menu', $args );
}
+
}
diff --git a/include/class-Footer.php b/include/class-PageNotFound.php
similarity index 75%
copy from include/class-Footer.php
copy to include/class-PageNotFound.php
index 0c73c38..db99301 100644
--- a/include/class-Footer.php
+++ b/include/class-PageNotFound.php
@@ -1,31 +1,30 @@
.
-/**
- * The footer of the web page
- */
-class Footer {
+class PageNotFound {
- /**
- * Spawn the footer to standard output
- *
- * @param $args array arguments
- */
public static function spawn() {
- template( 'footer', Header::$args );
+ http_response_code( 404 );
+ Header::spawn( [
+ 'title' => __( "Page not found" )
+ ] );
+ template( '404' );
+ Footer::spawn();
+ exit;
}
+
}
diff --git a/include/class-SMTPMail.php b/include/class-SMTPMail.php
index b47e013..3cde6b4 100644
--- a/include/class-SMTPMail.php
+++ b/include/class-SMTPMail.php
@@ -1,107 +1,107 @@
.
/**
* Another Net_SMTP wrapper
*/
class SMTPMail {
/**
* @var object
*/
private $smtp;
/**
* Get the singleton instance
*/
public static function instance() {
static $instance = false;
if( ! $instance ) {
$instance = new self();
}
return $instance;
}
/**
* Constructor
*/
public function __construct() {
if( ! class_exists( 'Net_SMTP' ) ) {
require NET_SMTP;
}
$this->smtp = new Net_SMTP( SMTP_SERVER );
if( ! $this->smtp ) {
die( "Unable to instantiate Net_SMTP object\n" );
}
/* Connect to the SMTP server. */
if( PEAR::isError($e = $this->smtp->connect()) ) {
die( $e->getMessage() . "\n" );
}
$this->smtp->auth( SMTP_USERNAME, SMTP_PASSWORD, SMTP_AUTH, SMTP_TLS );
/* Send the 'MAIL FROM:' SMTP command. */
if( PEAR::isError( $this->smtp->mailFrom( MAIL_FROM ) ) ) {
die("Unable to set sender to <$from>\n");
}
}
/**
* Add a recipient
*
* @param $to string E-mail
*/
public function to( $to ) {
if( PEAR::isError( $res = $this->smtp->rcptTo( $to ) ) ) {
die( "Unable to add recipient <$to>: " . $res->getMessage() . "\n" );
}
return $this;
}
/**
* Specify subject and message body
*
* @param $subject string
* @param $body string
*/
public function message( $subject, $body ) {
$data = '';
$headers = [ 'Subject' => $subject ];
foreach( $headers as $header => $value ) {
$value = str_replace( "\n", '', $value );
$data .= "$header: $value\n";
}
$data .= "\r\n$subject";
if (PEAR::isError( $this->smtp->data( $data ) ) ) {
die( "Unable to send data\n" );
}
return $this;
}
/**
* Disconnect to the SMTP server
*/
public function disconnect() {
$this->smtp->disconnect();
unset( $this->smtp );
}
}
diff --git a/include/functions.php b/include/functions.php
index d336ef5..a5b425f 100644
--- a/include/functions.php
+++ b/include/functions.php
@@ -1,58 +1,109 @@
.
/**
* 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( $name, $args = [] ) {
require TEMPLATE_PATH . __ . "$name.php";
}
/**
* 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' );
+ $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
+ *
+ * @param $n
+ */
+function url_parts( $n ) {
+ $parts = explode( _, $_SERVER[ 'PATH_INFO' ] );
+ array_shift( $parts );
+ if( count( $parts ) !== $n ) {
+ BadRequest::spawn();
+ }
+ return $parts;
+}
diff --git a/index.php b/index.php
index a8c7bbb..dbc0b94 100644
--- a/index.php
+++ b/index.php
@@ -1,45 +1,74 @@
.
-require 'load.php';
-
/*
* This is the homepage of your hosting panel
*/
-if( isset( $_POST[ 'user_password' ] ) ) {
- login();
-}
+// load framework
+require 'load.php';
-if( ! is_logged() ) {
- http_response_code( 401 );
-}
+// require read permissions
+require_permission( 'read' );
// spawn header
-Header::spawn( [
- 'title' => __( "Home" ),
-] );
+Header::spawn();
+
+// user domains
+$domains = ( new DomainAPI() )
+ ->select( [
+ 'domain.domain_ID',
+ 'domain_name',
+ 'domain_active',
+ ] )
+ ->whereDomainIsEditable()
+ ->orderBy( 'domain_name' )
+ ->queryGenerator();
?>
-
-
-
-
+
+
+ valid() ): ?>
+
+
+
+ -
+
+ domain_active ): ?>
+ getDomainPermalink(),
+ $domain->domain_name
+ ) ?>
+
+ domain_name ) ?>
+
+
+
+
+
.
/*
* 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';
diff --git a/load-post.php b/load-post.php
index 8a5020b..e3f1a55 100644
--- a/load-post.php
+++ b/load-post.php
@@ -1,64 +1,84 @@
.
// include path
define_default( 'INCLUDE_PATH', ABSPATH . __ . 'include' );
// template path
define_default( 'TEMPLATE_PATH', ABSPATH . __ . 'template' );
// autoload classes from the /include directory
spl_autoload_register( function( $name ) {
$path = INCLUDE_PATH . __ . "class-$name.php";
if( is_file( $path ) ) {
require $path;
}
} );
// load common functions
require INCLUDE_PATH . __ . 'functions.php';
// jquery URL
// provided by the libjs-jquery package as default
define_default( 'JQUERY_URL', '/javascript/jquery/jquery.min.js' );
// Bootstrap CSS/JavaScript files without trailing slash
// provided by the libjs-bootstrap package as default
define_default( 'BOOTSTRAP_DIR_URL', '/javascript/bootstrap' );
// path to the Net SMTP class
// provided by the php-net-smtp package as default
define_default( 'NET_SMTP', '/usr/share/php/Net/SMTP.php' );
// register JavaScript/CSS files
register_js( 'jquery', JQUERY_URL );
register_js( 'bootstrap', BOOTSTRAP_DIR_URL . '/js/bootstrap.min.js' );
register_css( 'bootstrap', BOOTSTRAP_DIR_URL . '/css/bootstrap.min.css' );
// GNU Gettext i18n
define( 'GETTEXT_DOMAIN', 'reyboz-hosting-panel' );
define( 'GETTEXT_DIRECTORY', 'l10n' );
define( 'GETTEXT_DEFAULT_ENCODE', CHARSET ); // UTF-8
// common strings
-define_default( 'SITE_NAME', "Reyboz Libre Hosting Panel" );
-
-// generic contact e-mail
+define_default( 'SITE_NAME', "Boz Libre Hosting Panel" );
define_default( 'CONTACT_EMAIL', 'support@' . DOMAIN );
-
-// repository project URL
define_default( 'REPO_URL', 'https://github.com/valerio-bozzolan/boz-libre-hosting-panel' );
+
+// register web pages
+call_user_func( function () {
+ $logged = is_logged();
+ $show_to_user = $logged ? null : 'hidden';
+ $show_to_anon = ! $logged ? null : 'hidden';
+ add_menu_entries( [
+ new MenuEntry( 'index', '', __( "Dashboard" ), $show_to_user ),
+ new MenuEntry( 'login', 'login.php', __( "Login" ), $show_to_anon ),
+ new MenuEntry( 'logout', 'logout.php', __( "Logout" ), $show_to_user ),
+ new MenuEntry( 'password-reset', 'password-reset.php', __( "Password reset" ), $show_to_anon ),
+ ] );
+} );
+
+// permissions
+register_permissions( 'user', [
+ 'read',
+ 'backend',
+] );
+inherit_permissions( 'admin', 'user', [
+ 'edit-user-all',
+ 'edit-email-all',
+ 'edit-domain-all',
+] );
diff --git a/template/login.php b/login.php
similarity index 61%
rename from template/login.php
rename to login.php
index 2db4b9a..62fd5f2 100644
--- a/template/login.php
+++ b/login.php
@@ -1,63 +1,79 @@
.
/*
- * This is the template for the login form
+ * This is the login page
*/
-// unuseful when load directly
-defined( 'BOZ_PHP' ) || die;
+// load framework
+require 'load.php';
-/**
- * Print the password reset URL
- */
-$password_reset_url = function () {
- echo http_build_get_query(
- ROOT . '/password-reset.php', [
- 'user_uid' => @ $_REQUEST[ 'user_uid' ],
- ]
- );
-};
+// spawn header
+Header::spawn();
+
+// go to the wanted page (or homepage)
+if( login() ) {
+ http_redirect( after_login_url(), 307 );
+}
?>
-
-
-
-
+
+
+
+getSitePage( URL );
+}
diff --git a/index.php b/logout.php
similarity index 60%
copy from index.php
copy to logout.php
index a8c7bbb..6510afe 100644
--- a/index.php
+++ b/logout.php
@@ -1,45 +1,47 @@
.
-require 'load.php';
-
/*
- * This is the homepage of your hosting panel
+ * This is the logout page
*/
-if( isset( $_POST[ 'user_password' ] ) ) {
- login();
-}
-
-if( ! is_logged() ) {
- http_response_code( 401 );
-}
+// load framework
+require 'load.php';
// spawn header
Header::spawn( [
- 'title' => __( "Home" ),
+ 'title' => __( "Please confirm logout" ),
] );
+
+// check login
+if( is_action( 'logout' ) ) {
+ logout();
+}
+
+// require to be logged, but do not redirect again here otherwise
+require_permission( 'read', false );
?>
-
-
-
-
-
+
+
+
.
+
+/*
+ * This is the mailbox edit page
+ */
+
+// load framework
+require 'load.php';
+
+// wanted domain and mailbox username
+list( $domain_name, $mailbox_username ) = url_parts( 2 );
+
+// retrieve domain
+$mailbox = ( new MailboxFullAPI )
+ ->select( [
+ 'domain.domain_ID',
+ 'domain.domain_name',
+ 'domain.domain_active',
+ 'mailbox_username',
+ ] )
+ ->whereStr( 'domain_name', $domain_name )
+ ->whereStr( 'mailbox_username', $mailbox_username )
+ ->whereDomainIsEditable()
+ ->queryRow();
+
+// 404?
+$mailbox or PageNotFound::spawn();
+
+$password = null;
+if( is_action( 'mailbox-password-reset' ) ) {
+ $password = $mailbox->updateMailboxPassword();
+}
+
+// spawn header
+Header::spawn( [
+ 'title' => sprintf(
+ __( "Mailbox: %s" ),
+ "" . esc_html( $mailbox->getMailboxAddress() ) . ""
+ ),
+] );
+
+// spawn the page content
+template( 'mailbox', [
+ 'mailbox' => $mailbox,
+ 'password' => $password,
+] );
+
+// spawn the footer
+Footer::spawn();
diff --git a/index.php b/password-reset.php
similarity index 50%
copy from index.php
copy to password-reset.php
index a8c7bbb..b23979c 100644
--- a/index.php
+++ b/password-reset.php
@@ -1,45 +1,49 @@
.
require 'load.php';
/*
- * This is the homepage of your hosting panel
+ * This is the password reset page
*/
-if( isset( $_POST[ 'user_password' ] ) ) {
- login();
-}
-
-if( ! is_logged() ) {
- http_response_code( 401 );
+// do something
+if( is_action( 'password-reset' ) ) {
+ if( is_logged() ) {
+ send_email( __( "Password reset" ), $message, $to = false );
+ } else {
+ send_email( __( "Password reset" ), $message, $to = false );
+ }
}
// spawn header
-Header::spawn( [
- 'title' => __( "Home" ),
-] );
+Header::spawn();
?>
-
-
-
-
-
+
.
/*
- * This is the template for the website dashboard
+ * This is the template for a bad request
*/
// unuseful when load directly
defined( 'BOZ_PHP' ) or die;
?>
-
+
+
+
diff --git a/template/dashboard.php b/template/bad-request.php
similarity index 76%
copy from template/dashboard.php
copy to template/bad-request.php
index ca408a8..85ed2b2 100644
--- a/template/dashboard.php
+++ b/template/bad-request.php
@@ -1,29 +1,28 @@
.
/*
- * This is the template for the website dashboard
+ * This is the template for a bad request
*/
// unuseful when load directly
defined( 'BOZ_PHP' ) or die;
?>
-
+
+
+
diff --git a/template/dashboard.php b/template/dashboard.php
index ca408a8..062cb3e 100644
--- a/template/dashboard.php
+++ b/template/dashboard.php
@@ -1,29 +1,29 @@
.
/*
* This is the template for the website dashboard
*/
// unuseful when load directly
defined( 'BOZ_PHP' ) or die;
?>
diff --git a/template/footer.php b/template/footer.php
index 5872d19..f8f1dfd 100644
--- a/template/footer.php
+++ b/template/footer.php
@@ -1,50 +1,70 @@
.
/*
* This is the template for the website footer
*/
// unuseful when load directly
defined( 'BOZ_PHP' ) or die;
load_module( 'footer' );
?>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+