require("lib/functions.php"); $user_agent = $_SERVER["HTTP_USER_AGENT"]; $action = 1; $stage = "init"; if (isset($_REQUEST["getscript"])) { $action = 2; } if (isset($_REQUEST['ip'])) { $ip = $_REQUEST['ip']; } else { $ip = $_SERVER['REMOTE_ADDR']; } $config_file ="configs/$ip"; if (!is_readable($config_file)) { $config_file = "default.conf"; } if (is_readable($config_file)) { $fh = fopen($config_file, "r"); } else { print "Can not open file: $config_file\n"; die; } if (!preg_match('/^fetch libfetch/', $user_agent, $matches)) print "
\n";
while (!feof ($fh)) {
$buffer = fgets($fh, 1048576);
if (preg_match('/(^#|^\n+|^\n\r+)/', $buffer, $matches))
continue;
if (preg_match('/%([-a-z]+)$/', $buffer, $matches)) {
if ($action == 2 && strcmp($matches[1], "post"))
continue;
if (strcmp($matches[1], $stage)){
if (!($action == 2 && !strcmp($matches[1], "post"))){
add_stage_data($stage,"post");
}
if ($action == 1 && !strcmp($matches[1], "post"))
break;
add_stage_data($matches[1],"pre");
}
$stage = $matches[1];
continue;
}
$me = selfURL();
if ($action == 1) {
if (!strcmp("sysinstall", $stage)) {
preg_match("/^([^\=]+)=([a-z]+)[[:space:]]+([0-9kMGTPE]+[[:space:]]+(.+))/", $buffer, $matches);
if (empty($matches[4])) {
print "$buffer";
} else {
print "$matches[1]=$matches[2] " . convert_to_sector_size($matches[3]) . " $matches[4]\n";
}
}
if (!strcmp("packages", $stage)) {
print "package=".$buffer;
print "addPackage\n";
}
} elseif ($action == 2) {
if (!strcmp("post", $stage))
print "$buffer";
}
}
print "# Generated by pflsa ($config_file)\n";
if (!preg_match('/fetch libfetch/', $user_agent, $matches))
print "";
fclose($fh);
?>