commit 461ed9a53b7c9de7dff3b543bb45460bee4cb085 from: mischa date: Fri Sep 02 21:06:08 2022 UTC rip and replace.. start commit - 81954500f3ed7441609824a68d21351f0f875155 commit + 461ed9a53b7c9de7dff3b543bb45460bee4cb085 blob - 29144aee14ec66f8f8f960a6cc68c425168cdf23 blob + 6da9fc0a22a2280cc39ec0f3351d99b66d1bde7b --- .gitignore +++ .gitignore @@ -1,2 +1,3 @@ +conf.php config.inc.php admin/.htpasswd blob - /dev/null blob + 89039a31eda8192a52a50a5c1c3ef37bc186c73f (mode 644) --- /dev/null +++ admin/add-admin.php @@ -0,0 +1,77 @@ + +// Copyright (c) 2022 High5! +// License Info: LICENSE.TXT +// +// File: create-admin.php +// +// Template File: admin_create-admin.tpl +// +// +// Template Variables: +// +// tMessage +// tUsername +// tDomains +// +// Form POST \ GET Variables: +// +// fUsername +// fPassword +// fPassword2 +// fDomains +// +require("../variables.inc.php"); +require("../config.inc.php"); +require("../functions.inc.php"); +include("../languages/" . check_language() . ".lang"); + +$list_domains = list_domains(); +$list_admins = list_admins(); + +if ($_SERVER['REQUEST_METHOD'] == "POST") { + $username = filter_input(INPUT_POST, 'username', FILTER_VALIDATE_EMAIL); + $password1 = filter_input(INPUT_POST, 'password1', FILTER_DEFAULT); + $password2 = filter_input(INPUT_POST, 'password2', FILTER_DEFAULT); + $domains = filter_input_array(INPUT_POST, array('domains' => array('filter' => FILTER_VALIDATE_DOMAIN, 'flags' => FILTER_REQUIRE_ARRAY))); + + if (empty($username) || in_array($username, array_column($list_admins, 'username'))) { + $message = $PALANG['pAdminCreate_admin_username_error']; + } + + if (empty($password1) or ($password1 != $password2)) { + $message = $PALANG['pAdminCreate_admin_password_error']; + } + + if (empty($domains['domains'])) { + $message = $PALANG['pAdminCreate_admin_domain_error']; + } + + if (empty($message)) { + $hashed = bcrypt($password1); + try { + $dbh = connect_db(); + $sth = $dbh->prepare("INSERT INTO admin (username,password,created,modified) VALUES (?,?,NOW(),NOW())"); + $sth->bindParam(1, $username, PDO::PARAM_STR); + $sth->bindParam(2, $hashed, PDO::PARAM_STR); + $sth->execute(); + foreach ($domains['domains'] as $row) { + $sth = $dbh->prepare("INSERT INTO domain_admins (username,domain,created) VALUES (?,?,NOW())"); + $sth->bindParam(1, $username, PDO::PARAM_STR); + $sth->bindParam(2, $row, PDO::PARAM_STR); + $sth->execute(); + } + $message = $PALANG['pAdminCreate_admin_result_succes'] . "
($username)
"; + } catch(PDOException $e) { + $message = $PALANG['pAdminCreate_admin_result_error'] . "
($username)
"; + } + } + +} +include("../templates/header.tpl"); +include("../templates/admin_menu.tpl"); +include("../templates/admin_create-admin.tpl"); +include("../templates/footer.tpl"); +?> blob - fa28d2fca200acdc3a03579bd6d78d6d5b382085 blob + 292d8ff983e2fb803d970b1976576648cce4c362 --- admin/create-admin.php +++ admin/create-admin.php @@ -29,67 +29,49 @@ require("../functions.inc.php"); include("../languages/" . check_language() . ".lang"); $list_domains = list_domains(); +$list_admins = list_admins(); -if ($_SERVER['REQUEST_METHOD'] == "GET") { - $pAdminCreate_admin_username_text = $PALANG['pAdminCreate_admin_username_text']; - $tDomains = array(); - - include("../templates/header.tpl"); - include("../templates/admin_menu.tpl"); - include("../templates/admin_create-admin.tpl"); - include("../templates/footer.tpl"); -} - if ($_SERVER['REQUEST_METHOD'] == "POST") { - $fUsername = escape_string($_POST['fUsername']); - $fPassword = escape_string($_POST['fPassword']); - $fPassword2 = escape_string($_POST['fPassword2']); - if (isset($_POST['fDomains'])) $tDomains = $_POST['fDomains']; + $username = filter_input(INPUT_POST, 'username', FILTER_VALIDATE_EMAIL); + $password1 = filter_input(INPUT_POST, 'password1', FILTER_DEFAULT); + $password2 = filter_input(INPUT_POST, 'password2', FILTER_DEFAULT); + $domains = filter_input_array(INPUT_POST, array('domains' => array('filter' => FILTER_VALIDATE_DOMAIN, 'flags' => FILTER_REQUIRE_ARRAY))); - if (!check_email($fUsername)) { - $error = 1; - $tUsername = escape_string($_POST['fUsername']); - if (isset($_POST['fDomains'])) $tDomains = $_POST['fDomains']; - $pAdminCreate_admin_username_text = $PALANG['pAdminCreate_admin_username_text_error1']; + if (empty($username) || in_array($username, array_column($list_admins, 'username'))) { + $message = $PALANG['pAdminCreate_admin_username_error']; } - if (empty($fUsername) or admin_exist($fUsername)) { - $error = 1; - $tUsername = escape_string($_POST['fUsername']); - if (isset($_POST['fDomains'])) $tDomains = $_POST['fDomains']; - $pAdminCreate_admin_username_text = $PALANG['pAdminCreate_admin_username_text_error2']; + if (empty($password1) or ($password1 != $password2)) { + $message = $PALANG['pAdminCreate_admin_password_error']; } - - if (empty($fPassword) or ($fPassword != $fPassword2)) { - $error = 1; - $tUsername = escape_string($_POST['fUsername']); - if (isset($_POST['fDomains'])) $tDomains = $_POST['fDomains']; - $pAdminCreate_admin_username_text = $PALANG['pAdminCreate_admin_username_text']; - $pAdminCreate_admin_password_text = $PALANG['pAdminCreate_admin_password_text_error']; + + if (empty($domains['domains'])) { + $message = $PALANG['pAdminCreate_admin_domain_error']; } - if ($error != 1) { - $password = pacrypt("$fPassword"); - $pAdminCreate_admin_username_text = $PALANG['pAdminCreate_admin_username_text']; - - - $result = db_query("INSERT INTO admin (username,password,created,modified) VALUES ('$fUsername','$password',NOW(),NOW())"); - if ($result['rows'] != 1) { - $tMessage = $PALANG['pAdminCreate_admin_result_error'] . "
($fUsername)
"; - } else { - if (!empty($tDomains[0])) { - for ($i = 0; $i < count($tDomains); $i++) { - $domain = $tDomains[$i]; - $result = db_query("INSERT INTO domain_admins (username,domain,created) VALUES ('$fUsername','$domain',NOW())"); - } + if (empty($message)) { + $hashed = bcrypt($password1); + try { + $dbh = connect_db(); + $sth = $dbh->prepare("INSERT INTO admin (username,password,created,modified) VALUES (?,?,NOW(),NOW())"); + $sth->bindParam(1, $username, PDO::PARAM_STR); + $sth->bindParam(2, $hashed, PDO::PARAM_STR); + $sth->execute(); + foreach ($domains['domains'] as $row) { + $sth = $dbh->prepare("INSERT INTO domain_admins (username,domain,created) VALUES (?,?,NOW())"); + $sth->bindParam(1, $username, PDO::PARAM_STR); + $sth->bindParam(2, $row, PDO::PARAM_STR); + $sth->execute(); } - $tMessage = $PALANG['pAdminCreate_admin_result_succes'] . "
($fUsername)
"; - } + $message = $PALANG['pAdminCreate_admin_result_succes'] . "
($username)
"; + } catch(PDOException $e) { + $message = $PALANG['pAdminCreate_admin_result_error'] . "
($username)
"; + } } - include("../templates/header.tpl"); - include("../templates/admin_menu.tpl"); - include("../templates/admin_create-admin.tpl"); - include("../templates/footer.tpl"); } +include("../templates/header.tpl"); +include("../templates/admin_menu.tpl"); +include("../templates/admin_create-admin.tpl"); +include("../templates/footer.tpl"); ?> blob - 6c54a20be4d06984f5e0b38ba4a22742bee208f2 blob + d66b1a58124ec160f945fded5242b99f1d37cc89 --- admin/create-alias.php +++ admin/create-alias.php @@ -14,13 +14,13 @@ // tMessage // tAddress // tGoto -// tDomain +// domain // // Form POST \ GET Variables: // -// fAddress +// address // fGoto -// fDomain +// domain // require("../variables.inc.php"); require("../config.inc.php"); @@ -29,74 +29,40 @@ include("../languages/" . check_language() . ".lang"); $list_domains = list_domains(); -if ($_SERVER['REQUEST_METHOD'] == "GET") { - $pCreate_alias_goto_text = $PALANG['pCreate_alias_goto_text']; - - if (isset($_GET['domain'])) $tDomain = escape_string($_GET['domain']); -} - if ($_SERVER['REQUEST_METHOD'] == "POST") { - $pCreate_alias_goto_text = $PALANG['pCreate_alias_goto_text']; + $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')); - $fAddress = escape_string($_POST['fAddress']) . "@" . escape_string($_POST['fDomain']); - $fAddress = strtolower($fAddress); - $fGoto = escape_string($_POST['fGoto']); - $fGoto = strtolower($fGoto); - $fDomain = escape_string($_POST['fDomain']); - - if (!preg_match('/@/',$fGoto)) { - $fGoto = $fGoto . "@" . escape_string($_POST['fDomain']); + $from = filter_var($address . '@' . $domain, FILTER_VALIDATE_EMAIL); + if (!str_contains($goto, '@')) { + $goto = $goto . "@" . $domain; } - - if (!check_alias($fDomain)) { - $error = 1; - $tAddress = escape_string($_POST['fAddress']); - $tGoto = $fGoto; - $tDomain = $fDomain; - $pCreate_alias_address_text = $PALANG['pCreate_alias_address_text_error3']; - } - - if (empty($fAddress) or !check_email($fAddress)) - { - $error = 1; - $tAddress = escape_string($_POST['fAddress']); - $tGoto = $fGoto; - $tDomain = $fDomain; - $pCreate_alias_address_text = $PALANG['pCreate_alias_address_text_error1']; - } + $goto = filter_var($goto, FILTER_VALIDATE_EMAIL); - if (empty($fGoto) or !check_email($fGoto)) - { - $error = 1; - $tAddress = escape_string($_POST['fAddress']); - $tGoto = $fGoto; - $tDomain = $fDomain; - $pCreate_alias_goto_text = $PALANG['pCreate_alias_goto_text_error']; + 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 (escape_string($_POST['fAddress']) == "*") $fAddress = "@" . escape_string($_POST['fDomain']); - - $result = db_query("SELECT * FROM alias WHERE address='$fAddress'"); - if ($result['rows'] == 1) { - $error = 1; - $tAddress = escape_string($_POST['fAddress']); - $tGoto = $fGoto; - $tDomain = $fDomain; - $pCreate_alias_address_text = $PALANG['pCreate_alias_address_text_error2']; + if (empty($address) || empty($goto)) { + $message = $PALANG['pCreate_alias_address_text_error1']; } - if ($error != 1) { - if (preg_match('/^\*@(.*)$/', $fGoto, $match)) $fGoto = "@" . $match[1]; - - $result = db_query("INSERT INTO alias (address,goto,domain,created,modified) VALUES ('$fAddress','$fGoto','$fDomain',NOW(),NOW())"); - if ($result['rows'] != 1) { - $tDomain = $fDomain; - $tMessage = $PALANG['pCreate_alias_result_error'] . "
($fAddress -> $fGoto)
"; - } else { - db_log($CONF['admin_email'], $fDomain, "create alias", "$fAddress -> $fGoto"); - - $tDomain = $fDomain; - $tMessage = $PALANG['pCreate_alias_result_succes'] . "
($fAddress -> $fGoto)
"; + 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
"; } } } blob - cd5ed76efe610f1286d548fd3e5542f7f0c9fb26 blob + 81f855d525d9b14946d07009fa0f0f89d37613fe --- admin/create-domain.php +++ admin/create-domain.php @@ -28,70 +28,38 @@ // fMaxquota // fDefaultaliases // -require("../variables.inc.php"); -require("../config.inc.php"); -require("../functions.inc.php"); -include("../languages/" . check_language() . ".lang"); +require_once '../functions.inc.php'; +include '../languages/' . check_language() . '.lang'; -if ($_SERVER['REQUEST_METHOD'] == "GET") { - $tAliases = $CONF['aliases']; - $tMailboxes = $CONF['mailboxes']; - $tMaxquota = $CONF['maxquota']; -} - if ($_SERVER['REQUEST_METHOD'] == "POST") { - $fDomain = escape_string($_POST['fDomain']); - !empty($_POST['fDescription']) ? $fDescription = escape_string($_POST['fDescription']) : $fDescription = "No Description"; - $fAliases = escape_string($_POST['fAliases']); - $fMailboxes = escape_string($_POST['fMailboxes']); - !empty($_POST['fMaxquota']) ? $fMaxquota = escape_string($_POST['fMaxquota']) : $fMaxquota = "0"; - !empty($_POST['fTransport']) ? $fTransport = escape_string($_POST['fTransport']) : $fTransport = "virtual"; - if (isset($_POST['fDefaultaliases'])) $fDefaultaliases = escape_string($_POST['fDefaultaliases']); - isset($_POST['fBackupmx']) ? $fBackupmx = escape_string($_POST['fBackupmx']) : $fBackupmx = "0"; - if (empty($fDomain) or domain_exist($fDomain)) { - $error = 1; - $tDomain = escape_string($_POST['fDomain']); - $tDescription = escape_string($_POST['fDescription']); - $tAliases = escape_string($_POST['fAliases']); - $tMailboxes = escape_string($_POST['fMailboxes']); - if (isset($_POST['fMaxquota'])) $tMaxquota = escape_string($_POST['fMaxquota']); - if (isset($_POST['fTransport'])) $tTransport = escape_string($_POST['fTransport']); - if (isset($_POST['fDefaultaliases'])) $tDefaultaliases = escape_string($_POST['fDefaultaliases']); - if (isset($_POST['fBackupmx'])) $tBackupmx = escape_string($_POST['fBackupmx']); - $pAdminCreate_domain_domain_text = $PALANG['pAdminCreate_domain_domain_text_error']; - } - - if ($error != 1) { - $tAliases = $CONF['aliases']; - $tMailboxes = $CONF['mailboxes']; - $tMaxquota = $CONF['maxquota']; + $list_domains = list_domains(); - if ($fBackupmx == "on") { - $fAliases = -1; - $fMailboxes = -1; - $fMaxquota = -1; - $fBackupmx = 1; - } else { - $fBackupmx = 0; + $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)
"; } - - $result = db_query("INSERT INTO domain (domain,description,aliases,mailboxes,maxquota,transport,backupmx,created,modified) VALUES ('$fDomain','$fDescription',$fAliases,$fMailboxes,$fMaxquota,'$fTransport',$fBackupmx,NOW(),NOW())"); - if ($result['rows'] != 1) { - $tMessage = $PALANG['pAdminCreate_domain_result_error'] . "
($fDomain)
"; - } else { - if ($fDefaultaliases == "on") { - foreach ($CONF['default_aliases'] as $address=>$goto) { - $address = $address . "@" . $fDomain; - $result = db_query("INSERT INTO alias (address,goto,domain,created,modified) VALUES ('$address','$goto','$fDomain',NOW(),NOW())"); - } - } - $tMessage = $PALANG['pAdminCreate_domain_result_succes'] . "
($fDomain)
"; - } + } else { + $message = $PALANG['pAdminCreate_domain_domain_text_error']; } } -include("../templates/header.tpl"); -include("../templates/admin_menu.tpl"); -include("../templates/admin_create-domain.tpl"); -include("../templates/footer.tpl"); + +include '../templates/header.tpl'; +include '../templates/admin_menu.tpl'; +include '../templates/admin_create-domain.tpl'; +include '../templates/footer.tpl'; ?> blob - a36a41f0d9a0ddd9445c89ed8d9d20bc65a658f3 blob + 59f8fa92ecc0def2a5b0875b2fc8fa19e9df228b --- admin/delete.php +++ admin/delete.php @@ -15,84 +15,171 @@ // // Form POST \ GET Variables: // -// fTable -// fWhere -// fDelete -// fDomain +// table +// where +// delete +// domain // -require("../variables.inc.php"); -require("../config.inc.php"); -require("../functions.inc.php"); +require_once("../functions.inc.php"); include("../languages/" . check_language() . ".lang"); if ($_SERVER['REQUEST_METHOD'] == "GET") { - if (isset($_GET['table'])) $fTable = escape_string($_GET['table']); - if (isset($_GET['where'])) $fWhere = escape_string($_GET['where']); - if (isset($_GET['delete'])) $fDelete = escape_string($_GET['delete']); - if (isset($_GET['domain'])) $fDomain = escape_string($_GET['domain']); - - if (empty($fTable)) { - $error = 1; - } - - if ($fTable == "domain") { - $result_domain = db_delete("domain",$fWhere,$fDelete); - $result_domain_admins = db_delete("domain_admins",$fWhere,$fDelete); - $result_alias = db_delete("alias",$fWhere,$fDelete); - $result_mailbox = db_delete("mailbox",$fWhere,$fDelete); - $result_log = db_delete("log",$fWhere,$fDelete); - if ($CONF['vacation'] == "YES") { - $result_vacation = db_delete("vacation",$fWhere,$fDelete); - } + $table = strtolower(filter_input(INPUT_GET, 'table', FILTER_DEFAULT)); + $delete = filter_input(INPUT_GET, 'delete', FILTER_DEFAULT); + $domain = filter_input(INPUT_GET, 'domain', FILTER_DEFAULT); - if (!($result_domain == 1) and ($result_domain_admins >= 0) and ($result_alias >= 0) and ($result_mailbox >= 0) and ($result_vacation >= 0)) { - $error = 1; - $tMessage = $PALANG['pAdminDelete_domain_error']; - } else { - $url = "list-domain.php"; + if ($table == "domain") { + try { + $dbh = connect_db(); + $dbh->beginTransaction(); + + $sth = $dbh->prepare("SELECT COUNT(*) FROM log WHERE domain=?"); + $sth->execute(array($domain)); + $count_log = $sth->fetchColumn(); + + $sth = $dbh->prepare("DELETE FROM log WHERE domain=?"); + $sth->execute(array($domain)); + if ($sth->rowCount() != $count_log) { + throw new RuntimeException('Unable to delete entries from the logs table.'); + } + + $sth = $dbh->prepare("SELECT COUNT(*) FROM vacation WHERE domain=?"); + $sth->execute(array($domain)); + $count_vacation = $sth->fetchColumn(); + + $sth = $dbh->prepare("DELETE FROM vacation WHERE domain=?"); + $sth->execute(array($domain)); + if ($sth->rowCount() != $count_vacation) { + throw new RuntimeException('Unable to delete entries from the vacation table.'); + } + + $sth = $dbh->prepare("SELECT COUNT(*) FROM alias WHERE domain=?"); + $sth->execute(array($domain)); + $count_alias = $sth->fetchColumn(); + + $sth = $dbh->prepare("DELETE FROM alias WHERE domain=?"); + $sth->execute(array($domain)); + if ($sth->rowCount() != $count_alias) { + throw new RuntimeException('Unable to delete entries from the alias table.'); + } + + $sth = $dbh->prepare("SELECT COUNT(*) FROM mailbox WHERE domain=?"); + $sth->execute(array($domain)); + $count_mailbox = $sth->fetchColumn(); + + $sth = $dbh->prepare("DELETE FROM mailbox WHERE domain=?"); + $sth->execute(array($domain)); + if ($sth->rowCount() != $count_mailbox) { + throw new RuntimeException('Unable to delete entries from the mailbox table.'); + } + + $sth = $dbh->prepare("SELECT COUNT(*) FROM domain_admins WHERE domain=?"); + $sth->execute(array($domain)); + $count_domain_admins = $sth->fetchColumn(); + + $sth = $dbh->prepare("DELETE FROM domain_admins WHERE domain=?"); + $sth->execute(array($domain)); + if ($sth->rowCount() != $count_domain_admins) { + throw new RuntimeException('Unable to delete entries from the domain_admins table.'); + } + + $sth = $dbh->prepare("SELECT COUNT(*) FROM domain WHERE domain=?"); + $sth->execute(array($domain)); + $count_domain = $sth->fetchColumn(); + + $sth = $dbh->prepare("DELETE FROM domain WHERE domain=?"); + $sth->execute(array($domain)); + if ($sth->rowCount() != $count_domain) { + throw new RuntimeException('Unable to delete entry from the domain table.'); + } + + $dbh->commit(); + header("Location: list-domain.php"); + } catch (RuntimeException $e) { + $message = $e->getMessage(); + $dbh->rollBack(); + } catch (PDOException $e) { + $message = $e->getMessage(); } } - if ($fTable == "admin") { - $result_admin = db_delete("admin",$fWhere,$fDelete); - $result_domain_admins = db_delete("domain_admins",$fWhere,$fDelete); - - if (!($result_admin == 1) and ($result_domain_admins >= 0)) { - $error = 1; - $tMessage = $PALANG['pAdminDelete_admin_error']; - } else { - $url = "list-admin.php"; + if ($table == "admin") { + try { + $dbh = connect_db(); + $dbh->beginTransaction(); + + $sth = $dbh->prepare("SELECT COUNT(*) FROM admin WHERE username=?"); + $sth->execute(array($delete)); + $count_admin = $sth->fetchColumn(); + + $sth = $dbh->prepare("DELETE FROM admin WHERE username=?"); + $sth->execute(array($delete)); + if ($sth->rowCount() != $count_admin) { + throw new RuntimeException('Unable to delete entry from the admin table.'); + } + + $sth = $dbh->prepare("SELECT COUNT(*) FROM domain_admins WHERE username=?"); + $sth->execute(array($delete)); + $count_domain_admins = $sth->fetchColumn(); + + $sth = $dbh->prepare("DELETE FROM domain_admins WHERE username=?"); + $sth->execute(array($delete)); + if ($sth->rowCount() != $count_domain_admins) { + throw new RuntimeException('Unable to delete entries from the domain_admins table.'); + } + + $dbh->commit(); + header("Location: list-admin.php"); + } catch (RuntimeException $e) { + $message = $e->getMessage(); + $dbh->rollBack(); + } catch (PDOException $e) { + $message = $e->getMessage(); } } - if ($fTable == "alias" or $fTable == "mailbox") { - $result = db_query("DELETE FROM alias WHERE address='$fDelete' AND domain='$fDomain'"); - if ($result['rows'] != 1) { - $error = 1; - $tMessage = $PALANG['pDelete_delete_error'] . "$fDelete (alias)!"; - } else { - $url = "list-virtual.php?domain=$fDomain"; - db_log($CONF['admin_email'], $fDomain, "delete alias", $fDelete); + if ($table == 'alias' || $table == 'mailbox') { + try { + $dbh = connect_db(); + $sth = $dbh->prepare("DELETE FROM alias WHERE address=? AND domain=?"); + $sth->bindParam(1, $delete, PDO::PARAM_STR); + $sth->bindParam(2, $domain, PDO::PARAM_STR); + $sth->execute(); + if ($sth->rowCount() != 1) { + throw new RuntimeException('alias'); + } + logging(ADMIN_EMAIL, $domain, "delete alias", $delete); + + header("Location: list-virtual.php?domain=$domain"); + } catch (RuntimeException $e) { + $message = $PALANG['pDelete_delete_error'] . "$delete (" . $e->getMessage() . ")!"; + } catch (PDOException $e) { + $message = $PALANG['pDelete_delete_error'] . "$delete (alias)! " . $e-getMessage(); } - $result = db_query("SELECT * FROM mailbox WHERE username='$fDelete' AND domain='$fDomain'"); - if ($result['rows'] == 1) { - $result = db_query("DELETE FROM mailbox WHERE username='$fDelete' AND domain='$fDomain'"); - if ($result['rows'] != 1) { - $error = 1; - $tMessage = $PALANG['pDelete_delete_error'] . "$fDelete (mailbox)!"; - } else { - $url = "list-virtual.php?domain=$fDomain"; - db_query("DELETE FROM vacation WHERE email='$fDelete' AND domain='$fDomain'"); - db_log($CONF['admin_email'], $fDomain, "delete mailbox", $fDelete); + try { + $dbh = connect_db(); + $sth = $dbh->prepare("DELETE FROM mailbox WHERE username=? AND domain=?"); + $sth->bindParam(1, $delete, PDO::PARAM_STR); + $sth->bindParam(2, $domain, PDO::PARAM_STR); + $sth->execute(); + if ($sth->rowCount() != 1) { + throw new RuntimeException('mailbox'); } + logging(ADMIN_EMAIL, $domain, "delete mailbox", $delete); + + $sth = $dbh->prepare("DELETE FROM vacation WHERE email=? AND domain=?"); + $sth->bindParam(1, $delete, PDO::PARAM_STR); + $sth->bindParam(2, $domain, PDO::PARAM_STR); + $sth->execute(); + + header("Location: list-virtual.php?domain=$domain"); + } catch (RuntimeException $e) { + $message = $PALANG['pDelete_delete_error'] . "$delete (" . $e->getMessage() . ")!"; + } catch (PDOException $e) { + $message = $PALANG['pDelete_delete_error'] . "$delete (mailbox)!"; } } - - if ($error != 1) { - header("Location: $url"); - exit; - } } include("../templates/header.tpl"); include("../templates/admin_menu.tpl"); blob - /dev/null blob + 9055b22c145c4f51fb791c36623d7dc3461ca01f (mode 644) --- /dev/null +++ admin/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_domain.tpl'; +include '../templates/footer.tpl'; +?> blob - 351ba00448d694c074ed164916d34b939d8de54d blob + d725e1c5ecc499e70b7ea20644fcc691a3aad014 --- admin/edit-domain.php +++ admin/edit-domain.php @@ -25,22 +25,18 @@ // fMaxquota // fActive // -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'] == "GET") { - $domain = escape_string($_GET['domain']); - $domain_properties = get_domain_properties($domain); - - $tDescription = $domain_properties['description']; - $tAliases = $domain_properties['aliases']; - $tMailboxes = $domain_properties['mailboxes']; - $tMaxquota = $domain_properties['maxquota']; - $tTransport = $domain_properties['transport']; - $tBackupmx = $domain_properties['backupmx']; - $tActive = $domain_properties['active']; + $action = filter_input(INPUT_GET, 'action', FILTER_DEFAULT); + $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") { @@ -49,21 +45,7 @@ if ($_SERVER['REQUEST_METHOD'] == "POST") { $fDescription = escape_string($_POST['fDescription']); $fAliases = escape_string($_POST['fAliases']); $fMailboxes = escape_string($_POST['fMailboxes']); - if (isset($_POST['fMaxquote']) ? $fMaxquota = escape_string($_POST['fMaxquota']) : $fMaxquota = "0"); - if (isset($_POST['fTransport'])) $fTransport = escape_string($_POST['fTransport']); - if (isset($_POST['fBackupmx'])) $fBackupmx = escape_string($_POST['fBackupmx']); - if (isset($_POST['fActive'])) $fActive = escape_string($_POST['fActive']); - if ($fBackupmx == "on") { - $fAliases = -1; - $fMailboxes = -1; - $fMaxquota = -1; - $fBackupmx = 1; - } else { - $fBackupmx = 0; - } - - $fActive = ($fActive == "on" ? 1 : 0); $result = db_query("UPDATE domain SET description='$fDescription',aliases='$fAliases',mailboxes='$fMailboxes',maxquota='$fMaxquota',transport='$fTransport',backupmx='$fBackupmx',active='$fActive',modified=NOW() WHERE domain='$domain'"); if ($result['rows'] == 1) { @@ -74,6 +56,6 @@ if ($_SERVER['REQUEST_METHOD'] == "POST") { } include("../templates/header.tpl"); include("../templates/admin_menu.tpl"); -include("../templates/admin_edit-domain.tpl"); +include("../templates/admin_add-domain.tpl"); include("../templates/footer.tpl"); ?> blob - e2f96c721e7581314c2a0f4c3c45c8d5063a1466 blob + d2ab8eb90cee982dcc343a3803ac31862571fe89 --- admin/list-admin.php +++ admin/list-admin.php @@ -11,30 +11,19 @@ // // Template Variables: // -// -none- +// list_admins // // Form POST \ GET Variables: // // -none- // -require("../variables.inc.php"); -require("../config.inc.php"); -require("../functions.inc.php"); -include("../languages/" . check_language() . ".lang"); +require '../functions.inc.php'; +include '../languages/' . check_language() . '.lang'; $list_admins = list_admins(); -if (!empty($list_admins)) { - $list_admins_count = count($list_admins); - if ((is_array($list_admins) and $list_admins_count > 0)) { - for ($i = 0; $i < $list_admins_count; $i++) { - $admin_properties[$i] = get_admin_properties($list_admins[$i]); - } - } -} - -include("../templates/header.tpl"); -include("../templates/admin_menu.tpl"); -include("../templates/admin_list-admin.tpl"); -include("../templates/footer.tpl"); +include '../templates/header.tpl'; +include '../templates/admin_menu.tpl'; +include '../templates/admin_list-admin.tpl'; +include '../templates/footer.tpl'; ?> blob - 185ba574954c51c7ca64f93005e8e3f41feb8bc4 blob + 560f8c63730e48fe1b24ccf2a3ad91142563acd1 --- admin/list-domain.php +++ admin/list-domain.php @@ -11,51 +11,26 @@ // // Template Variables: // -// -none- +// list_domains // -// Form POST \ GET Variables: +// Form GET Variables: // -// fUsername +// username // -require("../variables.inc.php"); -require("../config.inc.php"); -require("../functions.inc.php"); -include("../languages/" . check_language() . ".lang"); +require_once '../functions.inc.php'; +include '../languages/' . check_language() . '.lang'; $list_admins = list_admins(); if ($_SERVER['REQUEST_METHOD'] == "GET") { - if (isset($_GET['username'])) { - $fUsername = escape_string($_GET['username']); - - $list_domains = list_domains_for_admin($fUsername); - if ($list_domains != 0) { - for ($i = 0; $i < count($list_domains); $i++) { - $domain_properties[$i] = get_domain_properties($list_domains[$i]); - } - } - } else { - $list_domains = list_domains(); - if ((is_array($list_domains) and count($list_domains) > 0)) { - for ($i = 0; $i < count($list_domains); $i++) { - $domain_properties[$i] = get_domain_properties($list_domains[$i]); - } - } - } + $username = filter_input(INPUT_GET, 'username', FILTER_VALIDATE_EMAIL); + $list_domains = list_domains($username); +} else { + $list_domains = list_domains(); } -if ($_SERVER['REQUEST_METHOD'] == "POST") { - $fUsername = escape_string($_POST['fUsername']); - - $list_domains = list_domains_for_admin($fUsername); - if (!empty($list_domains)) { - for ($i = 0; $i < count($list_domains); $i++) { - $domain_properties[$i] = get_domain_properties($list_domains[$i]); - } - } -} -include("../templates/header.tpl"); -include("../templates/admin_menu.tpl"); -include("../templates/admin_list-domain.tpl"); -include("../templates/footer.tpl"); +include '../templates/header.tpl'; +include '../templates/admin_menu.tpl'; +include '../templates/admin_list-domain.tpl'; +include '../templates/footer.tpl'; ?> blob - 3f86a84ff7d40303e6544819f5f6c491b31d126c blob + 0f84adaee1988711ada6fcfc8114036f00ab0fba --- admin/list-virtual.php +++ admin/list-virtual.php @@ -11,117 +11,32 @@ // // Template Variables: // -// tMessage -// tAlias -// tMailbox +// list_alias +// list_mailbox // -// Form POST \ GET Variables: +// Form GET Variables: // -// fDomain +// domain +// offset // -require("../variables.inc.php"); -require("../config.inc.php"); -require("../functions.inc.php"); -include("../languages/" . check_language() . ".lang"); +require_once '../functions.inc.php'; +include '../languages/' . check_language() . '.lang'; $list_domains = list_domains(); -$tAlias = array(); -$tMailbox = array(); - if ($_SERVER['REQUEST_METHOD'] == "GET") { - $fDisplay = 0; - $page_size = $CONF['page_size']; - - if (isset($_GET['domain'])) $fDomain = escape_string($_GET['domain']); - if (isset($_GET['limit'])) $fDisplay = escape_string($_GET['limit']); - - if ((is_array($list_domains) and count($list_domains) > 0)) if (empty($fDomain)) $fDomain = $list_domains[0]; - - $limit = get_domain_properties($fDomain); - - if ((is_array($list_domains) and count($list_domains) > 0)) if (empty($fDomain)) $fDomain = $list_domains[1]; - - if ($CONF['alias_control'] == "YES") { - $query = "SELECT alias.address,alias.goto,alias.modified FROM alias WHERE alias.domain='$fDomain' ORDER BY alias.address LIMIT $fDisplay, $page_size"; - } else { - $query = "SELECT alias.address,alias.goto,alias.modified FROM alias LEFT JOIN mailbox ON alias.address=mailbox.username WHERE alias.domain='$fDomain' AND mailbox.maildir IS NULL ORDER BY alias.address LIMIT $fDisplay, $page_size"; + $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')); + $list_alias = list_aliases($domain, $offset, $limit); + $list_mailbox = list_mailboxes($domain, $offset, $limit); } - - $result = db_query("$query"); - if ($result['rows'] > 0) { - while ($row = db_array($result['result'])) { - $tAlias[] = $row; - } - } - - $result = db_query("SELECT * FROM mailbox WHERE domain='$fDomain' ORDER BY username LIMIT $fDisplay, $page_size"); - if ($result['rows'] > 0) { - while ($row = db_array($result['result'])) { - $tMailbox[] = $row; - } - } - - if (isset($limit)) { - if ($fDisplay >= $page_size) { - $tDisplay_back_show = 1; - $tDisplay_back = $fDisplay - $page_size; - } - if (($limit['alias_count'] > $page_size) or ($limit['mailbox_count'] > $page_size)) { - $tDisplay_up_show = 1; - } - if ((($fDisplay + $page_size) < $limit['alias_count']) or (($fDisplay + $page_size) < $limit['mailbox_count'])) { - $tDisplay_next_show = 1; - $tDisplay_next = $fDisplay + $page_size; - } - } } -if ($_SERVER['REQUEST_METHOD'] == "POST") { - $fDisplay = 0; - $page_size = $CONF['page_size']; - - $fDomain = escape_string($_POST['fDomain']); - if (isset($_POST['limit'])) $fDisplay = escape_string($_POST['limit']); - - $limit = get_domain_properties($fDomain); - - if ($CONF['alias_control'] == "YES") { - $query = "SELECT alias.address,alias.goto,alias.modified FROM alias WHERE alias.domain='$fDomain' ORDER BY alias.address LIMIT $fDisplay, $page_size"; - } else { - $query = "SELECT alias.address,alias.goto,alias.modified FROM alias LEFT JOIN mailbox ON alias.address=mailbox.username WHERE alias.domain='$fDomain' AND mailbox.maildir IS NULL ORDER BY alias.address LIMIT $fDisplay, $page_size"; - } - - $result = db_query("$query"); - if ($result['rows'] > 0) { - while ($row = db_array($result['result'])) { - $tAlias[] = $row; - } - } - - $result = db_query("SELECT * FROM mailbox WHERE domain='$fDomain' ORDER BY username LIMIT $fDisplay, $page_size"); - if ($result['rows'] > 0) { - while ($row = db_array($result['result'])) { - $tMailbox[] = $row; - } - } - - if (isset($limit)) { - if ($fDisplay >= $page_size) { - $tDisplay_back_show = 1; - $tDisplay_back = $fDisplay - $page_size; - } - if (($limit['alias_count'] > $page_size) or ($limit['mailbox_count'] > $page_size)) { - $tDisplay_up_show = 1; - } - if ((($fDisplay + $page_size) < $limit['alias_count']) or (($fDisplay + $page_size) < $limit['mailbox_count'])) { - $tDisplay_next_show = 1; - $tDisplay_next = $fDisplay + $page_size; - } - } -} -include("../templates/header.tpl"); -include("../templates/admin_menu.tpl"); -include("../templates/admin_list-virtual.tpl"); -include("../templates/footer.tpl"); +include '../templates/header.tpl'; +include '../templates/admin_menu.tpl'; +include '../templates/admin_list-virtual.tpl'; +include '../templates/footer.tpl'; ?> blob - 6fddc13292e78fa25154677d9f25b0303f89eb70 blob + fc9be7c398879dce9757eb523daed8fa5df04379 --- delete.php +++ delete.php @@ -24,12 +24,14 @@ require("./functions.inc.php"); include("./languages/" . check_language() . ".lang"); $SESSID_USERNAME = check_session(); +$list_domains = list_domains_for_admin($SESSID_USERNAME); if ($_SERVER['REQUEST_METHOD'] == "GET") { if (isset($_GET['delete'])) $fDelete = escape_string($_GET['delete']); if (isset($_GET['domain'])) $fDomain = escape_string($_GET['domain']); - if (!check_owner($SESSID_USERNAME, $fDomain)) { + if (in_array($_GET['domain'], array_column($list_domains, 'domain'))) { + #if (!check_owner($SESSID_USERNAME, $fDomain)) { $error = 1; $tMessage = $PALANG['pDelete_domain_error'] . "$fDomain!"; } else { blob - 6c9036f8a16227900dcd99c605be43801ec89f63 blob + 04de3e1f2306fcaea3c16ddf15641aaa14b26170 --- functions.inc.php +++ functions.inc.php @@ -12,12 +12,18 @@ if(preg_match("/functions.inc.php/", $_SERVER['SCRIPT_ exit; } +DEFINE("VERSION", "version 1.0.0"); +DEFINE('ROOT_PATH', dirname(__FILE__) . '/'); +require_once ROOT_PATH . 'conf.php'; +require_once ROOT_PATH . 'config.inc.php'; +require_once ROOT_PATH . 'variables.inc.php'; + $version = "1.0.0"; // // Check of debug is enabled or not // -if ($CONF['debug'] == 'true') { +if (DEBUG == 'true') { ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); @@ -100,60 +106,7 @@ function escape_string($string) { return $escaped_string; } -// -// get_domain_properties -// Action: Get all the properties of a domain. -// Call: get_domain_properties(string domain) -// -function get_domain_properties($domain) { - global $CONF; - $list = array(); - - $result = db_query("SELECT COUNT(*) FROM alias WHERE domain='$domain'"); - $row = db_row($result['result']); - $list['alias_count'] = $row[0]; - - $result = db_query("SELECT COUNT(*) FROM mailbox WHERE domain='$domain'"); - $row = db_row($result['result']); - $list['mailbox_count'] = $row[0]; - if ($CONF['alias_control'] == "NO") { - $list['alias_count'] = $list['alias_count'] - $list['mailbox_count']; - } else { - $list['alias_count'] = $list['alias_count']; - } - - $result = db_query("SELECT * FROM domain WHERE domain='$domain'"); - $row = db_array($result['result']); - $list['description'] = $row['description']; - $list['aliases'] = $row['aliases']; - $list['mailboxes'] = $row['mailboxes']; - $list['maxquota'] = $row['maxquota']; - $list['transport'] = $row['transport']; - $list['backupmx'] = $row['backupmx']; - $list['created'] = $row['created']; - $list['modified'] = $row['modified']; - $list['active'] = $row['active']; - if ($CONF['database_type'] == "pgsql") { - if ($row['active'] == "t") - { - $list['active'] = 1; - } else { - $list['active'] = 0; - } - - if ($row['backupmx'] == "t") { - $list['backupmx'] = 1; - } else { - $list['backupmx'] = 0; - } - } else { - $list['active'] = $row['active']; - $list['backupmx'] = $row['backupmx']; - } - return $list; -} - // // check_alias // Action: Checks if the domain is still able to create aliases. @@ -193,79 +146,85 @@ function check_mailbox($domain) { return true; } } - // -// check_quota -// Action: Checks if the user is creating a mailbox with the correct quota -// Call: check_quota(string domain) +// connect_db +// Action: make db connection +// Call: connect_db() // -function check_quota($quota, $domain) { - $limit = get_domain_properties($domain); - if ($limit['maxquota'] == 0) { - return true; +function connect_db() { + try { + $dbh = new PDO(DB_TYPE . ':host='. DB_HOST . ';dbname='. DB_NAME , DB_USER, DB_PASS, array(PDO::ATTR_PERSISTENT => true)); + $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + return $dbh; + } catch (PDOException $e) { + echo 'Connection failed: ' . $e; + die(); } - if (($limit['maxquota'] < 0) and ($quota < 0)) { - return true; - } - if (($limit['maxquota'] > 0) and ($quota == 0)) { - return false; - } - if ($quota > $limit['maxquota']) { - return false; - } else { - return true; - } } // -// check_owner -// Action: Checks if the admin is the owner of the domain. -// Call: check_owner(string admin, string domain) +// list_domains +// Action: List all available domains. +// Call: list_domains(string admin (optional)) // -function check_owner($username, $domain) { - $result = db_query("SELECT * FROM domain_admins WHERE username='$username' AND domain='$domain' AND active='1'"); - if ($result['rows'] != 1) { - return false; +function list_domains($username = null) { + $dbh = connect_db(); + if (isset($username)) { + $sth = $dbh->prepare("SELECT * FROM domain INNER JOIN domain_admins ON domain.domain=domain_admins.domain WHERE domain_admins.username=? ORDER BY domain_admins.domain"); + $sth->bindParam(1, $username, PDO::PARAM_STR); } else { - return true; + $sth = $dbh->prepare('SELECT * FROM domain ORDER BY domain'); } + $sth->execute(); + $list= $sth->fetchAll(); + + for ($i = 0; $i < count($list); $i++) { + $sth = $dbh->prepare("SELECT COUNT(*) FROM alias WHERE domain=? AND goto NOT IN ('vmail')"); + $sth->bindParam(1, $list[$i]['domain'], PDO::PARAM_STR); + $sth->execute(); + $list[$i]['alias_count'] = $sth->fetchColumn(); + + $sth = $dbh->prepare("SELECT COUNT(*) FROM mailbox WHERE domain=?"); + $sth->bindParam(1, $list[$i]['domain'], PDO::PARAM_STR); + $sth->execute(); + $list[$i]['mailbox_count'] = $sth->fetchColumn(); + } + return $list; } // -// list_domains_for_admin -// Action: Lists all the domains for an admin. -// Call: list_domains_for_admin(string admin) +// list_aliases +// Action: List all available aliases for domain. +// Call: list_aliases(string domain, int offset) // -function list_domains_for_admin($username) { - $list = array(); - - $result = db_query("SELECT * FROM domain LEFT JOIN domain_admins ON domain.domain=domain_admins.domain WHERE domain_admins.username='$username' AND domain.active='1' AND domain.backupmx='0' ORDER BY domain_admins.domain"); - if ($result['rows'] > 0) { - $i = 0; - while ($row = db_array($result['result'])) { - $list[$i] = $row['domain']; - $i++; - } +function list_aliases($domain, $offset, $limit) { + $dbh = connect_db(); + if (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 = $sth->fetchAll(); return $list; } // -// list_domains -// Action: List all available domains. -// Call: list_domains() +// list_mailboxes +// Action: List all available mailboxes for domain. +// Call: list_mailboxes(string domaini, int offset) // -function list_domains() { - $list = array(); - - $result = db_query("SELECT * FROM domain ORDER BY domain"); - if ($result['rows'] > 0) { - $i = 0; - while ($row = db_array($result['result'])) { - $list[$i] = $row['domain']; - $i++; - } - } +function list_mailboxes($domain, $offset, $limit) { + $dbh = connect_db(); + $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 = $sth->fetchAll(); return $list; } @@ -304,38 +263,18 @@ function domain_exist($domain) { // Action: Lists all the admins // Call: list_admins() // -// was admin_list_admins -// function list_admins() { - $list = array(); - - $result = db_query("SELECT * FROM admin ORDER BY username"); - if ($result['rows'] > 0) { - $i = 0; - while ($row = db_array($result['result'])) { - $list[$i] = $row['username']; - $i++; - } - } - return $list; -} + $dbh = new PDO(DB_TYPE . ':host='. DB_HOST . ';dbname='. DB_NAME , DB_USER, DB_PASS); + $sth = $dbh->prepare('SELECT * FROM admin ORDER BY username'); + $sth->execute(); + $list = $sth->fetchAll(); -// -// get_admin_properties -// Action: Get all the admin properties. -// Call: get_admin_properties(string admin) -function get_admin_properties($username) { - $list = array(); - - $result = db_query("SELECT COUNT(*) FROM domain_admins WHERE username='$username'"); - $row = db_row($result['result']); - $list['domain_count'] = $row[0]; - - $result = db_query("SELECT * FROM admin WHERE username='$username'"); - $row = db_array($result['result']); - $list['created'] = $row['created']; - $list['modified'] = $row['modified']; - $list['active'] = $row['active']; + for ($i = 0; $i < count($list); $i++) { + $sth = $dbh->prepare("SELECT COUNT(*) FROM domain_admins WHERE username=?"); + $sth->bindParam(1, $list[$i]['username'], PDO::PARAM_STR); + $sth->execute(); + $list[$i]['domain_count'] = $sth->fetchColumn(); + } return $list; } @@ -350,20 +289,15 @@ function generate_password() { } // -// pacrypt -// Action: Encrypts password based on config settings -// Call: pacrypt(string cleartextpassword) +// bcrypt +// Action: Hashs the password with bcrypt +// Call: bcrypt(string cleartextpassword) // -function pacrypt($pw, $pw_db="") { - global $CONF; - $password = ""; - - if ($CONF['encrypt'] == 'bcrypt') { - $options = ['cost' => 8]; - $password = password_hash($pw, PASSWORD_BCRYPT, $options); - $password = preg_replace('/\$2y\$/', '\$2b\$', $password); - } - return $password; +function bcrypt($password) { + $options = ['cost' => 8]; + $hashed = password_hash($password, PASSWORD_BCRYPT, $options); + $hashed = preg_replace('/\$2y\$/', '\$2b\$', $hashed); + return $hashed; } // @@ -392,16 +326,6 @@ function db_connect() { } } - if ($CONF['database_type'] == "pgsql") { - if(function_exists("pg_connect")) { - $connect_string = "host=" . $CONF['database_host'] . " dbname=" . $CONF['database_name'] . " user=" . $CONF['database_user'] . " password=" . $CONF['database_password']; - $link = @pg_connect($connect_string) or die("

DEBUG INFORMATION:
Connect: " . pg_last_error() . "$DEBUG_TEXT"); - } else { - print "

DEBUG INFORMATION:
PostgreSQL functions not available!
database_type = 'pgsql' in config.inc.php, are you using a different database? $DEBUG_TEXT"; - die; - } - } - if ($link) { return $link; } else { @@ -437,28 +361,17 @@ function db_query($query) { } if ($CONF['database_type'] == "mysqli") $result = @mysqli_query($link, $query) or die("

DEBUG INFORMATION:
Invalid query: " . mysqli_error($link) . "$DEBUG_TEXT"); - if ($CONF['database_type'] == "pgsql") { - if (preg_match("/LIMIT/i", $query)) { - $search = "/LIMIT(\w+), (\w+)/"; - $replace = "LIMIT \$2 OFFSET \$1"; - $query = preg_replace($search, $replace, $query); - } - $result = @pg_query($link, $query) or die("

DEBUG INFORMATION:
Invalid query: " . pg_last_error() . "$DEBUG_TEXT"); - } if (preg_match("/^SELECT/i", $query)) { // if $query was a SELECT statement check the number of rows with [database_type]_num_rows(). if ($CONF['database_type'] == "mysqli") $number_rows = mysqli_num_rows($result); - if ($CONF['database_type'] == "pgsql") $number_rows = pg_num_rows($result); } else { // if $query was something else, UPDATE, DELETE or INSERT check the number of rows with // [database_type]_affected_rows(). if ($CONF['database_type'] == "mysqli") $number_rows = mysqli_affected_rows($link); - if ($CONF['database_type'] == "pgsql") $number_rows = pg_affected_rows($result); } if ($CONF['database_type'] == "mysqli") mysqli_close($link); - if ($CONF['database_type'] == "pgsql") pg_close($link); $return = array( "result" => $result, @@ -475,7 +388,6 @@ function db_row($result) { global $CONF; $row = ""; if ($CONF['database_type'] == "mysqli") $row = mysqli_fetch_row($result); - if ($CONF['database_type'] == "pgsql") $row = pg_fetch_row($result); return $row; } @@ -487,7 +399,6 @@ function db_array($result) { global $CONF; $row = ""; if ($CONF['database_type'] == "mysqli") $row = mysqli_fetch_array($result); - if ($CONF['database_type'] == "pgsql") $row = pg_fetch_array($result); return $row; } @@ -499,7 +410,6 @@ function db_assoc($result) { global $CONF; $row = ""; if ($CONF['database_type'] == "mysqli") $row = mysqli_fetch_assoc($result); - if ($CONF['database_type'] == "pgsql") $row = pg_fetch_assoc($result); return $row; } @@ -517,14 +427,31 @@ function db_delete($table,$where,$delete) { } } +// logging +// Action: Logs actions from admin +// Call: logging(string username, string domain, string action, string data) // +function logging($username, $domain, $action, $data) { + $remote_addr = $_SERVER['HTTP_X_CLIENTIP'] ?? $_SERVER['REMOTE_ADDR']; + $username = $username . ' (' . $remote_addr . ')'; + if (LOGGING == 'YES') { + $dbh = connect_db(); + $sth = $dbh->prepare("INSERT INTO log (timestamp,username,domain,action,data) VALUES (NOW(),?,?,?,?)"); + $sth->bindParam(1, $username, PDO::PARAM_STR); + $sth->bindParam(2, $domain, PDO::PARAM_STR); + $sth->bindParam(3, $action, PDO::PARAM_STR); + $sth->bindParam(4, $data, PDO::PARAM_STR); + $sth->execute(); + } +} +// // db_log // Action: Logs actions from admin // Call: db_log(string username, string domain, string action, string data) // function db_log($username, $domain, $action, $data) { global $CONF; - if (!empty($_SERVER['HTTP_X_CLIENTIP'])) { + if (isset($_SERVER['HTTP_X_CLIENTIP'])) { $REMOTE_ADDR = $_SERVER['HTTP_X_CLIENTIP']; } else { $REMOTE_ADDR = $_SERVER['REMOTE_ADDR']; blob - f7692b819f249b36ee4c354fa686920dc755c3a9 blob + f3f27ade1f9fcf403514a6c15f85d24dfa5dc515 --- languages/en.lang +++ languages/en.lang @@ -7,8 +7,8 @@ $PALANG['YES'] = 'YES'; $PALANG['NO'] = 'NO'; $PALANG['edit'] = 'edit'; $PALANG['del'] = 'del'; -$PALANG['confirm'] = 'Are you sure you want to delete this?\n'; -$PALANG['confirm_domain'] = 'Do you really want to delete all records for this domain? This can not be undone!\n'; +$PALANG['confirm'] = 'Are you sure you want to delete this?'; +$PALANG['confirm_domain'] = 'Do you really want to delete all records for this domain? This can not be undone!'; $PALANG['check_update'] = 'Check for update'; $PALANG['pLogin_welcome'] = 'Mail admins login here to administer your domain.'; @@ -53,14 +53,12 @@ $PALANG['pOverview_alias_goto'] = 'To'; $PALANG['pOverview_alias_modified'] = 'Last Modified'; $PALANG['pOverview_mailbox_username'] = 'Email'; $PALANG['pOverview_mailbox_name'] = 'Name'; -$PALANG['pOverview_mailbox_quota'] = 'Quota (MB)'; $PALANG['pOverview_mailbox_modified'] = 'Last Modified'; $PALANG['pOverview_mailbox_active'] = 'Active'; $PALANG['pOverview_get_domain'] = 'Domain'; $PALANG['pOverview_get_aliases'] = 'Aliases'; $PALANG['pOverview_get_mailboxes'] = 'Mailboxes'; -$PALANG['pOverview_get_quota'] = 'Mailbox Quota (MB)'; $PALANG['pOverview_get_modified'] = 'Last Modified'; $PALANG['pDelete_delete_error'] = 'Unable to delete the entry '; @@ -68,14 +66,12 @@ $PALANG['pDelete_domain_error'] = 'The ALIAS is not valid.'; -$PALANG['pCreate_alias_address_text_error2'] = '
This email address already exists, please choose a different one.'; -$PALANG['pCreate_alias_address_text_error3'] = '
You have reached your limit to create aliases.'; +$PALANG['pCreate_alias_address_text_error1'] = 'The ALIAS or TO is not valid.'; +$PALANG['pCreate_alias_address_text_error2'] = 'You have reached your limit to create aliases.'; $PALANG['pCreate_alias_goto'] = 'To'; $PALANG['pCreate_alias_button'] = 'Add Alias'; $PALANG['pCreate_alias_goto_text'] = 'Where the mail needs to be send to.'; -$PALANG['pCreate_alias_goto_text_error'] = 'Where the email needs to go.
The TO is not valid.'; -$PALANG['pCreate_alias_result_error'] = 'Unable to add the alias to the alias table.'; +$PALANG['pCreate_alias_result_error'] = 'This email address already exists, unable to add to the alias table.'; $PALANG['pCreate_alias_result_succes'] = 'The alias has been added to the alias table.'; $PALANG['pCreate_alias_catchall_text'] = 'To create a catch-all use an "*" as alias.
For domain to domain forwarding use "*@domain.tld" as to.'; @@ -91,18 +87,15 @@ $PALANG['pEdit_alias_result_error'] = 'The EMAIL is not valid.'; -$PALANG['pCreate_mailbox_username_text_error2'] = '
This email address already exists, please choose a different one.'; -$PALANG['pCreate_mailbox_username_text_error3'] = '
You have reached your limit to create mailboxes.'; +$PALANG['pCreate_mailbox_username_text_error1'] = 'The USERNAME is not valid.'; +$PALANG['pCreate_mailbox_username_text_error2'] = 'This email address already exists, please choose a different one.'; +$PALANG['pCreate_mailbox_username_text_error3'] = 'You have reached your limit to create mailboxes.'; $PALANG['pCreate_mailbox_password'] = 'Password'; $PALANG['pCreate_mailbox_password2'] = 'Password (again)'; $PALANG['pCreate_mailbox_password_text'] = 'Password for POP3/IMAP'; -$PALANG['pCreate_mailbox_password_text_error'] = 'Password for POP3/IMAP
The passwords that you supplied don\'t match, or are empty.'; +$PALANG['pCreate_mailbox_password_text_error'] = 'The passwords that you supplied don\'t match, or are empty.'; $PALANG['pCreate_mailbox_name'] = 'Name'; $PALANG['pCreate_mailbox_name_text'] = 'Full name'; -$PALANG['pCreate_mailbox_quota'] = 'Quota'; -$PALANG['pCreate_mailbox_quota_text'] = 'MB'; -$PALANG['pCreate_mailbox_quota_text_error'] = 'MB
The quota that you specified is to high.'; $PALANG['pCreate_mailbox_active'] = 'Active'; $PALANG['pCreate_mailbox_mail'] = 'Create mailbox'; $PALANG['pCreate_mailbox_button'] = 'Add Mailbox'; @@ -116,9 +109,6 @@ $PALANG['pEdit_mailbox_password'] = 'New Password'; $PALANG['pEdit_mailbox_password2'] = 'New Password (again)'; $PALANG['pEdit_mailbox_password_text_error'] = 'The passwords that you supplied don\'t match.'; $PALANG['pEdit_mailbox_name'] = 'Name'; -$PALANG['pEdit_mailbox_quota'] = 'Quota'; -$PALANG['pEdit_mailbox_quota_text'] = 'MB'; -$PALANG['pEdit_mailbox_quota_text_error'] = 'MB
The quota that you specified is to high.'; $PALANG['pEdit_mailbox_domain_error'] = 'This domain is not yours: '; $PALANG['pEdit_mailbox_button'] = 'Edit Mailbox'; $PALANG['pEdit_mailbox_result_error'] = 'Unable to modify the mailbox.'; @@ -177,9 +167,6 @@ $PALANG['pAdminList_domain_domain'] = 'Domain'; $PALANG['pAdminList_domain_description'] = 'Description'; $PALANG['pAdminList_domain_aliases'] = 'Aliases'; $PALANG['pAdminList_domain_mailboxes'] = 'Mailboxes'; -$PALANG['pAdminList_domain_maxquota'] = 'Quota (MB)'; -$PALANG['pAdminList_domain_transport'] = 'Transport'; -$PALANG['pAdminList_domain_backupmx'] = 'Backup MX'; $PALANG['pAdminList_domain_modified'] = 'Last Modified'; $PALANG['pAdminList_domain_active'] = 'Active'; @@ -192,7 +179,6 @@ $PALANG['pAdminList_virtual_alias_goto'] = 'To'; $PALANG['pAdminList_virtual_alias_modified'] = 'Last Modified'; $PALANG['pAdminList_virtual_mailbox_username'] = 'Email'; $PALANG['pAdminList_virtual_mailbox_name'] = 'Name'; -$PALANG['pAdminList_virtual_mailbox_quota'] = 'Quota (MB)'; $PALANG['pAdminList_virtual_mailbox_modified'] = 'Last Modified'; $PALANG['pAdminList_virtual_mailbox_active'] = 'Active'; @@ -204,12 +190,6 @@ $PALANG['pAdminCreate_domain_aliases'] = 'Aliases'; $PALANG['pAdminCreate_domain_aliases_text'] = '-1 = disable | 0 = unlimited'; $PALANG['pAdminCreate_domain_mailboxes'] = 'Mailboxes'; $PALANG['pAdminCreate_domain_mailboxes_text'] = '-1 = disable | 0 = unlimited'; -$PALANG['pAdminCreate_domain_maxquota'] = 'Max Quota'; -$PALANG['pAdminCreate_domain_maxquota_text'] = 'MB
-1 = disable | 0 = unlimited'; -$PALANG['pAdminCreate_domain_transport'] = 'Transport'; -$PALANG['pAdminCreate_domain_transport_text'] = 'Define transport'; -$PALANG['pAdminCreate_domain_defaultaliases'] = 'Add default mail aliases'; -$PALANG['pAdminCreate_domain_backupmx'] = 'Mail server is backup MX'; $PALANG['pAdminCreate_domain_button'] = 'Add Domain'; $PALANG['pAdminCreate_domain_result_error'] = 'Unable to add domain.'; $PALANG['pAdminCreate_domain_result_succes'] = 'Domain has been added.'; @@ -221,23 +201,17 @@ $PALANG['pAdminEdit_domain_aliases'] = 'Aliases'; $PALANG['pAdminEdit_domain_aliases_text'] = '-1 = disable | 0 = unlimited'; $PALANG['pAdminEdit_domain_mailboxes'] = 'Mailboxes'; $PALANG['pAdminEdit_domain_mailboxes_text'] = '-1 = disable | 0 = unlimited'; -$PALANG['pAdminEdit_domain_maxquota'] = 'Max Quota'; -$PALANG['pAdminEdit_domain_maxquota_text'] = 'MB
-1 = disable | 0 = unlimited'; -$PALANG['pAdminEdit_domain_transport'] = 'Transport'; -$PALANG['pAdminEdit_domain_transport_text'] = 'Define transport'; -$PALANG['pAdminEdit_domain_backupmx'] = 'Mail server is backup MX'; $PALANG['pAdminEdit_domain_active'] = 'Active'; $PALANG['pAdminEdit_domain_button'] = 'Edit Domain'; $PALANG['pAdminEdit_domain_result_error'] = 'Unable to modify domain.'; $PALANG['pAdminCreate_admin_welcome'] = 'Add a new domain admin'; -$PALANG['pAdminCreate_admin_username'] = 'Admin'; -$PALANG['pAdminCreate_admin_username_text'] = 'email address'; -$PALANG['pAdminCreate_admin_username_text_error1'] = 'Email address
Admin is not a valid email address.'; -$PALANG['pAdminCreate_admin_username_text_error2'] = 'Email address
The admin already exists or is not valid'; -$PALANG['pAdminCreate_admin_password'] = 'Password'; +$PALANG['pAdminCreate_admin_username'] = 'Admin (email address)'; +$PALANG['pAdminCreate_admin_username_error'] = 'Admin already exists or is not valid.'; +$PALANG['pAdminCreate_admin_password1'] = 'Password'; $PALANG['pAdminCreate_admin_password2'] = 'Password (again)'; -$PALANG['pAdminCreate_admin_password_text_error'] = 'The passwords that you supplied don\'t match, or are empty.'; +$PALANG['pAdminCreate_admin_password_error'] = 'The passwords you supplied don\'t match, or are empty.'; +$PALANG['pAdminCreate_admin_domain_error'] = 'No domains selected.'; $PALANG['pAdminCreate_admin_button'] = 'Add Admin'; $PALANG['pAdminCreate_admin_result_error'] = 'Unable to add admin.'; $PALANG['pAdminCreate_admin_result_succes'] = 'Admin has been added.'; blob - 412495dc5381afaa6b006b9a7a3c692ba6532ed2 blob + 87e30838630b78c0f2bf69812d2070b44a4be7b4 --- login.php +++ login.php @@ -9,12 +9,12 @@ // // Template File: login.tpl // -// Template Variables: +// Template variables: // // tMessage // tUsername // -// Form POST \ GET Variables: +// GET / POST variables: // // fUsername // fPassword blob - 16df579ccc8af9e7ba0b6fb1ce4e8cd82314275f blob + a40318394ac407ade924f5a853f29beaffe5f577 --- overview.php +++ overview.php @@ -23,120 +23,14 @@ // fDomain // limit // -require("./variables.inc.php"); -require("./config.inc.php"); -require("./functions.inc.php"); -include("./languages/" . check_language() . ".lang"); +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_for_admin($SESSID_USERNAME); +$list_domains = list_domains($SESSID_USERNAME); -$tAlias = array(); -$tMailbox = array(); - -if ($_SERVER['REQUEST_METHOD'] == "GET") { - $fDisplay = 0; - $page_size = $CONF['page_size']; - - if (isset($_GET['domain'])) $fDomain = escape_string($_GET['domain']); - if (isset($_GET['limit'])) $fDisplay = escape_string($_GET['limit']); - - if (check_owner($SESSID_USERNAME, $fDomain)) { - $limit = get_domain_properties($fDomain); - - if ($CONF['alias_control'] == "YES") { - $query = "SELECT alias.address,alias.goto,alias.modified FROM alias WHERE alias.domain='$fDomain' ORDER BY alias.address LIMIT $fDisplay, $page_size"; - } else { - $query = "SELECT alias.address,alias.goto,alias.modified FROM alias LEFT JOIN mailbox ON alias.address=mailbox.username WHERE alias.domain='$fDomain' AND mailbox.maildir IS NULL ORDER BY alias.address LIMIT $fDisplay, $page_size"; - } - - $result = db_query("$query"); - if ($result['rows'] > 0) { - while ($row = db_array($result['result'])) { - $tAlias[] = $row; - } - } - - $result = db_query("SELECT * FROM mailbox WHERE domain='$fDomain' ORDER BY username LIMIT $fDisplay, $page_size"); - if ($result['rows'] > 0) { - while ($row = db_array($result['result'])) { - $tMailbox[] = $row; - } - } - $template = "overview.tpl"; - } else { - $template = "overview-get.tpl"; - } - - $tDomain = $fDomain; - - if (isset($limit)) { - if ($fDisplay >= $page_size) { - $tDisplay_back_show = 1; - $tDisplay_back = $fDisplay - $page_size; - } - if (($limit['alias_count'] > $page_size) or ($limit['mailbox_count'] > $page_size)) { - $tDisplay_up_show = 1; - } - if ((($fDisplay + $page_size) < $limit['alias_count']) or (($fDisplay + $page_size) < $limit['mailbox_count'])) { - $tDisplay_next_show = 1; - $tDisplay_next = $fDisplay + $page_size; - } - } - include("./templates/header.tpl"); - include("./templates/menu.tpl"); - include("./templates/$template"); - include("./templates/footer.tpl"); -} - -if ($_SERVER['REQUEST_METHOD'] == "POST") { - $fDisplay = 0; - $page_size = $CONF['page_size']; - - if (isset($_POST['limit'])) $fDisplay = escape_string($_POST['limit']); - - if (check_owner($SESSID_USERNAME, escape_string($_POST['fDomain']))) { - $fDomain = escape_string($_POST['fDomain']); - - $limit = get_domain_properties($fDomain); - - if ($CONF['alias_control'] == "YES") { - $query = "SELECT alias.address,alias.goto,alias.modified FROM alias WHERE alias.domain='$fDomain' ORDER BY alias.address LIMIT $fDisplay, $page_size"; - } else { - $query = "SELECT alias.address,alias.goto,alias.modified FROM alias LEFT JOIN mailbox ON alias.address=mailbox.username WHERE alias.domain='$fDomain' AND mailbox.maildir IS NULL ORDER BY alias.address LIMIT $fDisplay, $page_size"; - } - - $result = db_query("$query"); - if ($result['rows'] > 0) { - while ($row = db_array($result['result'])) { - $tAlias[] = $row; - } - } - - $result = db_query("SELECT * FROM mailbox WHERE domain='$fDomain' ORDER BY username LIMIT $fDisplay, $page_size"); - if ($result['rows'] > 0) { - while ($row = db_array($result['result'])) { - $tMailbox[] = $row; - } - } - } - - if (isset($limit)) { - if ($fDisplay >= $page_size) { - $tDisplay_back_show = 1; - $tDisplay_back = $fDisplay - $page_size; - } - if (($limit['alias_count'] > $page_size) or ($limit['mailbox_count'] > $page_size)) { - $tDisplay_up_show = 1; - } - if ((($fDisplay + $page_size) < $limit['alias_count']) or (($fDisplay + $page_size) < $limit['mailbox_count'])) { - $tDisplay_next_show = 1; - $tDisplay_next = $fDisplay + $page_size; - } - } - include("./templates/header.tpl"); - include("./templates/menu.tpl"); - include("./templates/overview.tpl"); - include("./templates/footer.tpl"); -} +include './templates/list-domains.tpl'; +include './templates/footer.tpl'; ?> blob - 1cc1dc76516ee95fc41149306e19ca66193cb8b6 blob + 5b6c8099f4783ec61bc522ed31c16682805d6ae7 --- setup.php +++ setup.php @@ -31,7 +31,6 @@ $html .= (version_compare(PHP_VERSION, '7.4.0') >= 0) $html .= ''; $html .= 'SQL support:'; $html .= (extension_loaded('mysqli')) ? 'MySQL/MariaDB' : 'MySQL/MariaDB'; -$html .= (extension_loaded('pgsql')) ? ' - PostgreSQL (change the database_type if you want to use PostgreSQL)' : ' - PostgreSQL'; $html .= ''; $html .= 'Functions:'; $html .= (extension_loaded('pcre')) ? 'pcre' : 'pcre'; blob - 779666dd033ecc149584a759fa59de1a120da0d9 blob + 0b35034feab122a422b5736429b276b18b0177ab --- stylesheet.css +++ stylesheet.css @@ -49,7 +49,7 @@ a:visited, a:active { } #login_header { - width: 800px; + width: 1024px; margin: 0 auto; padding-bottom: 10px; text-align: left; @@ -74,7 +74,7 @@ a:visited, a:active { } #menu { - width: 800px; + width: 1024px; margin: 0 auto; padding-top: 10px; } @@ -102,7 +102,7 @@ a:visited, a:active { #main_menu, #edit_form { - width: 800px; + width: 960px; margin: 0 auto; } @@ -164,7 +164,7 @@ a:visited, a:active { } #overview, #admin_domains, #admin_virtual { - width: 800px; + width: 1024px; margin: 0 auto; background: #AFE1A6; /*#9ACD32;*/ border: 1px solid #bbb; @@ -178,12 +178,12 @@ a:visited, a:active { #nav_bar { text-align: right; - width: 800px; + width: 1024px; margin: 0 auto; } #alias_table, #mailbox_table, #overview_table, #log_table, #admin_table { - width: 800px; + width: 1024px; margin: 0px auto; border: 1px solid #efefef; } @@ -213,7 +213,7 @@ a:visited, a:active { } #footer { - width: 800px; + width: 1024px; margin: 20px auto; border-top: 1px solid #bbbbbb; background: #efefef; blob - 3bdc8e206e7fa7c7f9900ebaf710bb26c8e15793 blob + 25b8a7c6ceca391b97aa285b34ab3119e84967eb --- templates/admin_create-admin.tpl +++ templates/admin_create-admin.tpl @@ -2,45 +2,39 @@

- + - - - + + - - - + + - - - + + - + - - + - +

 
- " . $list_domains[$i] . "\n"; - } else { - print "\n"; - } + foreach ($list_domains as $row) { + echo '\n"; } ?>  
blob - /dev/null blob + 25b8a7c6ceca391b97aa285b34ab3119e84967eb (mode 644) --- /dev/null +++ templates/admin_add-admin.tpl @@ -0,0 +1,41 @@ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + +

+ +
+
+
blob - 9e0efb87e4410a01eec2a1123ce75979f93a2d77 blob + 19e89e69be451daa5f5d2ad1cc3667ae646b4a52 --- templates/admin_create-domain.tpl +++ templates/admin_create-domain.tpl @@ -2,61 +2,34 @@
- + - - - + + + - - + + - - - + + + - - - + + + - - - - + - - - - + - - - - - - - - - - - - - - - - -

 
- /> -
- /> -  
blob - 8c640173b4ef1eb60b2d847ecc2da1a39480b332 blob + 14c636b6e381dcc108acadc5bd916153c81e3815 --- templates/admin_edit-domain.tpl +++ templates/admin_edit-domain.tpl @@ -11,49 +11,24 @@ - +   - + - + - - - - - - - - - - - - - - - - /> -   - - - - - /> -   - - - + blob - 9d031a2aca1d65b42edeeceab5837987d5e15177 blob + c713c518267d5e988bf67a9f390484477cf67363 --- templates/admin_list-admin.tpl +++ templates/admin_list-admin.tpl @@ -1,31 +1,27 @@ 0) { - if (is_array($list_admins) && $list_admins_count > 0) { - print "\n"; - print " \n"; - print " \n"; - print " \n"; - print " \n"; - print " \n"; - print " \n"; - print " \n"; + echo "
" . $PALANG['pAdminList_admin_username'] . "" . $PALANG['pAdminList_admin_count'] . "" . $PALANG['pAdminList_admin_modified'] . "" . $PALANG['pAdminList_admin_active'] . " 
\n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; - for ($i = 0; $i < $list_admins_count; $i++) { - if ((is_array($list_admins) and $list_admins_count > 0)) { - print " \n"; - print " "; - print " "; - print " "; - $active = ($admin_properties[$i]['active'] == 1) ? $PALANG['YES'] : $PALANG['NO']; - print " "; - print " "; - print " "; - print " \n"; - } - } - print "
" . $PALANG['pAdminList_admin_username'] . "" . $PALANG['pAdminList_admin_count'] . "" . $PALANG['pAdminList_admin_modified'] . "" . $PALANG['pAdminList_admin_active'] . " 
" . $list_admins[$i] . "" . $admin_properties[$i]['domain_count'] . "" . $admin_properties[$i]['modified'] . "" . $active . "" . $PALANG['edit'] . "" . $PALANG['del'] . "
\n"; + foreach ($list_admins as $row) { + + echo " \n"; + echo " " . $row['username'] . ""; + echo " " . $row['domain_count'] . ""; + echo " " . $row['modified'] . ""; + $active = ($row['active'] == 1) ? $PALANG['YES'] : $PALANG['NO']; + echo " " . $active . ""; + echo " " . $PALANG['edit'] . ""; + echo " " . $PALANG['del'] . ""; + echo " \n"; } + echo "\n"; } ?> blob - a19af99a3c05e24856837dd3177db8a7eb1446c7 blob + 18a57a0b4555a6f2028021ce94093f405e4abad3 --- templates/admin_list-domain.tpl +++ templates/admin_list-domain.tpl @@ -1,61 +1,46 @@
-
- " . $list_admins[$i] . "\n"; - } else { - print "\n"; - } +if (count($list_admins) > 0) { + foreach ($list_admins as $row) { + echo '\n"; } } ?> - +
- +
- 0) { - print "\n"; - print " \n"; - print " \n"; - print " \n"; - print " \n"; - print " \n"; - if ($CONF['quota'] == 'YES') print " \n"; - if ($CONF['transport'] == 'YES') print " \n"; - print " \n"; - print " \n"; - print " \n"; - print " \n"; - print " \n"; - - for ($i = 0; $i < count($list_domains); $i++) { - if ((is_array($list_domains) and count($list_domains) > 0)) { - print " \n"; - print ""; - print ""; - print ""; - print ""; - if ($CONF['quota'] == 'YES') print ""; - if ($CONF['transport'] == 'YES') print ""; - $backupmx = ($domain_properties[$i]['backupmx'] == 1) ? $PALANG['YES'] : $PALANG['NO']; - print ""; - print ""; - $active = ($domain_properties[$i]['active'] == 1) ? $PALANG['YES'] : $PALANG['NO']; - print ""; - print ""; - print ""; - print "\n"; - } + echo "
" . $PALANG['pAdminList_domain_domain'] . "" . $PALANG['pAdminList_domain_description'] . "" . $PALANG['pAdminList_domain_aliases'] . "" . $PALANG['pAdminList_domain_mailboxes'] . "" . $PALANG['pAdminList_domain_maxquota'] . "" . $PALANG['pAdminList_domain_transport'] . "" . $PALANG['pAdminList_domain_backupmx'] . "" . $PALANG['pAdminList_domain_modified'] . "" . $PALANG['pAdminList_domain_active'] . " 
" . $list_domains[$i] . "" . $domain_properties[$i]['description'] . "" . $domain_properties[$i]['alias_count'] . " / " . $domain_properties[$i]['aliases'] . "" . $domain_properties[$i]['mailbox_count'] . " / " . $domain_properties[$i]['mailboxes'] . "" . $domain_properties[$i]['maxquota'] . "" . $domain_properties[$i]['transport'] . "$backupmx" . $domain_properties[$i]['modified'] . "" . $active . "" . $PALANG['edit'] . "" . $PALANG['del'] . "
\n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + foreach ($list_domains as $row) { + echo " \n"; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + $active = ($row['active'] == 1) ? $PALANG['YES'] : $PALANG['NO']; + echo ""; + echo ""; + echo "\n"; } - print "
" . $PALANG['pAdminList_domain_domain'] . "" . $PALANG['pAdminList_domain_description'] . "" . $PALANG['pAdminList_domain_aliases'] . "" . $PALANG['pAdminList_domain_mailboxes'] . "" . $PALANG['pAdminList_domain_modified'] . " 
" . $row['domain'] . "" . $row['description'] . "" . $row['alias_count'] . " / " . $row['aliases'] . "" . $row['mailbox_count'] . " / " . $row['mailboxes'] . "" . $row['modified'] . "" . $PALANG['edit'] . "" . $PALANG['del'] . "
\n"; + echo "\n"; } ?> blob - a2c391c1df0c2358ef87a177ba02c6080b6c6407 blob + 3e35140fb3fa2a2080eabdb53145424929998b04 --- templates/admin_list-virtual.tpl +++ templates/admin_list-virtual.tpl @@ -1,12 +1,12 @@
-
- $list_domains[$i]\n"; - } else { - print "\n"; +if (count($list_domains) > 0) { + foreach ($list_domains as $row) { + echo '\n"; } } ?> @@ -14,28 +14,34 @@ for ($i = 0; $i < count($list_domains); $i++) {
-

-

-

+ +

+

+

+
- +
\n"; -if ($tDisplay_back_show == 1) { - print "\""\n"; -} -if ($tDisplay_up_show == 1) { - print "\""\n"; +if ($list_domains[$selected_domain]['alias_count'] > $limit || $list_domains[$selected_domain]['mailbox_count'] > $limit) { + echo "
\n"; + if ($offset >= $limit) { + + echo "\n"; + } + if (($list_domains[$selected_domain]['alias_count'] > $limit) || ($list_domains[$selected_domain]['mailbox_count'] > $limit)) { + + echo "\n"; + } + if ((($offset + $limit) < $list_domains[$selected_domain]['alias_count']) || (($offset + $limit) < $list_domains[$selected_domain]['mailbox_count'])) { + echo "\n"; + } + echo "
\n"; } -if ($tDisplay_next_show == 1) { - print "\""\n"; -} -print "\n"; -if (count($tAlias) > 0) { +if (count($list_alias) > 0) { print "\n"; print " \n"; print " "; @@ -47,21 +53,19 @@ if (count($tAlias) > 0) { print " \n"; print " \n"; - for ($i = 0; $i < count($tAlias); $i++) { - if ((is_array($tAlias) and count($tAlias) > 0)) { + foreach ($list_alias as $row) { print " \n"; - print " \n"; - print " \n"; - print " \n"; - print " \n"; - print " \n"; + print " \n"; + print " \n"; + print " \n"; + print " \n"; + print " \n"; print " \n"; - } } print "

" . $PALANG['pOverview_alias_title'] . "

 
" . $tAlias[$i]['address'] . "" . preg_replace("/,/", "
", $tAlias[$i]['goto']) . "
" . $tAlias[$i]['modified'] . "" . $PALANG['edit'] . "" . $PALANG['del'] . "" . $row['address'] . "" . preg_replace("/,/", "
", $row['goto']) . "
" . $row['modified'] . "" . $PALANG['edit'] . "" . $PALANG['del'] . "
\n"; } -if (count($tMailbox) > 0) { +if (count($list_mailbox) > 0) { print "\n"; print " \n"; print " "; @@ -75,19 +79,16 @@ if (count($tMailbox) > 0) { print " \n"; print " \n"; - for ($i = 0; $i < count($tMailbox); $i++) { - if ((is_array($tMailbox) and count($tMailbox) > 0)) { + foreach ($list_mailbox as $row) { print " \n"; - print " \n"; - print " \n"; - if ($CONF['quota'] == 'YES') print " \n"; - print " \n"; - $active = ($tMailbox[$i]['active'] == 1) ? $PALANG['YES'] : $PALANG['NO']; - print " \n"; - print " \n"; - print " \n"; + print " \n"; + print " \n"; + print " \n"; + $active = ($row['active'] == 1) ? $PALANG['YES'] : $PALANG['NO']; + print " \n"; + print " \n"; + print " \n"; print " \n"; - } } print "

" . $PALANG['pOverview_mailbox_title'] . "

 
" . $tMailbox[$i]['username'] . "" . $tMailbox[$i]['name'] . "" . $tMailbox[$i]['quota'] / $CONF['quota_multiplier'] . "" . $tMailbox[$i]['modified'] . "" . $active . "" . $PALANG['edit'] . "" . $PALANG['del'] . "" . $row['username'] . "" . $row['name'] . "" . $row['modified'] . "" . $active . "" . $PALANG['edit'] . "" . $PALANG['del'] . "
\n"; } blob - 9437ae62732372dd406441030766a276aeae1678 blob + 54f7e3d94bd940e1f09d6868a257a4d80f47f0ef --- templates/admin_menu.tpl +++ templates/admin_menu.tpl @@ -1,22 +1,13 @@ -\n"; - include("../motd-admin.txt"); - print ""; -} -?> blob - 384b8b2f191de0fbca2fcd72b4a9f069b442a999 blob + c8ca0b248b7181b22151e86ad5eb04de535b6005 --- templates/create-alias.tpl +++ templates/create-alias.tpl @@ -2,39 +2,34 @@
- + - - + + - - - + + + - + - + - - -

- $list_domains[$i]\n"; - } else { - print "\n"; - } - } + + foreach ($list_domains as $row) { + echo '\n"; + } ?> -
blob - 47328c811a27fd4fd8dc93decb8445763c1b16d0 blob + 1e2d5f25331c32ee1b488077fc9632ea076e8e2c --- templates/footer.tpl +++ templates/footer.tpl @@ -1,5 +1,5 @@ +/div> blob - a38efffcbeb15d611687dd1a5b114b6cef093844 blob + 7b49e1a86794d0751396d6da00ee4c3cf3533e06 --- templates/menu.tpl +++ templates/menu.tpl @@ -1,10 +1,8 @@
\n"; +if ($list_domains[$selected_domain]['alias_count'] > $limit || $list_domains[$selected_domain]['mailbox_count'] > $limit) { + echo "
\n"; + if ($offset >= $limit) { -if (count($tAlias) > 0) { - print "\n"; - print " \n"; - print " "; - print " "; - print " \n"; - print " \n"; - print " \n"; - print " \n"; - print " \n"; - print " \n"; + echo "\n"; + } + if (($list_domains[$selected_domain]['alias_count'] > $limit) || ($list_domains[$selected_domain]['mailbox_count'] > $limit)) { - for ($i = 0; $i < count($tAlias); $i++) { - if ((is_array($tAlias) and count($tAlias) > 0)) { - print " \n"; - print " \n"; - print " \n"; - print " \n"; + echo "\n"; + } + if ((($offset + $limit) < $list_domains[$selected_domain]['alias_count']) || (($offset + $limit) < $list_domains[$selected_domain]['mailbox_count'])) { + echo "\n"; + } + echo "\n"; +} +if (count($list_alias) > 0) { + echo "

".$PALANG['pOverview_alias_title']."

" . $PALANG['pOverview_alias_address'] . "" . $PALANG['pOverview_alias_goto'] . "" . $PALANG['pOverview_alias_modified'] . " 
" . $tAlias[$i]['address'] . "" . preg_replace("/,/", "
", $tAlias[$i]['goto']) . "
" . $tAlias[$i]['modified'] . "
\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') { - print " \n"; - print " \n"; + echo " \n"; + echo " \n"; } else { - if (!in_array($tAlias[$i]['goto'], $CONF['default_aliases'])) { - print " \n"; - print " \n"; + if (!in_array($row['goto'], $CONF['default_aliases'])) { + echo " \n"; + echo " \n"; } else { - print " \n"; - print " \n"; + echo " \n"; + echo " \n"; } } - print " \n"; - } + echo " \n"; } - print "

".$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'] . "" . $PALANG['edit'] . "" . $PALANG['del'] . "" . $PALANG['edit'] . "" . $PALANG['del'] . "    
\n"; + echo "\n"; } -if (count($tMailbox) > 0) { - print "\n"; - print " \n"; - print " "; - print " "; - print " \n"; - print " \n"; - print " \n"; - if ($CONF['quota'] == 'YES') print " \n"; - print " \n"; - print " \n"; - print " \n"; - print " \n"; +if (count($list_mailbox) > 0) { + echo "

".$PALANG['pOverview_mailbox_title']."

" . $PALANG['pOverview_mailbox_username'] . "" . $PALANG['pOverview_mailbox_name'] . "" . $PALANG['pOverview_mailbox_quota'] . "" . $PALANG['pOverview_mailbox_modified'] . "" . $PALANG['pOverview_mailbox_active'] . " 
\n"; + echo " \n"; + echo " "; + echo " "; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; - for ($i = 0; $i < count($tMailbox); $i++) { - if ((is_array($tMailbox) and count($tMailbox) > 0)) { - print " \n"; - print " \n"; - print " \n"; - if ($CONF['quota'] == 'YES') { - print " \n"; - } - print " \n"; - $active = ($tMailbox[$i]['active'] == 1) ? $PALANG['YES'] : $PALANG['NO']; - print " \n"; - print " \n"; - print " \n"; - print " \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"; } - print "

".$PALANG['pOverview_mailbox_title']."

" . $PALANG['pOverview_mailbox_username'] . "" . $PALANG['pOverview_mailbox_name'] . "" . $PALANG['pOverview_mailbox_modified'] . "" . $PALANG['pOverview_mailbox_active'] . " 
" . $tMailbox[$i]['username'] . "" . $tMailbox[$i]['name'] . ""; - if ($tMailbox[$i]['quota'] == 0) { - print $PALANG['pOverview_unlimited']; - } elseif ($tMailbox[$i]['quota'] < 0) { - print $PALANG['pOverview_disabled']; - } else { - print $tMailbox[$i]['quota'] / $CONF['quota_multiplier']; - } - print "" . $tMailbox[$i]['modified'] . "" . $active . "" . $PALANG['edit'] . "" . $PALANG['del'] . "
" . $row['username'] . "" . $row['name'] . "" . $row['modified'] . "" . $active . "" . $PALANG['edit'] . "" . $PALANG['del'] . "
\n"; + echo "\n"; } ?>