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 @@ . /** * 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 @@ . /** * 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 @@ . /* - * 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 ] ); +
+ + +
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 @@ . /* * 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 @@ . /* * 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(); ?>

- valid() ): ?> - - + + valid() ): ?>

getDomainName() ), __( "Create" ) ) ?>

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 @@ . /* * 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; ?> -

- + + -

-
- -