diff --git a/include/class-Domain.php b/include/class-Domain.php index fbabbe2..12578ad 100644 --- a/include/class-Domain.php +++ b/include/class-Domain.php @@ -1,317 +1,317 @@ . // load Plan trait class_exists( 'Plan' ); /** * Methods for a Domain class */ trait DomainTrait { use PlanTrait; /** * Count of the Domain's Mailboxes * * This is a kind of cache * * @var int */ private $domainMailboxCount = null; /** * Count of the Domain's FTP accounts * * This is a kind of cache * * @var int */ private $domainFTPAccountCount = null; /** * Get domain ID * * @return int */ public function getDomainID() { return $this->get( 'domain_ID' ); } /* * Get domain name * * @return string */ public function getDomainName() { return $this->get( 'domain_name' ); } /** * Get a printable Domain firm * * It may be a link if you are allowed to edit this Domain. * * @return string */ public function getDomainFirm() { return HTML::a( $this->getDomainPermalink(), esc_html( $this->getDomainName() ) ); } /** * Get the sanitized relative directory name of this domain name * * Actually this should be valid for both the MTA and for the webserver. * * @return string */ public function getDomainDirname() { $dir = $this->getDomainName(); // it was validated during creation time, but validate also now // to prevent malicious actions over hacked databases require_safe_dirname( $dir ); return $dir; } /** * Get the domain edit URL * * @param boolean $absolute True for an absolute URL * @return string */ public function getDomainPermalink( $absolute = false ) { return Domain::permalink( $this->getDomainName(), $absolute ); } /** * Get the permalink to the edit plan page * * @param boolean $absolute True for an absolute URL * @return string */ public function getDomainPlanPermalink( $absolute = false ) { return Plan::domainPermalink( $this->getDomainName(), $absolute ); } /** * Check if you can create a new Mailbox for this Domain * * The Domain must have Plan informations. * * @return boolean */ public function canCreateMailboxInDomain() { return $this->getPlanMailboxes() > $this->getDomainMailboxCount() || has_permission( 'edit-email-all' ); } /** * Check if you can create a new FTP account for this Domain * * The Domain must have Plan informations. * * The Domain must have Plan informations. */ public function canCreateFTPAccountForDomain() { return $this->getPlanFTPUsers() > $this->getDomainFTPAccountCount() || has_permission( 'edit-ftp-all' ); } /** * Factory mailbox from this domain * * @return MailboxFullAPI */ public function factoryMailbox() { return ( new MailboxFullAPI() )->whereDomain( $this ); } /** * Factory e-mail forward from this domain * * @return MailforwardFullAPI */ public function factoryMailforwardfrom() { return ( new MailforwardfromQuery() )->whereDomain( $this ); } /** * Set a count of Domain's Mailboxes * * This method should not be used directly. * * @param $count int * @return self */ public function setDomainMailboxCount( $count ) { $this->domainMailboxCount = $count; } /** * Get the number of Mailboxes of this Domain * * This method has a layer of cache. * * @return int */ public function getDomainMailboxCount() { // check if we already know the count if( !isset( $this->domainMailboxCount ) ) { // count the number of mailboxes associated to this Domain $count = $this->factoryMailbox() ->select( 'COUNT(*) count' ) ->queryValue( 'count' ); // save in cache $this->domainMailboxCount = (int) $count; } return $this->domainMailboxCount; } /** * Get the number of FTP accounts of this Domain * * This method has a layer of cache. * * @return int */ public function getDomainFTPAccountCount() { // check if we already know the count if( !isset( $this->domainFTPAccountCount ) ) { // count the number of mailboxes associated to this Domain $count = $this->factoryFTP() ->select( 'COUNT(*) count' ) ->queryValue( 'count' ); // save in cache $this->domainFTPAccountCount = (int) $count; } return $this->domainFTPAccountCount; } /** * Get the expected MTA directory containing Domain's mailboxes * * This pathname should be considered true for the MTA host. * * TODO: actually all the mailbox are on the same host. * Then, we should support multiple hosts. * * @return string */ public function getDomainMailboxesPath() { // mailboxes are stored under a $BASE/domain/username filesystem structure return MAILBOX_BASE_PATH . __ . $this->getDomainDirname(); } /** * Get the expected and sanitized base domain directory containing its directories * * This pathname should be considered true both for the webserver serving * that domain and for the related FTP server. * * TODO: actually all the domains are on the same host. * Then, we should support multiple hosts. * * @return string */ public function getDomainBasePath() { // mailboxes are stored under a $BASE/domain/username filesystem structure - return VIRTUALHOSTS_DIR . __ . $this->getDomainDirname(); + return VIRTUALHOST_BASE_PATH . __ . $this->getDomainDirname(); } /** * Factory FTP users from this domain * * @return FTPAPI */ public function factoryFTP() { return ( new FTPAPI() )->whereDomain( $this ); } /** * Normalize a Domain object after being retrieved from database */ protected function normalizeDomain() { $this->integers( 'domain_ID' ); $this->booleans( 'domain_active' ); $this->dates( 'domain_born', 'domain_expiration' ); $this->normalizePlan(); } } /** * Describe the 'domain' table */ class Domain extends Queried { use DomainTrait; /** * Table name */ const T = 'domain'; const UID = 'domain_name'; /** * Constructor */ public function __construct() { $this->normalizeDomain(); } /** * Get the domain permalink * * @param string $domain_name Domain name * @param boolean $absolute True for an absolute URL */ public static function permalink( $domain_name = null, $absolute = false ) { $url = 'domain.php'; if( $domain_name ) { $url .= _ . $domain_name; } return site_page( $url, $absolute ); } /** * Force to get a Domain ID, whatever is passed * * @param mixed $domain Domain object or Domain ID * @return int */ public static function getID( $domain ) { return is_object( $domain ) ? $domain->getDomainID() : (int)$domain; } } diff --git a/load-post.php b/load-post.php index aeb1796..04d470f 100644 --- a/load-post.php +++ b/load-post.php @@ -1,131 +1,136 @@ . /** * This is your versioned configuration file * * It does not contains secrets. * * This file is required after loading your * unversioned configuration file: * * load.php */ -// database version +// Database vesion // -// you can increase your database version if you added some patches in: +// Do not touch if not sure. +// +// the maintainer increases this database version +// each version is related to a patch here: // documentation/database/patches define( 'DATABASE_VERSION', 7 ); +/** + * VirtualHost(s) base path + * + * e.g. you may have /var/www/example.com/index.html + * do NOT end with a slash + */ +define_default( 'VIRTUALHOST_BASE_PATH', '/var/www' ); + +/** + * Mailbox base path + * + * Used by CLI scripts to calculate the current quotas. + * + * The mailboxes should have paths like: + * MAILBOX_BASE_PATH/domain_name/user_name/ + */ +define_default( 'MAILBOX_BASE_PATH', '/home/vmail' ); + // include path define_default( 'INCLUDE_PATH', ABSPATH . __ . 'include' ); // template path define_default( 'TEMPLATE_PATH', ABSPATH . __ . 'template' ); +// override default user class +define_default( 'SESSIONUSER_CLASS', 'User' ); + // autoload classes from the /include directory spl_autoload_register( function( $name ) { // TODO: autoload classes and create DomainTrait and use in Mailbox $path = INCLUDE_PATH . __ . "class-$name.php"; if( is_file( $path ) ) { require $path; } } ); -// override default user class -define( 'SESSIONUSER_CLASS', 'User' ); - // 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' ); -// base directory for your virtualhosts -// e.g. you may have /var/www/example.com/index.html -// do NOT end with a slash -// TODO: support multiple hosts -define_default( 'VIRTUALHOSTS_DIR', '/var/www' ); - // default currency simbol define_default( 'DEFAULT_CURRENCY_SYMBOL', '€' ); // 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', "KISS Libre Hosting Panel" ); +define_default( 'SITE_NAME', "Libre Hosting Panel" ); define_default( 'CONTACT_EMAIL', 'support@' . DOMAIN ); -define_default( 'REPO_URL', 'https://gitpull.it/project/profile/15/' ); +define_default( 'REPO_URL', 'https://gitpull.it/source/boz-libre-hosting-panel/' ); // limit session duration to 5 minutes (60s * 100m) define_default( 'SESSION_DURATION', 6000 ); -/** - * Mailbox base path - * - * Used by CLI scripts to calculate the current quotas. - * - * The mailboxes should have paths like: - * MAILBOX_BASE_PATH/domain_name/user_name/ - */ -define_default( 'MAILBOX_BASE_PATH', '/home/vmail' ); - // register web pages add_menu_entries( [ - new MenuEntry( 'index', '/', __( "Dashboard" ), null, 'backend' ), + new MenuEntry( 'index', '', __( "Dashboard" ), null, 'backend' ), new MenuEntry( 'login', 'login.php', __( "Login" ) ), - new MenuEntry( 'profile', 'profile.php', __( "Profile" ) ), + new MenuEntry( 'profile', 'profile.php', __( "Profile" ), null, 'read' ), new MenuEntry( 'logout', 'logout.php', __( "Logout" ), null, 'read' ), new MenuEntry( 'user-list', 'user-list.php', __( "Users" ), null, 'edit-user-all' ), new MenuEntry( 'activity', 'activity.php', __( "Last Activity" ), null, 'monitor' ), new MenuEntry( 'password-reset', 'password-reset.php', __( "Password reset" ) ), ] ); // permissions of a normal user register_permissions( 'user', [ 'read', 'backend', ] ); // permissions of an admin inherit_permissions( 'admin', 'user', [ 'edit-user-all', 'edit-email-all', 'edit-domain-all', 'edit-plan-all', 'edit-ftp-all', 'monitor', ] );