| ".htmlentities ($key)." | ";
if (is_array($value)) {
$table .= N_ArrayToTable ($value, $table_spacing, $table_cell_properties);
} else {
$table .= "".str_replace ([" ", "\n"], [" ", " "], htmlentities ($value)).""; } $table .= " |
";
if (N_CLI()) {
if (is_array($object)) {
echo '(arr: ' . N_Count ($object) . ')'.PHP_EOL;
print_r($object);
} else if (is_string($object)) {
$lineCount = ($object === '') ? 0 : preg_match_all("/\r\n|\r|\n/", $object) + 1;
echo '(str: ' . strlen($object) . ', lines: ' . $lineCount . ')' . PHP_EOL;
print_r($object);
} else if (is_bool($object)) {
echo '(' . gettype($object) . ') '.PHP_EOL;
echo $object ? "true" : "false";
} else {
echo '(' . gettype($object) . ') '.PHP_EOL;
print_r($object);
}
} else {
echo '';
if (is_array($object)) {
echo '(arr: ' . N_Count ($object) . ')'.PHP_EOL;
echo htmlentities(print_r($object, 1), 2, 'ISO-8859-1'); // ENT_COMPAT | ENT_HTML401 = 2
} else if (is_string($object)) {
$lineCount = ($object === '') ? 0 : preg_match_all("/\r\n|\r|\n/", $object) + 1;
echo '(str: ' . strlen($object) . ', lines: ' . $lineCount . ')' . PHP_EOL;
echo htmlentities(print_r($object, 1), 2, 'ISO-8859-1'); // ENT_COMPAT | ENT_HTML401 = 2
} else if (is_bool($object)) {
echo '(' . gettype($object) . ') '.PHP_EOL;
echo $object ? "true" : "false";
} else {
echo '(' . gettype($object) . ') '.PHP_EOL;
echo htmlentities(print_r($object, 1), 2, 'ISO-8859-1'); // ENT_COMPAT | ENT_HTML401 = 2
}
echo ''; // ENT_COMPAT | ENT_HTML401 = 2
}
if (count ($args) > 1) echo " | ";
}
if (count ($args) > 1) echo "
' : '';
$offset = 0;
$len = strlen($data);
$x = ($uppercase === false) ? 'x' : 'X';
for ($i = $j = 0; $i < $len; ++$i) {
$hexi .= sprintf("%02$x ", ord($data[$i]));
if (ord($data[$i]) >= 32) {
$ascii .= ($htmloutput === true) ? htmlentities($data[$i]) : $data[$i];
} else {
$ascii .= '.';
}
if ($j === 7 || $j === 13 || $j === 23) {
$hexi .= ' ';
$ascii .= ' ';
}
if (++$j === 32 || $i === $len - 1) {
$dump .= sprintf("%04$x %-49s %s", $offset, $hexi, $ascii);
$hexi = $ascii = '';
$offset += 32;
$j = 0;
if ($i !== $len - 1) {
$dump .= "\n";
}
}
}
$dump .= $htmloutput === true ? '' : '';
$dump .= "\n";
return $dump;
}
function N_GUID($chars = 32) {
if ($chars > 32) {
return N_GUID() . N_GUID($chars - 32);
} else {
global $LastGUID;
$LastGUID = md5(getmypid() . time() . microtime() . serialize($_SERVER) . $LastGUID);
return substr($LastGUID, 0, $chars);
}
}
function N_Year() {
return date('Y');
}
function N_Regexp($string, $patern, $index = 1) {
if (preg_match_all("#$patern#i", $string, $matches) === false) {
return null;
}
return $matches[0][$index - 1];
}
function N_Windows() {
return strtoupper(substr(PHP_OS, 0, 3)) === 'WIN';
}
function N_GetPage ($url, $maxms=-1) {
M1 ();
if ($maxms != -1) {
$ch = curl_init($url);
curl_setopt ($ch, CURLOPT_TIMEOUT_MS, 1000 + $maxms); // maximum time the transfer is allowed to complete
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT_MS, 100 + $maxms); // timeout for the connect phase
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
return M2R (curl_exec($ch));
} else {
return M2R (file_get_contents($url));
}
}
function N_KeepAfter($body, $marker) {
if ('' . $marker == '') {
return $body;
}
if (strpos($body, $marker) === false) {
return '';
} else {
return substr($body, strpos($body, $marker) + strlen($marker));
}
}
function N_KeepBefore($body, $marker) {
if ('' . $marker == '') {
return $body;
}
if (strpos($body, $marker) === false) {
return '';
} else {
return substr($body, 0, strpos($body, $marker));
}
}
function N_CheckPortsDefault() {
return [21 => 'FTP', 22 => 'SSH', 23 => 'Telnet', 25 => 'SMTP', 80 => 'HTTP', 139 => 'NetBIOS', 143 => 'IMAP', 389 => 'LDAP', 443 => 'HTTPS', 3306 => 'MariaDB', 3389 => 'RDP', 8006 => 'Proxmox'];
}
function N_CheckPortsConcurrent($targets, $ports_to_check = [], $timeout = 3) {
if (!$ports_to_check) $ports_to_check = N_CheckPortsDefault();
$results = $socks = [];
$ports = array_keys($ports_to_check);
foreach ($targets as $target) {
$ip = gethostbyname($target);
if ($ip === $target) {
foreach ($ports as $port) $results[$target][$port] = "DNS failed";
continue;
}
foreach ($ports as $port) {
$key = "$target:$port";
if (($sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP)) === false) {
$results[$target][$port] = "Socket error";
continue;
}
socket_set_nonblock($sock);
@socket_connect($sock, $ip, $port);
$socks[$key] = $sock;
$results[$target][$port] = "Gesloten/Gefilterd";
}
}
$start = microtime(true);
while ($socks && (microtime(true) - $start < $timeout)) {
$write = $socks;
$read = $except = null;
if (@socket_select($read, $write, $except, 1) > 0) {
foreach ($write as $key => $sock) {
if (socket_get_option($sock, SOL_SOCKET, SO_ERROR) === 0) {
[$t, $p] = explode(':', $key);
$results[$t][$p] = "Open";
}
unset($socks[$key]);
socket_close($sock);
}
}
}
foreach ($socks as $sock) socket_close($sock);
return $results;
}
function N_ReportPortsConcurrent($targets, $ports_to_check=[], $timeout = 3) {
if (!$ports_to_check) $ports_to_check = N_CheckPortsDefault();
$reports = N_CheckPortsConcurrent($targets, $ports_to_check, $timeout);
$result = "";
$result .= "| Host | "; foreach ($ports_to_check as $port => $name) { $result .= "$port ($name) | "; } $result .= "
|---|---|
| $target | "; foreach ($ports_to_check as $port => $name) { $status = $report[$port] ?? "Onbekend"; $result .= "$status | "; } $result .= "
| ";
foreach ($dirs as $e) {
$extra = "";
if (!strstr($e, "pnkit_")) if ($search) if (!in_array ($e, $skiplist)) {
$rii = new RecursiveIteratorIterator(new RecursiveDirectoryIterator("$dir/$e"));
$rii->setMaxDepth(0);
foreach ($rii as $x) {
if (is_file($x->getPathname()) && filesize($x->getPathname()) < 1024 * 1024) {
if (in_array (strtolower (pathinfo ($x->getPathname(), PATHINFO_EXTENSION)), $validextensions)) {
$content = file_get_contents($x->getPathname());
if (stripos(" $content", $search)) $extra = "FOUND";
}
}
}
} else {
$extra = "skipped";
}
if ($search) {
echo "[$e] $extra \n"; } else { echo "[$e] $extra \n"; } } echo " "; foreach ($files as $e) if (strpos($e, ".php")) { // All php files $extra = ""; if ($search) { $content = file_get_contents("$dir/$e"); if (stripos(" $content", $search)) $extra = "FOUND"; } echo "[$e] $extra \n"; } echo " "; foreach ($files as $e) if (!strpos($e, ".php")) { // All other files < 1 MB $extra = ""; if ($search && filesize("$dir/$e") < 1024 * 1024 && in_array (strtolower (pathinfo ($e, PATHINFO_EXTENSION)), $validextensions)) { $content = file_get_contents("$dir/$e"); if (stripos(" $content", $search)) $extra = "FOUND"; } echo "[$e] $extra \n"; } echo " | ";
$sortedfiles_subs = array();
foreach ($dirs as $e) {
if (!strstr($e, "pnkit_")) if (!in_array ($e, $skiplist)) {
$rii = new RecursiveIteratorIterator(new RecursiveDirectoryIterator("$dir/$e"));
$rii->setMaxDepth(0);
foreach ($rii as $x) {
if (is_file($x->getPathname()) && filesize($x->getPathname()) < 1024 * 1024) {
if (in_array (strtolower (pathinfo ($x->getPathname(), PATHINFO_EXTENSION)), $validextensions)) {
$sortedfiles_subs[filemtime ($x->getPathname())] = str_replace ("$dir/", "", $x->getPathname());
}
}
}
}
}
$ctr = 0;
foreach ($sortedfiles as $t => $e) if (strpos($e, ".php") || strpos($e, ".css") || strpos($e, ".scss") || strpos($e, ".js")) {
echo "".date ("Y-m-d H:i:s", $t)." [$e] \n"; if (++$ctr==10) break; } echo " "; krsort($sortedfiles_subs); $ctr = 0; foreach ($sortedfiles_subs as $t => $e) if (strpos($e, ".php") || strpos($e, ".css") || strpos($e, ".scss") || strpos($e, ".js")) { echo "".date ("Y-m-d H:i:s", $t)." [$e] \n"; if (++$ctr==10) break; } echo " |
';
N_GlobalProfiler (4 * 3600);
echo "
";
$entries = @scandir($GLOBALS['pnkit_data_dir']);
$rows = [];
foreach ($entries as $name) {
if (strpos($name, "profile") === false) continue;
$st = @lstat($GLOBALS['pnkit_data_dir'] . "/$name");
$rows[] = ['mtime' => $st['mtime'], 'name' => $name, 'size' => $st['size']];
}
usort($rows, function ($a, $b) { return ($a['mtime'] > $b['mtime']) ? -1 : 1; });
foreach ($rows as $r) {
$url = $_SERVER["SCRIPT_NAME"] . "?pnkit=txtedit&file=".urlencode($GLOBALS['pnkit_data_dir'] . "/" . $r['name']);
echo sprintf("%10d %s %s", $r['size'], date('M d H:i', $r['mtime']), $r['name'])." view
";
}
} else if ($module == "ulog") {
puuse ("ulog");
ULOG_Show();
echo "
Server response time: ".round(MS())." ms, showing {$GLOBALS["ULOG_Show_rows"]} rows";
if ($_REQUEST["lines"] == $GLOBALS["ULOG_Show_rows"]) {
echo " (max)";
} else {
echo " (< {$_REQUEST["lines"]})";
}
echo ".";
} else if ($module == "log") {
touch($GLOBALS["pnkit_data_dir"] . "/debuglog.html");
echo implode("\n", array_slice(array_reverse(explode("\n", file_get_contents($GLOBALS["pnkit_data_dir"] . "/debuglog.html"))), 0, 100));
echo "
More...";
} else if ($module == "morelog") {
touch($GLOBALS["pnkit_data_dir"] . "/debuglog.html");
echo implode("\n", array_slice(array_reverse(explode("\n", file_get_contents($GLOBALS["pnkit_data_dir"] . "/debuglog.html"))), 0, 10000));
echo "
Even more? Look at: ".$GLOBALS["pnkit_data_dir"] . "/debuglog.html";
} else if ($module == "slog") {
puuse("secure");
echo "
This security log show files changed since the last time the security log was viewed (generating this can take some time).
" . str_repeat(" ", 7000000);
flush();
SECURE_DeltaScanAllAndLog("/var/www");
SECURE_ShowLog();
}
echo "\n";
}
/******************************************************************************/
// INIT #2
function PNKIT_Init2() {
if (N_CLI()) $_REQUEST["argv"] = $_SERVER["argv"];
if (!@$GLOBALS["pnkit_mode"]) $GLOBALS["pnkit_mode"] = "offline";
$pathinfo = pathinfo(__FILE__);
if ($pathinfo["dirname"]) $pathinfo2 = pathinfo($pathinfo["dirname"]);
if (!@$GLOBALS["pnkit_version"]) $GLOBALS["pnkit_version"] = file_get_contents($pathinfo["dirname"] . "/.pnkit_version");
if (!$GLOBALS["pnkit_data_dir"]) {
if (N_CLI() && N_Windows()) {
$GLOBALS["pnkit_data_dir"] = $_ENV["APPDATA"] . "\\pnkit_data_dir";
@mkdir($GLOBALS["pnkit_data_dir"]);
} else if (N_CLI()) {
$GLOBALS["pnkit_data_dir"] = $_SERVER["HOME"] . "/pnkit_data_dir";
} else if ($pathinfo2["dirname"] && @file_exists($pathinfo2["dirname"] . "/pnkit_data_dir")) {
$GLOBALS["pnkit_data_dir"] = $pathinfo2["dirname"] . "/pnkit_data_dir";
} else if ($_SERVER["DOCUMENT_ROOT"] && @file_exists($_SERVER["DOCUMENT_ROOT"] . "/pnkit_data_dir")) {
$GLOBALS["pnkit_data_dir"] = $_SERVER["DOCUMENT_ROOT"] . "/pnkit_data_dir";
} else if (@file_exists(getcwd() . "/pnkit_data_dir")) {
$GLOBALS["pnkit_data_dir"] = getcwd() . "/pnkit_data_dir";
$_SERVER["DOCUMENT_ROOT"] = getcwd(); // In case DOCUMENT_ROOT makes no sense, e.g. 000webhost.com
} else if (session_save_path()) {
$sessionpath = session_save_path();
if (strpos($sessionpath, ";") !== FALSE)
$sessionpath = substr($sessionpath, strpos($sessionpath, ";") + 1);
$GLOBALS["pnkit_data_dir"] = $sessionpath . "/pnkit_data_dir";
} else {
$GLOBALS["pnkit_data_dir"] = sys_get_temp_dir() . "/pnkit_data_dir";
}
}
if (!$GLOBALS["pnkit_public_cache_dir_internal"]) {
if (N_CLI() && N_Windows()) {
$GLOBALS["pnkit_public_cache_dir_external"] = "***";
$GLOBALS["pnkit_public_cache_dir_internal"] = $_ENV["APPDATA"] . "\\pnkit_public_cache_dir";
@mkdir($GLOBALS["pnkit_public_cache_dir"]);
} else if (N_CLI()) {
$GLOBALS["pnkit_public_cache_dir_external"] = "***";
$GLOBALS["pnkit_public_cache_dir_internal"] = $_SERVER["HOME"] . "/pnkit_public_cache_dir";
} else {
$GLOBALS["pnkit_public_cache_dir_external"] = "/pnkit_public_cache_dir";
$GLOBALS["pnkit_public_cache_dir_internal"] = $_SERVER['DOCUMENT_ROOT'] . $GLOBALS["pnkit_public_cache_dir_external"];
}
}
if (!$GLOBALS["pnkit_owner_ip"]) {
$GLOBALS["pnkit_owner_ip"] = PMB_Load ("globalvars", "pnkit_owner_ip");
if (!$GLOBALS["pnkit_owner_ip"]) {
$ip = gethostbyname("home.nicodevries.com");
if ($ip && $ip !== "home.nicodevries.com") {
PMB_Save ("globalvars", "pnkit_owner_ip", $ip);
$GLOBALS["pnkit_owner_ip"] = $ip;
}
}
}
if (N_CLI() || $_SERVER["REMOTE_ADDR"] == $GLOBALS["pnkit_owner_ip"] || $_SERVER["REMOTE_ADDR"] == "127.0.0.1") {
$GLOBALS["owner"] = true;
error_reporting(E_ERROR | E_PARSE | E_CORE_ERROR | E_COMPILE_ERROR | E_RECOVERABLE_ERROR);
ini_set('display_errors', 1);
@set_time_limit(7200);
} else {
error_reporting(E_ERROR | E_PARSE | E_CORE_ERROR | E_COMPILE_ERROR | E_RECOVERABLE_ERROR); // Log, but do not show, the most relevant errors
ini_set('display_errors', 0);
}
if ($GLOBALS["pnkit_classic"]) {
// Keep old crap working
foreach ($_REQUEST as $var => $val) {
$var = str_replace ("-", "_", $var);
@eval("global \$$var; \$$var=unserialize(base64_decode('" . base64_encode(serialize($val)) . "'));");
}
foreach ($_SERVER as $var => $val) {
$var = str_replace ("-", "_", $var);
@eval("global \$$var; \$$var=unserialize(base64_decode('" . base64_encode(serialize($val)) . "'));");
}
if (!headers_sent()) header("Content-Type: text/html; charset=ISO-8859-1");
} else {
if (!headers_sent()) header('Content-Type: text/html; charset=utf-8');
}
if (!ini_get('date.timezone')) date_default_timezone_set("Europe/Amsterdam");
if (!file_exists($GLOBALS["pnkit_data_dir"])) {
mkdir($GLOBALS["pnkit_data_dir"]);
}
if (!file_exists($GLOBALS["pnkit_public_cache_dir_internal"])) {
@mkdir($GLOBALS["pnkit_public_cache_dir_internal"]);
}
if (N_CLI() && N_Windows()) {
@mkdir($_ENV["APPDATA"] . "\\pnkit_winassets");
if ($GLOBALS["pnkit_mode"] == "online") {
puuse("sys");
SYS_PNKIT_Download("winmanifest2", $_ENV["APPDATA"] . "\\pnkit_winassets\\", "/winassets/");
}
}
}
PNKIT_Init2();
function PNKIT_Handler() {
if (array_key_exists("pnkitassets", $_REQUEST)) {
$relurl = N_KeepAfter($_SERVER["QUERY_STRING"], "pnkitassets=/");
$ext = pathinfo($relurl, PATHINFO_EXTENSION);
$mimemap = N_MimeMap();
if ($mimemap[$ext]) {
$mime = $mimemap[$ext];
} else {
$mime = "text/plain";
}
header("Content-Type: $mime");
$content = N_GetPage("https://fastsimple.com/pnkit/$relurl");
if (strpos($relurl, "7.2.0-web")) {
$content = str_replace("'../fonts/fontawesome", "'" . $_SERVER["SCRIPT_NAME"] . "?pnkitassets=/webassets/fontawesome-pro-7.2.0-web/fonts/fontawesome", $content);
} else {
$content = str_replace("'../fonts/fontawesome", "'" . $_SERVER["SCRIPT_NAME"] . "?pnkitassets=/webassets/startbootstrap-sb-admin-2-1.0.8/bower_components/font-awesome/fonts/fontawesome", $content);
$content = str_replace("\"font/context-menu-icons.", "\"" . $_SERVER["SCRIPT_NAME"] . "?pnkitassets=/webassets/npm_packages/node_modules/jquery-contextmenu/dist/font/context-menu-icons.", $content);
$content = str_replace("url(font/context-menu-icons.", "url(" . $_SERVER["SCRIPT_NAME"] . "?pnkitassets=/webassets/npm_packages/node_modules/jquery-contextmenu/dist/font/context-menu-icons.", $content);
$content = str_replace("sourceMappingURL=bootstrap.min.css.map", "sourceMappingURL=" . $_SERVER["SCRIPT_NAME"] . "?pnkitassets=/webassets/startbootstrap-sb-admin-2-1.0.8/bower_components/bootstrap/dist/css/bootstrap.min.css.map", $content);
$content = str_replace("sourceMappingURL=jquery.min.map", "sourceMappingURL=" . $_SERVER["SCRIPT_NAME"] . "?pnkitassets=/webassets/startbootstrap-sb-admin-2-1.0.8/bower_components/jquery/dist/jquery.min.map", $content);
}
$etag = md5($content);
header("Etag: $etag");
if (@trim($_SERVER['HTTP_IF_NONE_MATCH']) == $etag) {
header("HTTP/1.1 304 Not Modified");
die("");
}
$seconds_to_cache = 604800;
$ts = gmdate("D, d M Y H:i:s", time() + $seconds_to_cache) . " GMT";
header("Expires: $ts");
header("Pragma: cache");
header("Cache-Control: max-age=$seconds_to_cache");
die($content);
}
if (array_key_exists("pnkitdynasset", $_REQUEST)) {
header('Content-Type: ' . $_REQUEST["mime"]);
if ($_REQUEST["id"]) {
die(PMB_Load("n_dynasset", $_REQUEST["id"]));
} else {
die(base64_decode($_REQUEST["b64_data"]));
}
}
if (array_key_exists("pnkitexec", $_REQUEST)) {
N_HandleExecInBackground($_REQUEST["key"]);
die();
}
if (array_key_exists("pnkitexecnow", $_REQUEST)) {
N_HandleExecNow ($_REQUEST["pnkitexecnow"]);
die();
}
if (array_key_exists("pnkit", $_REQUEST)) {
N_PNKIT();
die();
}
if (array_key_exists("pnkit_ui_ajax", $_REQUEST)) {
puuse ("ui");
UI_HandleAjax ($_REQUEST);
die();
}
if (array_key_exists("pnkit_pwa_ajax", $_REQUEST)) {
puuse ("pwa");
PWA_HandleAjax ($_REQUEST);
die();
}
}
PNKIT_Handler();
/******************************************************************************/
// END
} // if (!function_exists ("puuse"))