query($sql); //else die(mysql_error()); } function fetch($res) { global $mysql_result; if($res) return $res->fetch_all(MYSQLI_BOTH); else return false; } function connect() { global $cid,$db; $cid = new mysqli(db_server, db_user, db_pwd, db_name); if ($cid->connect_errno) die("Verbindung fehlgeschlagen: " . $mysqli->connect_error); } function disconnect() { global $cid; if(!($cid->close())) die("Fehler beim Trennen der Verbindung!"); } function pw_encode($password, $rounds=10000) { $salt = substr ( str_shuffle ( './0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' ) , 0, 22 ); return crypt ($password, '$5$rounds=' . $rounds . '$' . $salt); } /* Initialize */ connect(); $do = array_key_exists('do', $_REQUEST) ? $_REQUEST['do'] : false; $id = array_key_exists('id', $_REQUEST) ? $_REQUEST['id'] : false; $new = array_key_exists('new', $_REQUEST) ? $_REQUEST['new'] : false; $del = array_key_exists('del', $_REQUEST) ? $_REQUEST['del'] : false; $chg = array_key_exists('chg', $_REQUEST) ? $_REQUEST['chg'] : false; $ack = array_key_exists('ack', $_REQUEST) ? $_REQUEST['ack'] : false; $domain = array_key_exists('domain' , $_REQUEST) ? $_REQUEST['domain' ] : false; $source = array_key_exists('source' , $_REQUEST) ? $_REQUEST['source' ] : false; $usr = array_key_exists('usr' , $_REQUEST) ? $_REQUEST['usr' ] : false; $pwd = array_key_exists('pwd' , $_REQUEST) ? $_REQUEST['pwd' ] : false; $dest = array_key_exists('dest' , $_REQUEST) ? $_REQUEST['dest' ] : false; $enabled = array_key_exists('enabled', $_REQUEST) ? $_REQUEST['enabled'] : false; $ndomain = array_key_exists('ndomain', $_REQUEST) ? $_REQUEST['ndomain'] : false; $orderby = array_key_exists('orderby', $_REQUEST) ? $_REQUEST['orderby'] : false; $sel = array_key_exists('sel' , $_REQUEST) ? $_REQUEST['sel' ] : false; $fetch_list = $cid->query("SELECT * FROM `domains` ORDER BY `domain` ASC"); $orderbysql = $orderby ? ' ORDER BY '.$orderby.';' : ';'; $selectsql = $sel ? ' AND domain_id = '.$sel : ''; ## Query Aliases ## $sql[1] = "SELECT alias_id, source_username, source_domain, destinations, enabled FROM view_aliases"; if ($sel) $sql[1] .= " WHERE domain_id=" . ($sel+0); $sql[1] .= $orderbysql; ## Query Domains ## $sql[2] = "SELECT * FROM domains " . $orderbysql; ## Query Users ## $sql[3] = "SELECT account_id, user, domain FROM view_accounts"; if ($sel) $sql[3] .= " WHERE domain_id=" . ($sel+0); $sql[3] .= $orderbysql; ## Insert Alias Query ## if(($domain <> "") && ($dest <> "")) $sql[4] = "INSERT INTO aliases (source_username, source_domain, destination, enabled) VALUES ('$source','$domain','$dest',1);"; ## Insert Domain Query ## if($ndomain <> "") { $sql0 = "SELECT domain FROM domains WHERE domain = '$ndomain';"; $qr = query($sql0); if($qr->num_rows() < 1) $sql[5] = "INSERT INTO domains (domain) VALUES ('$ndomain');"; } ## Insert User Query ## if(($domain <> "") && ($usr <> "") && ($pwd <> "")) { $sql1 = "SELECT domain_id, user, password FROM accounts WHERE domain = $domain AND username = '$usr';"; $qr = query($sql1); if($qr->num_rows() < 1) $sql[6] = "INSERT INTO accounts (domain, username, password, enabled) VALUES ('$domain','$usr','".pw_encode($pwd)."',1);"; } ## Delete Query ## if(($del <> "") && ($id <> "") && ($ack == 'Yes')) { switch ($del) { case 1: $sql = "DELETE FROM aliases WHERE id = $id;"; break; case 2: $sql = "DELETE FROM domains WHERE id = $id;"; break; case 3: $sql = "DELETE FROM accounts WHERE id = $id;"; break; } $qry = query($sql); } ## Update Alias Query## if(($chg == 1) && ($id <> "") && ($domain <> "") && ($dest <> "") && ($ack == 'Save')) { $sql = "UPDATE aliases SET source_domain = '".$domain."', source_username = '".$source."', destination = '".$dest."', enabled = '".$enabled."' WHERE id = ".$id.";"; $qry = query($sql); } ## Update Domain Query ## if(($chg == 2) && ($id <> "") && ($domain <> "") && ($ack == 'Save')) { $sql = "UPDATE domains SET domain='".$domain."' WHERE id = ".$id.";"; $qry = query($sql); } ## Update User Query ## if(($chg == 3) && ($id <> "") && ($domain <> "") && ($usr <> "") && ($pwd <> "") && ($ack == 'Save')) { $sql = "UPDATE accounts SET domain ='".$domain."', username ='".$usr."', password = '".pw_encode($pwd)."' WHERE id = ".$id.";"; $qry = query($sql); } if($do) { $qry = query($sql[$do]); if($qry) $result = true; else $result = false; } /* Code */ ?>