This blob has been accessed 361 times via Git panel.
- <?php
- /* modify the values of $db_host, $db_name, $db_user, $db_pass, and $mail_root for basic configuration */
- $db_host = "localhost";
- $db_name = "kartero";
- $db_user = "kartero";
- $db_pass = "fr1ng3!";
- $mail_root = "/var/spool/kartero";
- /* feel free to hack the succeeding code to suit your needs (basic php and mysql skills required) */
- require_once("core.php");
- function rmdirr($recurse_dirname) {
- if (!file_exists($recurse_dirname)) {
- return false;
- }
- if (is_file($recurse_dirname)) {
- return unlink($recurse_dirname);
- }
- $recurse_dir = dir($recurse_dirname);
- while (false !== $recurse_entry = $recurse_dir->read()) {
- if ($recurse_entry == '.' || $recurse_entry == '..') {
- continue;
- }
- rmdirr("$recurse_dirname/$recurse_entry");
- }
- $recurse_dir->close();
- return rmdir($recurse_dirname);
- }
- function ack($ack_string) {
- echo "<table width=\"100%\"><tr></td><div class=\"ack\">$ack_string</div></td></tr></table>";
- }
- function nak($nak_string) {
- echo "<table width=\"100%\"><tr></td><div class=\"nak\">$nak_string</div></td></tr></table>";
- }
- if (file_exists("css.php")) {
- $css = file_get_contents("css.php");
- $css = str_replace("<style>","",$css);
- $css = str_replace("</style>","",$css);
- echo "<style>\r\n$css</style>\r\n\r\n";
- }
- if (!file_exists("$mail_root")) {
- $mail_dirs = explode("/",$mail_root);
- foreach ($mail_dirs as $mail_dir) {
- if (!empty($mail_dir)) {
- $mail_mkdir = $mail_mkdir . "/" . $mail_dir;
- mkdir("$mail_mkdir");
- }
- }
- if (!file_exists("$mail_root")) {
- nak("Can't create '$mail_root' (check filesystem permissions or change '$mail_root' and try again)");
- }
- }
- $db_link = mysql_pconnect($db_host, $db_user, $db_pass);
- if (!$db_link) {
- nak(mysql_error());
- exit;
- }
- $db_query = mysql_query("use $db_name");
- if (!$db_query) {
- $pw_crypt = crypt($db_pass);
- $db_query = mysql_query("create database $db_name");
- $db_query = mysql_query("use $db_name");
- $db_query = mysql_query("create table admins (id varchar(16) not null, pw varchar(64) not null, primary key (id), unique key (id))");
- $db_query = mysql_query("create table domains (id varchar(128) not null, pw varchar(64) not null, max int(6) default '0', mode int(1) default '1', primary key (id), unique key (id), key id_2 (id))");
- $db_query = mysql_query("create table users (id varchar(255) not null, pw varchar(64) not null, maildir varchar(255) not null, name varchar(128), domain varchar(128), mode int(1) default '1', host varchar(255), primary key (id), unique key(id), key id_2 (id))");
- $db_query = mysql_query("create table aliases (id varchar(255) not null, alias varchar(255) not null, domain varchar(128), mode int(1) default '1', primary key (id), unique key (id), key id_2 (id))");
- $db_query = mysql_query("insert into admins values('$db_user','$pw_crypt')");
- }
- $id_put = strip_tags($_POST['id']);
- $id_put = trim($id_put);
- $id_put = strtolower($id_put);
- if (get_magic_quotes_gpc()) {
- $id_put = stripslashes($id_put);
- }
- if (!is_int($id_put)) {
- $id_put = mysql_real_escape_string($id_put);
- }
- $lvl_put = strip_tags($_POST['lvl']);
- if ($lvl_put == "subscriber") {
- $pw_get = mysql_query("select pw from users where id='$id_put'");
- }
- if ($lvl_put == "postmaster") {
- $pw_get = mysql_query("select pw from domains where id='$id_put'");
- }
- if ($lvl_put == "administrator") {
- $pw_get = mysql_query("select pw from admins where id='$id_put'");
- }
- $pw_get = mysql_fetch_row($pw_get);
- $pw_get = $pw_get[0];
- $pw_put = $_POST['pw'];
- if (get_magic_quotes_gpc()) {
- $pw_put = stripslashes($pw_put);
- }
- if (!is_int($pw_put)) {
- $pw_put = mysql_real_escape_string($pw_put);
- }
- $pw_put = strip_tags($pw_put);
- $pw_mbox = $pw_put;
- $pw_put = crypt($pw_put,$pw_get);
- if ($pw_put == $pw_get) {
- $_SESSION['logged_uid'] = $id_put;
- $_SESSION['logged_lvl'] = $lvl_put;
- if ($_SESSION['logged_lvl'] == "subscriber") {
- $_SESSION['logged_key'] = $pw_mbox;
- }
- }
- unset($pw_mbox);
- if ($_SESSION['logged_lvl'] == "subscriber") {
- if (isset($_SESSION['clean_up_i']) and file_exists("attach/i/$fileUsr/{$_SESSION['clean_up_i']}") and (!isset($_POST['filedrop_box']) or empty($_POST['filedrop_box']))) {
- rmdirr("attach/i/$fileUsr/{$_SESSION['clean_up_i']}");
- unset($_SESSION['clean_up_i']);
- if (count(glob("attach/i/$fileUsr/*")) == 0) {
- rmdirr("attach/i/$fileUsr");
- }
- }
- if (isset($_SESSION['clean_up_o']) and file_exists("attach/o/$fileUsr/{$_SESSION['clean_up_o']}")) {
- rmdirr("attach/o/$fileUsr/{$_SESSION['clean_up_o']}");
- unset($_SESSION['clean_up_o']);
- if (count(glob("attach/o/$fileUsr/*")) == 0) {
- rmdirr("attach/o/$fileUsr");
- }
- }
- }
- if (isset($_GET['do']) and ($_GET['do'] == "logout")) {
- $_SESSION = array();
- session_destroy();
- header("Location: .");
- exit;
- }
- /* logo here? */
- if (!isset($_SESSION['logged_uid']) and (($pw_put != $pw_get) or !isset($_POST['id']) or !isset($_POST['pw']) or empty($_POST['id']) or empty($_POST['pw']))) {
- echo "<title>Kartero</title>";
- echo "<div class=\"login\"><center>";
- echo "<img src=\"images/logo.png\" border=\"0\" width=\"100\" height=\"100\">";
- echo "<br>kartero v1.0 at {$_SERVER['SERVER_NAME']}<br><br>";
- echo "<table border=\"0\" cellspacing=\"1\" cellpadding=\"2\" bgcolor=\"#cccccc\">";
- echo "<form method=\"post\">";
- echo "<tr bgcolor=\"#ffffff\"><td><select class=\"input\" name=\"lvl\"><option value=\"subscriber\">subscriber</option><option value=\"postmaster\">postmaster</option><option value=\"administrator\">administrator</option></select></td></tr>";
- echo "<tr bgcolor=\"#ffffff\"><td><input required autofocus class=\"input\" type=\"text\" name=\"id\" autocomplete=\"off\" maxlength=\"128\"></td></tr>";
- echo "<tr bgcolor=\"#ffffff\"><td><input required class=\"input\" type=\"password\" name=\"pw\" autocomplete=\"off\" maxlength=\"64\"></td></tr>";
- echo "<tr bgcolor=\"#ffffff\"><td><input class=\"button\" type=\"submit\" value=\"login\"></td></tr>";
- echo "</form>";
- echo "</table>";
- echo "</center></div>";
- echo "<iframe name=\"preload\" src=\"preload.php\" frameborder=\"0\" scrolling=\"0\" width=\"0\" height=\"0\"></iframe>";
- exit;
- }
- if (isset($_SESSION['logged_uid'])) {
- //echo "<center>";
- echo "<nobr>You are currently logged in to your {$_SESSION['logged_uid']} {$_SESSION['logged_lvl']} account. Click <a href=\"?do=logout\">here</a> to logout.</nobr><br><br>";
- echo "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
- echo "<tr><td colspan=\"3\" valign=\"top\">";
- if ($_SESSION['logged_lvl'] == "subscriber") {
- $usr_query = mysql_query("select * from users where id='{$_SESSION['logged_uid']}'");
- $usr_data = mysql_fetch_row($usr_query);
- $dom_query = mysql_query("select mode from domains where id='{$usr_data[4]}'");
- $dom_data = mysql_fetch_row($dom_query);
- if ($dom_data[0] == 0) {
- nak("{$usr_data[4]} disabled by admin - new settings will take effect once it is re-enabled");
- }
- if ($usr_data[5] == 0) {
- nak("{$_SESSION['logged_uid']} disabled by postmaster - new settings will take effect once it is re-enabled");
- }
- $usr_name = $usr_data[3];
- if (isset($_POST['usr_name']) and !empty($_POST['usr_name'])) {
- $usr_name = trim($_POST['usr_name']);
- $usr_name = ucwords($usr_name);
- if ($usr_name != $usr_data[3]) {
- $usr_query = mysql_query("update users set name='$usr_name' where id='{$_SESSION['logged_uid']}'");
- if (!usr_query) {
- nak(strtolower(mysql_error()));
- }
- else {
- ack("name changed");
- }
- }
- else {
- $usr_name = $usr_data[3];
- }
- }
- $usr_pw0 = $usr_data[1];
- if (isset($_POST['usr_pw1']) and !empty($_POST['usr_pw1']) and isset($_POST['usr_pw2']) and !empty($_POST['usr_pw2']) and isset($_POST['usr_pw3']) and !empty($_POST['usr_pw3'])) {
- $usr_pw1 = trim($_POST['usr_pw1']);
- $usr_pw2 = trim($_POST['usr_pw2']);
- $usr_pw3 = trim($_POST['usr_pw3']);
- if ($usr_pw0 == crypt($usr_pw1,$usr_pw0)) {
- if ($usr_pw2 == $usr_pw3) {
- $usr_pw = crypt($usr_pw2);
- $usr_query = mysql_query("update users set pw='$usr_pw' where id='{$_SESSION['logged_uid']}'");
- if (!usr_query) {
- nak(strtolower(mysql_error()));
- }
- else {
- ack("password changed");
- }
- }
- else {
- nak("new passwords do not match");
- }
- }
- else {
- nak("current password entered is incorrect");
- }
- }
- }
- if ($_SESSION['logged_lvl'] == "postmaster") {
- $dom_query = mysql_query("select mode from domains where id='{$_SESSION['logged_uid']}'");
- $dom_query = mysql_fetch_row($dom_query);
- if ($dom_query[0] == "0") {
- nak("{$_SESSION['logged_uid']} disabled by admin - new settings will take effect once it is re-enabled");
- }
- $max_get = mysql_query("select max from domains where id='{$_SESSION['logged_uid']}'");
- $pm_max = mysql_fetch_row($max_get);
- $pm_get = mysql_query("select * from users where domain='{$_SESSION['logged_uid']}' order by id");
- $pm_now = mysql_num_rows($pm_get);
- if (isset($_POST['pm_id']) and isset($_POST['pm_name']) and isset($_POST['pm_pw']) and !empty($_POST['pm_id']) and !empty($_POST['pm_name']) and !empty($_POST['pm_pw'])) {
- if (($pm_now >= $pm_max[0]) and ($pm_max[0] != 0)) {
- nak("{$_SESSION['logged_uid']} limit exceeded");
- }
- else {
- $pm_id = trim($_POST['pm_id']);
- $pm_id = strtolower($pm_id);
- if (preg_match("/@/",$pm_id)) {
- $pm_id = substr($pm_id,0,strpos($pm_id,"@"));
- }
- $pm_addr = $pm_id . "@" . $_SESSION['logged_uid'];
- $alias_query = mysql_query("select id from aliases where id='$pm_addr'");
- if (mysql_fetch_row($alias_query) > 0) {
- nak("$pm_addr alias exists");
- }
- else {
- $pm_name = trim($_POST['pm_name']);
- $pm_name = ucwords($pm_name);
- $pm_pw = trim($_POST['pm_pw']);
- $pm_pw = crypt($pm_pw);
- $pm_init = substr($pm_id,0,1);
- $pm_maildir = "{$_SESSION['logged_uid']}/$pm_init/$pm_id";
- $pm_host = trim($_POST['pm_host']);
- $pm_host = strtolower($pm_host);
- $pm_query = mysql_query("insert into users values('$pm_addr','$pm_pw','$pm_maildir/','$pm_name','{$_SESSION['logged_uid']}','1','$pm_host')");
- if (!$pm_query) {
- nak(strtolower(mysql_error()));
- }
- else {
- if (!file_exists("$mail_root/{$_SESSION['logged_uid']}")) {
- mkdir("$mail_root/{$_SESSION['logged_uid']}");
- }
- if (!file_exists("$mail_root/{$_SESSION['logged_uid']}/$pm_init")) {
- mkdir("$mail_root/{$_SESSION['logged_uid']}/$pm_init");
- }
- if (!file_exists("$mail_root/$pm_maildir")) {
- mkdir("$mail_root/$pm_maildir");
- }
- if (!file_exists("$mail_root/$pm_maildir/cur")) {
- mkdir("$mail_root/$pm_maildir/cur");
- }
- if (!file_exists("$mail_root/$pm_maildir/new")) {
- mkdir("$mail_root/$pm_maildir/new");
- }
- if (!file_exists("$mail_root/$pm_maildir/tmp")) {
- mkdir("$mail_root/$pm_maildir/tmp");
- }
- ack("$pm_addr added");
- }
- }
- }
- }
- if (isset($_POST['pm_mod']) and !empty($_POST['pm_mod'])) {
- $pm_mod = trim($_POST['pm_mod']);
- if (isset($_POST['pm_name']) and !empty($_POST['pm_name'])) {
- $pm_name = trim($_POST['pm_name']);
- $pm_name = ucwords($pm_name);
- $pm_query = mysql_query("select name from users where id='$pm_mod'");
- $name_get = mysql_fetch_row($pm_query);
- if ($name_get[0] != $pm_name) {
- $pm_query = mysql_query("update users set name='$pm_name' where id='$pm_mod'");
- if (!$pm_query) {
- nak(strtolower(mysql_error()));
- }
- else {
- ack("$pm_mod complete name updated");
- }
- }
- }
- if (isset($_POST['pm_pass']) and !empty($_POST['pm_pass'])) {
- $pm_pass = $_POST['pm_pass'];
- $pm_pass = crypt($pm_pass);
- $pm_query = mysql_query("update users set pw='$pm_pass' where id='$pm_mod'");
- if (!$pm_query) {
- nak(strtolower(mysql_error()));
- }
- else {
- ack("$pm_mod password updated");
- }
- }
- if (isset($_POST['pm_host'])) {
- $pm_host = trim($_POST['pm_host']);
- $pm_host = strtolower($pm_host);
- $pm_query = mysql_query("select host from users where id='$pm_mod'");
- $host_get = mysql_fetch_row($pm_query);
- if ($host_get[0] != $pm_host) {
- $pm_query = mysql_query("update users set host='$pm_host' where id='$pm_mod'");
- if (!$pm_query) {
- nak(strtolower(mysql_error()));
- }
- else {
- ack("$pm_mod delivery host updated");
- }
- }
- }
- }
- if (isset($_POST['pm_set']) and !empty($_POST['pm_set']) and isset($_POST['pm_do']) and !empty($_POST['pm_do'])) {
- $pm_set = trim($_POST['pm_set']);
- $pm_do = trim($_POST['pm_do']);
- if ($pm_do == "disable") {
- $pm_do = "0";
- }
- if ($pm_do == "enable") {
- $pm_do = "1";
- }
- $pm_query = mysql_query("update aliases set mode='$pm_do' where alias='$pm_set'");
- $pm_query = mysql_query("update users set mode='$pm_do' where id='$pm_set'");
- if (!$pm_query) {
- nak(strtolower(mysql_error()));
- }
- else {
- $pm_query = mysql_query("select alias from aliases where alias='$pm_set'");
- $pm_aka = mysql_num_rows($pm_query);
- if ($pm_do == "0") {
- if ($pm_aka > 0) {
- if ($pm_aka < 2) {
- ack("$pm_set account and 1 alias disabled");
- }
- else {
- ack("$pm_set account and $pm_aka aliases disabled");
- }
- }
- else {
- ack("$pm_set account disabled");
- }
- }
- if ($pm_do == "1") {
- if (mysql_fetch_row($pm_query) > 0) {
- if ($pm_aka < 2) {
- ack("$pm_set account and 1 alias enabled");
- }
- else {
- ack("$pm_set account and $pm_aka aliases enabled");
- }
- }
- else {
- ack("$pm_set account enabled");
- }
- }
- }
- }
- if (isset($_POST['pm_del']) and !empty($_POST['pm_del'])) {
- $pm_del = trim($_POST['pm_del']);
- $pm_query = mysql_query("delete from aliases where alias='$pm_del'");
- $pm_query = mysql_query("delete from users where id='$pm_del'");
- if (!$pm_query) {
- nak(strtolower(mysql_error()));
- }
- else {
- $pm_init = substr($pm_del,0,1);
- $pm_box = substr($pm_del,0,strpos($pm_del,"@"));
- if (file_exists("$mail_root/{$_SESSION['logged_uid']}/$pm_init/$pm_box")) {
- rmdirr("$mail_root/{$_SESSION['logged_uid']}/$pm_init/$pm_box");
- }
- if (count(glob("$mail_root/{$_SESSION['logged_uid']}/$pm_init/*")) < 1) {
- rmdir("$mail_root/{$_SESSION['logged_uid']}/$pm_init");
- }
- ack("$pm_del deleted");
- }
- }
- if (isset($_POST['alias_add']) and !empty($_POST['alias_add']) and isset($_POST['alias_to']) and !empty($_POST['alias_to'])) {
- $alias_add = trim($_POST['alias_add']);
- if (preg_match("/@/",$alias_add)) {
- $alias_add = substr($alias_add,0,strpos($alias_add,"@"));
- }
- $alias_add = "$alias_add@{$_SESSION['logged_uid']}";
- $alias_to = trim($_POST['alias_to']);
- $alias_query = mysql_query("select id from users where id='$alias_add'");
- if (mysql_num_rows($alias_query) > 0) {
- nak("$alias_add account exists");
- }
- else {
- if (!preg_match("/@/",$alias_to) or preg_match("/@{$_SESSION['logged_uid']}/",$alias_to)) {
- if (preg_match("/@{$_SESSION['logged_uid']}/",$alias_to)) {
- $alias_to = substr($alias_to,0,strpos($alias_to,"@"));
- }
- $alias_to = "$alias_to@{$_SESSION['logged_uid']}";
- $alias_query = mysql_query("select id from users where id='$alias_to'");
- if (mysql_num_rows($alias_query) < 1) {
- nak("$alias_to does not exist");
- }
- else {
- $alias_query = mysql_query("insert into aliases values('$alias_add','$alias_to','{$_SESSION['logged_uid']}','1')");
- if (!$alias_query) {
- nak(strtolower(mysql_error()));
- }
- else {
- ack("$alias_add added");
- }
- }
- }
- else {
- $alias_query = mysql_query("insert into aliases values('$alias_add','$alias_to','{$_SESSION['logged_uid']}','1')");
- if (!$alias_query) {
- nak(strtolower(mysql_error()));
- }
- else {
- ack("$alias_add added");
- }
- }
- }
- }
- if (isset($_POST['alias_mod']) and !empty($_POST['alias_mod']) and isset($_POST['alias_to']) and !empty($_POST['alias_to'])) {
- $alias_mod = trim($_POST['alias_mod']);
- $alias_to = trim($_POST['alias_to']);
- if (!preg_match("/@/",$alias_to) or preg_match("/@{$_SESSION['logged_uid']}/",$alias_to)) {
- if (preg_match("/@{$_SESSION['logged_uid']}/",$alias_to)) {
- $alias_to = substr($alias_to,0,strpos($alias_to,"@"));
- }
- $alias_to = "$alias_to@{$_SESSION['logged_uid']}";
- $alias_query = mysql_query("select id from users where id='$alias_to'");
- if (mysql_num_rows($alias_query) < 1) {
- nak("$alias_to does not exist");
- }
- else {
- $alias_query = mysql_query("update aliases set alias='$alias_to' where id='$alias_mod'");
- if (!$alias_query) {
- nak(strtolower(mysql_error()));
- }
- else {
- ack("$alias_mod updated");
- }
- }
- }
- else {
- $alias_query = mysql_query("update aliases set alias='$alias_to' where id='$alias_mod'");
- if (!$alias_query) {
- nak(strtolower(mysql_error()));
- }
- else {
- ack("$alias_mod updated");
- }
- }
- }
- if (isset($_POST['alias_set']) and !empty($_POST['alias_set']) and isset($_POST['alias_do']) and !empty($_POST['alias_do'])) {
- $alias_set = trim($_POST['alias_set']);
- $alias_do = trim($_POST['alias_do']);
- if ($alias_do == "disable") {
- $alias_do = "0";
- $alias_query = mysql_query("update aliases set mode='$alias_do' where id='$alias_set'");
- if (!$alias_query) {
- nak(strtolower(mysql_error()));
- }
- else {
- ack("$alias_set alias disabled");
- }
- }
- if ($alias_do == "enable") {
- $alias_query = mysql_query("select alias from aliases where id='$alias_set'");
- $alias_recipient = mysql_fetch_row($alias_query);
- $alias_recipient = $alias_recipient[0];
- $usr_query = mysql_query("select mode from users where id='$alias_recipient'");
- $alias_recipient_mode = mysql_fetch_row($usr_query);
- $alias_recipient_mode = $alias_recipient_mode[0];
- if ($alias_recipient_mode == "0") {
- nak("cannot enable $alias_set alias while $alias_recipient recipient account is disabled");
- }
- else {
- $alias_do = "1";
- $alias_query = mysql_query("update aliases set mode='$alias_do' where id='$alias_set'");
- if (!$alias_query) {
- nak(strtolower(mysql_error()));
- }
- else {
- ack("$alias_set alias enabled");
- }
- }
- }
- }
- if (isset($_POST['alias_del']) and !empty($_POST['alias_del'])) {
- $alias_del = trim($_POST['alias_del']);
- $alias_query = mysql_query("delete from aliases where id='$alias_del'");
- if (!$alias_query) {
- nak(strtolower(mysql_error()));
- }
- else {
- ack("$alias_del deleted");
- }
- }
- }
- if ($_SESSION['logged_lvl'] == "administrator") {
- if (isset($_POST['dom_name']) and isset($_POST['dom_pass']) and isset($_POST['dom_max']) and !empty($_POST['dom_name']) and !empty($_POST['dom_pass']) and is_numeric($_POST['dom_max'])) {
- $dom_name = trim($_POST['dom_name']);
- $dom_pass = trim($_POST['dom_pass']);
- $dom_pass = crypt($dom_pass);
- $dom_max = trim($_POST['dom_max']);
- $dom_query = mysql_query("insert into domains values('$dom_name','$dom_pass','$dom_max','1')");
- if (!$dom_query) {
- nak(strtolower(mysql_error()));
- }
- else {
- if (!file_exists("$mail_root/$dom_name")) {
- mkdir("$mail_root/$dom_name");
- }
- ack("$dom_name added");
- }
- }
- if (isset($_POST['dom_mod']) and !empty($_POST['dom_mod'])) {
- $dom_mod = trim($_POST['dom_mod']);
- if (isset($_POST['dom_pass']) and !empty($_POST['dom_pass'])) {
- $dom_pass = $_POST['dom_pass'];
- $dom_pass = crypt($dom_pass);
- $dom_query = mysql_query("update domains set pw='$dom_pass' where id='$dom_mod'");
- if (!$dom_query) {
- nak(strtolower(mysql_error()));
- }
- else {
- ack("$dom_mod postmaster password updated");
- }
- }
- if (isset($_POST['dom_max']) and is_numeric($_POST['dom_max'])) {
- $dom_max = $_POST['dom_max'];
- $dom_query = mysql_query("select max from domains where id='$dom_mod'");
- $max_get = mysql_fetch_row($dom_query);
- if ($max_get[0] != $dom_max) {
- $dom_query = mysql_query("update domains set max='$dom_max' where id='$dom_mod'");
- if (!$dom_query) {
- nak(strtolower(mysql_error()));
- }
- else {
- ack("$dom_mod account limit updated");
- }
- }
- }
- }
- if (isset($_POST['dom_set']) and !empty($_POST['dom_set']) and isset($_POST['dom_do']) and !empty($_POST['dom_do'])) {
- $dom_set = trim($_POST['dom_set']);
- $dom_do = trim($_POST['dom_do']);
- if ($dom_do == "disable") {
- $dom_do = "0";
- }
- if ($dom_do == "enable") {
- $dom_do = "1";
- }
- $dom_query = mysql_query("update domains set mode='$dom_do' where id='$dom_set'");
- if (!$dom_query) {
- nak(strtolower(mysql_error()));
- }
- else {
- if ($dom_do == "0") {
- ack("$dom_set disabled");
- }
- if ($dom_do == "1") {
- ack("$dom_set enabled");
- }
- }
- }
- if (isset($_POST['dom_del']) and !empty($_POST['dom_del'])) {
- $dom_del = trim($_POST['dom_del']);
- $dom_query = mysql_query("delete from aliases where domain='$dom_del'");
- $dom_query = mysql_query("delete from users where domain='$dom_del'");
- $dom_query = mysql_query("delete from domains where id='$dom_del'");
- if (!$dom_query) {
- nak(strtolower(mysql_error()));
- }
- else {
- if (file_exists("$mail_root/$dom_del")) {
- rmdirr("$mail_root/$dom_del");
- }
- ack("$dom_del deleted");
- }
- }
- }
- echo "</td></tr>";
- echo "<tr><td valign=\"top\">";
- if ($_SESSION['logged_lvl'] == "subscriber") {
- $filedrop_box = sha1(microtime(true));
- echo "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
- if (isset($_POST['reply_from']) and isset($_POST['reply_to']) and isset($_POST['reply_subj']) and isset($_POST['reply_body']) and !empty($_POST['reply_from']) and !empty($_POST['reply_to']) and !empty($_POST['reply_subj']) and !empty($_POST['reply_body'])) {
- $reply_from = trim($_POST['reply_from']);
- $reply_to = trim($_POST['reply_to']);
- $reply_subj = trim($_POST['reply_subj']);
- $reply_body = trim($_POST['reply_body']);
- $reply_headers = "From: $reply_from\r\nX-Mailer: Kartero/1.0 (PHP/" . phpversion() . ")";
- if (isset($_POST['reply_cc']) and !empty($_POST['reply_cc'])) {
- $reply_cc = trim($_POST['reply_cc']);
- $reply_headers = "$reply_headers\r\nCc: $reply_cc";
- }
- if (isset($_POST['reply_bcc']) and !empty($_POST['reply_bcc'])) {
- $reply_bcc = trim($_POST['reply_bcc']);
- $reply_headers = "$reply_headers\r\nBcc: $reply_bcc";
- }
- if (isset($_POST['filedrop_box']) and !empty($_POST['filedrop_box'])) {
- $do_filedrop_box = $_POST['filedrop_box'];
- if (file_exists("attach/i/$fileUsr/$do_filedrop_box") and (count(glob("attach/i/$fileUsr/$do_filedrop_box/*")) > 0)) {
- $mime_boundary = md5(microtime(true));
- $reply_headers .= "\r\nMIME-Version: 1.0";
- $reply_headers .= "\r\nContent-Type: multipart/mixed; boundary=\"{$mime_boundary}\"";
- $reply_body = "\r\nThis is a multi-part message in MIME format.\r\n\r\n--{$mime_boundary}\r\nContent-type: text/plain; charset=UTF-8\r\nContent-Transfer-Encoding: 8bit\r\n\r\n{$reply_body}";
- $do_reply_from = extract_emails_from($reply_from);
- $do_reply_to = extract_emails_from($reply_to);
- $do_filedrop_msg = glob("attach/i/$fileUsr/$do_filedrop_box/*");
- sort($do_filedrop_msg);
- reset($do_filedrop_msg);
- foreach ($do_filedrop_msg as $do_filedrop_put) {
- $do_filedrop_nom = str_replace("attach/i/$fileUsr/$do_filedrop_box/","",$do_filedrop_put);
- $reply_body = $reply_body . "\r\n\r\n--{$mime_boundary}\r\nContent-Type: application/octet-stream; name=\"$do_filedrop_nom\"\r\nContent-Disposition: attachment; filename=\"$do_filedrop_nom\"\r\nContent-Transfer-Encoding: base64\r\n\r\n" . chunk_split(base64_encode(file_get_contents($do_filedrop_put)));
- }
- $reply_body = $reply_body . "--{$mime_boundary}--";
- rmdirr("attach/i/$fileUsr/$do_filedrop_box");
- if (count(glob("attach/i/$fileUsr/*")) == 0) {
- rmdirr("attach/i/$fileUsr");
- }
- }
- }
- $host = "{127.0.0.1:143/imap/notls/norsh}";
- if ($_POST['redirect'] == 1) {
- $mbox = @imap_open("{$host}{$_POST['box']}", $_SESSION['logged_uid'], $_SESSION['logged_key']) or die("Connection to server failed");
- $redirect_date = date("D, j M Y H:i:s O (T)");
- $reply_headers = "Resent-Date: $redirect_date\r\nResent-To: $reply_to\r\n";
- if (isset($_POST['reply_cc']) and !empty($_POST['reply_cc'])) {
- $reply_cc = trim($_POST['reply_cc']);
- $reply_headers = $reply_headers . "Resent-Cc: $reply_cc\r\n";
- }
- if (isset($_POST['reply_bcc']) and !empty($_POST['reply_bcc'])) {
- $reply_bcc = trim($_POST['reply_bcc']);
- $reply_headers = $reply_headers . "Resent-Bcc: $reply_bcc\r\n";
- }
- $reply_headers = $reply_headers . imap_fetchheader($mbox,$_POST['msg']);
- $reply_body = imap_body($mbox,$_POST['msg']);
- }
- else {
- $mbox = @imap_open($host, $_SESSION['logged_uid'], $_SESSION['logged_key']) or die("Connection to server failed");
- }
- imap_createmailbox($mbox,"{$host}Sent");
- $reply_date = date ("d-M-Y H:i:s O");
- $reply_body = preg_replace("#(?<!\r)\n#si", "\r\n", $reply_body);
- $reply_headers = preg_replace('#(?<!\r)\n#si', "\r\n", $reply_headers);
- imap_append($mbox,"{$host}Sent","To: $reply_to\r\nSubject: $reply_subj\r\nDate: $reply_date\r\n$reply_headers\r\n\r\n$reply_body\r\n");
- mail($reply_to, $reply_subj, $reply_body, $reply_headers);
- if ($_POST['ack'] == 1) {
- imap_reopen($mbox, "{$host}{$_POST['box']}");
- imap_setflag_full($mbox, $_POST['msg'], '\\Answered');
- }
- imap_close($mbox);
- }
- if (isset($_POST['not']) and !empty($_POST['not']) and is_numeric($_POST['not'])) {
- $host = "{127.0.0.1:143/imap/notls/norsh}";
- $mbox = @imap_open("{$host}{$_POST['box']}", $_SESSION['logged_uid'], $_SESSION['logged_key']) or die("Connection to server failed");
- imap_clearflag_full($mbox, $_POST['msg'], '\\Seen');
- imap_close($mbox, CL_EXPUNGE);
- }
- if (isset($_POST['emt']) and !empty($_POST['emt']) and is_numeric($_POST['emt'])) {
- $host = "{127.0.0.1:143/imap/notls/norsh}";
- $mbox = @imap_open("{$host}{$_POST['box']}", $_SESSION['logged_uid'], $_SESSION['logged_key']) or die("Connection to server failed");
- imap_delete($mbox,'1:*');
- imap_close($mbox, CL_EXPUNGE);
- }
- echo "<tr><td valign=\"top\" width=\"700\"><div id=\"main\" class=\"main\">";
- if (isset($_POST['get']) and !empty($_POST['get'])) {
- include("read.php");
- }
- elseif (isset($_POST['rep']) and !empty($_POST['rep'])) {
- include("send.php");
- }
- elseif (isset($_POST['new']) and !empty($_POST['new'])) {
- include("post.php");
- }
- elseif (isset($_POST['dig']) and !empty($_POST['dig'])) {
- include("search.php");
- }
- else {
- include("inbox.php");
- //echo "<script type=\"text/javascript\" src=\"jquery-1.3.2.min.js\"></script>";
- //echo "<script type=\"text/javascript\"> $(document).ready(function() { setInterval(function() { $('#main').fadeOut(\"fast\").load('inbox.php').fadeIn(\"slow\"); }, 5000); }); </script>";
- }
- echo "</div></td>";
- echo "<td width=\"10\"></td>";
- echo "<td valign=\"top\" width=\"100\">";
- include("folders.php");
- echo "</td>";
- /*
- echo "<td valign=\"top\" width=\"100\">";
- echo "<table border=\"0\" cellspacing=\"1\" cellpadding=\"1\">";
- echo "<form method=\"post\">";
- echo "<tr bgcolor=\"#ffffff\"><td align=\"center\" valign=\"middle\"><img src=\"images/preferences-desktop-personal.png\" border=\"0\" width=\"22\" height=\"22\"></td><td><input class=\"input\" type=\"text\" name=\"usr_name\" value=\"$usr_name\" autocomplete=\"off\" maxlength=\"128\"></td></tr>";
- echo "<tr bgcolor=\"#ffffff\"><td align=\"center\" valign=\"middle\"><img src=\"images/flag-red.png\" border=\"0\" width=\"22\" height=\"22\"></td><td><input class=\"input\" type=\"password\" name=\"usr_pw1\" autocomplete=\"off\" maxlength=\"64\"></td></tr>";
- echo "<tr bgcolor=\"#ffffff\"><td align=\"center\" valign=\"middle\"><img src=\"images/flag-green.png\" border=\"0\" width=\"22\" height=\"22\"></td><td><input class=\"input\" type=\"password\" name=\"usr_pw2\" autocomplete=\"off\" maxlength=\"64\"></td></tr>";
- echo "<tr bgcolor=\"#ffffff\"><td align=\"center\" valign=\"middle\"><img src=\"images/flag-green.png\" border=\"0\" width=\"22\" height=\"22\"></td><td><input class=\"input\" type=\"password\" name=\"usr_pw3\" autocomplete=\"off\" maxlength=\"64\"></td></tr>";
- echo "<tr bgcolor=\"#ffffff\"><td align=\"center\" valign=\"middle\"></td><td><input class=\"button\" type=\"submit\" value=\"update\"></td></tr>";
- echo "</form></table>";
- echo "</td>";
- */
- echo "</tr></table>";
- }
- if ($_SESSION['logged_lvl'] == "postmaster") {
- echo "<table border=\"0\" cellspacing=\"1\" cellpadding=\"2\" bgcolor=\"#cccccc\">";
- echo "<tr bgcolor=\"#eeeeee\"><td colspan=\"4\" align=\"center\">status</td><td align=\"center\">username</td><td align=\"center\">complete name</td><td align=\"center\">password</td><td align=\"center\">host</td><td align=\"center\" colspan=\"2\">action</td></tr>";
- echo "<form method=\"post\">";
- echo "<tr bgcolor=\"#ffffff\"><td align=\"center\">new</td><td align=\"center\">cur</td><td align=\"center\">aka</td><td align=\"center\">rcv</td><td><input class=\"input\" type=\"text\" name=\"pm_id\" autocomplete=\"off\" maxlength=\"255\"></td><td><input class=\"input\" type=\"text\" name=\"pm_name\" autocomplete=\"off\" maxlength=\"128\"></td><td><input class=\"input\" type=\"text\" name=\"pm_pw\" autocomplete=\"off\" maxlength=\"64\"></td><td><input class=\"input\" type=\"text\" name=\"pm_host\" autocomplete=\"off\" maxlength=\"255\"></td><td colspan=\"2\"><input class=\"button\" type=\"submit\" value=\"add\"></td></tr>";
- echo "</form>";
- $pm_get = mysql_query("select * from users where domain='{$_SESSION['logged_uid']}' order by id");
- while ($pm_row = mysql_fetch_array($pm_get)) {
- if ($pm_row[5] == "1") {
- $pm_do = "disable";
- $pm_bg = "#ffffff";
- }
- if ($pm_row[5] == "0") {
- $pm_do = "enable";
- $pm_bg = "#eeeeee";
- }
- $msg_new = "$mail_root/{$_SESSION['logged_uid']}/" . substr($pm_row[0],0,1) . "/" . substr($pm_row[0],0,strpos($pm_row[0],"@")) . "/new/*";
- $msg_new = count(glob($msg_new));
- $msg_cur = "$mail_root/{$_SESSION['logged_uid']}/" . substr($pm_row[0],0,1) . "/" . substr($pm_row[0],0,strpos($pm_row[0],"@")) . "/cur/*";
- $msg_cur = count(glob($msg_cur));
- $pm_aka = mysql_query("select * from aliases where alias='{$pm_row[0]}'");
- $pm_aka = mysql_num_rows($pm_aka);
- echo "<tr bgcolor=\"$pm_bg\"><td align=\"right\">$msg_new</td><td align=\"right\">$msg_cur</td><td align=\"right\">$pm_aka</td><form method=\"post\"><input type=\"hidden\" name=\"pm_set\" value=\"{$pm_row[0]}\"><input type=\"hidden\" name=\"pm_do\" value=\"$pm_do\"><td align=\"center\" valign=\"middle\" width=\"10\"><input type=\"image\" src=\"images/{$pm_do}.png\"></td></form><form method=\"post\"><input type=\"hidden\" name=\"pm_mod\" value=\"{$pm_row[0]}\"><td>{$pm_row[0]}</td><td><input class=\"input\" type=\"text\" name=\"pm_name\" maxlength=\"128\" autocomplete=\"off\" value=\"{$pm_row[3]}\"></td><td><input class=\"input\" type=\"text\" name=\"pm_pass\" maxlength=\"64\" autocomplete=\"off\"></td><td><input class=\"input\" type=\"text\" name=\"pm_host\" maxlength=\"255\" autocomplete=\"off\" value=\"{$pm_row[6]}\"></td><td><input class=\"button\" type=\"submit\" value=\"mod\"></td></form><form method=\"post\"><input type=\"hidden\" name=\"pm_del\" value=\"{$pm_row[0]}\"><td><input class=\"button\" type=\"submit\" value=\"del\" onclick=\"if (confirm('Do you really want to delete {$pm_row[0]} plus all messages and aliases associated with this account?')) {return true;} else {return false;}\"></td></form></tr>";
- }
- echo "</table>";
- }
- if ($_SESSION['logged_lvl'] == "administrator") {
- echo "<table border=\"0\" cellspacing=\"1\" cellpadding=\"2\" bgcolor=\"#cccccc\">";
- echo "<tr bgcolor=\"#eeeeee\"><td colspan=\"2\" align=\"center\">status</td><td align=\"center\"><nobr>domain name</nobr></td><td align=\"center\"><nobr>account limit</nobr></td><td align=\"center\"><nobr>postmaster password</nobr></td><td align=\"center\" colspan=\"2\">action</td></tr>";
- echo "<form method=\"post\"><tr bgcolor=\"#ffffff\"><td align=\"center\">usr</td><td align=\"center\">rcv</td><td align=\"center\"><input class=\"input\" type=\"text\" name=\"dom_name\" maxlength=\"128\" autocomplete=\"off\"></td><td align=\"center\"><input class=\"input\" style=\"text-align: right;\" type=\"text\" name=\"dom_max\" maxlength=\"6\" autocomplete=\"off\" value=\"0\"></td><td align=\"center\"><input class=\"input\" type=\"text\" name=\"dom_pass\" maxlength=\"64\" autocomplete=\"off\"></td><td align=\"center\" colspan=\"2\"><input class=\"button\" type=\"submit\" value=\"add\"></td></tr></form>";
- $dom_get = mysql_query("select * from domains order by id");
- while ($dom_row = mysql_fetch_array($dom_get)) {
- $dom_usr = mysql_query("select * from users where domain='{$dom_row[0]}'");
- $dom_usr = mysql_num_rows($dom_usr);
- if ($dom_row[3] == "1") {
- $dom_do = "disable";
- $dom_bg = "#ffffff";
- }
- if ($dom_row[3] == "0") {
- $dom_do = "enable";
- $dom_bg = "#eeeeee";
- }
- echo "<tr bgcolor=\"$dom_bg\"><td align=\"right\">$dom_usr</td><form method=\"post\"><input type=\"hidden\" name=\"dom_set\" value=\"{$dom_row[0]}\"><input type=\"hidden\" name=\"dom_do\" value=\"$dom_do\"><td align=\"center\" valign=\"middle\" width=\"10\"><input type=\"image\" src=\"images/{$dom_do}.png\"></td></form><form method=\"post\"><input type=\"hidden\" name=\"dom_mod\" value=\"{$dom_row[0]}\"><td>{$dom_row[0]}</td><td><input class=\"input\" style=\"text-align: right;\" type=\"text\" name=\"dom_max\" maxlength=\"6\" autocomplete=\"off\" value=\"{$dom_row[2]}\"></td><td><input class=\"input\" type=\"text\" name=\"dom_pass\" maxlength=\"64\" autocomplete=\"off\"></td><td><input class=\"button\" type=\"submit\" value=\"mod\"></td></form><form method=\"post\"><input type=\"hidden\" name=\"dom_del\" value=\"{$dom_row[0]}\"><td><input class=\"button\" type=\"submit\" value=\"del\" onclick=\"if (confirm('Do you really want to delete {$dom_row[0]} plus all accounts and messages associated with this domain?')) {return true;} else {return false;}\"></td></form></tr>";
- }
- echo "</table>";
- }
- echo "</td>";
- if ($_SESSION['logged_lvl'] == "postmaster") {
- echo "<td width=\"10\"></td><td valign=\"top\">";
- echo "<table border=\"0\" cellspacing=\"1\" cellpadding=\"2\" bgcolor=\"#cccccc\">";
- echo "<tr bgcolor=\"#eeeeee\"><td align=\"center\">alias</td><td align=\"center\">recipient</td><td align=\"center\" colspan=\"3\">action</td></tr>";
- echo "<form method=\"post\">";
- echo "<tr bgcolor=\"#ffffff\"><td><input class=\"input\" type=\"text\" name=\"alias_add\" autocomplete=\"off\" maxlength=\"255\"></td><td><input class=\"input\" type=\"text\" name=\"alias_to\" autocomplete=\"off\" maxlength=\"128\"></td><td colspan=\"3\"><input class=\"button\" type=\"submit\" value=\"add\"></td></tr>";
- echo "</form>";
- $get_aliases = mysql_query("select * from aliases where domain='{$_SESSION['logged_uid']}' order by id");
- while ($aliases_row = mysql_fetch_array($get_aliases)) {
- if ($aliases_row[3] == "1") {
- $alias_do = "disable";
- $alias_bg = "#ffffff";
- }
- if ($aliases_row[3] == "0") {
- $alias_do = "enable";
- $alias_bg = "#eeeeee";
- }
- echo "<tr bgcolor=\"$alias_bg\"><form method=\"post\"><input type=\"hidden\" name=\"alias_mod\" value=\"{$aliases_row[0]}\"><td>{$aliases_row[0]}</td><td><input class=\"input\" type=\"text\" name=\"alias_to\" maxlength=\"255\" autocomplete=\"off\" value=\"{$aliases_row[1]}\"></td><td><input class=\"button\" type=\"submit\" value=\"mod\"></td></form><form method=\"post\"><input type=\"hidden\" name=\"alias_set\" value=\"{$aliases_row[0]}\"><input type=\"hidden\" name=\"alias_do\" value=\"$alias_do\"><td align=\"center\" valign=\"middle\" width=\"10\"><input type=\"image\" src=\"images/{$alias_do}.png\"></td></form><form method=\"post\"><input type=\"hidden\" name=\"alias_del\" value=\"{$aliases_row[0]}\"><td><input class=\"button\" type=\"submit\" value=\"del\" onclick=\"if (confirm('Do you really want to delete the {$aliases_row[0]} alias of {$aliases_row[1]}?')) {return true;} else {return false;}\"></td></form></tr>";
- }
- echo "</table>";
- }
- echo "</td></tr>";
- echo "</table>";
- }
- mysql_close($db_link);
- ?>