diff --git a/admin/add-alias.php b/admin/add-alias.php new file mode 100644 index 0000000..031d7f3 --- /dev/null +++ b/admin/add-alias.php @@ -0,0 +1,74 @@ + +// Copyright (c) 2022 High5! +// License Info: LICENSE.TXT +// +// File: create-alias.php +// +// Template File: create-alias.tpl +// +// Template Variables: +// +// tMessage +// tAddress +// tGoto +// domain +// +// Form POST \ GET Variables: +// +// address +// fGoto +// domain +// +require("../variables.inc.php"); +require("../config.inc.php"); +require("../functions.inc.php"); +include("../languages/" . check_language() . ".lang"); + +$list_domains = list_domains(); + +if ($_SERVER['REQUEST_METHOD'] == "POST") { + $address = strtolower(filter_input(INPUT_POST, 'address', FILTER_DEFAULT)); + $domain = filter_input(INPUT_POST, 'domain', FILTER_VALIDATE_DOMAIN); + $goto = strtolower(filter_input(INPUT_POST, 'goto', FILTER_DEFAULT)); + + $domain_key = array_search($domain, array_column($list_domains, 'domain')); + + $from = filter_var($address . '@' . $domain, FILTER_VALIDATE_EMAIL); + if (!str_contains($goto, '@')) { + $goto = $goto . "@" . $domain; + } + $goto = filter_var($goto, FILTER_VALIDATE_EMAIL); + + if ($list_domains[$domain_key]['alias_count'] < 0 || $list_domains[$domain_key]['alias_count'] >= $list_domains[$domain_key]['aliases']) { + $message = $PALANG['pCreate_alias_address_text_error2']; + } + + if (empty($address) || empty($goto)) { + $message = $PALANG['pCreate_alias_address_text_error1']; + } + + if (empty($message)) { + try { + $dbh = connect_db(); + $sth = $dbh->prepare("INSERT INTO alias (address,goto,domain,created,modified) VALUES (?,?,?,NOW(),NOW())"); + $sth->bindParam(1, $from, PDO::PARAM_STR); + $sth->bindParam(2, $goto, PDO::PARAM_STR); + $sth->bindParam(3, $domain, PDO::PARAM_STR); + $sth->execute(); + logging(ADMIN_EMAIL, $domain, "create alias", "$from -> $goto"); + $message = $PALANG['pCreate_alias_result_succes'] . "
($from -> $goto)
"; + $address = ''; + $goto = ''; + } catch(PDOException $e) { + $message = $PALANG['pCreate_alias_result_error'] . "
($from -> $goto) - $e
"; + } + } +} +include("../templates/header.tpl"); +include("../templates/admin_menu.tpl"); +include("../templates/add-alias.tpl"); +include("../templates/footer.tpl"); +?> diff --git a/admin/add-domain.php b/admin/add-domain.php new file mode 100644 index 0000000..f856144 --- /dev/null +++ b/admin/add-domain.php @@ -0,0 +1,91 @@ + +// Copyright (c) 2022 High5! +// License Info: LICENSE.TXT +// +// File: create-domain.php +// +// Template File: admin_create-domain.tpl +// +// Template Variables: +// +// tMessage +// tDomain +// tDescription +// tAliases +// tMailboxes +// tMaxquota +// tDefaultaliases +// +// Form POST \ GET Variables: +// +// fDomain +// fDescription +// fAliases +// fMailboxes +// fMaxquota +// fDefaultaliases +// +require_once '../functions.inc.php'; +include '../languages/' . check_language() . '.lang'; + +$list_domains = list_domains(); + +if ($_SERVER['REQUEST_METHOD'] == "GET") { + $action = filter_input(INPUT_GET, 'action', FILTER_DEFAULT) ?? 'new'; + if ($action == 'edit') { + $domain = filter_input(INPUT_GET, 'domain', FILTER_VALIDATE_DOMAIN); + $domain_key = array_search($domain, array_column($list_domains, 'domain')); + $description = $list_domains[$domain_key]['description']; + $aliases = $list_domains[$domain_key]['aliases']; + $mailboxes = $list_domains[$domain_key]['mailboxes']; + } +} + +if ($_SERVER['REQUEST_METHOD'] == "POST") { + $action = filter_input(INPUT_GET, 'action', FILTER_DEFAULT) ?? 'new'; + $domain = strtolower(filter_input(INPUT_POST, 'domain', FILTER_VALIDATE_DOMAIN)); + $description = filter_input(INPUT_POST, 'description', FILTER_CALLBACK, array('options' => 'htmlspecialchars')); + $aliases = filter_input(INPUT_POST, 'aliases', FILTER_VALIDATE_INT); + $mailboxes = filter_input(INPUT_POST, 'mailboxes', FILTER_VALIDATE_INT); + + if (!in_array($domain, array_column($list_domains, 'domain'))) { + try { + $dbh = connect_db(); + $sth = $dbh->prepare("INSERT INTO domain (domain,description,aliases,mailboxes,created,modified) VALUES (?,?,?,?,NOW(),NOW())"); + $sth->bindParam(1, $domain, PDO::PARAM_STR); + $sth->bindParam(2, $description, PDO::PARAM_STR); + $sth->bindParam(3, $aliases, PDO::PARAM_INT); + $sth->bindParam(4, $mailboxes, PDO::PARAM_INT); + $sth->execute(); + $message = $PALANG['pAdminCreate_domain_result_succes'] . "
($domain)
"; + } catch(PDOException $e) { + $message = $PALANG['pAdminCreate_domain_result_error'] . "
($domain)
"; + } + } else { + $message = $PALANG['pAdminCreate_domain_domain_text_error']; + } + + if (in_array($domain, array_column($list_domains, 'domain')) && $action == 'edit') { + try { + $dbh = connect_db(); + $sth = $dbh->prepare("UPDATE domain SET description=?,aliases=?,mailboxes=?,modified=NOW() WHERE domain=?"); + $sth->bindParam(1, $description, PDO::PARAM_STR); + $sth->bindParam(2, $aliases, PDO::PARAM_INT); + $sth->bindParam(3, $mailboxes, PDO::PARAM_INT); + $sth->bindParam(4, $domain, PDO::PARAM_STR); + $sth->execute(); + header("Location: list-domain.php"); + } catch(PDOException $e) { + $message = $PALANG['pAdminEdit_domain_result_error']; + } + } +} + +include '../templates/header.tpl'; +include '../templates/admin_menu.tpl'; +include '../templates/admin_add-domain.tpl'; +include '../templates/footer.tpl'; +?> diff --git a/admin/add-mailbox.php b/admin/add-mailbox.php new file mode 100644 index 0000000..1de342c --- /dev/null +++ b/admin/add-mailbox.php @@ -0,0 +1,97 @@ + +// Copyright (c) 2022 High5! +// License Info: LICENSE.TXT +// +// File: create-mailbox.php +// +// Template File: create-mailbox.tpl +// +// Template Variables: +// +// tMessage +// tUsername +// tName +// tQuota +// tDomain +// +// Form POST \ GET Variables: +// +// username +// fPassword +// fPassword2 +// fName +// fQuota +// domain +// fActive +// fMail +// +require_once("../functions.inc.php"); +include("../languages/" . check_language() . ".lang"); + +$list_domains = list_domains(); + +if ($_SERVER['REQUEST_METHOD'] == "POST") { + + $username = strtolower(filter_input(INPUT_POST, 'username', FILTER_DEFAULT)); + $domain = filter_input(INPUT_POST, 'domain', FILTER_VALIDATE_DOMAIN); + $password1 = filter_input(INPUT_POST, 'password1', FILTER_DEFAULT); + $password2 = filter_input(INPUT_POST, 'password2', FILTER_DEFAULT); + $name = filter_input(INPUT_POST, 'name', FILTER_DEFAULT); + + $domain_key = array_search($domain, array_column($list_domains, 'domain')); + + $from = filter_var($username . '@' . $domain, FILTER_VALIDATE_EMAIL); + + if ($list_domains[$domain_key]['mailbox_count'] < 0 || $list_domains[$domain_key]['mailbox_count'] >= $list_domains[$domain_key]['mailboxes']) { + $message = $PALANG['pCreate_mailbox_username_text_error3']; + } + + if (empty($username)) { + $message = $PALANG['pCreate_mailbox_username_text_error1']; + } + + if (empty($password1) or ($password1 != $password2)) { + $message = $PALANG['pCreate_mailbox_password_text_error']; + } + + if (empty($message)) { + $hashed = bcrypt($password1); + $maildir = $from . "/"; + + try { + $dbh = connect_db(); + $sth = $dbh->prepare("INSERT INTO alias (address,goto,domain,created,modified) VALUES (?,'vmail',?,NOW(),NOW())"); + $sth->bindParam(1, $from, PDO::PARAM_STR); + $sth->bindParam(2, $domain, PDO::PARAM_STR); + $sth->execute(); + $username = ''; + } catch(PDOException $e) { + $message = $PALANG['pCreate_alias_result_error'] . "
($from) - $e
"; + } + + try { + $dbh = connect_db(); + $sth = $dbh->prepare("INSERT INTO mailbox (username,password,name,maildir,domain,created,modified) VALUES (?,?,?,?,?,NOW(),NOW())"); + $sth->bindParam(1, $from, PDO::PARAM_STR); + $sth->bindParam(2, $hashed, PDO::PARAM_STR); + $sth->bindParam(3, $name, PDO::PARAM_STR); + $sth->bindParam(4, $maildir, PDO::PARAM_STR); + $sth->bindParam(5, $domain, PDO::PARAM_STR); + $sth->execute(); + logging(ADMIN_EMAIL, $domain, "create mailbox", "$from"); + $message = $PALANG['pCreate_mailbox_result_succes'] . "
($from)"; + $username = ''; + $name = ''; + } catch(PDOException $e) { + $message = $PALANG['pCreate_alias_result_error'] . "
($from) - $e
"; + } + } +} +include("../templates/header.tpl"); +include("../templates/admin_menu.tpl"); +include("../templates/add-mailbox.tpl"); +include("../templates/footer.tpl"); +?> diff --git a/admin/list-virtual.php-orig b/admin/list-virtual.php-orig new file mode 100644 index 0000000..4896fad --- /dev/null +++ b/admin/list-virtual.php-orig @@ -0,0 +1,61 @@ + +// Copyright (c) 2022 High5! +// License Info: LICENSE.TXT +// +// File: list-virtual.php +// +// Template File: admin_list-virtual.tpl +// +// Template Variables: +// +// list_alias +// list_mailbox +// +// Form GET Variables: +// +// domain +// offset +// +require_once '../functions.inc.php'; +include '../languages/' . check_language() . '.lang'; + +$list_domains = list_domains(); + +$dbh = new PDO(DB_TYPE . ':host='. DB_HOST . ';dbname='. DB_NAME , DB_USER, DB_PASS); + +if ($_SERVER['REQUEST_METHOD'] == "GET") { + $offset = filter_input(INPUT_GET, 'offset', FILTER_VALIDATE_INT) ?? '0'; + $limit = PAGE_SIZE; + + if (count($list_domains) > 0) { + $domain = filter_input(INPUT_GET, 'domain', FILTER_VALIDATE_DOMAIN) ?? $list_domains[0]['domain']; + $selected_domain = array_search($domain, array_column($list_domains, 'domain')); + + if ($CONF['alias_control'] == "NO") { + $sth = $dbh->prepare("SELECT alias.address,alias.goto,alias.modified FROM alias LEFT JOIN mailbox ON alias.address=mailbox.username WHERE alias.domain=? AND mailbox.maildir IS NULL ORDER BY alias.address LIMIT ?, ?"); + } else { + $sth = $dbh->prepare("SELECT alias.address,alias.goto,alias.modified FROM alias WHERE alias.domain=? ORDER BY alias.address LIMIT ?, ?"); + } + + $sth->bindParam(1, $domain, PDO::PARAM_STR); + $sth->bindParam(2, $offset, PDO::PARAM_INT); + $sth->bindParam(3, $limit, PDO::PARAM_INT); + $sth->execute(); + $list_alias = $sth->fetchAll(); + + $sth = $dbh->prepare("SELECT * FROM mailbox WHERE domain=? ORDER BY username LIMIT ?, ?"); + $sth->bindParam(1, $domain, PDO::PARAM_STR); + $sth->bindParam(2, $offset, PDO::PARAM_INT); + $sth->bindParam(3, $limit, PDO::PARAM_INT); + $sth->execute(); + $list_mailbox = $sth->fetchAll(); + } +} +include '../templates/header.tpl'; +include '../templates/admin_menu.tpl'; +include '../templates/admin_list-virtual.tpl'; +include '../templates/footer.tpl'; +?> diff --git a/conf.php-sample b/conf.php-sample new file mode 100644 index 0000000..c30f2e5 --- /dev/null +++ b/conf.php-sample @@ -0,0 +1,17 @@ + diff --git a/list-domains.php b/list-domains.php new file mode 100644 index 0000000..04bfc12 --- /dev/null +++ b/list-domains.php @@ -0,0 +1,30 @@ + +// Copyright (c) 2022 High5! +// License Info: LICENSE.TXT +// +// File: overview.php +// +// Template File: overview.tpl +// +// Template variables: +// +// list_domains +// +// GET / POST variables: +// +// -none- +// +require_once './functions.inc.php'; +include './languages/' . check_language() . '.lang'; +include './templates/header.tpl'; +include './templates/menu.tpl'; + +$SESSID_USERNAME = check_session(); +$list_domains = list_domains($SESSID_USERNAME); + +include './templates/list-domains.tpl'; +include './templates/footer.tpl'; +?> diff --git a/list-virtuals.php b/list-virtuals.php new file mode 100644 index 0000000..b10de07 --- /dev/null +++ b/list-virtuals.php @@ -0,0 +1,43 @@ + +// Copyright (c) 2022 High5! +// License Info: LICENSE.TXT +// +// File: list-virtual.php +// +// Template File: list-virtual.tpl +// +// Template Variables: +// +// list_alias +// list_mailbox +// +// Form GET Variables: +// +// domain +// offset +// +require_once './functions.inc.php'; +include './languages/' . check_language() . '.lang'; +include './templates/header.tpl'; + +$SESSID_USERNAME = check_session(); +$list_domains = list_domains($SESSID_USERNAME); + +if ($_SERVER['REQUEST_METHOD'] == "GET") { + $offset = filter_input(INPUT_GET, 'offset', FILTER_VALIDATE_INT) ?? '0'; + $limit = PAGE_SIZE; + $domain = filter_input(INPUT_GET, 'domain', FILTER_VALIDATE_DOMAIN); + if (in_array($domain, array_column($list_domains, 'domain'))) { + $domain_key = array_search($domain, array_column($list_domains, 'domain')); + $list_alias = list_aliases($domain, $offset, $limit); + $list_mailbox = list_mailboxes($domain, $offset, $limit); + $template = "list-virtual.tpl"; + include './templates/menu.tpl'; + include './templates/list-virtuals.tpl'; + } +} +include './templates/footer.tpl'; +?> diff --git a/templates/add-alias.tpl b/templates/add-alias.tpl new file mode 100644 index 0000000..afa5760 --- /dev/null +++ b/templates/add-alias.tpl @@ -0,0 +1,34 @@ +
+
+ + + + + + + + + + + + + + + + + + + + +

+ +
+
diff --git a/templates/add-mailbox.tpl b/templates/add-mailbox.tpl new file mode 100644 index 0000000..93bdcd0 --- /dev/null +++ b/templates/add-mailbox.tpl @@ -0,0 +1,45 @@ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

+ +
 
+ +
diff --git a/templates/admin_add-domain.tpl b/templates/admin_add-domain.tpl new file mode 100644 index 0000000..2071a1d --- /dev/null +++ b/templates/admin_add-domain.tpl @@ -0,0 +1,43 @@ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

 
 
+
+
diff --git a/templates/admin_domain.tpl b/templates/admin_domain.tpl new file mode 100644 index 0000000..2071a1d --- /dev/null +++ b/templates/admin_domain.tpl @@ -0,0 +1,43 @@ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

 
 
+
+
diff --git a/templates/list-domains.tpl b/templates/list-domains.tpl new file mode 100644 index 0000000..a91dc97 --- /dev/null +++ b/templates/list-domains.tpl @@ -0,0 +1,28 @@ +
+
+Search: +
+
+\n"; +echo " \n"; +echo "

".$PALANG['pOverview_title']."

"; +echo " "; +echo " \n"; +echo " " . $PALANG['pOverview_get_domain'] . "\n"; +echo " " . $PALANG['pOverview_get_aliases'] . "\n"; +echo " " . $PALANG['pOverview_get_mailboxes'] . "\n"; +echo " \n"; +foreach ($list_domains as $row) { + if ($row['aliases'] == 0) $row['aliases'] = $PALANG['pOverview_unlimited']; + if ($row['mailboxes'] == 0) $row['mailboxes'] = $PALANG['pOverview_unlimited']; + if ($row['aliases'] < 0) $row['aliases'] = $PALANG['pOverview_disabled']; + if ($row['mailboxes'] < 0) $row['mailboxes'] = $PALANG['pOverview_disabled']; + echo " \n"; + echo " " . $row['domain'] . "\n"; + echo " " . $row['alias_count'] . " / " . $row['aliases'] . "\n"; + echo " " . $row['mailbox_count'] . " / " . $row['mailboxes'] . "\n"; + echo " \n"; +} +echo "\n"; +?> diff --git a/templates/list-virtuals.tpl b/templates/list-virtuals.tpl new file mode 100644 index 0000000..54fc7f6 --- /dev/null +++ b/templates/list-virtuals.tpl @@ -0,0 +1,111 @@ +
+
+ + + +
+ +

+

+

+ +
+ +
+
+ $limit || $list_domains[$domain_key]['mailbox_count'] > $limit) { + echo "
\n"; + if ($offset >= $limit) { + + echo "\n"; + } + if (($list_domains[$domain_key]['alias_count'] > $limit) || ($list_domains[$domain_key]['mailbox_count'] > $limit)) { + + echo "\n"; + } + if ((($offset + $limit) < $list_domains[$domain_key]['alias_count']) || (($offset + $limit) < $list_domains[$domain_key]['mailbox_count'])) { + echo "\n"; + } + echo "
\n"; +} + +if (count($list_alias) > 0) { + echo "\n"; + echo " \n"; + echo " "; + echo " "; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + + foreach ($list_alias as $row) { + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + + if ($CONF['special_alias_control'] == 'YES') { + echo " \n"; + echo " \n"; + } else { + if (!in_array($row['goto'], $CONF['default_aliases'])) { + echo " \n"; + echo " \n"; + } else { + echo " \n"; + echo " \n"; + } + } + echo " \n"; + } + + echo "

".$PALANG['pOverview_alias_title']."

" . $PALANG['pOverview_alias_address'] . "" . $PALANG['pOverview_alias_goto'] . "" . $PALANG['pOverview_alias_modified'] . " 
" . $row['address'] . "" . preg_replace("/,/", "
", $row['goto']) . "
" . $row['modified'] . "" . $PALANG['edit'] . "" . $PALANG['del'] . "" . $PALANG['edit'] . "" . $PALANG['del'] . "  
\n"; +} + +if (count($list_mailbox) > 0) { + echo "\n"; + echo " \n"; + echo " "; + echo " "; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + + foreach ($list_mailbox as $row) { + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + $active = ($row['active'] == 1) ? $PALANG['YES'] : $PALANG['NO']; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + } + echo "

".$PALANG['pOverview_mailbox_title']."

" . $PALANG['pOverview_mailbox_username'] . "" . $PALANG['pOverview_mailbox_name'] . "" . $PALANG['pOverview_mailbox_modified'] . "" . $PALANG['pOverview_mailbox_active'] . " 
" . $row['username'] . "" . $row['name'] . "" . $row['modified'] . "" . $active . "" . $PALANG['edit'] . "" . $PALANG['del'] . "
\n"; +} +?>