Page MenuHomeGitPull.it

No OneTemporary

Authored By
Unknown
Size
29 KB
Referenced Files
None
Subscribers
None
diff --git a/include/class-Domain.php b/include/class-Domain.php
index cf5df76..5708b4e 100644
--- a/include/class-Domain.php
+++ b/include/class-Domain.php
@@ -1,86 +1,100 @@
<?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/>.
/**
* A domain handled by the user
*/
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' );
}
/**
* 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 the domain edit URl
*
+ * @param boolean $absolute True for an absolute URL
* @return string
*/
public function getDomainPermalink( $absolute = false ) {
- return ROOT . '/domain.php/' . $this->get( 'domain_name' );
+ return Domain::permalink( $this->get( 'domain_name' ), $absolute );
}
/**
* 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 MailforwardfromAPI() )->whereDomain( $this );
}
/**
* Factory FTP users from this domain
*
* @return FTPAPI
*/
public function factoryFTP() {
return ( new FTPAPI() )->whereDomain( $this );
}
+ /**
+ * 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 );
+ }
}
diff --git a/include/class-Mailbox.php b/include/class-Mailbox.php
index aa00a65..6c77b9d 100644
--- a/include/class-Mailbox.php
+++ b/include/class-Mailbox.php
@@ -1,97 +1,99 @@
<?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/>.
/**
* 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 = generate_password();
}
$enc_password = Mailbox::encryptPassword( $password );
query_update( 'mailbox', [
new DBCol( 'mailbox_password', $enc_password, 's' ),
], sprintf(
"domain_ID = %d AND mailbox_username = '%s'",
$this->getDomainID(),
esc_sql( $this->get( 'mailbox_username' ) )
) );
return $password;
}
/**
* Get the mailbox permalink
*
+ * @param $domain string
+ * @param $mailbox string
+ * @param $absolute boolean
* @return string
*/
- public static function permalink( $domain, $mailbox ) {
- return sprintf(
- '%s/%s/%s',
- ROOT . '/mailbox.php',
- $domain,
- $mailbox
- );
+ public static function permalink( $domain, $mailbox = null, $absolute = false ) {
+ $part = site_page( 'mailbox.php', $absolute ) . _ . $domain;
+ if( $mailbox ) {
+ $part .= _ . $mailbox;
+ }
+ return $part;
}
/**
* 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" );
}
}
diff --git a/template/domain.php b/template/domain-create.php
similarity index 69%
copy from template/domain.php
copy to template/domain-create.php
index f6e3092..9d1a80f 100644
--- a/template/domain.php
+++ b/template/domain-create.php
@@ -1,35 +1,33 @@
<?php
-# Copyright (C) 2018 Valerio Bozzolan
+# Copyright (C) 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 template for the website domain dashboard page
+ * This is the template for the create domain form
*
* Called from:
* domain.php
*/
// unuseful when load directly
defined( 'BOZ_PHP' ) or die;
-// spawn the mailboxes list
-template( 'mailboxes', [ 'domain' => $domain ] );
+?>
-// spawn the mail forwardings list
-template( 'mailforwards', [ 'domain' => $domain ] );
-
-// spawn the ftp list
-template( 'ftp-users', [ 'domain' => $domain ] );
+<form method="post">
+ <input type="text" name="domain_name" />
+ <button type="submit" class="btn" name="action" value="add-domain"><?php _e( "Add" ) ?></button>
+</form>
diff --git a/template/domain.php b/template/domain.php
index f6e3092..412e8d9 100644
--- a/template/domain.php
+++ b/template/domain.php
@@ -1,35 +1,38 @@
<?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 website domain dashboard page
*
* Called from:
* domain.php
+ *
+ * Available variables:
+ * $domain object
*/
// unuseful when load directly
defined( 'BOZ_PHP' ) or die;
// spawn the mailboxes list
template( 'mailboxes', [ 'domain' => $domain ] );
// spawn the mail forwardings list
template( 'mailforwards', [ 'domain' => $domain ] );
// spawn the ftp list
template( 'ftp-users', [ 'domain' => $domain ] );
diff --git a/template/ftp-users.php b/template/ftp-users.php
index e5df027..d3d88be 100644
--- a/template/ftp-users.php
+++ b/template/ftp-users.php
@@ -1,71 +1,70 @@
<?php
# Copyright (C) 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 template for the FTP user list
*
* Called from:
* domain.php
*
* Available variables:
* $domain Domain object
*/
// unuseful when load directly
defined( 'BOZ_PHP' ) or die;
// domain FTP users
$ftps = $domain->factoryFTP()
->select( [
'ftp_login',
] )
->queryGenerator();
?>
<!-- FTP users -->
<h3><?php printf(
__( "Your %s" ),
__( "FTP users" )
) ?></h3>
- <?php if( $ftps->valid() ): ?>
-
- <?php template( 'ftp-description' ) ?>
+ <?php template( 'ftp-description' ) ?>
+ <?php if( $ftps->valid() ): ?>
<ul>
<?php foreach( $ftps as $ftp ): ?>
<li>
<code><?php echo HTML::a(
FTP::permalink(
$domain->getDomainName(),
$ftp->getFTPLogin()
),
$ftp->getFTPLogin()
) ?></code>
</li>
<?php endforeach ?>
</ul>
<?php else: ?>
<p><?php _e( "None yet.") ?></p>
<?php endif ?>
<?php if( has_permission( 'edit-ftp-all' ) ): ?>
<p><?php the_link(
FTP::permalink( $domain->getDomainName() ),
__( "Create" )
) ?></p>
<?php endif ?>
<!-- end FTP users -->
diff --git a/template/mailbox.php b/template/mailbox.php
index 8bbd9a8..20798eb 100644
--- a/template/mailbox.php
+++ b/template/mailbox.php
@@ -1,48 +1,67 @@
<?php
-# Copyright (C) 2018 Valerio Bozzolan
+# 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 template for a mailbox
*
* Called from:
* mailbox.php
+ *
+ * Available variables:
+ * $mailbox object
+ * $domain object
+ * $mailbox_password string|null
*/
// unuseful when load directly
defined( 'BOZ_PHP' ) or die;
?>
<?php template( 'mailbox-description' ) ?>
- <h3><?php _e( "Resources" ) ?></h3>
- <ul>
- <li>
- <a href="https://mail.reyboz.it?email=<?php echo urlencode( $mailbox->getMailboxAddress() ) ?>" target="_blank" />
+ <!-- resources -->
+ <?php if( $mailbox ): ?>
+ <h3><?php _e( "Resources" ) ?></h3>
+ <ul>
+ <li>
+ <a href="https://mail.reyboz.it?email=<?php echo urlencode( $mailbox->getMailboxAddress() ) ?>" target="_blank" />
<?php _e( "How to setup your IMAP/SMTP client" ) ?>
- </a>
- </li>
- </ul>
+ </a>
+ </li>
+ </ul>
+ <?php endif ?>
+ <!-- /resources -->
- <h3><?php _e( "Actions" ) ?></h3>
- <form method="post">
- <?php if( $password ): ?>
- <label for="password"><?php _e( "Please copy your new password:" ) ?><br />
- <input type="text" id="password" readonly<?php _value( $password ) ?> />
- <?php else: ?>
- <p><button type="submit" class="btn btn-default" name="action" value="mailbox-password-reset"><?php _e( "Generate new password" ) ?></button></p>
- <?php endif ?>
- </form>
+ <?php if( $mailbox ): ?>
+ <h3><?php _e( "Actions" ) ?></h3>
+ <form method="post">
+ <?php if( $mailbox_password ): ?>
+ <label for="password"><?php _e( "Please copy your new password:" ) ?><br />
+ <input type="text" id="password" readonly<?php _value( $mailbox_password ) ?> />
+ <?php else: ?>
+ <p><button type="submit" class="btn btn-default" name="action" value="mailbox-password-reset"><?php _e( "Generate new password" ) ?></button></p>
+ <?php endif ?>
+ </form>
+ <?php else: ?>
+ <form method="post">
+ <p><label for="mailbox-username"><?php _e( "Mailbox name:" ) ?></label><br />
+ <input type="text" name="mailbox_username" id="mailbox-username" length="64" /> @ <?php _esc_html( $domain->getDomainName() ) ?>
+ </p>
+ <p><button type="submit" class="btn btn-default" name="action" value="mailbox-create"><?php _e( "Create" ) ?></button></p>
+ </form>
+ <?php endif ?>
+ <!-- /actions -->
diff --git a/template/mailboxes.php b/template/mailboxes.php
index 753c945..6030226 100644
--- a/template/mailboxes.php
+++ b/template/mailboxes.php
@@ -1,58 +1,63 @@
<?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',
+ 'domain_name',
+ 'mailbox_username',
+ 'mailbox_receive',
] )
->queryGenerator();
?>
<!-- mail boxes -->
- <?php if( $mailboxes->valid() ): ?>
- <h3><?php printf(
- __( "Your %s" ),
- __( "mailboxes" )
- ) ?></h3>
+ <h3><?php printf(
+ __( "Your %s" ),
+ __( "mailboxes" )
+ ) ?></h3>
- <?php template( 'mailbox-description' ) ?>
+ <?php template( 'mailbox-description' ) ?>
+ <?php if( $mailboxes->valid() ): ?>
<ul>
<?php foreach( $mailboxes as $mailbox ): ?>
<li>
<code><?php echo HTML::a(
$mailbox->getMailboxPermalink(),
$mailbox->getMailboxAddress()
) ?></code>
</li>
<?php endforeach ?>
</ul>
<?php endif ?>
+
+ <?php /* TODO: check counter on domain */ ?>
+ <?php if( has_permission( 'edit-email-all' ) ): ?>
+ <p><?php the_link( Mailbox::permalink( $domain->getDomainName() ), __( "Create" ) ) ?></p>
+ <?php endif ?>
<!-- end mail boxes -->
diff --git a/template/mailforward.php b/template/mailforward.php
index ff537e5..1c139d3 100644
--- a/template/mailforward.php
+++ b/template/mailforward.php
@@ -1,62 +1,62 @@
<?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 a single e-mail forwarding
*
* Called from:
* mailforward.php
*
* Available variables:
* $domain Domain object
* $mailforwardfrom Mailforward object
*/
// unuseful when load directly
defined( 'BOZ_PHP' ) or die;
-?>
+?>
<?php template( 'mailforward-description' ) ?>
<form method="post">
<p>
<label for="mailforward-source"><?php _e( "E-mail address:") ?></label><br />
<?php if( $mailforwardfrom ): ?>
<input type="text" id="mailforward-address" readonly<?php _value( $mailforwardfrom->getMailforwardfromAddress() ) ?> />
<?php else: ?>
<input type="string" name="mailforwardfrom_username" id="mailforwardfrom-username"<?php
if( $mailforwardfrom ) {
_value( $mailforwardfrom->getMailforwardfromUsername() );
}
?> /> <code>@<?php _esc_html( $domain->getDomainName() ) ?></code>
<?php endif ?>
<?php if( $mailforwardfrom ): ?>
<button type="submit" class="btn btn-danger" name="action" value="mailforward-delete"><?php _e( "Delete" ) ?></button>
<?php else: ?>
<button type="submit" class="btn btn-default" name="action" value="mailforward-save"><?php _e( "Create" ) ?></button>
<?php endif ?>
</p>
</form>
<?php if( $mailforwardfrom ): ?>
<p><?php _e( "Forward the incoming e-mails to these destinations:" ) ?></label></p>
<?php template( 'mailforwardto', [
'domain' => $domain,
'mailforwardfrom' => $mailforwardfrom,
] ) ?>
<?php endif ?>
diff --git a/template/mailforwards.php b/template/mailforwards.php
index b65551f..50596c5 100644
--- a/template/mailforwards.php
+++ b/template/mailforwards.php
@@ -1,67 +1,66 @@
<?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
*
* Available variables:
* $domain object
*/
// unuseful when load directly
defined( 'BOZ_PHP' ) or die;
// domain mail forwardings
$mailforwardfroms = $domain->factoryMailforwardfrom()
->select( [
'mailforwardfrom.mailforwardfrom_ID',
'mailforwardfrom_username',
'domain_name',
] )
->queryGenerator();
?>
<!-- mail forwardings -->
<h3><?php printf(
__( "Your %s" ),
__( "mail forwardings" )
) ?></h3>
- <?php if( $mailforwardfroms->valid() ): ?>
-
- <?php template( 'mailforward-description' ) ?>
+ <?php template( 'mailforward-description' ) ?>
+ <?php if( $mailforwardfroms->valid() ): ?>
<ul>
<?php foreach( $mailforwardfroms as $mailforwardfrom ): ?>
<li>
<code><?php echo HTML::a(
$mailforwardfrom->getMailforwardfromPermalink(),
$mailforwardfrom->getMailforwardfromAddress()
) ?></code>
</li>
<?php endforeach ?>
</ul>
<?php else: ?>
<p><?php _e( "None yet.") ?></p>
<?php endif ?>
<p><?php the_link(
Mailforwardfrom::permalink( $domain->getDomainName() ),
__( "Create" )
) ?></p>
<!-- end mail forwardings -->
diff --git a/www/domain.php b/www/domain.php
index 900b298..0f2f4bf 100644
--- a/www/domain.php
+++ b/www/domain.php
@@ -1,49 +1,77 @@
<?php
-# Copyright (C) 2018 Valerio Bozzolan
+# 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 );
+list( $domain_name ) = url_parts( 1, 0 );
-// retrieve domain
-$domain = ( new DomainAPI() )
- ->whereDomainName( $domain_name )
- ->whereDomainIsEditable()
- ->queryRow();
+$domain = null;
-// 404?
-$domain or PageNotFound::spawn();
+if( $domain_name ) {
+ // retrieve domain
+ $domain = ( new DomainAPI() )
+ ->whereDomainName( $domain_name )
+ ->whereDomainIsEditable()
+ ->queryRow();
+
+ // 404?
+ $domain or PageNotFound::spawn();
+} else {
+ // try to create
+
+ require_permission( 'edit-domain-all' );
+
+ if( is_action( 'add-domain' ) && isset( $_POST[ 'domain_name' ] ) ) {
+ $domain_name = luser_input( $_POST[ 'domain_name' ], 64 );
+
+ // @TODO: check for duplicates
+
+ insert_row( Domain::T, [
+ new DBCol( 'domain_name', $domain_name, 's' ),
+ new DBCol( 'domain_active', 1, 'd' ),
+ new DBCol( 'domain_born', 'NOW()', '-' ),
+ ] );
+
+ // POST -> redirect -> GET
+ http_redirect( Domain::permalink( $domain_name, true ) );
+ }
+}
// spawn header
Header::spawn( [
'title-prefix' => __( "Domain" ),
- 'title' => $domain_name,
+ 'title' => $domain_name ? $domain_name : __( "Add" ),
] );
-// spawn the domain template
-template( 'domain', [
- 'domain' => $domain,
-] );
+if( $domain ) {
+ // spawn the domain template
+ template( 'domain', [
+ 'domain' => $domain,
+ ] );
+} else {
+ // form to create the domain
+ template( 'domain-create' );
+}
// spawn the footer
Footer::spawn();
diff --git a/www/index.php b/www/index.php
index 3c3a51d..1b052bb 100644
--- a/www/index.php
+++ b/www/index.php
@@ -1,76 +1,80 @@
<?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 homepage of your hosting panel
*/
// load framework
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();
?>
<p class="lead"><?php printf(
__( "Welcome in your %s dashboard!" ),
SITE_NAME
) ?></p>
<?php if( $domains->valid() ): ?>
<h3><?php printf(
__( "Your %s" ),
__( "domains" )
) ?></h3>
<ul>
- <?php foreach( $domains as $domain ): ?>
+ <?php foreach( $domains as $domain ): ?>
<li>
<code>
<?php if( $domain->domain_active ): ?>
<?php echo HTML::a(
$domain->getDomainPermalink(),
$domain->domain_name
) ?>
<?php else: ?>
<del><?php _esc_html( $domain->domain_name ) ?></del>
<?php endif ?>
</code>
</li>
- <?php endforeach ?>
+ <?php endforeach ?>
</ul>
+
+ <?php if( has_permission( 'edit-domain-all' ) ): ?>
+ <p><a class="btn btn-default" href="<?php echo ROOT ?>/domain.php"><?php _e( "Add" ) ?></a></p>
+ <?php endif ?>
<?php endif ?>
<?php
// spawn footer
Footer::spawn();
diff --git a/www/mailbox.php b/www/mailbox.php
index 95889d8..81d0138 100644
--- a/www/mailbox.php
+++ b/www/mailbox.php
@@ -1,65 +1,132 @@
<?php
-# Copyright (C) 2018 Valerio Bozzolan
+# 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 );
-
-// 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();
+list( $domain_name, $mailbox_username ) = url_parts( 2, 1 );
+
+$domain = null;
+$mailbox = null;
+$mailbox_password = null;
+if( $mailbox_username ) {
+ // retrieve the mailbox and its domain
+ $mailbox = ( new MailboxFullAPI() )
+ ->select( [
+ 'domain.domain_ID',
+ 'domain_name',
+ 'domain_active',
+ 'mailbox_username',
+ ] )
+ ->whereDomainName( $domain_name )
+ ->whereStr( 'mailbox_username', $mailbox_username )
+ ->whereMailboxIsEditable()
+ ->queryRow();
+
+ // 404?
+ $mailbox or PageNotFound::spawn();
+
+ // the mailbox has the domain stuff
+ $domain = $mailbox;
+} else {
+ // retrieve just the domain
+ $domain = ( new DomainAPI() )
+ ->select( [
+ 'domain.domain_ID',
+ 'domain_name',
+ 'domain_active',
+ ] )
+ ->whereDomainName( $domain_name )
+ ->whereDomainIsEditable()
+ ->queryRow();
+
+ // 404?
+ $domain or PageNotFound::spawn();
+}
+
+/*
+ * 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' ] ) ) {
+
+ // TODO: check max. creation number in single domain props
+ require_permission( 'edit-email-all' );
+
+ $_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 ) {
+ insert_row( 'mailbox', [
+ new DBCol( 'mailbox_username', $_POST[ 'mailbox_username' ], 's' ),
+ new DBCol( 'domain_ID', $domain->getDomainID(), 'd' ),
+ ] );
+ }
+
+ $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( [
'title-prefix' => __( "Mailbox" ),
- 'title' => $mailbox->getMailboxAddress(),
+ 'title' => $mailbox ? $mailbox->getMailboxAddress() : __( "create" ),
'breadcrumb' => [
- new MenuEntry( null, $mailbox->getDomainPermalink(), $mailbox->getDomainName() ),
+ new MenuEntry( null, $domain->getDomainPermalink(), $domain->getDomainName() ),
],
] );
// spawn the page content
template( 'mailbox', [
- 'mailbox' => $mailbox,
- 'password' => $password,
+ 'mailbox' => $mailbox,
+ 'mailbox_password' => $mailbox_password,
+ 'domain' => $domain,
] );
// spawn the footer
Footer::spawn();

File Metadata

Mime Type
text/x-diff
Expires
Thu, Nov 19, 04:44 (10 h, 27 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2264810
Default Alt Text
(29 KB)

Event Timeline