diff --git a/load-post.php b/load-post.php
index 4aad756..34b3cdf 100644
--- a/load-post.php
+++ b/load-post.php
@@ -1,84 +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' );
register_css( 'custom-css', ROOT . '/content/style.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', "Boz Libre Hosting Panel" );
define_default( 'CONTACT_EMAIL', 'support@' . DOMAIN );
define_default( 'REPO_URL', 'https://github.com/valerio-bozzolan/boz-libre-hosting-panel' );
-// limit session duration to 5 minutes (60s * 5m)
-define_default( 'SESSION_DURATION', 300 );
+// limit session duration to 5 minutes (60s * 100m)
+define_default( 'SESSION_DURATION', 6000 );
// register web pages
add_menu_entries( [
new MenuEntry( 'index', '/', __( "Dashboard" ) ),
new MenuEntry( 'login', 'login.php', __( "Login" ) ),
new MenuEntry( 'profile', 'profile.php', __( "Profile" ) ),
new MenuEntry( 'logout', 'logout.php', __( "Logout" ) ),
new MenuEntry( 'password-reset', 'password-reset.php', __( "Password reset" ) ),
] );
// permissions
register_permissions( 'user', [
'read',
'backend',
] );
inherit_permissions( 'admin', 'user', [
'edit-user-all',
'edit-email-all',
'edit-domain-all',
] );
diff --git a/404.php b/www/404.php
similarity index 97%
rename from 404.php
rename to www/404.php
index a117860..5837edd 100644
--- a/404.php
+++ b/www/404.php
@@ -1,25 +1,25 @@
.
/*
* This is the page not found
*/
// load framework
-require 'load.php';
+require '../load.php';
PageNotFound::spawn();
diff --git a/domain.php b/www/domain.php
similarity index 98%
rename from domain.php
rename to www/domain.php
index 56f4604..900b298 100644
--- a/domain.php
+++ b/www/domain.php
@@ -1,49 +1,49 @@
.
/*
* This is the domain edit page
*/
// load framework
-require 'load.php';
+require '../load.php';
// wanted domain
list( $domain_name ) = url_parts( 1 );
// retrieve domain
$domain = ( new DomainAPI() )
->whereDomainName( $domain_name )
->whereDomainIsEditable()
->queryRow();
// 404?
$domain or PageNotFound::spawn();
// spawn header
Header::spawn( [
'title-prefix' => __( "Domain" ),
'title' => $domain_name,
] );
// spawn the domain template
template( 'domain', [
'domain' => $domain,
] );
// spawn the footer
Footer::spawn();
diff --git a/index.php b/www/index.php
similarity index 98%
rename from index.php
rename to www/index.php
index e6999eb..3c3a51d 100644
--- a/index.php
+++ b/www/index.php
@@ -1,76 +1,76 @@
.
/*
* This is the homepage of your hosting panel
*/
// load framework
-require 'load.php';
+require '../load.php';
// require read permissions
require_permission( 'read' );
// spawn header
Header::spawn( [
'breadcrumb' => false,
] );
// 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 the login page
*/
// load framework
-require 'load.php';
+require '../load.php';
// spawn header
Header::spawn();
// go to the wanted page (or homepage)
if( login() ) {
http_redirect( after_login_url(), 307 );
}
?>
getSitePage( URL );
}
diff --git a/logout.php b/www/logout.php
similarity index 97%
rename from logout.php
rename to www/logout.php
index e0459d8..283bc89 100644
--- a/logout.php
+++ b/www/logout.php
@@ -1,42 +1,42 @@
.
/*
* This is the logout page
*/
// load framework
-require 'load.php';
+require '../load.php';
// spawn header
Header::spawn( [
'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 );
// spawn the logout template
template( 'logout' );
// spawn footer
Footer::spawn();
diff --git a/mailbox.php b/www/mailbox.php
similarity index 98%
rename from mailbox.php
rename to www/mailbox.php
index 919e193..95889d8 100644
--- a/mailbox.php
+++ b/www/mailbox.php
@@ -1,65 +1,65 @@
.
/*
* This is the mailbox edit page
*/
// load framework
-require 'load.php';
+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-prefix' => __( "Mailbox" ),
'title' => $mailbox->getMailboxAddress(),
'breadcrumb' => [
new MenuEntry( null, $mailbox->getDomainPermalink(), $mailbox->getDomainName() ),
],
] );
// spawn the page content
template( 'mailbox', [
'mailbox' => $mailbox,
'password' => $password,
] );
// spawn the footer
Footer::spawn();
diff --git a/mailforward.php b/www/mailforward.php
similarity index 99%
rename from mailforward.php
rename to www/mailforward.php
index 333e52d..6e4c0fa 100644
--- a/mailforward.php
+++ b/www/mailforward.php
@@ -1,178 +1,178 @@
.
/*
* This is the single e-mail forwarding edit page
*/
// load framework
-require 'load.php';
+require '../load.php';
// wanted informations
$domain = null;
$mailforwardfrom = null;
// URL paramenters (maximum both domain and mailforward source, minimum just domain)
list( $domain_name, $mailforwardfrom_username ) = url_parts( 2, 1 );
// eventually retrieve mailforward from database
if( $mailforwardfrom_username ) {
$mailforwardfrom = ( new MailforwardfromAPI )
->select( [
'domain.domain_ID',
'domain_name',
'mailforwardfrom.mailforwardfrom_ID',
'mailforwardfrom_username',
] )
->whereDomainName( $domain_name )
->whereMailforwardfromUsername( $mailforwardfrom_username )
->whereDomainIsEditable()
->queryRow();
// 404
$mailforwardfrom or PageNotFound::spawn();
// recycle the mailforward object that has domain informations
$domain = $mailforwardfrom;
}
// eventually retrieve domain from database
if( ! $domain ) {
$domain = ( new DomainAPI() )
->select( [
'domain.domain_ID',
'domain.domain_name',
] )
->whereDomainName( $domain_name )
->whereDomainIsEditable()
->queryRow();
// 404
$domain or PageNotFound::spawn();
}
// save destination action
if( is_action( 'mailforward-save' ) ) {
// save source only during creation
if( ! $mailforwardfrom ) {
// sanitize
if( ! isset( $_POST[ 'mailforwardfrom_username' ] ) ) {
BadRequest::spawn( __( "missing parameter" ) );
}
$username = luser_input( $_POST[ 'mailforwardfrom_username' ], 128 );
if( ! validate_mailbox_username( $username ) ) {
BadRequest::spawn( __( "invalid mailbox name" ) );
}
// check existence
$mailforwardfrom_exists = ( new MailforwardfromAPI )
->select( 1 )
->whereDomain( $domain )
->whereMailforwardfromUsername( $source )
->queryRow();
// die if exists
if( $mailforwardfrom_exists ) {
BadRequest::spawn( __( "e-mail forwarding already existing" ) );
}
// insert as new row
insert_row( 'mailforwardfrom', [
new DBCol( 'domain_ID', $domain->getDomainID(), 'd' ),
new DBCol( 'mailforwardfrom_username', $username, 's' ),
] );
// POST/redirect/GET
http_redirect( Mailforwardfrom::permalink(
$domain->getDomainName(),
$username,
true
), 303 );
}
}
// delete action
if( $mailforwardfrom ) {
// action fired when deleting a whole mailforward
if( is_action( 'mailforward-delete' ) ) {
// drop th
query( sprintf(
"DELETE FROM %s WHERE domain_ID = %d AND mailforwardfrom_username = '%s'",
T( 'mailforwardfrom' ),
$mailforwardfrom->getDomainID(),
$mailforwardfrom->getMailforwardfromUsername()
) );
// POST/redirect/GET
http_redirect( $domain->getDomainPermalink( true ), 303 );
}
// action fired when adding/removing a mailforward
if( ( is_action( 'mailforwardto-add' ) || is_action( 'mailforwardto-remove' ) ) && isset( $_POST[ 'address' ] ) ) {
$address = require_email( $_POST[ 'address' ] );
$existing_address =
( new MailforwardtoAPI() )
->whereMailforwardfrom( $mailforwardfrom )
->whereMailforwardtoAddress( $address )
->queryRow();
// action fired when removing a mailforward
if( is_action( 'mailforwardto-remove' ) && $existing_address ) {
query( sprintf(
"DELETE FROM %s WHERE mailforwardfrom_ID = %d and mailforwardto_address = '%s'",
T( 'mailforwardto' ),
$mailforwardfrom->getMailforwardfromID(),
esc_sql( $address )
) );
}
// action fired when adding a mailforward
if( is_action( 'mailforwardto-add' ) && ! $existing_address ) {
insert_row( 'mailforwardto', [
new DBCol( 'mailforwardfrom_ID', $mailforwardfrom->getMailforwardfromID(), 'd' ),
new DBCol( 'mailforwardto_address', $address, 's' ),
] );
}
}
}
// spawn header
Header::spawn( [
'title-prefix' => __( "E-mail forwarding" ),
'title' => $mailforwardfrom
? $mailforwardfrom->getMailforwardfromAddress()
: __( "create" ),
'breadcrumb' => [
new MenuEntry( null, $domain->getDomainPermalink(), $domain->getDomainName() ),
],
] );
// spawn the page content
template( 'mailforward', [
'domain' => $domain,
'mailforwardfrom' => $mailforwardfrom,
] );
// spawn the footer
Footer::spawn();
diff --git a/password-reset.php b/www/password-reset.php
similarity index 98%
rename from password-reset.php
rename to www/password-reset.php
index 52e2fa3..82c59e2 100644
--- a/password-reset.php
+++ b/www/password-reset.php
@@ -1,50 +1,50 @@
.
-require 'load.php';
+require '../load.php';
/*
* This is the password reset page
*/
// do something
if( is_action( 'password-reset' ) ) {
die( "Apologies. This feature is not ready :(" );
if( is_logged() ) {
send_email( __( "Password reset" ), $message, $to = false );
} else {
send_email( __( "Password reset" ), $message, $to = false );
}
}
// spawn header
Header::spawn();
?>
.
/*
* This is the user profile page
*/
// load framework
-require 'load.php';
+require '../load.php';
// must be logged
require_permission( 'read' );
// myself
$user = get_user();
// edit whatever user
if( isset( $_SERVER[ 'PATH_INFO' ] ) ) {
require_permission( 'edit-all-user' );
list( $user_uid ) = url_parts( 1 );
$user = Sessionuser::factoryFromUID( $user_uid )
->queryRow();
if( ! $user ) {
PageNotFound::spaqn();
}
}
// spawn header
Header::spawn( [
'title' => __( "Profile" ),
] );
// user e-mail
$email = $user->get( 'user_email' );
// handle send user password action
if( is_action( 'send-user-password' ) ) {
// generate
$password = generate_password();
// e-mail body
$mail_content = template_content( 'mail-user-password', [
'email' => $email,
'name' => $user->get( 'user_name' ),
'uid' => $user->get( 'user_uid' ),
'surname' => $user->get( 'user_surname' ),
'password' => $password,
] );
// update
query_update( 'user', [
new DBCol( 'user_password', Sessionuser::encryptPassword( $password ), 's' ),
], sprintf(
'user_ID = %d',
$user->get( 'user_ID' )
) );
// send
send_email( __( "Password reset" ), $mail_content, $email );
}
// spawn the profile page
template( 'profile', [ 'email' => $email ] );
// spawn footer
Footer::spawn();