From 127a9061b2af28e3cb59f67b5cf7268b59d312cd Mon Sep 17 00:00:00 2001 From: "Suren A. Chilingaryan" Date: Wed, 4 Jul 2018 23:08:02 +0200 Subject: Initial release --- index.php | 226 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 226 insertions(+) create mode 100644 index.php (limited to 'index.php') diff --git a/index.php b/index.php new file mode 100644 index 0000000..61f4650 --- /dev/null +++ b/index.php @@ -0,0 +1,226 @@ + $server) { + if (find_mac($server['macs'], $mac_header)) + return get_server($srvid); + } + return false; +} + +function find_server_by_header($http_header, $value) { + global $SERVER_LIST; + + foreach ($SERVER_LIST as $srvid => $server) { + if ((is_array($server["headers"]))&&(isset($server["headers"][$http_header]))) { + $expected = $server["headers"][$http_header]; + if (!is_array($expected)) $expected = array($expected); + foreach ($expected as $re) { + if (preg_match("/$re/", $value)) + return get_server($srvid); + } + } + } + return false; +} + +function find_server() { + global $DEFAULT_SERVER; + global $_SERVER; + + $headers = getallheaders(); + for ($i = 0; $i < 10; $i++) { + $if = "X-RHN-Provisioning-MAC-$i"; + if (!isset($headers[$if])) break; + + $server = find_server_by_mac($headers[$if]); + if ($server) return $server; + } + + foreach ($_SERVER as $header => $value) { + $server = find_server_by_header($header, $value); + if ($server) return $server; + } + + if (isset($DEFAULT_SERVER)) { + return get_server($DEFAULT_SERVER); + } + + return false; +} + + + + +$server = find_server(); + +$f = fopen("/srv/www/htdocs/ands/logs/kickstart.log", "a+"); +if ($f) { + fprintf($f, "%s %s\n", $_SERVER["REMOTE_ADDR"], ($server?$server["fqdn"]:"-")); + fclose($f); +} + +if (!$server) { + $f = fopen("/srv/www/htdocs/ands/logs/kickstart-new.log", "a+"); + if ($f) { + fwrite($f, print_r($_SERVER, true)); + fwrite($f, print_r(getallheaders(), true)); + fclose($f); + } + return; +} + +$templates = get_templates($server); + +$ks = file_get_contents($server["ks"]); + + +$patterns=array(); $values=array(); +foreach ($templates as $key => $val) { + array_push($patterns, "/@" . strtoupper($key) . "@/"); + array_push($values, $val); +} +$ks = preg_replace($patterns, $values, $ks); + + +$patterns=array(); $values=array(); +foreach ($server as $key => $val) { + array_push($patterns, "/@" . strtoupper($key) . "@/"); + if (is_bool($val)) { + if (preg_match("/^skip_/", $key)) { + if ($val) $val = "#"; + else $val = ""; + } elseif (preg_match("/^enable_/", $key)) { + if ($val) $val = ""; + else $val = "#"; + } else { + if ($val) $val = 1; + else $val = 0; + } + } + array_push($values, $val); +} + +foreach ($DISTRIBUTIONS as $distrib) { + array_push($patterns, "/@" . strtoupper($distrib) . "@/"); + array_push($values, (strcasecmp($distrib, $DISTRIBUTION)?"#":"")); +} + +//print_r($patterns); + +$ks = preg_replace($patterns, $values, $ks); + +if ($VERBOSE) { + $f = fopen("/srv/www/htdocs/ands/logs/kickstart-verbose.log", "a+"); + if ($f) { + fwrite($f, "-----------------------------------------------------\n"); + fwrite($f, print_r($server, true)); + fwrite($f, print_r($_SERVER, true)); + fwrite($f, print_r(getallheaders(), true)); + fwrite($f, "-----------------------------------------------------\n"); + fwrite($f, $ks); + fwrite($f, "=====================================================\n"); + fclose($f); + } +} + +header("Content-type: text/plain"); +echo $ks; + +?> -- cgit v1.2.3