/dev/null | /usr/bin/tr -s ' ' '\n'",$relinfo); array_shift($relinfo); $rellist = []; foreach($relinfo as $rel): $arel = preg_split("/\s+/",ltrim($rel)); $relname = chop($arel[0]); if(substr($relname,-1) === '*'): $relname = substr($relname,0,strlen($relname) - 1); endif; $rellist[$relname] = []; endforeach; return $rellist; } // Get all interface list. function get_all_interface_list() { global $g; exec("/bin/echo; /sbin/ifconfig -l | /usr/bin/tr -s ' ' '\n'; /bin/echo 'Config'",$linkinfo); array_shift($linkinfo); $iflist = []; foreach($linkinfo as $link): $alink = preg_split("/\s+/",ltrim($link)); $ifname = chop($alink[0]); if(substr($ifname,-1) === '*'): $ifname = substr($ifname,0,strlen($ifname) - 1); endif; $iflist[$ifname] = []; endforeach; return $iflist; } // list base releases $a_release = get_all_release_list(); $l_release = []; foreach($a_release as $k_release => $release): $l_release[$k_release] = $k_release; endforeach; // list of configured interfaces $a_interface = get_all_interface_list(); $l_interfaces = []; foreach($a_interface as $k_interface => $ifinfo): $l_interfaces[$k_interface] = $k_interface; endforeach; // ===== CACHE FUNCTIONS ===== function is_cache_valid() { if (!file_exists(JAIL_INFO_CACHE_FILE)) { return false; } $cache_age = time() - filemtime(JAIL_INFO_CACHE_FILE); return $cache_age < JAIL_INFO_CACHE_TIME; } function get_cached_jail_info() { if (!is_cache_valid()) { return null; } $cache_data = @file_get_contents(JAIL_INFO_CACHE_FILE); if ($cache_data === false) { return null; } return json_decode($cache_data, true); } function save_jail_info_cache($data) { @file_put_contents(JAIL_INFO_CACHE_FILE, json_encode($data)); } function invalidate_jail_cache() { @unlink(JAIL_INFO_CACHE_FILE); } // ===== OPTIMIZED: Get jail infos ===== // Get jail infos - OPTIMIZED VERSION function get_jail_infos() { global $img_path; global $image_dir; global $configfile; global $jail_dir; // Try cache first $cached = get_cached_jail_info(); if ($cached !== null) { return $cached; } $result = []; if (!is_dir($jail_dir)) { return $result; } // OPTIMIZATION: Get bastille list ONCE and parse all jails // Format: JID Name Boot Prio State Type IP_Address Published_Ports Release Tags $cmd = '/usr/local/bin/bastille list 2>&1'; mwexec2($cmd, $rawdata); // Build a lookup table from bastille list output $jail_data_map = []; $header_skipped = false; foreach ($rawdata as $line) { // Skip header line if (!$header_skipped) { $header_skipped = true; continue; } // Parse fields: JID Name Boot Prio State Type IP Ports Release Tags $fields = preg_split('/\s+/', trim($line), 10); if (count($fields) >= 6) { $name = $fields[1]; $jail_data_map[$name] = [ 'jid' => $fields[0], 'boot' => $fields[2], 'prio' => $fields[3], 'state' => $fields[4], 'type' => $fields[5], 'ip' => $fields[6] ?? '-', 'ports' => $fields[7] ?? '-', 'release' => $fields[8] ?? '-', 'tags' => $fields[9] ?? '-' ]; } } // Now process each jail from bastille list jail (for jail names) $cmd = '/usr/local/bin/bastille list jail 2>&1'; mwexec2($cmd, $jail_names); foreach ($jail_names as $line) { $a = preg_split('/\t/', $line); $r = []; $name = $a[0]; if (preg_match('/(.*)/', $name, $m)) { $r['name'] = $m[1]; } else { $r['name'] = '-'; } $r['jailname'] = $r['name']; $item = $r['jailname']; // Get data from our lookup table instead of executing bastille list again if (isset($jail_data_map[$item])) { $jail_data = $jail_data_map[$item]; $r['id'] = $jail_data['jid']; $r['boot'] = $jail_data['boot']; $r['prio'] = $jail_data['prio']; $r['state'] = $jail_data['state']; $r['type'] = $jail_data['type']; $r['ip'] = $jail_data['ip']; $r['ports'] = $jail_data['ports']; $r['rel'] = $jail_data['release']; $r['tags'] = $jail_data['tags']; } else { // Fallback if jail not in bastille list output $r['id'] = '-'; $r['boot'] = '-'; $r['prio'] = '-'; $r['state'] = '-'; $r['type'] = '-'; $r['ip'] = '-'; $r['ports'] = '-'; $r['rel'] = '-'; $r['tags'] = '-'; } // Set defaults for empty values if (!$r['id']) $r['id'] = "-"; if (!$r['boot']) $r['boot'] = "-"; if (!$r['prio']) $r['prio'] = "-"; if (!$r['state']) $r['state'] = "-"; if (!$r['type']) $r['type'] = "-"; if (!$r['ip']) $r['ip'] = "-"; if (!$r['ports']) $r['ports'] = "-"; if (!$r['rel']) $r['rel'] = "-"; if (!$r['tags']) $r['tags'] = "-"; // Display running status icons if ($r['state'] == "Up") { $r['stat'] = $img_path['ena']; } else { $r['stat'] = $img_path['dis']; } // Display custom template icons if available $template_icon = "{$jail_dir}/{$item}/plugin_icon.png"; if (file_exists($template_icon)) { if (!file_exists("{$image_dir}/{$item}_icon.png")) { @copy("$template_icon", "{$image_dir}/{$item}_icon.png"); } $r['logo'] = "{$image_dir}/{$item}_icon.png"; } else { $template_icon = exec("/usr/bin/grep linsysfs {$jail_dir}/{$item}/fstab 2>/dev/null"); if ($template_icon) { // Display standard Linux icon $r['logo'] = "{$image_dir}/linux_icon.png"; } else { // Display standard FreeBSD icon $r['logo'] = "{$image_dir}/bsd_icon.png"; } } $result[] = $r; } // Save to cache save_jail_info_cache($result); return $result; } ?>