Exemple #1
0
function AddDNSEntry()
{
    $computername = $_GET["computername"];
    $DnsZoneName = $_GET["DnsZoneName"];
    $ComputerIP = $_GET["ComputerIP"];
    $pdns = new pdns($DnsZoneName);
    if (!$pdns->EditIPName($computername, $ComputerIP, "A", null)) {
        echo $pdns->last_error;
    }
}
Exemple #2
0
function add_web_service()
{
    $ou = $_GET["ou"];
    $ServerWWWType = $_GET['ServerWWWType'];
    $servername = $_GET["servername"];
    $domain = $_GET["domain"];
    $IP = $_GET["IP"];
    $tpl = new templates();
    $noneed_mysql = false;
    $noneed_appliPass = false;
    if ($_GET["host"] == null) {
        if ($servername == null) {
            echo $tpl->_ENGINE_parse_body("{server_name}=null");
            exit;
        }
        if ($IP == null) {
            echo $tpl->_ENGINE_parse_body("{address}=null");
            exit;
        }
        if ($domain == null) {
            echo $tpl->_ENGINE_parse_body("{domain}=null");
            exit;
        }
        if ($ServerWWWType == null) {
            echo $tpl->_ENGINE_parse_body("{service_type}=null");
            exit;
        }
    }
    $noneed_mysql = false;
    if ($ou == null) {
        echo $tpl->_ENGINE_parse_body("{organization}=null");
        exit;
    }
    $vhosts = new vhosts($_GET["ou"]);
    $vvhosts = new vhosts();
    $noneeduser = $vvhosts->noneeduser;
    $noneeduser_mysql = $vvhosts->noneeduser_mysql;
    if ($noneeduser[$ServerWWWType]) {
        $noneed_appliPass = true;
    }
    if ($noneeduser_mysql[$ServerWWWType]) {
        $noneed_mysql = true;
    }
    if (!$noneed_mysql) {
        if ($_GET["WWWMysqlUser"] == null) {
            echo $tpl->_ENGINE_parse_body("\"{$ServerWWWType}\":\n{WWWMysqlUser}=null\n{$noneed_mysql}\nL." . __LINE__);
            exit;
        }
        if ($_GET["WWWMysqlPassword"] == null) {
            echo $tpl->_ENGINE_parse_body("{$ServerWWWType}:{WWWMysqlPassword}=null");
            exit;
        }
    }
    if (!$noneeduser["{$ServerWWWType}"]) {
        if ($_GET["WWWAppliUser"] == null) {
            echo $tpl->_ENGINE_parse_body("{$ServerWWWType}:\n{WWWAppliUser}=null\n{$vhosts->noneeduser["{$ServerWWWType}"]}");
            exit;
        }
    }
    if (!$noneed_appliPass) {
        if ($_GET["WWWAppliPassword"] == null) {
            echo $tpl->_ENGINE_parse_body("{WWWAppliPassword}=null");
            exit;
        }
    }
    if ($_GET["host"] == null) {
        $hostname = $servername . "." . $domain;
        $pdns = new pdns($domain);
        $pdns->EditIPName($servername, $IP, "A", null);
    } else {
        $hostname = $_GET["host"];
    }
    $hostname = str_replace(" ", "_", $hostname);
    $database = str_replace("-", "_", $database);
    $database = str_replace(".", "_", $database);
    $vhosts->ou = $ou;
    $vhosts->BuildRoot();
    $vhosts->WWWAppliPassword = $_GET["WWWAppliPassword"];
    $vhosts->WWWAppliUser = $_GET["WWWAppliUser"];
    $vhosts->WWWMysqlUser = $_GET["WWWMysqlUser"];
    $vhosts->WWWMysqlPassword = $_GET["WWWMysqlPassword"];
    $vhosts->WWWSSLMode = $_GET["WWWSSLMode"];
    if (isset($_GET["WWWEnableAddressBook"])) {
        $vhosts->WWWEnableAddressBook = $_GET["WWWEnableAddressBook"];
    }
    writelogs("WWWMultiSMTPSender={$_GET["WWWMultiSMTPSender"]}", __FUNCTION__, __FILE__, __LINE__);
    $vhosts->WWWMultiSMTPSender = $_GET["WWWMultiSMTPSender"];
    $vhosts->Addhost($hostname, $ServerWWWType);
    $sock = new sockets();
    writelogs("Scheduling =>cmd.php?install-web-services=yes", __FUNCTION__, __FILE__, __LINE__);
    $sock->getFrameWork("cmd.php?install-web-services=yes");
}
Exemple #3
0
function SimpleShareAddCompToPath()
{
    $uid = $_GET["add-uid"];
    $samba = new samba();
    $keypath = $samba->GetShareName(base64_decode($_GET["path"]));
    $hosts = explode(" ", $samba->main_array[$keypath]["hosts allow"]);
    if (is_array($hosts)) {
        while (list($index, $host) = each($hosts)) {
            if ($host == null) {
                continue;
            }
            $hote[$host] = $host;
        }
    }
    $comp = new computers($uid);
    $pdns = new pdns();
    $array = $pdns->IpToHosts($comp->ComputerIP);
    if (is_array($array)) {
        while (list($index, $val) = each($array)) {
            $hote[$val] = $val;
        }
    } else {
        $hote[$comp->ComputerIP] = $comp->ComputerIP;
    }
    $hote[$comp->ComputerRealName] = $comp->ComputerRealName;
    if (is_array($hote)) {
        while (list($index, $host) = each($hote)) {
            if (strpos($host, '$') > 0) {
                continue;
            }
            $final[] = $host;
        }
    }
    if (count($final) > 0) {
        $samba->main_array[$keypath]["hosts allow"] = @implode(" ", $final);
        $samba->main_array[$keypath]["hosts deny"] = "0.0.0.0/0";
        $samba->main_array[$keypath]["public"] = "yes";
        $samba->main_array[$keypath]["force user"] = "******";
        $samba->main_array[$keypath]["guest ok"] = "yes";
        $samba->main_array[$keypath]["read only"] = "no";
        $samba->main_array[$keypath]["browseable"] = "yes";
        $samba->main_array["global"]["guest account"] = "nobody";
        $samba->main_array["global"]["map to guest"] = "Bad Password";
        unset($samba->main_array[$keypath]["write list"]);
        unset($samba->main_array[$keypath]["valid users"]);
        unset($samba->main_array[$keypath]["read list"]);
    } else {
        unset($samba->main_array[$keypath]["force user"]);
        unset($samba->main_array[$keypath]["public"]);
        unset($samba->main_array[$keypath]["guest ok"]);
        unset($samba->main_array[$keypath]["read only"]);
        unset($samba->main_array[$keypath]["hosts deny"]);
        unset($samba->main_array[$keypath]["hosts allow"]);
    }
    $samba->SaveToLdap();
}
function update_computer($ip, $mac, $name)
{
    $mac = trim($mac);
    $name = trim(strtolower($name));
    $ip = trim($ip);
    if ($ip == null) {
        return;
    }
    if ($mac == null) {
        return;
    }
    if ($name == null) {
        return;
    }
    $ip = nmblookup($name, $ip);
    $unix = new unix();
    $unix->add_EtcHosts($name, $ip);
    $dhcp = new dhcpd();
    $GLOBALS["domain"] = $dhcp->ddns_domainname;
    $comp = new computers();
    $uid = $comp->ComputerIDFromMAC($mac);
    if ($uid == null) {
        $add = true;
        $uid = "{$name}\$";
        $comp = new computers();
        $comp->ComputerRealName = $name;
        $comp->ComputerMacAddress = $mac;
        $comp->ComputerIP = $ip;
        $comp->DnsZoneName = $GLOBALS["domain"];
        $comp->uid = $uid;
        $ComputerRealName = $HOST;
        $comp->Add();
    } else {
        $comp = new computers($uid);
        if ($comp->ComputerRealName == null) {
            $ComputerRealName = $name;
        }
        if (preg_match("#[0-9]+\\.[0-9]+\\.#", $comp->ComputerRealName)) {
            $comp->ComputerRealName = $name;
        }
        $comp->ComputerIP = $ip;
        $comp->DnsZoneName = $GLOBALS["domain"];
        $comp->Edit();
    }
    $dns = new pdns($GLOBALS["domain"]);
    $dns->EditIPName(strtolower($name), $ip, 'A', $mac);
}
function websites_search()
{
    include_once dirname(__FILE__) . '/ressources/class.apache.inc';
    $vhosts = new vhosts();
    $GLOBALS["IMG_ARRAY_64"] = $vhosts->IMG_ARRAY_64;
    $searchstring = string_to_flexquery("websites-search");
    $DNS_INSTALLED = false;
    $q = new mysql();
    $sql = "SELECT * FROM freeweb WHERE 1 {$searchstring} LIMIT 0,250";
    $results = $q->QUERY_SQL($sql, 'artica_backup');
    $tpl = new templates();
    $GLOBALS["CLASS_TPL"] = $tpl;
    $boot = new boostrap_form();
    if ($users->dnsmasq_installed) {
        $DNS_INSTALLED = true;
    }
    if ($users->POWER_DNS_INSTALLED) {
        $DNS_INSTALLED = true;
    }
    $pdns = new pdns();
    while ($ligne = mysql_fetch_array($results, MYSQL_ASSOC)) {
        if ($ligne["useSSL"] == 1) {
            $ssl = "check-32.png";
        } else {
            $ssl = "check-32-grey.png";
        }
        $DirectorySize = FormatBytes($ligne["DirectorySize"] / 1024);
        $WebCopyID = $ligne["WebCopyID"];
        $statistics = " ";
        $exec_statistics = " ";
        $Members = null;
        $groupware = null;
        $forward_text = null;
        $error_text = null;
        $checkDNS = "<img src='img/check-48.png'>";
        $checkMember = "<img src='img/check-48-grey.png'>";
        $JSDNS = 0;
        if ($DNS_INSTALLED) {
            $ip = $pdns->GetIpDN($ligne["servername"]);
            if ($ip != null) {
                $checkDNS = "<img src='img/check-48.png'>";
                $JSDNS = 1;
            }
        }
        $ServerAlias = null;
        $Params = @unserialize(base64_decode($ligne["Params"]));
        $f = array();
        if (isset($Params["ServerAlias"])) {
            while (list($host, $num) = each($Params["ServerAlias"])) {
                $f[] = $host;
            }
            $ServerAlias = div_groupware("<a href=\"javascript:blur();\"\n\t\t\t\t\tOnClick=\"javascript:Loadjs('freeweb.edit.ServerAlias.php?servername={$ligne["servername"]}')\"\n\t\t\t\t\tstyle='text-decoration:underline'><i>" . @implode(", ", $f) . "</i>");
        }
        if ($ligne["uid"] != null) {
            $checkMember = "<img src='img/20-check.png'>";
        }
        $added_port = null;
        $icon = build_icon($ligne, $ligne["servername"]);
        $ServerPort = $ligne["ServerPort"];
        if ($ServerPort > 0) {
            $added_port = ":{$ServerPort}";
        }
        if ($ligne["groupware"] != null) {
            $groupware = div_groupware("({{$vhosts->TEXT_ARRAY[$ligne["groupware"]]["TITLE"]}})", $ligne["enabled"]);
        }
        if ($ligne["Forwarder"] == 1) {
            $forward_text = div_groupware("{www_forward} <b>{$ligne["ForwardTo"]}</b>", $ligne["enabled"]);
        }
        $js_edit = "Loadjs('freeweb.edit.php?hostname={$ligne["servername"]}&t={$_GET["t"]}')";
        $servername_text = $ligne["servername"];
        if ($servername_text == "_default_") {
            $servername_text = "{all}";
            $groupware = div_groupware("({default_website})", $ligne["enabled"]);
        } else {
            if (!preg_match("#^[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+#", $ligne["servername"])) {
                $checkResolv = "<img src='img/20-check.png'>";
                if (trim($ligne["resolved_ipaddr"]) == null) {
                    $error_text = $tpl->_ENGINE_parse_body("\n\t\t\t\t\t<p class=text-error style='font-size:12px;margin-top:10px'>\n\t\t\t\t\t\t{could_not_find_iphost}\n\t\t\t\t\t</p>");
                    $checkResolv = "<img src='img/20-check-grey.png'>";
                }
            }
        }
        $colorhref = null;
        if ($ligne["enabled"] == 0) {
            $colorhref = "color:#8C8C8C";
        }
        $href = "<a href=\"javascript:blur();\"\n\t\tOnClick=\"javascript:Loadjs('freeweb.edit.php?hostname={$ligne["servername"]}&t={$_GET["t"]}')\"\n\t\tstyle='font-size:13px;text-decoration:underline;font-weight:bold;{$colorhref}'>";
        $color = "black";
        $md5S = md5($ligne["servername"]);
        $delete = icon_href("delete-48.png", "FreeWebDelete('{$ligne["servername"]}',{$JSDNS},'{$md5S}')");
        $sql = "SELECT ID FROM drupal_queue_orders WHERE `ORDER`='DELETE_FREEWEB' AND `servername`='{$ligne["servername"]}'";
        $ligneDrup = @mysql_fetch_array($q->QUERY_SQL($sql, 'artica_backup'));
        if ($ligne["ID"] > 0) {
            $edit = imgtootltip("folder-tasks-32.png", "{delete}");
            $color = "#8a8a8a";
            $delete = imgtootltip("delete-48-grey.png", "{delete} {scheduled}");
        }
        $sql = "SELECT ID FROM drupal_queue_orders WHERE `ORDER`='INSTALL_GROUPWARE' AND `servername`='{$ligne["servername"]}'";
        if ($ligne["ID"] > 0) {
            $edit = icon_href("folder-tasks-32.png", "Loadjs('freeweb.edit.php?hostname={$ligne["servername"]}')");
            $color = "#8a8a8a";
            $delete = icon_href("delete-48-grey.png");
            $groupware = div_groupware("({installing} {{$vhosts->TEXT_ARRAY[$ligne["groupware"]]["TITLE"]}})", $ligne["enabled"]);
        }
        $Params = @unserialize(base64_decode($ligne["Params"]));
        $IsAuthen = false;
        if ($Params["LDAP"]["enabled"] == 1) {
            $IsAuthen = true;
        }
        if ($Params["NTLM"]["enabled"] == 1) {
            $IsAuthen = true;
        }
        $color_orange = "#B64B13";
        if ($ligne["enabled"] == 0) {
            $color_orange = "#8C8C8C";
        }
        if ($IsAuthen) {
            $Members = "<span style='font-size:14px;font-weight:bold;color:{$color_orange};'>&nbsp;&laquo;<a href=\"javascript:blur();\"\n\t\tOnClick=\"javascript:Loadjs('freeweb.edit.ldap.users.php?servername={$ligne["servername"]}');\"\n\t\tstyle='font-size:14px;font-weight:bold;color:{$color_orange};text-decoration:underline;font-style:italic'>{$members_text}</a>\n\t\t&nbsp;&raquo;</span>";
        }
        $memory = "-";
        $requests_second = "-";
        $traffic_second = "-";
        $uptime = null;
        $table_name_stats = "apache_stats_" . date('Ym');
        $sql = "SELECT * FROM {$table_name_stats} WHERE servername='{$ligne["servername"]}' ORDER by zDate DESC LIMIT 0,1";
        $ligneStats = mysql_fetch_array($q->QUERY_SQL($sql, "artica_events"));
        if ($ligneStats["total_memory"] > 0) {
            $memory = FormatBytes($ligneStats["total_memory"] / 1024);
            $requests_second = "{$ligneStats["requests_second"]}/s";
            $traffic_second = FormatBytes($ligneStats["traffic_second"] / 1024) . "/s";
            $uptime = div_groupware("{uptime}:{$ligneStats["UPTIME"]}", $ligne["enabled"]);
        }
        $groupware = $tpl->_ENGINE_parse_body($groupware);
        $forward_text = $tpl->_ENGINE_parse_body($forward_text);
        $servername_text = $tpl->_ENGINE_parse_body($servername_text);
        $ServerAlias = $tpl->_ENGINE_parse_body($ServerAlias);
        $uptime = $tpl->_ENGINE_parse_body($uptime);
        $memory = $tpl->_ENGINE_parse_body($memory);
        $requests_second = $tpl->_ENGINE_parse_body("{$requests_second}");
        $traffic_second = $tpl->_ENGINE_parse_body($traffic_second);
        $checkResolv = $tpl->_ENGINE_parse_body($checkResolv);
        $checkDNS = $tpl->_ENGINE_parse_body($checkDNS);
        $checkMember = $tpl->_ENGINE_parse_body($checkMember);
        $delete = $tpl->_ENGINE_parse_body($delete);
        if ($WebCopyID > 0) {
            $ligne2 = mysql_fetch_array($q->QUERY_SQL("SELECT sitename FROM httrack_sites WHERE ID={$WebCopyID}", "artica_backup"));
            $groupware = div_groupware("WebCopy: {$ligne2["sitename"]}", $ligne["enabled"]);
        }
        if ($ligne["groupware"] == "UPDATEUTILITY") {
            $iconPlus = "<a href=\"javascript:blur();\" OnClick=\"javascript:Loadjs('UpdateUtility.php?js=yes');\"><img src='img/settings-15.png' align='left'></a>";
        }
        $color_span = "#5F5656";
        if ($ligne["enabled"] == 0) {
            $color_span = "#8C8C8C";
        }
        $compile = imgsimple("refresh-32.png", null, "FreeWebsRebuildvHostsTable('{$ligne["servername"]}')");
        $enable = Field_checkbox("enable_{$md5S}", 1, $ligne["enabled"], "FreeWebsEnableSite('{$ligne["servername"]}')");
        if ($ligne["enabled"] == 0) {
            $requests_second = "-";
            $traffic_second = "-";
            $memory = "-";
            $color = "#8C8C8C";
            $color_span = $color;
            $icon = "status_disabled.gif";
            $compile = "&nbsp;";
        }
        $jsedit = $boot->trswitch($js_edit);
        $tr[] = "\n\t\t\t\t<tr style='color:{$color}' id='row{$md5S}'>\n\t\t\t\t\t<td width=1% nowrap {$jsedit}><img src='img/{$icon}'></td>\n\t\t\t\t\t<td width=80% {$jsedit}><span style='font-size:18px;font-weight:bold'>{$servername_text}</span>{$iconPlus}{$groupware}{$forward_text}{$added_port}{$Members}{$sizevg}{$ServerAlias}{$uptime}{$error_text}</td>\n\t\t\t\t\t<td width=1% nowrap>{$compile}</td>\n\t\t\t\t\t<td width=1% nowrap>{$enable}</td>\n\t\t\t\t\t<td width=1% nowrap>{$DirectorySize}</td>\n\t\t\t\t\t<td width=1% nowrap>{$memory}</td>\n\t\t\t\t\t<td width=1% nowrap>{$requests_second}&nbsp;|&nbsp;{$traffic_second}</td>\t\t\t\t\n\t\t\t\t\t<td width=1% nowrap><img src='img/{$ssl}'></td>\n\t\t\t\t\t<td width=1% nowrap>{$delete}</td>\n\t\t\t\t</tr>\n\t\t\t\t";
    }
    $t = time();
    $freeweb_compile_background = $tpl->javascript_parse_text("{freeweb_compile_background}");
    $reset_admin_password = $tpl->javascript_parse_text("{reset_admin_password}");
    $delete_freeweb_text = $tpl->javascript_parse_text("{delete_freeweb_text}");
    $delete_freeweb_dnstext = $tpl->javascript_parse_text("{delete_freeweb_dnstext}");
    echo $tpl->_ENGINE_parse_body("\n\t\n\t\t<table class='table table-bordered table-hover'>\n\t\n\t\t\t<thead>\n\t\t\t\t<tr>\n\t\t\t\t\t<th colspan=2>{website}</th>\n\t\t\t\t\t<th>&nbsp;</th>\n\t\t\t\t\t<th>{enable}</th>\n\t\t\t\t\t<th>{size}</th>\n\t\t\t\t\t<th>{memory}</th>\n\t\t\t\t\t<th>Rq/s</th>\n\t\t\t\t\t<th>SSL</th>\n\t\t\t\t\t<th>&nbsp;</th>\n\t\t\t\t</tr>\n\t\t\t</thead>\n\t\t\t <tbody>") . @implode("", $tr) . "</tbody></table>\n<script>\nvar FreeWebIDMEM{$t}='';\n\n\tfunction HelpSection(){\n\t\tLoadHelp('freewebs_explain','',false);\n\t}\n\n\tfunction AddNewFreeWebServer(){\n\t\t Loadjs('freeweb.edit.php?hostname=&force-groupware={$_GET["force-groupware"]}&t={$t}')\n\t}\n\t\n\tfunction AddNewFreeWebServerZarafa(){\n\t\tYahooWin('650','freeweb.servers.php?freeweb-zarafa-choose=yes&t={$t}','{$choose_your_zarafa_webserver_type}');\n\t}\n\t\n\t\n\tfunction ApacheAllstatus(){\n\t\tLoadjs('freeweb.status.php');\n\t}\n\t\n\t\n\tfunction FreeWebWebDavPerUsers(){\n\t\tLoadjs('freeweb.webdavusr.php?t={$t}')\n\t}\n\t\n\tfunction RestoreSite(){\n\t\tLoadjs('freeweb.restoresite.php?t={$t}')\n\t}\n\t\n\tfunction FreeWebsRefreshWebServersList(){\n\t\tExecuteByClassName('SearchFunction');\n\t}\n\t\n\t\n\tvar x_EmptyEvents= function (obj) {\n\t\tvar results=obj.responseText;\n\t\tif(results.length>3){alert(results);return;}\n\t\tExecuteByClassName('SearchFunction');\n\n\t\t\n\t}\t\n\t\n\tvar x_FreeWebsRebuildvHostsTable= function (obj) {\n\t\tvar results=obj.responseText;\n\t\tif(results.length>3){alert(results);return;}\n\t\talert('{$freeweb_compile_background}');\n\t\tExecuteByClassName('SearchFunction');\n\t\t}\n\n\t\n\tvar x_klmsresetwebpassword{$t}= function (obj) {\n\t\tvar results=obj.responseText;\n\t\tif(results.length>3){alert(results);return;}\n\t\tExecuteByClassName('SearchFunction');\n\t}\t\n\t\n\tvar x_FreeWebDelete=function (obj) {\n\t\t\tvar results=obj.responseText;\n\t\t\tif(results.length>10){alert(results);return;}\t\n\t\t\t\$('#row'+FreeWebIDMEM{$t}).remove();\n\t\t\tif(document.getElementById('container-www-tabs')){\tRefreshTab('container-www-tabs');}\n\t\t}\t\n\t\t\n\t\tfunction FreeWebDelete(server,dns,md){\n\t\t\tFreeWebIDMEM{$t}=md;\n\t\t\tif(confirm('{$delete_freeweb_text}')){\n\t\t\t\tvar XHR = new XHRConnection();\n\t\t\t\tif(dns==1){if(confirm('{$delete_freeweb_dnstext}')){XHR.appendData('delete-dns',1);}else{XHR.appendData('delete-dns',0);}}\n\t\t\t\tXHR.appendData('delete-servername',server);\n    \t\t\tXHR.sendAndLoad('freeweb.php', 'GET',x_FreeWebDelete);\n\t\t\t}\n\t\t}\n\n\tvar x_FreeWebRefresh=function (obj) {\n\t\t\tvar results=obj.responseText;\n\t\t\tif(results.length>10){alert(results);return;}\t\n\t\t\tExecuteByClassName('SearchFunction');\n\t\t}\t\t\n\t\t\n\t\tfunction FreeWebAddDefaultVirtualHost(){\n\t\t\tvar XHR = new XHRConnection();\n\t\t\tXHR.appendData('AddDefaultOne','yes');\n    \t\tXHR.sendAndLoad('freeweb.php', 'POST',x_FreeWebRefresh);\t\t\n\t\t}\n\t\t\n\t\tfunction FreeWeCheckVirtualHost(){\n\t\t\tvar XHR = new XHRConnection();\n\t\t\tXHR.appendData('CheckAVailable','yes');\n    \t\tXHR.sendAndLoad('freeweb.php', 'POST',x_FreeWebDelete);\t\t\t\n\t\t}\n\t\t\n\t\tvar x_RebuildFreeweb{$t}=function (obj) {\n\t\t\tvar results=obj.responseText;\n\t\t\tif(results.length>0){alert(results);}\t\t\t\n\t\t\tExecuteByClassName('SearchFunction');\n\t\t}\t\t\t\n\t\t\n\t\tfunction RebuildFreeweb(){\n\t\t\tvar XHR = new XHRConnection();\n\t\t\tXHR.appendData('rebuild-items','yes');\n    \t\tXHR.sendAndLoad('freeweb.php', 'GET',x_RebuildFreeweb{$t});\n\t\t\n\t\t}\n\n\t\tfunction klmsresetwebpassword(){\n\t\t  if(confirm('{$reset_admin_password} ?')){\n\t\t\t\tvar XHR = new XHRConnection();\n\t\t\t\tXHR.appendData('klms-reset-password','yes');\n    \t\t\tXHR.sendAndLoad('klms.php', 'POST',x_klmsresetwebpassword{$t});\n    \t\t}\t\t\n\t\t}\n\t\t\n\tfunction FreeWebsRebuildvHostsTable(servername){\n\t\tvar XHR = new XHRConnection();\n\t\tXHR.appendData('FreeWebsRebuildvHosts',servername);\n\t\tXHR.sendAndLoad('freeweb.edit.php', 'POST',x_FreeWebsRebuildvHostsTable);\n\t}\n\n</script>\t\t\t \t\t\t\t\t \t\t\t\t \t\t\n";
}
function ImportDatas($datas)
{
    $import = unserialize(base64_decode($datas));
    $hash = $import["COMPUTERS"];
    for ($i = 0; $i < $hash["count"]; $i++) {
        $comp = new computers();
        $uidorg = $hash[$i]["uid"][0];
        $dnszonename = $hash[$i]["dnszonename"][0];
        $dnstype = $hash[$i]["dnstype"][0];
        $computermachinetype = $hash[$i]["computermachinetype"][0];
        $computerip = $hash[$i]["computerip"][0];
        $computermacaddress = $hash[$i]["computermacaddress"][0];
        $ComputerRealName = $hash[$i][strtolower("ComputerRealName")][0];
        if ($ComputerRealName == null) {
            $ComputerRealName = str_replace('$', '', $uidorg);
        }
        writelogs("Importing computer: {$uid} {$computerip} {$computermacaddress}", __FUNCTION__, __FILE__, __LINE__);
        $uid = $comp->ComputerIDFromMAC($computermacaddress);
        if ($uid == null) {
            $uid = $uidorg;
            $comp = new computers();
            $comp->ComputerRealName = $ComputerRealName;
            $comp->ComputerMacAddress = $computermacaddress;
            $comp->ComputerIP = $computerip;
            $comp->DnsZoneName = $dnszonename;
            $comp->ComputerMachineType = $computermachinetype;
            $comp->uid = $uid;
            $comp->Add();
        } else {
            $comp = new computers($uid);
            $comp->ComputerIP = $computerip;
            $comp->DnsZoneName = $dnszonename;
            $comp->ComputerMachineType = $computermachinetype;
            $comp->Edit();
        }
        $dns = new pdns($dnszonename);
        $dns->EditIPName(strtolower($ComputerRealName), $computerip, $dnstype, $computermacaddress);
    }
}
function servers_list()
{
    include_once dirname(__FILE__) . '/ressources/class.apache.inc';
    unset($_SESSION["MYSQL_PARAMETERS"]);
    $vhosts = new vhosts();
    $search = $_GET["search"];
    $MyPage = CurrentPageName();
    $page = 1;
    $users = new usersMenus();
    $DNS_INSTALLED = false;
    $tpl = new templates();
    $GLOBALS["CLASS_TPL"] = $tpl;
    $sock = new sockets();
    $where = null;
    $query_groupware = null;
    $ZarafaWebAccessInFrontEnd = $sock->GET_INFO("ZarafaWebAccessInFrontEnd");
    if (!is_numeric($ZarafaWebAccessInFrontEnd)) {
        $ZarafaWebAccessInFrontEnd = 1;
    }
    if (!$users->ZARAFA_INSTALLED) {
        $ZarafaWebAccessInFrontEnd = 0;
    }
    $FreeWebDisableSSL = intval(trim($sock->GET_INFO("FreeWebDisableSSL")));
    $addg = imgtootltip("plus-24.png", "{add} {joomlaservername}", "Loadjs('freeweb.edit.php?hostname=&force-groupware={$_GET["force-groupware"]}')");
    if ($_POST["query"] != null) {
        $search = $_POST["query"];
    }
    $q = new mysql();
    $q->QUERY_SQL("DELETE FROM freeweb WHERE servername=''", 'artica_backup');
    if ($_GET["force-groupware"] != null) {
        if ($_GET["force-groupware"] == "ZARAFA-WEBS") {
            if ($_GET["ForceInstanceZarafaID"] > 0) {
                $ForceInstanceZarafaIDQ = " AND ForceInstanceZarafaID={$_GET["ForceInstanceZarafaID"]}";
            }
            $query_groupware = " AND ((groupware='ZARAFA'{$ForceInstanceZarafaIDQ}) OR (groupware='ZARAFA_MOBILE'{$ForceInstanceZarafaIDQ}) OR (groupware='Z-PUSH'{$ForceInstanceZarafaIDQ}) OR (groupware='WEBAPP'{$ForceInstanceZarafaIDQ}))";
        }
        if ($query_groupware == null) {
            $query_groupware = " AND groupware='{$_GET["force-groupware"]}'";
        }
    }
    if (!$users->AsSystemAdministrator) {
        $whereOU = "  AND ou='{$_SESSION["ou"]}'";
        $ou = "&nbsp;&raquo;&nbsp;{$_SESSION["ou"]}";
    }
    if (strlen($search) > 1) {
        $search = "*{$search}*";
        $search = str_replace("*", "%", $search);
        $search = str_replace("%%", "%", $search);
        $whereOU = "AND (servername LIKE '{$search}' {$whereOU}{$query_groupware}) OR (domainname LIKE '{$search}' {$whereOU}{$query_groupware})";
    } else {
        $query_groupware_single = $query_groupware;
    }
    if ($users->dnsmasq_installed) {
        $DNS_INSTALLED = true;
    }
    if ($users->POWER_DNS_INSTALLED) {
        $DNS_INSTALLED = true;
    }
    $data = array();
    $data['rows'] = array();
    if (strlen($search) < 2) {
        if ($_GET["force-groupware"] != "ZARAFA-WEBS") {
            $sock = new sockets();
            $EnableWebDavPerUser = $sock->GET_INFO("EnableWebDavPerUser");
            if (!is_numeric($EnableWebDavPerUser)) {
                $EnableWebDavPerUser = 0;
            }
            $WebDavPerUserSets = unserialize(base64_decode($sock->GET_INFO("WebDavPerUserSets")));
            if ($EnableWebDavPerUser == 1) {
                $icon = "webdav-32.png";
                $groupware = div_groupware("WebDav");
                $href = "<a href=\"javascript:blur();\" \n\t\t\t\tOnClick=\"javascript:Loadjs('freeweb.webdavusr.php')\" \n\t\t\t\tstyle='font-size:13px;text-decoration:underline;font-weight:bold'>";
                $edit = imgtootltip($icon, "{apply} *.{$WebDavPerUserSets["WebDavSuffix"]}", "Loadjs('freeweb.webdavusr.php')");
                if ($WebDavPerUserSets["EnableSSL"] == 1) {
                    $ssl = "20-check.png";
                } else {
                    $ssl = "none-20.png";
                }
                $data['rows'][] = array('id' => '-200', 'cell' => array($icon, "{$href}*.{$WebDavPerUserSets["WebDavSuffix"]}</a>", "&nbsp;", "&nbsp;", "&nbsp;", "&nbsp;", "&nbsp;", "&nbsp;", "&nbsp;", "&nbsp;", "&nbsp;", "&nbsp;"));
            }
        }
    }
    if (isset($_POST["sortname"])) {
        if ($_POST["sortname"] != null) {
            $ORDER = "ORDER BY {$_POST["sortname"]} {$_POST["sortorder"]}";
        }
    }
    if (isset($_POST['page'])) {
        $page = $_POST['page'];
    }
    if (isset($_POST['rp'])) {
        $rp = $_POST['rp'];
    }
    if (!is_numeric($rp)) {
        $rp = 50;
    }
    $pageStart = ($page - 1) * $rp;
    $limitSql = "LIMIT {$pageStart}, {$rp}";
    $q = new mysql();
    $sqlCount = "SELECT COUNT(*) AS TCOUNT FROM freeweb WHERE 1 {$whereOU}{$query_groupware_single}";
    $ligne = mysql_fetch_array($q->QUERY_SQL($sqlCount, "artica_backup"));
    if (!$q->ok) {
        writelogs("{$q->mysql_error}", __FUNCTION__, __FILE__, __LINE__);
        json_error_show($q->mysql_error, 1);
    }
    $countDeRows = $ligne["TCOUNT"];
    writelogs($sqlCount . " {$countDeRows} rows", __FUNCTION__, __FILE__, __LINE__);
    if ($countDeRows == 0) {
        json_error_show("");
    }
    $total = $countDeRows;
    $data['page'] = $page;
    $data['total'] = $total;
    $members_text = $tpl->_ENGINE_parse_body("{members}");
    if (!isset($_SESSION["CheckTableWebsites"])) {
        $q->BuildTables();
        $_SESSION["CheckTableWebsites"] = true;
    }
    $sql = "SELECT * FROM freeweb WHERE 1 {$whereOU}{$query_groupware_single} {$ORDER} {$limitSql}";
    $results = $q->QUERY_SQL($sql, 'artica_backup');
    writelogs($sql . " " . mysql_num_rows($results) . " rows", __FUNCTION__, __FILE__, __LINE__);
    if (!$q->ok) {
        writelogs("{$q->mysql_error}", __FUNCTION__, __FILE__, __LINE__);
    }
    $vgservices = unserialize(base64_decode($sock->GET_INFO("vgservices")));
    $duplicate = $tpl->javascript_parse_text("{duplicate}");
    $pdns = new pdns();
    while ($ligne = mysql_fetch_array($results, MYSQL_ASSOC)) {
        if ($ligne["useSSL"] == 1) {
            $ssl = "20-check.png";
        } else {
            $ssl = "20-check-grey.png";
        }
        if ($FreeWebDisableSSL == 1) {
            $ssl = "20-check-grey.png";
        }
        $DirectorySize = FormatBytes($ligne["DirectorySize"] / 1024);
        $WebCopyID = $ligne["WebCopyID"];
        $groupware_duplicate = null;
        $statistics = "&nbsp;";
        $exec_statistics = "&nbsp;";
        $Members = null;
        $groupware = null;
        $forward_text = null;
        $checkDNS = "<img src='img/20-check-grey.png'>";
        $checkMember = "<img src='img/20-check-grey.png'>";
        $JSDNS = 0;
        if ($DNS_INSTALLED) {
            $ip = $pdns->GetIpDN($ligne["servername"]);
            if ($ip != null) {
                $checkDNS = "<img src='img/20-check.png'>";
                $JSDNS = 1;
            }
        }
        $ServerAlias = null;
        $Params = @unserialize(base64_decode($ligne["Params"]));
        $f = array();
        if (isset($Params["ServerAlias"])) {
            while (list($host, $num) = each($Params["ServerAlias"])) {
                $f[] = $host;
            }
            $ServerAlias = div_groupware("<a href=\"javascript:blur();\" \n\t\t\tOnClick=\"javascript:Loadjs('freeweb.edit.ServerAlias.php?servername={$ligne["servername"]}')\" \n\t\t\tstyle='text-decoration:underline'><i>" . @implode(", ", $f) . "</i>");
        }
        if ($ligne["uid"] != null) {
            $checkMember = "<img src='img/20-check.png'>";
        }
        $added_port = null;
        $icon = build_icon($ligne, $ligne["servername"]);
        if ($vgservices["freewebs"] != null) {
            if ($ligne["lvm_size"] > 0) {
                $ligne["lvm_size"] = $ligne["lvm_size"] * 1024;
                $sizevg = "&nbsp;<i style='font-size:11px'>(" . FormatBytes($ligne["lvm_size"]) . ")</i>";
            }
        }
        $ServerPort = $ligne["ServerPort"];
        if ($ServerPort > 0) {
            $added_port = ":{$ServerPort}";
        }
        if ($ligne["groupware"] != null) {
            $groupware = div_groupware("({{$vhosts->TEXT_ARRAY[$ligne["groupware"]]["TITLE"]}})", $ligne["enabled"]);
        }
        if ($ligne["Forwarder"] == 1) {
            $forward_text = div_groupware("{www_forward} <b>{$ligne["ForwardTo"]}</b>", $ligne["enabled"]);
        }
        $js_edit = "Loadjs('freeweb.edit.php?hostname={$ligne["servername"]}&t={$_GET["t"]}')";
        $servername_text = $ligne["servername"];
        if ($servername_text == "_default_") {
            $servername_text = "{all}";
            if ($ZarafaWebAccessInFrontEnd == 1) {
                $servername_text = "{APP_ZARAFA}";
            }
            if ($FreeWebDisableSSL == 0) {
                $ssl = "20-check.png";
            }
            $groupware = div_groupware("({default_website})", $ligne["enabled"]);
        } else {
            $checkResolv = "<img src='img/20-check.png'>";
            if (trim($ligne["resolved_ipaddr"]) == null) {
                $error_text = "{could_not_find_iphost}";
                $checkResolv = "<img src='img/20-check-grey.png'>";
            }
        }
        $colorhref = null;
        if ($ligne["enabled"] == 0) {
            $colorhref = "color:#8C8C8C";
        }
        $href = "<a href=\"javascript:blur();\" \n\t\tOnClick=\"javascript:Loadjs('freeweb.edit.php?hostname={$ligne["servername"]}&t={$_GET["t"]}')\"\n\t\tstyle='font-size:16px;text-decoration:underline;font-weight:bold;{$colorhref}'>";
        $color = "black";
        $md5S = md5($ligne["servername"]);
        $delete = icon_href("delete-32.png", "FreeWebDelete('{$ligne["servername"]}',{$JSDNS},'{$md5S}')");
        $sql = "SELECT ID FROM drupal_queue_orders WHERE `ORDER`='DELETE_FREEWEB' AND `servername`='{$ligne["servername"]}'";
        $ligneDrup = @mysql_fetch_array($q->QUERY_SQL($sql, 'artica_backup'));
        if ($ligne["ID"] > 0) {
            $edit = imgtootltip("folder-tasks-32.png", "{delete}");
            $color = "#8a8a8a";
            $delete = imgtootltip("delete-32-grey.png", "{delete} {scheduled}");
        }
        $sql = "SELECT ID FROM drupal_queue_orders WHERE `ORDER`='INSTALL_GROUPWARE' AND `servername`='{$ligne["servername"]}'";
        if ($ligne["ID"] > 0) {
            $edit = icon_href("folder-tasks-32.png", "Loadjs('freeweb.edit.php?hostname={$ligne["servername"]}')");
            $color = "#8a8a8a";
            $delete = icon_href("delete-32-grey.png");
            $groupware = div_groupware("({installing} {{$vhosts->TEXT_ARRAY[$ligne["groupware"]]["TITLE"]}})", $ligne["enabled"]);
        }
        $Params = @unserialize(base64_decode($ligne["Params"]));
        $IsAuthen = false;
        if ($Params["LDAP"]["enabled"] == 1) {
            $IsAuthen = true;
        }
        if ($Params["NTLM"]["enabled"] == 1) {
            $IsAuthen = true;
        }
        $color_orange = "#B64B13";
        if ($ligne["enabled"] == 0) {
            $color_orange = "#8C8C8C";
        }
        if ($IsAuthen) {
            $Members = "<span style='font-size:11px;font-weight:bold;color:{$color_orange};'>&nbsp;&laquo;<a href=\"javascript:blur();\" \n\t\t\tOnClick=\"javascript:Loadjs('freeweb.edit.ldap.users.php?servername={$ligne["servername"]}');\"\n\t\t\tstyle='font-size:11px;font-weight:bold;color:{$color_orange};text-decoration:underline;font-style:italic'>{$members_text}</a>\n\t\t\t&nbsp;&raquo;</span>";
        }
        $memory = "-";
        $requests_second = "-";
        $traffic_second = "-";
        $uptime = null;
        $table_name_stats = "apache_stats_" . date('Ym');
        $sql = "SELECT * FROM {$table_name_stats} WHERE servername='{$ligne["servername"]}' ORDER by zDate DESC LIMIT 0,1";
        $ligneStats = mysql_fetch_array($q->QUERY_SQL($sql, "artica_events"));
        if ($ligneStats["total_memory"] > 0) {
            $memory = FormatBytes($ligneStats["total_memory"] / 1024);
            $requests_second = "{$ligneStats["requests_second"]}/s";
            $traffic_second = FormatBytes($ligneStats["traffic_second"] / 1024) . "/s";
            $uptime = div_groupware("{uptime}:{$ligneStats["UPTIME"]}", $ligne["enabled"]);
        }
        $groupware = $tpl->_ENGINE_parse_body($groupware);
        $forward_text = $tpl->_ENGINE_parse_body($forward_text);
        $servername_text = $tpl->_ENGINE_parse_body($servername_text);
        $ServerAlias = $tpl->_ENGINE_parse_body($ServerAlias);
        $uptime = $tpl->_ENGINE_parse_body($uptime);
        $memory = $tpl->_ENGINE_parse_body($memory);
        $requests_second = $tpl->_ENGINE_parse_body("{$requests_second}");
        $traffic_second = $tpl->_ENGINE_parse_body($traffic_second);
        $checkResolv = $tpl->_ENGINE_parse_body($checkResolv);
        $checkDNS = $tpl->_ENGINE_parse_body($checkDNS);
        $checkMember = $tpl->_ENGINE_parse_body($checkMember);
        $delete = $tpl->_ENGINE_parse_body($delete);
        if ($WebCopyID > 0) {
            $ligne2 = mysql_fetch_array($q->QUERY_SQL("SELECT sitename FROM httrack_sites WHERE ID={$WebCopyID}", "artica_backup"));
            $groupware = div_groupware("WebCopy: {$ligne2["sitename"]}", $ligne["enabled"]);
        }
        if ($ligne["groupware"] == "UPDATEUTILITY") {
            $iconPlus = "<a href=\"javascript:blur();\" OnClick=\"javascript:Loadjs('UpdateUtility.php?js=yes');\"><img src='img/settings-15.png' align='left'></a>";
        }
        $servername_enc = urlencode($ligne["servername"]);
        $color_span = "#5F5656";
        if ($ligne["enabled"] == 0) {
            $color_span = "#8C8C8C";
        }
        $compile = imgsimple("apply-config-32.png", null, "Loadjs('freeweb.rebuild.progress.php?servername={$servername_enc}')");
        $enable = Field_checkbox("enable_{$md5S}", 1, $ligne["enabled"], "Loadjs('freeweb.servers.php?enable-site-js=yes&t={$_GET["t"]}&servername={$servername_enc}&enabled={$ligne["enabled"]}');");
        if ($ligne["groupware_duplicate"] != null) {
            $groupware_duplicate = "<br><span style='color:#d32d2d'>{$duplicate} :{$ligne["groupware_duplicate"]}</span>";
        }
        if ($ligne["enabled"] == 0) {
            $requests_second = "-";
            $traffic_second = "-";
            $memory = "-";
            $color = "#8C8C8C";
            $color_span = $color;
            $icon = "status_disabled.gif";
            $compile = "&nbsp;";
        }
        $spanStyle1 = "<span style='font-size:11px;font-weight:bold;color:#5F5656;'>";
        $data['rows'][] = array('id' => $md5S, 'cell' => array("<img src='img/{$icon}'>", "<strong style='font-size:13px;style='color:{$color}'>{$href}{$servername_text}</a>{$groupware_duplicate}{$iconPlus}{$groupware}{$forward_text}\n\t\t\t\t\t{$added_port}{$Members}{$sizevg}</strong></span>{$ServerAlias}{$uptime}", $compile, $enable, "{$spanStyle1}{$DirectorySize}</span>", "{$spanStyle1}{$memory}</span>", "{$spanStyle1}{$requests_second}&nbsp;|&nbsp;{$traffic_second}</span>", "<img src='img/{$ssl}'>", "{$checkResolv}", "{$checkDNS}", "{$checkMember}", $delete));
    }
    echo json_encode($data);
}
Exemple #8
0
<?php
	include_once('ressources/class.computers.inc');
	include_once('ressources/class.pdns.inc');
	
	
	$ip=$argv[1];
	
	
	$pdns=new pdns();
	
	print_r($pdns->IpToHosts($ip));
	
	echo "gethostbyaddr():". gethostbyaddr($ip)."\n";
	
	
	
	
	
	
	
	
?>
Exemple #9
0
function DNS_LINKER()
{
    include_once "ressources/class.pdns.inc";
    $ME = $_SERVER["SERVER_ADDR"];
    $content_dir = dirname(__FILE__) . "/ressources/conf/upload";
    writelogs("DNS_LINKER:: Request from " . $_SERVER["REMOTE_ADDR"] . " tmp_file={$tmp_file}", __FILE__, __FUNCTION__, __LINE__);
    writelogs("DNS_LINKER:: ->LDAP()", __FILE__, __FUNCTION__, __LINE__);
    $ldap = new clladp();
    if (preg_match("#^(.+?):(.+)#", $_POST["CREDS"], $re)) {
        $SuperAdmin = $re[1];
        $SuperAdminPass = $re[2];
    }
    if ($SuperAdmin != $ldap->ldap_admin) {
        writelogs("DNS_LINKER:: Invalid credential...", __FILE__, __FUNCTION__, __LINE__);
        header_status(500);
        echo "Invalid credential...\n";
        die("Invalid credential...");
    }
    if (md5($ldap->ldap_password) != $SuperAdminPass) {
        writelogs("DNS_LINKER:: Invalid credential...", __FILE__, __FUNCTION__, __LINE__);
        header_status(500);
        echo "Invalid credential...\n";
        die("Invalid credential...");
    }
    $TFILE = tempnam($content_dir, "dns-linker-");
    @file_put_contents($TFILE, base64_decode($_POST["DNS_LINKER"]));
    writelogs("DNS_LINKER:: zuncompress() {$TFILE}", __FILE__, __FUNCTION__, __LINE__);
    zuncompress($TFILE, "{$TFILE}.txt");
    @unlink($TFILE);
    $filesize = @filesize("{$TFILE}.txt");
    echo "{$TFILE}.txt -> {$filesize} bytes\n";
    $curlparms = unserialize(base64_decode(@file_get_contents("{$TFILE}.txt")));
    writelogs("DNS_LINKER:: Loading() {$TFILE}.txt -> ( " . count($curlparms) . " items )", __FILE__, __FUNCTION__, __LINE__);
    @unlink("{$TFILE}.txt");
    if (!is_array($curlparms)) {
        writelogs("DNS_LINKER:: Loading() curlparms no such array", __FILE__, __FUNCTION__, __LINE__);
        header_status(500);
        die;
    }
    $zdate = time();
    $sql = "SELECT name,domain_id FROM records WHERE `content`='{$curlparms["listen_addr"]}'";
    $hostname = $curlparms["hostname"];
    $q = new mysql();
    $ligne = mysql_fetch_array($q->QUERY_SQL($sql, "powerdns"));
    if ($ligne["name"] == null) {
        $tr = explode(".", $hostname);
        $netbiosname = $tr[0];
        $dnsname = str_replace("{$netbiosname}.", "", $hostname);
        $dns = new pdns($dnsname);
        $dns->EditIPName($netbiosname, $curlparms["listen_addr"], "A");
        $ligne = mysql_fetch_array($q->QUERY_SQL($sql, "powerdns"));
    }
    if ($ligne["name"] == null) {
        writelogs("DNS_LINKER:: Error, unable to get name", __FILE__, __FUNCTION__, __LINE__);
        header_status(500);
        die;
    }
    $domain_id = $ligne["domain_id"];
    $hostname_sql = $ligne["name"];
    while (list($name, $val) = each($curlparms["FREEWEBS_SRV"])) {
        if ($name == $hostname_sql) {
            continue;
        }
        $ligne = mysql_fetch_array($q->QUERY_SQL("SELECT name FROM records WHERE `name`='{$name}' AND `type`='CNAME'", "powerdns"));
        writelogs("DNS_LINKER::{$hostname_sql}:: {$name} QUERY = `{$ligne["name"]}`", __FILE__, __FUNCTION__, __LINE__);
        if ($ligne["name"] != null) {
            continue;
        }
        writelogs("DNS_LINKER:: {$name} ADD {$curlparms["listen_addr"]}", __FILE__, __FUNCTION__, __LINE__);
        $q->QUERY_SQL("INSERT INTO records (`domain_id`,`name`,`type`,`content`,`ttl`,`prio`,`change_date`)\n\t\t\tVALUES({$domain_id},'{$name}','CNAME','{$hostname_sql}','86400','0','{$zdate}')", "powerdns");
        header_status(500);
        if (!$q->ok) {
            echo $q->mysql_error . "\n";
        }
    }
    header_status(200);
    die;
}
Exemple #10
0
function replic_artica_servers_perform($host, $username, $password)
{
    $unix = new unix();
    $curl = new ccurl("https://{$host}/exec.gluster.php");
    $curl->parms["PDNS_REPLIC"] = base64_encode(serialize(array("username" => $username, "password" => md5($password))));
    if (!$curl->get()) {
        system_admin_events("Error while fetching {$host} with {$curl->error}", __FUNCTION__, __FILE__, __LINE__, "pdns");
        return;
    }
    if (preg_match("#<ERROR>(.*?)</ERROR>#is", $curl->data, $re)) {
        system_admin_events("Connection error while fetching {$host} {$re[1]}", __FUNCTION__, __FILE__, __LINE__, "pdns");
    }
    if (!preg_match("#<REPLIC>(.*?)</REPLIC>#is", $curl->data, $re)) {
        system_admin_events("Protocol error while fetching {$host}", __FUNCTION__, __FILE__, __LINE__, "pdns");
        return;
    }
    $datas = unserialize(base64_decode($re[1]));
    system_admin_events("Received " . count($datas) . " from {$host}", __FUNCTION__, __FILE__, __LINE__, "pdns");
    $sql = "DELETE FROM records WHERE articasrv='{$host}'";
    $q = new mysql();
    $q->QUERY_SQL($sql, "powerdns");
    if (!$q->ok) {
        system_admin_events($q->mysql_error . " For Host {$host}", __FUNCTION__, __FILE__, __LINE__, "pdns");
        return;
    }
    $t = time();
    $pdns = new pdns();
    $pdns->articasrv = $host;
    while (list($ip, $hostname) = each($datas)) {
        if (strpos($hostname, ".") > 0) {
            $tr = explode(".", $hostname);
            $hostname = strtolower($tr[0]);
            unset($tr[0]);
            $pdns->domainname = strtolower(@implode(".", $tr));
        }
        $pdns->EditIPName($hostname, $ip, "A");
    }
    $took = $unix->distanceOfTimeInWords($t, time(), true);
    system_admin_events("Success update " . count($datas) . " records from {$host} took:{$took}", __FUNCTION__, __FILE__, __LINE__, "pdns");
}
function item_delete()
{
    $pdns = new pdns();
    $pdns->mysql_delete_record_id($_POST["delete-item"]);
}
Exemple #12
0
function AddDNSEntry()
{
    $computername = $_GET["computername"];
    $DnsZoneName = $_GET["DnsZoneName"];
    $pse = strpos($computername, ".");
    writelogs("computername={$computername} in DNS {$DnsZoneName} pos:{$pse}", __FUNCTION__, __FILE__, __LINE__);
    if ($pse > 0) {
        $t = explode(".", $computername);
        $computername = $t[0];
        unset($t[0]);
        $DnsZoneName = @implode('.', $t);
        writelogs("SPLITED: computername={$computername} in DNS {$DnsZoneName}", __FUNCTION__, __FILE__, __LINE__);
    }
    $ComputerIP = $_GET["ComputerIP"];
    $pdns = new pdns($DnsZoneName);
    if (!$pdns->EditIPName($computername, $ComputerIP, "A", null)) {
        echo $pdns->last_error;
        return;
    }
    $sock = new sockets();
    $sock->getFrameWork("cmd.php?artica-meta-export-dns=yes");
    restart_dnsmasq();
}
Exemple #13
0
function Save()
{
    $servername = trim(strtolower($_GET["servername"]));
    if (substr($servername, 0, 1) == '.') {
        echo $servername . " FAILED\n";
        return;
    }
    $users = new usersMenus();
    $sock = new sockets();
    $FreewebsStorageDirectory = $sock->GET_INFO("FreewebsStorageDirectory");
    if (!$users->AsWebMaster) {
        return "FALSE";
    }
    $uid = $_GET["uid"];
    $mysql_database = format_mysql_table($_GET["mysql_database"]);
    $mysql_password = $_GET["mysql_password"];
    $mysql_username = $_GET["mysql_username"];
    $lvm_vg = $_GET["lvm_vg"];
    $vg_size = $_GET["vg_size"];
    $ServerPort = $_GET["ServerPort"];
    if (!is_numeric($ServerPort)) {
        $ServerPort = 0;
    }
    if ($_GET["UseDefaultPort"] == 1) {
        $ServerPort = 0;
    }
    if (!is_numeric($vg_size)) {
        $vg_size = 5000;
    }
    $ftpuser = $_GET["ftpuser"];
    $ftppassword = $_GET["ftppassword"];
    $useSSL = $_GET["useSSL"];
    if (!$users->PUREFTP_INSTALLED) {
        $_GET["useFTP"] = 0;
        $ftpuser = null;
        $ftppassword = null;
    }
    $sql = "SELECT servername FROM freeweb WHERE servername='{$_GET["servername"]}'";
    $q = new mysql();
    $ligne = @mysql_fetch_array($q->QUERY_SQL($sql, 'artica_backup'));
    if ($ligne["servername"] != null) {
        if ($uid != null) {
            $u = new user($uid);
            $ou = $u->ou;
        }
        if (!$users->AsSystemAdministrator) {
            $ou = $_SESSION["ou"];
        }
        $sql = "UPDATE freeweb SET \n\t\t\tmysql_password='******',\n\t\t\tmysql_username='******',\n\t\t\tmysql_database='{$mysql_database}',\n\t\t\tftpuser='******',\n\t\t\tftppassword='******',\n\t\t\tuid='{$uid}',\n\t\t\tuseMysql='{$_GET["useMysql"]}',\n\t\t\tuseFTP='{$_GET["useFTP"]}',\n\t\t\tlvm_vg='{$_GET["lvm_vg"]}',\n\t\t\tlvm_size='{$_GET["vg_size"]}',\n\t\t\tUseLoopDisk='{$_GET["UseLoopDisk"]}',\n\t\t\tLoopMounts='{$_GET["LoopMounts"]}',\n\t\t\tUseReverseProxy='{$_GET["UseReverseProxy"]}',\n\t\t\tProxyPass='******',\n\t\t\tuseSSL='{$useSSL}',\n\t\t\tServerPort='{$ServerPort}',\n\t\t\tou='{$ou}',\n\t\t\tForwarder='{$_GET["Forwarder"]}',\n\t\t\tForwardTo='{$_GET["ForwardTo"]}'\n\t\t\t\n\t\t\tWHERE servername='{$servername}'\n\t\t";
    } else {
        if ($uid != null) {
            $u = new user($uid);
            $ou = $u->ou;
        }
        if ($ou != null) {
            if ($FreewebsStorageDirectory != null) {
                $www_dir = "{$FreewebsStorageDirectory}/{$servername}";
            }
        }
        $sock = new sockets();
        $servername = str_replace('..', '.', $servername);
        $servername = str_replace('/', '.', $servername);
        $servername = str_replace('\\', '.', $servername);
        $servername = str_replace(' ', '.', $servername);
        $servername = str_replace('$', '.', $servername);
        $servername = str_replace('#', '.', $servername);
        $servername = str_replace('%', '.', $servername);
        $servername = str_replace('*', '.', $servername);
        if (substr($servername, strlen($servername) - 1, 1) == '.') {
            $servername = substr($servername, 0, strlen($servername) - 1);
        }
        if (substr($servername, 0, 1) == '.') {
            $servername = substr($servername, 1, strlen($servername));
        }
        $sock->getFrameWork("freeweb.php?force-resolv=yes");
        $sql = "INSERT INTO freeweb (mysql_password,mysql_username,ftpuser,ftppassword,useSSL,servername,mysql_database,\n\t\tuid,useMysql,useFTP,lvm_vg,lvm_size,UseLoopDisk,LoopMounts,ou,domainname,www_dir,ServerPort,UseReverseProxy,ProxyPass,Forwarder,ForwardTo)\n\t\tVALUES('{$mysql_password}','{$mysql_username}','{$ftpuser}','{$ftppassword}','{$useSSL}','{$servername}','{$mysql_database}',\n\t\t'{$uid}','{$_GET["useMysql"]}',\n\t\t'{$_GET["useFTP"]}','{$_GET["lvm_vg"]}','{$_GET["vg_size"]}','{$_GET["UseLoopDisk"]}','{$_GET["LoopMounts"]}','{$ou}',\n\t\t'{$_GET["domainname"]}','{$FreewebsStorageDirectory}','{$ServerPort}','{$_GET["UseReverseProxy"]}','{$_GET["ProxyPass"]}',\n\t\t'{$_GET["Forwarder"]}','{$_GET["ForwardTo"]}'\n\t\t)";
    }
    writelogs("{$sql}", __FUNCTION__, __FILE__, __LINE__);
    $q = new mysql();
    $q->BuildTables();
    $q->QUERY_SQL($sql, "artica_backup");
    if (!$q->ok) {
        echo $q->mysql_error;
        return;
    }
    $sock = new sockets();
    if ($_GET["useFTP"] == 1) {
        if ($users->PUREFTP_INSTALLED) {
            if (trim($ftpuser) != null) {
                if (trim($ftppassword) != null) {
                    $pure = new pureftpd_user();
                    if (!$pure->CreateUser($ftpuser, $ftppassword, $servername)) {
                        echo "FTP: Failed\n";
                        return;
                    }
                    $sock->getFrameWork("services.php?reload-pure-ftpd=yes");
                }
            }
        }
    }
    if ($_GET["useMysql"] == 1) {
        if (!$q->DATABASE_EXISTS($mysql_database)) {
            $q->CREATE_DATABASE("{$mysql_database}");
        }
        if (!$q->PRIVILEGES($mysql_username, $mysql_password, $mysql_database)) {
            echo "GRANT {$mysql_database} FAILED FOR {$mysql_username}\n{$q->mysql_error}";
        }
    }
    if (isset($_GET["ADD_DNS_ENTRY"])) {
        $dnsDOM = explode(".", $_GET["servername"]);
        $netbiosname = $dnsDOM[0];
        unset($dnsDOM[0]);
        $domainname = implode(".", $dnsDOM);
        include_once dirname(__FILE__) . "/ressources/class.pdns.inc";
        $pdns = new pdns($domainname);
        $pdns->EditIPName($netbiosname, $_GET["ADD_DNS_ENTRY"], "A");
    }
    $sock->getFrameWork("cmd.php?freeweb-restart=yes");
}
Exemple #14
0
function delete()
{
    writelogs("Delete server \"{$_GET["delete-servername"]}\" delete dns={$_GET["delete-dns"]}", __FUNCTION__, __FILE__, __LINE__);
    if (isset($_GET["delete-dns"])) {
        if ($_GET["delete-dns"] == 1) {
            $dns = new pdns();
            $dns->DelHostname($_GET["delete-servername"]);
        }
    }
    $sql = "INSERT INTO drupal_queue_orders(`ORDER`,`servername`) VALUES('DELETE_FREEWEB','{$_GET["delete-servername"]}')";
    writelogs($sql, __FUNCTION__, __FILE__, __LINE__);
    $q = new mysql();
    $q->QUERY_SQL($sql, "artica_backup");
    if (!$q->ok) {
        echo $q->mysql_error;
        return;
    }
    $sock = new sockets();
    $sock->getFrameWork("drupal.php?perform-orders=yes");
}
Exemple #15
0
function update_computer($ip, $mac, $name)
{
    $sock = new sockets();
    $ComputersAllowDHCPLeases = $sock->GET_INFO("ComputersAllowDHCPLeases");
    if ($ComputersAllowDHCPLeases == null) {
        $ComputersAllowDHCPLeases = 1;
    }
    if ($ComputersAllowDHCPLeases == 0) {
        writelogs("ComputersAllowDHCPLeases is disabled, aborting...", "update_computer", __FILE__, __LINE__);
        die;
    }
    $mac = trim($mac);
    $name = trim(strtolower($name));
    $ip = trim($ip);
    if ($ip == null) {
        return;
    }
    if ($mac == null) {
        return;
    }
    if ($name == null) {
        return;
    }
    $ip = nmblookup($name, $ip);
    $unix = new unix();
    $unix->add_EtcHosts($name, $ip);
    $dhcp = new dhcpd();
    $GLOBALS["domain"] = $dhcp->ddns_domainname;
    $comp = new computers();
    $uid = $comp->ComputerIDFromMAC($mac);
    if ($uid == null) {
        $add = true;
        $uid = "{$name}\$";
        $comp = new computers();
        $comp->ComputerRealName = $name;
        $comp->ComputerMacAddress = $mac;
        $comp->ComputerIP = $ip;
        $comp->DnsZoneName = $GLOBALS["domain"];
        $comp->uid = $uid;
        $ComputerRealName = $HOST;
        $comp->Add();
    } else {
        $comp = new computers($uid);
        if ($comp->ComputerRealName == null) {
            $ComputerRealName = $name;
        }
        if (preg_match("#[0-9]+\\.[0-9]+\\.#", $comp->ComputerRealName)) {
            $comp->ComputerRealName = $name;
        }
        $comp->ComputerIP = $ip;
        $comp->DnsZoneName = $GLOBALS["domain"];
        $comp->Edit();
    }
    $dns = new pdns($GLOBALS["domain"]);
    $dns->EditIPName(strtolower($name), $ip, 'A', $mac);
}
Exemple #16
0
function delete()
{
    include_once dirname(__FILE__) . "/ressources/class.squid.reverse.inc";
    $tpl = new templates();
    $servername = $_GET["delete-servername"];
    $q = new mysql_squid_builder();
    if (!$q->TABLE_EXISTS("reverse_www")) {
        $nginx = new squid_reverse();
    }
    if ($q->TABLE_EXISTS("reverse_www")) {
        $q->QUERY_SQL("DELETE FROM reverse_www WHERE servername='{$servername}'");
        if (!$q->ok) {
            echo $q->mysql_error;
            return;
        }
    }
    if ($q->TABLE_EXISTS("reverse_privs")) {
        $q->QUERY_SQL("DELETE FROM reverse_privs WHERE servername='{$servername}'");
        if (!$q->ok) {
            echo $q->mysql_error;
            return;
        }
    }
    if ($q->TABLE_EXISTS("nginx_replace_www")) {
        $q->QUERY_SQL("DELETE FROM nginx_replace_www WHERE servername='{$servername}'");
        if (!$q->ok) {
            echo $q->mysql_error;
            return;
        }
    }
    if ($q->TABLE_EXISTS("nginx_aliases")) {
        $q->QUERY_SQL("DELETE FROM nginx_aliases WHERE servername='{$servername}'");
        if (!$q->ok) {
            echo $q->mysql_error;
            return;
        }
    }
    if ($q->TABLE_EXISTS("nginx_exploits_fw")) {
        $q->QUERY_SQL("DELETE FROM nginx_exploits_fw WHERE servername='{$servername}'");
        if (!$q->ok) {
            echo $q->mysql_error;
            return;
        }
    }
    if ($q->TABLE_EXISTS("nginx_exploits")) {
        $q->QUERY_SQL("DELETE FROM nginx_exploits WHERE servername='{$servername}'");
        if (!$q->ok) {
            echo $q->mysql_error;
            return;
        }
    }
    $sock = new sockets();
    $sock->getFrameWork("squid.php?reverse-proxy-apply=yes");
    $free = new freeweb($_GET["delete-servername"]);
    if ($free->groupware == "MAILMAN") {
        $q = new mysql();
        $sql = "SELECT `list` FROM mailmaninfos WHERE `urlhost`='{$_GET["delete-servername"]}'";
        $ligne = mysql_fetch_array($q->QUERY_SQL($sql, "artica_backup"));
        if ($ligne["list"] != null) {
            echo $tpl->javascript_parse_text("{unable_freeweb_delete_mailman}\n- - {$ligne["list"]} - -\n");
            return;
        }
    }
    writelogs("Delete server \"{$_GET["delete-servername"]}\" delete dns={$_GET["delete-dns"]}", __FUNCTION__, __FILE__, __LINE__);
    if (isset($_GET["delete-dns"])) {
        if ($_GET["delete-dns"] == 1) {
            $dns = new pdns();
            $dns->DelHostname($_GET["delete-servername"]);
        }
    }
    $sql = "INSERT INTO drupal_queue_orders(`ORDER`,`servername`) VALUES('DELETE_FREEWEB','{$_GET["delete-servername"]}')";
    writelogs($sql, __FUNCTION__, __FILE__, __LINE__);
    $q = new mysql();
    $q->QUERY_SQL($sql, "artica_backup");
    if (!$q->ok) {
        echo $q->mysql_error;
        return;
    }
    $sock = new sockets();
    $sock->getFrameWork("drupal.php?perform-orders=yes");
}
function SAVE_FREEWEB_MAIN()
{
    $servername = trim(strtolower($_POST["servername"]));
    if (substr($servername, 0, 1) == '.') {
        echo $servername . " FAILED\n";
        return;
    }
    $users = new usersMenus();
    $sock = new sockets();
    $FreewebsStorageDirectory = $sock->GET_INFO("FreewebsStorageDirectory");
    if (!$users->AsWebMaster) {
        return "FALSE";
    }
    $uid = $_POST["uid"];
    $lvm_vg = $_POST["lvm_vg"];
    $vg_size = $_POST["vg_size"];
    $ServerIP = $_POST["ServerIP"];
    $ServerPort = 0;
    if (preg_match("#(.+?):([0-9]+)#", $ServerIP, $re)) {
        $ServerIP = $re[1];
        $ServerPort = $re[2];
    }
    $EnableFreeWeb = $sock->GET_INFO("EnableFreeWeb");
    if (!is_numeric($EnableFreeWeb)) {
        $EnableFreeWeb = 0;
    }
    if ($EnableFreeWeb == 0) {
        $sock->SET_INFO("EnableFreeWeb", 1);
        $sock->SET_INFO("EnableApacheSystem", 1);
        $sock->getFrameWork("freeweb.php?changeinit-off=yes");
        $sock->getFrameWork("cmd.php?restart-artica-status=yes");
        $sock->getFrameWork("cmd.php?freeweb-restart=yes");
    }
    if (!is_numeric($vg_size)) {
        $vg_size = 5000;
    }
    $useSSL = $_POST["useSSL"];
    if ($_POST["domainname"] == null) {
        $TDOM = explode(".", $_POST["domainname"]);
        unset($TDOM[0]);
        $_POST["domainname"] = @implode(".", $TDOM);
    }
    if (!isset($_POST["WebCopyID"])) {
        $_POST["WebCopyID"] = 0;
    }
    $sql = "SELECT servername FROM freeweb WHERE servername='{$_POST["servername"]}'";
    $q = new mysql();
    $ligne = @mysql_fetch_array($q->QUERY_SQL($sql, 'artica_backup'));
    if ($ligne["servername"] != null) {
        if ($uid != null) {
            $u = new user($uid);
            $ou = $u->ou;
        }
        if (!$users->AsSystemAdministrator) {
            $ou = $_SESSION["ou"];
        }
        if (isset($_POST["www_dir"])) {
            $www_dir_field = "www_dir='{$_POST["www_dir"]}',";
        }
        $sql = "UPDATE freeweb SET \n\t\t\tuid='{$uid}',\n\t\t\tgpid='{$_POST["gpid"]}',\n\t\t\tlvm_vg='{$_POST["lvm_vg"]}',\n\t\t\tlvm_size='{$_POST["vg_size"]}',\n\t\t\tUseLoopDisk='{$_POST["UseLoopDisk"]}',\n\t\t\tLoopMounts='{$_POST["LoopMounts"]}',\n\t\t\tUseReverseProxy='{$_POST["UseReverseProxy"]}',\n\t\t\tProxyPass='******',\n\t\t\tuseSSL='{$useSSL}',\n\t\t\tServerPort='{$ServerPort}',\n\t\t\t{$www_dir_field}\n\t\t\tou='{$ou}',\n\t\t\tForwarder='{$_POST["Forwarder"]}',\n\t\t\tForwardTo='{$_POST["ForwardTo"]}',\n\t\t\tServerIP='{$ServerIP}',\n\t\t\tWebCopyID='{$_POST["WebCopyID"]}',\n\t\t\tsslcertificate='{$_POST["sslcertificate"]}'\n\t\t\tWHERE servername='{$servername}'\n\t\t";
    } else {
        if ($uid != null) {
            $u = new user($uid);
            $ou = $u->ou;
        }
        if ($ou != null) {
            if ($FreewebsStorageDirectory != null) {
                $www_dir = "{$FreewebsStorageDirectory}/{$servername}";
            }
        }
        $sock = new sockets();
        $servername = strip_bad_characters($servername);
        if (substr($servername, strlen($servername) - 1, 1) == '.') {
            $servername = substr($servername, 0, strlen($servername) - 1);
        }
        if (substr($servername, 0, 1) == '.') {
            $servername = substr($servername, 1, strlen($servername));
        }
        if ($_POST["force-groupware"] != null) {
            $groupware_field = ",groupware";
            $groupware_value = ",'{$_POST["force-groupware"]}'";
        }
        if (!is_numeric($_POST["WebCopyID"])) {
            $WebCopyID_field = ",WebCopyID";
            $WebCopyID_value = ",'{$_POST["WebCopyID"]}'";
        }
        $sslcertificate = $_POST["sslcertificate"];
        $sock->getFrameWork("freeweb.php?force-resolv=yes");
        $sql = "INSERT INTO freeweb (useSSL,servername,\n\t\tuid,gpid,lvm_vg,lvm_size,UseLoopDisk,LoopMounts,ou,domainname,www_dir,ServerPort,UseReverseProxy,\n\t\tProxyPass,Forwarder,ForwardTo,ForceInstanceZarafaID,ServerIP,sslcertificate{$groupware_field}{$WebCopyID_field})\n\t\tVALUES('{$useSSL}','{$servername}','{$uid}','{$_POST["gpid"]}','{$_POST["lvm_vg"]}','{$_POST["vg_size"]}','{$_POST["UseLoopDisk"]}','{$_POST["LoopMounts"]}','{$ou}',\n\t\t'{$_POST["domainname"]}','{$FreewebsStorageDirectory}','{$ServerPort}','{$_POST["UseReverseProxy"]}','{$_POST["ProxyPass"]}',\n\t\t'{$_POST["Forwarder"]}','{$_POST["ForwardTo"]}','{$_POST["ForceInstanceZarafaID"]}','{$ServerIP}','{$sslcertificate}'{$groupware_value}{$WebCopyID_value}\n\t\t)";
    }
    writelogs("{$sql}", __FUNCTION__, __FILE__, __LINE__);
    $q = new mysql();
    $q->BuildTables();
    $q->QUERY_SQL($sql, "artica_backup");
    if (!$q->ok) {
        echo "Function " . __FUNCTION__ . "\nLine:" . __LINE__ . "\nFile:" . __FILE__ . "\n" . $q->mysql_error;
        return;
    }
    if ($_POST["www_dir"] != null) {
        $sql = "UPDATE freeweb SET `www_dir`='{$_POST["www_dir"]}' WHERE servername='{$servername}'";
        $q->QUERY_SQL($sql, "artica_backup");
        if (!$q->ok) {
            echo "Function " . __FUNCTION__ . "\nLine:" . __LINE__ . "\nFile:" . __FILE__ . "\n" . $q->mysql_error;
            return;
        }
    }
    $sock = new sockets();
    if (isset($_POST["ADD_DNS_ENTRY"])) {
        $dnsDOM = explode(".", $_POST["servername"]);
        $netbiosname = $dnsDOM[0];
        unset($dnsDOM[0]);
        $domainname = implode(".", $dnsDOM);
        include_once dirname(__FILE__) . "/ressources/class.pdns.inc";
        $pdns = new pdns($domainname);
        $pdns->EditIPName($netbiosname, $_POST["ADD_DNS_ENTRY"], "A");
    }
    if ($ligne["servername"] == null) {
        if ($_POST["force-groupware"] != null) {
            $sql = "INSERT INTO drupal_queue_orders(`ORDER`,`servername`) VALUES('INSTALL_GROUPWARE','{$servername}')";
            $q = new mysql();
            $q->QUERY_SQL($sql, "artica_backup");
            $sock->getFrameWork("freeweb.php?rebuild-vhost=yes&servername={$servername}");
        }
    }
    $sock->getFrameWork("services.php?freeweb-start=yes");
    sleep(2);
    $sock->getFrameWork("cmd.php?freeweb-restart=yes");
    $sock->getFrameWork("freeweb.php?rebuild-vhost=yes&servername={$servername}");
}
function pdns_save()
{
    if (!preg_match("#(.+?)\\.(.+)\$#", $_GET["www"], $re)) {
        echo "Unable to find the domain name";
        exit;
    }
    $pdns = new pdns($re[2]);
    $pdns->EditIPName($re[1], $_GET["pdns_ip"], "A");
    echo "{$re[2]} [{$re[1]}] => {$_GET["pdns_ip"]}";
}
function DNS_ENTRY($value)
{
    $EXEC_NICE = EXEC_NICE();
    if (is_file("/usr/bin/nohup")) {
        $nohup = "/usr/bin/nohup ";
    }
    $reload_datas = $nohup . $EXEC_NICE . LOCATE_PHP5_BIN() . " " . dirname(__FILE__) . "/exec.artica.meta.users.php --export-all-dns >/dev/null 2>&1 &";
    include_once dirname(__FILE__) . "/ressources/class.pdns.inc";
    $array = unserialize(base64_decode($value));
    if (!is_array($array)) {
        send_email_events("Failed to add/modify DNS entry (not an array)", null, "CLOUD");
        shell_exec($reload_datas);
        return true;
    }
    $sock = new sockets();
    $MAC = $array["MAC"];
    $computername = $array["hostname"];
    $DnsZoneName = $array["DOMAIN"];
    $ComputerIP = $array["IP"];
    $tbl = explode(".", $computername);
    $computername = $tbl[0];
    if ($DnsZoneName == null) {
        unset($tbl[0]);
        $DnsZoneName = @implode(".", $tbl);
    }
    writelogs("Adding New dns entry {$computername} ({$ComputerIP}) mac:{$MAC} in \"{$DnsZoneName}\" domain", __FUNCTION__, __FILE__, __LINE__);
    $pdns = new pdns($DnsZoneName);
    if (!$pdns->EditIPName($computername, $ComputerIP, "A", $MAC)) {
        send_email_events("Failed to add/modify DNS entry {$computername} {$pdns->last_error}", null, "CLOUD");
        shell_exec($reload_datas);
        return true;
    } else {
        send_email_events("Success to add/modify DNS entry {$computername} ({$ComputerIP})", null, "CLOUD");
        return true;
    }
}
Exemple #20
0
function Save()
{
    $servername = trim(strtolower($_GET["servername"]));
    if (substr($servername, 0, 1) == '.') {
        echo $servername . " FAILED\n";
        return;
    }
    $users = new usersMenus();
    $sock = new sockets();
    $tpl = new templates();
    $FreewebsStorageDirectory = $sock->GET_INFO("FreewebsStorageDirectory");
    if (!$users->AsWebMaster) {
        return "FALSE";
    }
    $uid = $_GET["uid"];
    $mysql_database = format_mysql_table($_GET["mysql_database"]);
    $mysql_password = $_GET["mysql_password"];
    $mysql_username = $_GET["mysql_username"];
    $lvm_vg = $_GET["lvm_vg"];
    $vg_size = $_GET["vg_size"];
    $ServerIP = $_GET["ServerIP"];
    $ServerPort = 0;
    if (preg_match("#(.+?):([0-9]+)#", $ServerIP, $re)) {
        $ServerIP = $re[1];
        $ServerPort = $re[2];
    }
    if (!is_numeric($vg_size)) {
        $vg_size = 5000;
    }
    $ftpuser = $_GET["ftpuser"];
    $ftppassword = $_GET["ftppassword"];
    $useSSL = $_GET["useSSL"];
    if (!$users->PUREFTP_INSTALLED) {
        $_GET["useFTP"] = 0;
        $ftpuser = null;
        $ftppassword = null;
    }
    $sql = "SELECT servername FROM freeweb WHERE servername='{$_GET["servername"]}'";
    $q = new mysql();
    $ligne = @mysql_fetch_array($q->QUERY_SQL($sql, 'artica_backup'));
    if ($ligne["servername"] != null) {
        if ($uid != null) {
            $u = new user($uid);
            $ou = $u->ou;
        }
        if (!$users->AsSystemAdministrator) {
            $ou = $_SESSION["ou"];
        }
        $sql = "UPDATE freeweb SET \n\t\t\tmysql_password='******',\n\t\t\tmysql_username='******',\n\t\t\tmysql_database='{$mysql_database}',\n\t\t\tmysql_instance_id='{$_GET["mysql_instance_id"]}',\n\t\t\tftpuser='******',\n\t\t\tftppassword='******',\n\t\t\tuid='{$uid}',\n\t\t\tgpid='{$_GET["gpid"]}',\n\t\t\tuseMysql='{$_GET["useMysql"]}',\n\t\t\tuseFTP='{$_GET["useFTP"]}',\n\t\t\tlvm_vg='{$_GET["lvm_vg"]}',\n\t\t\tlvm_size='{$_GET["vg_size"]}',\n\t\t\tUseLoopDisk='{$_GET["UseLoopDisk"]}',\n\t\t\tLoopMounts='{$_GET["LoopMounts"]}',\n\t\t\twww_dir='{$_GET["www_dir"]}',\n\t\t\tUseReverseProxy='{$_GET["UseReverseProxy"]}',\n\t\t\tProxyPass='******',\n\t\t\tuseSSL='{$useSSL}',\n\t\t\tServerPort='{$ServerPort}',\n\t\t\tou='{$ou}',\n\t\t\tForwarder='{$_GET["Forwarder"]}',\n\t\t\tForwardTo='{$_GET["ForwardTo"]}',\n\t\t\tServerIP='{$ServerIP}'\n\t\t\tWHERE servername='{$servername}'\n\t\t";
    } else {
        $ApacheServerName = $sock->GET_INFO("ApacheServerName");
        if ($ApacheServerName == null) {
            $ApacheServerName = $users->fqdn;
        }
        if ($uid != null) {
            $u = new user($uid);
            $ou = $u->ou;
        }
        if ($ou != null) {
            if ($FreewebsStorageDirectory != null) {
                $www_dir = "{$FreewebsStorageDirectory}/{$servername}";
            }
        }
        $sock = new sockets();
        $servername = str_replace('..', '.', $servername);
        $servername = str_replace('/', '.', $servername);
        $servername = str_replace('\\', '.', $servername);
        $servername = str_replace(' ', '.', $servername);
        $servername = str_replace('$', '.', $servername);
        $servername = str_replace('#', '.', $servername);
        $servername = str_replace('%', '.', $servername);
        $servername = str_replace('*', '.', $servername);
        if (substr($servername, strlen($servername) - 1, 1) == '.') {
            $servername = substr($servername, 0, strlen($servername) - 1);
        }
        if (substr($servername, 0, 1) == '.') {
            $servername = substr($servername, 1, strlen($servername));
        }
        if ($servername == $ApacheServerName) {
            echo $tpl->javascript_parse_text("{virtual_hostname_cannot_same_main_hostname}", 1);
            return;
        }
        if ($_GET["force-groupware"] != null) {
            $groupware_field = ",groupware";
            $groupware_value = ",'{$_GET["force-groupware"]}'";
        }
        if ($_GET["www_dir"] != null) {
            $www_dir_field = ",www_dir";
            $www_dir_value = ",'{$_GET["www_dir"]}'";
        }
        $sock->getFrameWork("freeweb.php?force-resolv=yes");
        $sql = "INSERT INTO freeweb (mysql_password,mysql_username,ftpuser,ftppassword,useSSL,servername,mysql_database,\n\t\tuid,gpid,useMysql,useFTP,lvm_vg,lvm_size,UseLoopDisk,LoopMounts,ou,domainname,www_dir,ServerPort,UseReverseProxy,\n\t\tProxyPass,Forwarder,ForwardTo,ForceInstanceZarafaID,mysql_instance_id,ServerIP{$groupware_field}{$www_dir_field})\n\t\tVALUES('{$mysql_password}','{$mysql_username}','{$ftpuser}','{$ftppassword}','{$useSSL}','{$servername}','{$mysql_database}',\n\t\t'{$uid}','{$_GET["gpid"]}','{$_GET["useMysql"]}',\n\t\t'{$_GET["useFTP"]}','{$_GET["lvm_vg"]}','{$_GET["vg_size"]}','{$_GET["UseLoopDisk"]}','{$_GET["LoopMounts"]}','{$ou}',\n\t\t'{$_GET["domainname"]}','{$FreewebsStorageDirectory}','{$ServerPort}','{$_GET["UseReverseProxy"]}','{$_GET["ProxyPass"]}',\n\t\t'{$_GET["Forwarder"]}','{$_GET["ForwardTo"]}','{$_GET["ForceInstanceZarafaID"]}','{$_GET["mysql_instance_id"]}','{$ServerIP}'{$groupware_value}{$www_dir_value}\n\t\t)";
    }
    writelogs("{$sql}", __FUNCTION__, __FILE__, __LINE__);
    $q = new mysql();
    $q->BuildTables();
    $q->QUERY_SQL($sql, "artica_backup");
    if (!$q->ok) {
        echo $q->mysql_error;
        return;
    }
    $sock = new sockets();
    $sock->getFrameWork("system.php?dns-linker=yes");
    if ($_GET["useFTP"] == 1) {
        if ($users->PUREFTP_INSTALLED) {
            if (trim($ftpuser) != null) {
                if (trim($ftppassword) != null) {
                    $pure = new pureftpd_user();
                    if (!$pure->CreateUser($ftpuser, $ftppassword, $servername)) {
                        echo "FTP: Failed\n";
                        return;
                    }
                    $sock->getFrameWork("services.php?reload-pure-ftpd=yes");
                }
            }
        }
    }
    if ($_GET["useMysql"] == 1) {
        if (!$q->DATABASE_EXISTS($mysql_database)) {
            $q->CREATE_DATABASE("{$mysql_database}");
        }
        if (!$q->PRIVILEGES($mysql_username, $mysql_password, $mysql_database)) {
            echo "GRANT {$mysql_database} FAILED FOR {$mysql_username}\n{$q->mysql_error}";
        }
    }
    if (isset($_GET["ADD_DNS_ENTRY"])) {
        $dnsDOM = explode(".", $_GET["servername"]);
        $netbiosname = $dnsDOM[0];
        unset($dnsDOM[0]);
        $domainname = implode(".", $dnsDOM);
        include_once dirname(__FILE__) . "/ressources/class.pdns.inc";
        $pdns = new pdns($domainname);
        $pdns->EditIPName($netbiosname, $_GET["ADD_DNS_ENTRY"], "A");
    }
    if ($ligne["servername"] == null) {
        if ($_GET["force-groupware"] != null) {
            $sql = "INSERT INTO drupal_queue_orders(`ORDER`,`servername`) VALUES('INSTALL_GROUPWARE','{$servername}')";
            $q = new mysql();
            $q->QUERY_SQL($sql, "artica_backup");
            $sock->getFrameWork("freeweb.php?rebuild-vhost=yes&servername={$servername}");
        }
    }
    $sock->getFrameWork("services.php?freeweb-start=yes");
    sleep(2);
    $sock->getFrameWork("cmd.php?freeweb-restart=yes");
}
function update_computer($ip, $mac, $name)
{
    $sock = new sockets();
    $ComputersAllowDHCPLeases = $sock->GET_INFO("ComputersAllowDHCPLeases");
    if ($ComputersAllowDHCPLeases == null) {
        $ComputersAllowDHCPLeases = 1;
    }
    if ($ComputersAllowDHCPLeases == 0) {
        localsyslog("`ComputersAllowDHCPLeases` Aborting updating the LDAP database");
        return;
    }
    $mac = trim($mac);
    $name = trim(strtolower($name));
    $ip = trim($ip);
    if ($ip == null) {
        return;
    }
    if ($mac == null) {
        return;
    }
    if ($name == null) {
        return;
    }
    $mac = strtolower(str_replace("-", ":", $mac));
    $ipClass = new IP();
    if ($ipClass->isIPAddress($name)) {
        localsyslog("`{$name}` is a TCP IP address, aborting updating the LDAP database");
        return;
    }
    $ip = nmblookup($name, $ip);
    $dhcp = new dhcpd();
    $GLOBALS["domain"] = $dhcp->ddns_domainname;
    $comp = new computers();
    $uid = $comp->ComputerIDFromMAC($mac);
    if (strpos($name, ".") > 0) {
        $NAMETR = explode(".", $name);
        $name = $NAMETR[0];
        unset($NAMETR[0]);
        $GLOBALS["domain"] = @implode(".", $NAMETR);
    }
    if ($ipClass->isIPAddress($uid)) {
        $comp = new computers($uid);
        localsyslog("Removing computer ({$uid}) {$mac}");
        $comp->DeleteComputer();
        $uid = null;
        $uid = $comp->ComputerIDFromMAC($mac);
    }
    localsyslog("{$mac} -> uid:`{$uid}`");
    if ($uid == null) {
        $add = true;
        $uid = "{$name}\$";
        $comp = new computers();
        $comp->ComputerRealName = $name;
        $comp->ComputerMacAddress = $mac;
        $comp->ComputerIP = $ip;
        $comp->DnsZoneName = $GLOBALS["domain"];
        $comp->uid = $uid;
        $ComputerRealName = $name;
        localsyslog("Create new computer {$name[$ip]} ({$uid}) {$mac} in domain {$comp->DnsZoneName}");
        $comp->Add();
    } else {
        $comp = new computers($uid);
        if (strpos($comp->ComputerRealName, ".") > 0) {
            $NAMETR = explode(".", $name);
            $comp->ComputerRealName = $NAMETR[0];
        }
        if ($comp->ComputerRealName == null) {
            $comp->ComputerRealName = $name;
        }
        if ($ipClass->isIPAddress($comp->ComputerRealName)) {
            $comp->ComputerRealName = $name;
        }
        $comp->ComputerIP = $ip;
        $comp->DnsZoneName = $GLOBALS["domain"];
        localsyslog("Update computer {$comp->ComputerRealName}[{$ip}] ({$uid}) {$mac} in domain {$comp->DnsZoneName}");
        $comp->Edit();
    }
    $dns = new pdns($GLOBALS["domain"]);
    $dns->EditIPName(strtolower($name), $ip, 'A', $mac);
}
function import($fileenc, $domain)
{
    $domain = trim($domain);
    if (preg_match("#--#", $domain)) {
        $domain = null;
    }
    $q = new mysql();
    $q->BuildTables();
    $filename = base64_decode($fileenc);
    if (!is_file($filename)) {
        echo "{$filename}, no such file...\n";
        return;
    }
    echo "{$filename}, Open file\n";
    $f = file($filename);
    $F = 0;
    $S = 0;
    while (list($index, $line) = each($f)) {
        $line = trim($line);
        $line = str_replace("\r", "", $line);
        $line = str_replace("\n", "", $line);
        $line = str_replace("\r\n", "", $line);
        if ($line == null) {
            continue;
        }
        if (substr($line, 0, 1) == "#") {
            continue;
        }
        $posDieze = strpos($line, "#");
        if ($posDieze > 0) {
            if ($posDieze < 5) {
                continue;
            }
        }
        $Obs = substr($line, $posDieze, strlen($line));
        $line = str_replace($Obs, "", $line);
        $Obs = trim(utf8_encode($Obs));
        if (strlen($Obs) > 2) {
            $Obs = trim(str_replace("#", "", $Obs));
        }
        if (!preg_match("#^([0-9\\.]+)\\s+(.+?)\$#", $line, $re)) {
            continue;
        }
        $IP = trim($re[1]);
        $domainname = $domain;
        $hostname = trim(strtolower($re[2]));
        if (strpos($hostname, " ") > 0) {
            $tze = explode(" ", $hostname);
            while (list($a, $b) = each($tze)) {
                if (trim($b) == null) {
                    continue;
                }
                $tzf[] = $b;
            }
            if (strlen($tzf[0]) > 2) {
                $hostname = $tzf[0];
            }
        }
        $netbiosname = $hostname;
        if (strpos($hostname, ".") > 0) {
            $tb = explode(".", $hostname);
            $netbiosname = $tb[0];
            unset($tb[0]);
            $domainname = trim(@implode(".", $tb));
        }
        $host = $netbiosname . "." . $domainname;
        $pdns = new pdns($domainname);
        if (!$pdns->EditIPName($netbiosname, $IP, "A", null, $Obs)) {
            echo "Item [{$re[1]}] - `{$host}` ({$Obs}) failed\n";
            $F++;
        } else {
            echo "Item [{$re[1]}] - `{$host}` ({$Obs}) Success\n";
            $S++;
        }
    }
    echo "Success: {$S} item(s), Failed: {$F} item(s)\n";
}