Page Menu
Home
GitPull.it
Search
Configure Global Search
Log In
Files
F15187234
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Authored By
Unknown
Size
11 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/include/class-PlanAPI.php b/include/class-PlanAPI.php
index ab578aa..65a4480 100644
--- a/include/class-PlanAPI.php
+++ b/include/class-PlanAPI.php
@@ -1,100 +1,101 @@
<?php
# Copyright (C) 2018, 2019 Valerio Bozzolan
# 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 General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
/**
* Methods related to a Plan class
*/
trait PlanAPITrait {
/**
* Limit to a specific Plan by its UID
*
* @param $plan_name string
* @return self
*/
public function wherePlanUID( $uid ) {
return $this->whereStr( 'plan_uid', $plan_uid );
}
/**
* Constructor from a plan ID
*
* @param $plan_ID int
* @return self
*/
public function wherePlanID( $plan_ID ) {
return $this->whereInt( static::PLAN_ID, $plan_ID );
}
/**
* Constructor from a Plan object
*
* @param $plan object
* @return self
*/
public function wherePlan( $plan ) {
return $this->wherePlanID( $plan->getPlanID() );
}
/**
* Order by the Plan name
*
* @param string $direction DESC|ASC
* @return self
*/
public function orderByPlanName( $direction = null ) {
return $this->orderBy( 'plan_name', $direction );
}
/**
* Join whatever table with the plan table
*
+ * @param string $type Join type
* @return self
*/
- public function joinPlan() {
- return $this->joinOn( 'INNER', 'plan', static::PLAN_ID, 'plan.plan_ID' );
+ public function joinPlan( $type = 'INNER' ) {
+ return $this->joinOn( $type, 'plan', static::PLAN_ID, 'plan.plan_ID' );
}
}
/**
* Plan API
*/
class PlanAPI extends Query {
use PlanAPITrait;
/**
* Plan ID column name
*/
const PLAN_ID = 'plan.plan_ID';
/**
* Constructor
*
* @param object $db Database (or NULL for the current one)
*/
public function __construct( $db = null ) {
// set database connection and default class name for the results
parent::__construct( $db, 'Plan' );
// select from this database table
$this->from( Plan::T );
}
}
diff --git a/template/mailboxes.php b/template/mailboxes.php
index f28b5d9..15d8684 100644
--- a/template/mailboxes.php
+++ b/template/mailboxes.php
@@ -1,74 +1,76 @@
<?php
# Copyright (C) 2018 Valerio Bozzolan
# 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 General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
/*
* This is the template for the mailboxes list
*
* Called from:
* template/domain.php
*/
// unuseful when load directly
defined( 'BOZ_PHP' ) or die;
// domain mailboxes
$mailboxes = $domain->factoryMailbox()
->select( [
'domain_name',
'mailbox_username',
'mailbox_receive',
] )
->queryGenerator();
// total number of mailboxes
$count = DB::instance()->affectedRows();
?>
<!-- mail boxes -->
<h3><?php printf(
__( "Your %s" ),
__( "mailboxes" )
) ?></h3>
-<?php template( 'mailbox-description' ) ?>
+<?php template( 'mailbox-description', [
+ 'mailbox' => null,
+] ) ?>
<?php if( $mailboxes->valid() ): ?>
<ul>
<?php foreach( $mailboxes as $mailbox ): ?>
<li>
<code><?= HTML::a(
$mailbox->getMailboxPermalink(),
- $mailbox->getMailboxAddress()
+ esc_html( $mailbox->getMailboxAddress() )
) ?></code>
</li>
<?php endforeach ?>
</ul>
<?php endif ?>
<p><?= esc_html( sprintf(
__( "Your Plan \"%s\" allows %s %s." ),
$plan->getPlanName(),
$plan->getPlanMailboxes(),
__( "Mailboxes" )
) ) ?></p>
<?php if( $plan->getPlanMailboxes() > $count || has_permission( 'edit-email-all' ) ): ?>
<p><?php the_link( Mailbox::permalink( $domain->getDomainName() ), __( "Create" ) ) ?></p>
<?php endif ?>
<!-- end mail boxes -->
diff --git a/www/domain.php b/www/domain.php
index adbcf0f..e7e3747 100644
--- a/www/domain.php
+++ b/www/domain.php
@@ -1,91 +1,91 @@
<?php
# Copyright (C) 2018, 2019 Valerio Bozzolan
# 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 General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
/*
* This is the domain edit page
*/
// load framework
require '../load.php';
// wanted domain
list( $domain_name ) = url_parts( 1, 0 );
$domain = null;
if( $domain_name ) {
// retrieve domain
$domain = ( new DomainAPI() )
->whereDomainName( $domain_name )
->whereDomainIsEditable()
- ->joinPlan()
+ ->joinPlan( 'LEFT' )
->queryRow();
// 404?
$domain or PageNotFound::spawn();
} else {
// try to create
require_permission( 'edit-domain-all' );
if( is_action( 'add-domain' ) && isset( $_POST[ 'domain_name' ] ) ) {
// trim and normalize to max length
$domain_name = luser_input( $_POST[ 'domain_name' ], 64 );
// existing domain
$existing = ( new DomainAPI() )
->whereDomainName( $domain_name )
->queryRow();
// go to the existing one
if( $existing ) {
http_redirect( $existing->getDomainPermalink() );
}
// insert this new domain
insert_row( Domain::T, [
new DBCol( 'domain_name', $domain_name, 's' ),
new DBCol( 'domain_active', 1, 'd' ),
new DBCol( 'domain_born', 'NOW()', '-' ),
] );
// go to the new domain
http_redirect( Domain::permalink( $domain_name, true ) );
}
}
// spawn header
Header::spawn( [
'uid' => false,
'title-prefix' => __( "Domain" ),
'title' => $domain_name ? $domain_name : __( "Add" ),
] );
if( $domain ) {
// spawn the domain template
template( 'domain', [
'domain' => $domain,
'plan' => $domain,
] );
} else {
// form to create the domain
template( 'domain-create' );
}
// spawn the footer
Footer::spawn();
diff --git a/www/mailbox.php b/www/mailbox.php
index 7e90968..24803f9 100644
--- a/www/mailbox.php
+++ b/www/mailbox.php
@@ -1,147 +1,152 @@
<?php
# Copyright (C) 2018, 2019 Valerio Bozzolan
# 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 General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
/*
* This is the mailbox edit page
*/
// load framework
require '../load.php';
// wanted domain and mailbox username
list( $domain_name, $mailbox_username ) = url_parts( 2, 1 );
$domain = null;
$mailbox = null;
$plan = null;
$mailbox_password = null;
if( $mailbox_username ) {
// retrieve the mailbox and its domain and its Plan
$mailbox = ( new MailboxFullAPI() )
- ->joinPlan()
+ ->joinPlan( 'LEFT' )
->whereDomainName( $domain_name )
->whereMailboxUsername( $mailbox_username )
->whereMailboxIsEditable()
->queryRow();
// 404?
$mailbox or PageNotFound::spawn();
// the mailbox has the domain stuff
$domain = $mailbox;
// the mailbox has the Plan stuff
$plan = $mailbox;
} else {
// retrieve just the domain and its Plan
$domain = ( new DomainAPI() )
->whereDomainName( $domain_name )
->whereDomainIsEditable()
- ->joinPlan()
+ ->joinPlan( 'LEFT' )
->queryRow();
// 404?
$domain or PageNotFound::spawn();
$plan = $domain;
}
// does the user want to create a Mailbox?
if( !$mailbox ) {
// count the actual number of Domain Mailbox(es)
$mailbox_count = (int)
( new MailboxAPI() )
->select( 'COUNT(*) count' )
->whereDomain( $domain )
->queryValue( 'count' );
// check if I can add another Mailbox
if( $mailbox_count >= $plan->getPlanMailboxes() && !has_permission( 'edit-email-all' ) ) {
BadRequest::spawn( __( "Your Plan does not allow this action" ), 401 );
}
}
/*
* Change the mailbox password
*/
if( $mailbox && is_action( 'mailbox-password-reset' ) ) {
$mailbox_password = $mailbox->updateMailboxPassword();
}
/*
* Create the mailbox
*/
if( !$mailbox && is_action( 'mailbox-create' ) && isset( $_POST[ 'mailbox_username' ] ) ) {
$_POST[ 'mailbox_username' ] = luser_input( $_POST[ 'mailbox_username' ], 64 );
$mailbox = ( new MailboxFullAPI() )
->select( [
'domain.domain_ID',
'domain_name',
'mailbox_username',
] )
->whereDomainName( $domain_name )
->whereStr( 'mailbox_username', $_POST[ 'mailbox_username' ] )
->queryRow();
if( !$mailbox ) {
+ // assign a damn temporary password
+ $mailbox_password = generate_password();
+ $mailbox_password_safe = Mailbox::encryptPassword( $mailbox_password );
+
insert_row( 'mailbox', [
new DBCol( 'mailbox_username', $_POST[ 'mailbox_username' ], 's' ),
new DBCol( 'domain_ID', $domain->getDomainID(), 'd' ),
+ new DBCol( 'mailbox_password', $mailbox_password_safe, 's' ),
] );
}
$mailbox = ( new MailboxFullAPI() )
->select( [
'domain.domain_ID',
'domain_name',
'mailbox_username',
] )
->whereDomainName( $domain_name )
->whereStr( 'mailbox_username', $_POST[ 'mailbox_username' ] )
->queryRow();
if( $mailbox ) {
http_redirect( $mailbox->getMailboxPermalink( true ) );
}
}
// spawn header
Header::spawn( [
'uid' => false,
'title-prefix' => __( "Mailbox" ),
'title' => $mailbox ? $mailbox->getMailboxAddress() : __( "create" ),
'breadcrumb' => [
new MenuEntry( null, $domain->getDomainPermalink(), $domain->getDomainName() ),
],
] );
// spawn the page content
template( 'mailbox', [
'mailbox' => $mailbox,
'mailbox_password' => $mailbox_password,
'domain' => $domain,
] );
// spawn the footer
Footer::spawn();
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Thu, Nov 19, 09:45 (20 m, 22 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2265669
Default Alt Text
(11 KB)
Attached To
Mode
R3 KISS Libre Hosting Panel
Attached
Detach File
Event Timeline