function gennewcamdusers($file, $expire)
{
    consolewrite("generating newcamd users");
    $newcamdusers = "";
    $mysqli = new mysqli(DBHOST, DBUSER, DBPASS, DBNAME);
    if ($expire == "1") {
        $users = $mysqli->query("SELECT user,password,displayname,ipmask,profiles,enabled,startdate,expiredate FROM users WHERE boxtype='newcamd'");
    } else {
        $users = $mysqli->query("SELECT user,password,displayname,ipmask,profiles FROM users WHERE (enabled='1' OR enabled='') AND boxtype='newcamd'");
    }
    while ($usrdata = $users->fetch_array()) {
        if ($expire == "1" && checkuserdate($usrdata["startdate"], $usrdata["expiredate"], $usrdata["enabled"]) == "1" || $expire == "0") {
            $profres = "";
            $profvalues = "";
            if ($usrdata["profiles"] == "") {
                $profres = "";
            } else {
                $dbprof = unserialize($usrdata["profiles"]);
                $cmumprof = getprofiles();
                if ($dbprof != "" && $dbprof != "N;") {
                    foreach ($dbprof as $useprof) {
                        $profvalues .= $cmumprof[$useprof] . ", ";
                    }
                    $profres = trim($profvalues);
                    $profres = substr($profres, 0, -1);
                    $profdata = "";
                    $profvalues = "";
                } else {
                    $profres = "";
                }
            }
            $newcamdusers .= "USER: "******"user"] . " " . $usrdata["password"] . " { " . $profres . " }\n";
        }
    }
    mysqli_close($mysqli);
    $usrfile = fopen($file, "w");
    fwrite($usrfile, $newcamdusers);
    fclose($usrfile);
}
Пример #2
0
function genxml($genxmlkey, $reqip, $option)
{
    if (file_exists("config.php")) {
        require "config.php";
    } else {
        require "../config.php";
    }
    $dogen = "";
    $xmlout = "";
    $mysqli = new mysqli($dbhost, $dbuser, $dbpass, $dbname);
    $genxmlkey = $mysqli->real_escape_string($genxmlkey);
    $opts = explode(";", $option);
    $sql = $mysqli->query("SELECT genxmlkey,genxmlusrgrp,genxmllogreq,genxmldateformat,extrausrtbl FROM settings WHERE id='1'");
    $setres = $sql->fetch_array();
    if ($setres["genxmlkey"] != "") {
        if ($setres["genxmlkey"] == $genxmlkey) {
            $dogen = "1";
            if ($setres["genxmllogreq"] == "1") {
                $mysqli->query("INSERT INTO log_genxmlreq (status,ip,genxmlkey) VALUES ('0','" . $reqip . "','')");
            }
        } else {
            if ($setres["genxmllogreq"] == "1" || $setres["genxmllogreq"] == "2") {
                $mysqli->query("INSERT INTO log_genxmlreq (status,ip,genxmlkey) VALUES ('1','" . $reqip . "','" . $genxmlkey . "')");
            }
        }
    } elseif ($setres["genxmlkey"] == "") {
        $dogen = "1";
        if ($setres["genxmllogreq"] == "1") {
            $mysqli->query("INSERT INTO log_genxmlreq (status,ip,genxmlkey) VALUES ('0','" . $reqip . "','')");
        }
    }
    if ($dogen == "1") {
        $enabledgroups = enabledgroups();
        $intstrexp = checksetting("genxmlintstrexp");
        $xmlout = "<xml-user-manager ver=\"1.0\">\n";
        $profvalues = "";
        $usql = $mysqli->query("SELECT user,password,displayname,ipmask,profiles,maxconn,admin,enabled,mapexclude,debug,email,customvalues,ecmrate,startdate,expiredate,usrgroup FROM users");
        while ($usrdata = $usql->fetch_array()) {
            $profres = "";
            if ($usrdata["profiles"] == "") {
                $profres = "";
            } else {
                $dbprof = unserialize($usrdata["profiles"]);
                $profdata = getprofiles();
                if ($dbprof != "" && $dbprof != "N;") {
                    foreach ($dbprof as $useprof) {
                        $profvalues .= $profdata[$useprof] . " ";
                    }
                    $profres = trim($profvalues);
                    $profdata = "";
                    $profvalues = "";
                } else {
                    $profres = "";
                }
            }
            if (in_array("nousername", $opts)) {
                $username = "";
            } else {
                $username = xmloutformat("name", $usrdata["user"]);
            }
            if (in_array("nopassword", $opts)) {
                $password = "";
            } else {
                $password = xmloutformat("password", $usrdata["password"]);
            }
            if (in_array("nodisplayname", $opts)) {
                $displayname = "";
            } else {
                if ($setres["genxmlusrgrp"] == "1") {
                    $displayname = xmloutformatwusrgrp("display-name", $usrdata["displayname"], $usrdata["usrgroup"]);
                } else {
                    $displayname = xmloutformat("display-name", $usrdata["displayname"]);
                }
            }
            if (in_array("noipmask", $opts)) {
                $ipmask = "";
            } else {
                $ipmask = xmloutformat("ip-mask", $usrdata["ipmask"]);
            }
            if (in_array("noprofiles", $opts)) {
                $profiles = "";
            } else {
                $profiles = xmloutformat("profiles", $profres);
            }
            if (in_array("nomaxconnections", $opts)) {
                $maxconn = "";
            } else {
                $maxconn = xmloutformat("max-connections", $usrdata["maxconn"]);
            }
            if (in_array("noadmin", $opts)) {
                $admin = "";
            } else {
                $admin = xmloutformat("admin", numbertotf($usrdata["admin"]));
            }
            if (in_array("noenabled", $opts)) {
                $enabled = "";
            } else {
                if (!in_array($usrdata["usrgroup"], $enabledgroups)) {
                    $enabled = xmloutformat("enabled", "false");
                } elseif ($intstrexp == "1") {
                    $usrexp = checkstartexpire($usrdata["startdate"], $usrdata["expiredate"], $usrdata["enabled"]);
                    if ($usrexp == "0") {
                        $enabled = xmloutformat("enabled", "false");
                    } elseif ($usrexp == "1") {
                        $enabled = xmloutformat("enabled", "true");
                    } elseif ($usrexp == "2") {
                        $enabled = xmloutformat("enabled", "false");
                    } elseif ($usrexp == "3") {
                        $enabled = xmloutformat("enabled", "false");
                    } else {
                        $enabled = xmloutformat("enabled", numbertotf($usrdata["enabled"]));
                    }
                } else {
                    $enabled = xmloutformat("enabled", numbertotf($usrdata["enabled"]));
                }
            }
            if (in_array("nomapexclude", $opts)) {
                $mapexclude = "";
            } else {
                $mapexclude = xmloutformat("map-exclude", numbertotf($usrdata["mapexclude"]));
            }
            if (in_array("nodebug", $opts)) {
                $debug = "";
            } else {
                $debug = xmloutformat("debug", numbertotf($usrdata["debug"]));
            }
            if (in_array("noemail", $opts)) {
                $email = "";
            } else {
                $email = xmloutformat("email-address", $usrdata["email"]);
            }
            if (in_array("nostartdate", $opts) || $intstrexp == "1") {
                $startdate = "";
            } else {
                $startdate = xmloutformat("start-date", formatdate($setres["genxmldateformat"], $usrdata["startdate"]));
            }
            if (in_array("noexpiredate", $opts) || $intstrexp == "1") {
                $expiredate = "";
            } else {
                $expiredate = xmloutformat("expire-date", formatdate($setres["genxmldateformat"], $usrdata["expiredate"]));
            }
            if (in_array("nocustomvalues", $opts)) {
                $customvalues = "";
            } else {
                $customvalues = $usrdata["customvalues"];
            }
            $xmlout .= "<user " . $username . $password . $displayname . $ipmask . $profiles . $maxconn . $admin . $enabled . $mapexclude . $debug . $email . $startdate . $expiredate . $customvalues . "/>\n";
        }
        $xmlout .= "</xml-user-manager>";
    }
    mysqli_close($mysqli);
    return $xmlout;
}