function formdata_validate($data) { $errors = array(); if ($data['Network_Protocol'] == "static") { if (!validateIpAddress($data['Network_Gateway'])) { $errors['Network_Gateway'] = true; } for ($i = 0; $i < 2; $i++) { if ($data['dns' . $i]) { if (!validateIpAddress($data['dns' . $i])) { $errors['Network_DNS' . $i] = true; } } } } foreach ($data['Network_Additional_LAN'] as $Network) { if (!preg_match('/^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\/\\d{1,2}$/', $Network)) { if (!preg_match('/^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\/\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$/', $Network)) { $errors['Network_Additional_LAN'][] = $Network; } } } if ($data['Network_UseNAT'] == '1') { if (!preg_match('/^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$/', $data['Network_ExternalAddress'])) { $errors['Network_ExternalAddress']['Invalid'] = true; } } return $errors; }
function validateHostName($url) { if (validateIpAddress($url)) { return true; } else { if (preg_match('|^[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i', $url)) { return true; } else { return false; } } }
$old_ip = trim($_POST['old_ip']); $new_ip = trim($_POST['new_ip']); if (strlen($old_ip) < 8) { echo 'You must enter old IP address'; exit; } if (strlen($new_ip) < 8) { echo 'You must enter new IP address'; exit; } if (!validateIpAddress($old_ip)) { echo 'Invalid IP adddress : ' . $old_ip; exit; } if (!validateIpAddress($new_ip)) { echo 'Invalid IP adddress : ' . $new_ip; exit; } $domains_txt = $_POST['domains']; $domains = explode("\n", $domains_txt); $num_domains = count($domains); echo '<pre>'; for ($i = 0; $i < $num_domains; $i++) { $domain = trim($domains[$i]); if (strlen($domain) > 3) { echo "replace {$old_ip} {$new_ip} -- /var/named/{$domain}.db\n"; } } echo "service named restart\n"; ##############################
function syncSubdomains($file = '', $domainname) { $this->requireCommandLine(__FUNCTION__); echo "\nstart syncing sub domains, "; if ($file == '') { $file = "apachehcp_subdomains.conf"; } $arr = $this->query("select * from " . $this->conf['subdomainstable']['tablename']); $webserverip = $this->getWebServer(); $success = True; $arr2 = array(); $ips = array(); $webserver_template_filename = "{$this->ehcpdir}/apache_subdomain_template"; if ($arr) { foreach ($arr as $dom) { // setup necessry dirs/files if doesnt exist.. $subdir = $dom['homedir']; print "\nProcessing subdir: {$subdir} \n"; $this->initialize_subdomain_files($dom, $domainname); $dom['customsubdomainhttp'] = ''; $dom['webserverip'] = $webserverip; # modified at 27.4.2014 if ($dom['webserverips'] != '') { list($i) = explode(',', $dom['webserverips']); if (validateIpAddress($i)) { echo "\nThis subdomain has custom webserverips,adjusting:" . $dom['subdomain'] . "." . $dom['domainname'] . ":" . $dom['webserverips']; $dom['webserverip'] = $i; # if entered in db exclusively. # diger ip ler ne olacak ? sanirim multiserver fonksiyonlarinda halledilecek... # todo: this part will be reorganized. if subdomain contains specific IP,this part is wrong in this situation. Config should be built for each subdomain, not in array_to_file below.. switch ($this->miscconfig['webservertype']) { case 'apache2': $webserver_template_filename = "{$this->ehcpdir}/apache_subdomain_template_ipbased"; break; case 'nginx': $webserver_template_filename = "{$this->ehcpdir}/etc/nginx/apache_subdomain_template.nginx"; break; # other servers, if multi-ip supported } if (!in_array($i, $ips)) { $ips[] = $i; } if (!in_array($webserverip, $ips)) { $ips[] = $webserverip; } # add default ip too. } } $arr2[] = $dom; # arr2 used because, customsubdomainhttp is used or similar... if (!file_exists($subdir . "/ehcpinfo.html")) { passthru2("cp -f ehcpinfo.html " . $subdir . "/ehcpinfo.html"); } } } # you may see daemon mode output at logfile, typically tail -f /var/log/ehcp.log from command line echo __FUNCTION__ . ": syncing subdomains:"; print_r($arr2); if ($this->putArrayToFile($arr2, $file, $webserver_template_filename)) { $this->echoln("SUBDOMAINS-Domain list exported (" . __FUNCTION__ . ")\n"); } else { $success = false; } return $success; }
// Setting up the MySQL Connection $mysqlhost = "localhost"; // MySQL-Host angeben $mysqluser = "******"; // MySQL-User angeben $mysqlpwd = "bdd"; // Passwort angeben $mysqldb = "bot"; // Gewuenschte Datenbank angeben $connection = mysql_connect($mysqlhost, $mysqluser, $mysqlpwd) or die("Verbindungsversuch fehlgeschlagen"); mysql_select_db($mysqldb, $connection) or die("Konnte die Datenbank nicht waehlen."); // Get IP-Address $ip = $_SERVER['REMOTE_ADDR']; $user = $_POST['user']; $pass = $_POST['pass']; $auth_type = $_POST['auth_type']; // Is the POST-Variable "init" set? if (validateIpAddress($ip) && isset($user) && isset($user)) { $sql = "SELECT * FROM login WHERE ip ='" . $ip . "' AND user = '******'"; $adressen_query = mysql_query($sql) or die("Anfrage nicht erfolgreich"); $anzahl = mysql_num_rows($adressen_query); // Es existiert bereits ein Eintrag mit dieser IP und Benutzer, also Updaten... if ($anzahl === 1) { $sql = "UPDATE login SET pass = '******', auth_type = '" . $auth_type . "', last_login = NOW() WHERE ip ='" . $ip . "' AND user = '******'"; } else { $sql = "INSERT INTO login (ip, user, pass, auth_type, last_login) VALUES ('" . $ip . "', '" . $user . "', '" . $pass . "', '" . $auth_type . "', NOW())"; } $adressen_query = mysql_query($sql) or die("Anfrage nicht erfolgreich"); } else { echo "Error"; }
function doPost() { global $error, $conf_centreon; $db = dbConnect($conf_centreon['hostCentreon'], $conf_centreon['user'], $conf_centreon['password'], $conf_centreon['db'], true); if (isset($_POST["net"])) { $nbPlage = mysql_query("SELECT count(*) FROM mod_discovery_rangeip WHERE id!=0;"); $nbPlageData = mysql_fetch_array($nbPlage); if ($nbPlageData[0] <= 15) { $tmp = explode(" ", $_POST["net"]); if (isset($tmp[1])) { if (validateIpAddress($tmp[0]) && validateMask($tmp[1])) { $netAddr = ip2Subnet($tmp[0], $tmp[1]); if (mysql_num_rows(mysql_query("SELECT * FROM mod_discovery_rangeip WHERE plage='" . $netAddr . "';")) == 0) { $poller = findPoller($netAddr, maskToCidr($tmp[1])); if (!mysql_query("INSERT INTO mod_discovery_rangeip (plage,masque,cidr,nagios_server_id) VALUES('" . $netAddr . "','" . $tmp[1] . "','" . maskToCidr($tmp[1]) . "','" . $poller["poller_id"] . "');")) { echo mysql_error(); } } else { $error = 2; } } else { $error = 1; } } else { $tmp = explode("/", $_POST["net"]); if ($tmp[1]) { if (validateIpAddress($tmp[0]) && validateCidr($tmp[1])) { $netAddr = ip2Subnet($tmp[0], cidrToMask($tmp[1])); if (mysql_num_rows(mysql_query("SELECT * FROM mod_discovery_rangeip WHERE plage='" . $netAddr . "';")) == 0) { $poller = findPoller($netAddr, $tmp[1]); if (!mysql_query("INSERT INTO mod_discovery_rangeip (plage,masque,cidr,nagios_server_id) VALUES('" . $netAddr . "','" . cidrToMask($tmp[1]) . "','" . $tmp[1] . "','" . $poller["poller_id"] . "');")) { echo mysql_error(); } } else { $error = 2; } } else { $error = 1; } } else { $error = 1; } } } else { $error = 3; } unset($_POST); } if (isset($_POST["ClearAll"])) { if ($_POST["ClearAll"] == " Clear All ") { clearArray(); } } if (isset($_GET["id"])) { clearRow($_GET["id"]); unset($_GET); } doInput($error); doFormTab($error); dbClose($db); }
$prefs = Preferences::getInstance(); $all_prefs = $prefs->get('HA', 'high_availability'); if (isset($all_prefs["VIP"])) { $ret = ShellExec::exec_shell_cmd("reload_vip", $all_prefs["VIP"], "0", "0"); checkConfigurationHasChanged(true); popup_info(_('Changing configuration... Please wait a few seconds')); } else { popup_error(_('Changing configuration failded... Verify configuration at field HA::Virtual IP')); } break; case "delete": deleteAllUnregisteredServers($SQL, $table); break; case "update_vip": if (isset($_POST["ha_vip"])) { if (validateIpAddress($_POST["ha_vip"])) { $t = updateVIP($_POST["ha_vip"]); redirect("configuration.php"); } else { popup_error(sprintf(_('Virtual IP "%s" is not valid!'), $_POST["ha_vip"])); } } break; default: break; } } page_header(); echo '<div>'; echo '<h1>' . _('Configuration') . '</h1>'; echo '<div>';
} //if format of ip address doesn't matches } // Setting up the MySQL Connection $mysqlhost = "localhost"; // MySQL-Host angeben $mysqluser = "******"; // MySQL-User angeben $mysqlpwd = "bdd"; // Passwort angeben $mysqldb = "bot"; // Gewuenschte Datenbank angeben $connection = mysql_connect($mysqlhost, $mysqluser, $mysqlpwd) or die("Verbindungsversuch fehlgeschlagen"); mysql_select_db($mysqldb, $connection) or die("Konnte die Datenbank nicht waehlen."); // Get IP-Address $ip = $_SERVER['REMOTE_ADDR']; // Is the POST-Variable "init" set? if (validateIpAddress($ip) && isset($_POST['init']) && intval($_POST['init']) === 1) { $sql = "SELECT * FROM active WHERE ip ='" . $ip . "'"; $adressen_query = mysql_query($sql) or die("Anfrage nicht erfolgreich"); $anzahl = mysql_num_rows($adressen_query); // Es existiert bereits ein Eintrag mit dieser IP, also Updaten... if ($anzahl === 1) { $sql = "UPDATE active SET last_keep_alive = NOW() WHERE ip = '" . $ip . "'"; } else { $sql = "INSERT INTO active (ip, init_keep_alive, last_keep_alive) VALUES ('" . $ip . "', NOW(), NOW())"; } $adressen_query = mysql_query($sql) or die("Anfrage nicht erfolgreich"); } else { echo "Error"; }