function fetch_node_inv($dbfilepath) { global $allncpu, $allcpufreq, $allphysmem, $allnodes, $nodetable, $alljails, $knownfreq, $workdir; ?> <form id="editor" action="save.php" method="post"> <div class="buttons"> <input id="edit-area-cancel" name="yt0" type="button" value="Cancel"> <input id="edit-area-ok" type="submit" name="save" value="Commit"> </div> </form> <?php $stat = file_exists($dbfilepath); if (!$stat) { $nodetable .= "<tr><td bgcolor=\"#CCFFCC\">{$allnodes}</td><td colspan=10><center>{$dbfilepath} not found</center></td></tr>"; return 0; } $db = new SQLite3($dbfilepath); $db->busyTimeout(5000); $results = $db->query('SELECT COUNT(*) FROM jails;'); if (!$results instanceof Sqlite3Result) { $numjails = 0; } else { while ($row = $results->fetchArray()) { $numjails = $row[0]; } } $gwinfo = ""; $netres = $db->query('SELECT ip4,ip6,mask4,mask6 FROM net;'); if (!$netres instanceof Sqlite3Result) { echo "Error: {$dbfilepath}"; $gwinfo = "unable to fetch net info"; } else { while ($row = $netres->fetchArray()) { for ($i = 0; $i < 4; $i++) { if (isset($row[$i])) { $gwinfo .= $row[$i] . " "; } } } } $netres = $db->query('SELECT * FROM gw;'); if (!$netres instanceof Sqlite3Result) { } else { while ($row = $netres->fetchArray()) { for ($i = 0; $i < 4; $i++) { if (isset($row[$i])) { $gwinfo .= $row[$i] . " "; } } } } $results = $db->query('SELECT nodename,nodeip,fs,ncpu,physmem,cpufreq,osrelease FROM local;'); if (!$results instanceof Sqlite3Result) { $nodetable .= <<<EOF \t\t<tr> \t\t\t<td bgcolor="#CCFFCC">{$allnodes}</td><td colspan=10></td> \t\t</tr> EOF; } else { while ($row = $results->fetchArray()) { list($nodename, $nodeip, $fs, $ncpu, $physmem, $cpufreq, $osrelease) = $row; $descrfile = $workdir . "/var/db/nodedescr/" . $nodename . ".descr"; $desc = ""; if (file_exists($descrfile)) { $fp = fopen($descrfile, "r"); $size = filesize($descrfile); if ($size > 0) { $desc = fread($fp, filesize($descrfile)); } fclose($fp); } $locfile = $workdir . "/var/db/nodedescr/" . $nodename . ".location"; $loc = ""; if (file_exists($locfile)) { $fp = fopen($locfile, "r"); $size = filesize($locfile); if ($size > 0) { $loc = fread($fp, filesize($locfile)); } fclose($fp); } $notesfile = $workdir . "/var/db/nodedescr/" . $nodename . ".notes"; $notes = ""; if (file_exists($notesfile)) { $fp = fopen($notesfile, "r"); $size = filesize($notesfile); if ($size > 0) { $notes = fread($fp, filesize($notesfile)); } fclose($fp); } $idle = check_locktime($nodeip); if ($idle == 0) { $hdr = '<tr rel="${nodename}" style="background-color:#D6D2D0">'; } else { $hdr = '<tr rel="${nodename}">'; } $nodetable .= <<<EOF \t\t\t{$hdr} \t\t\t\t<td bgcolor="#CCFFCC" class="node-name" data-file="descr" data-type="text">{$nodename}</td> \t\t\t\t<td data-togle="toolkip" title="{$gwinfo}">{$nodeip}</td> \t\t\t\t<td class="edited" data-file="descr" data-type="textarea">{$desc}</td> \t\t\t\t<td class="edited" data-file="location" data-type="text">{$loc}</td> \t\t\t\t<td>{$osrelease}</td> \t\t\t\t<td>{$fs}</td> \t\t\t\t<td>{$physmem}</td> \t\t\t\t<td>{$ncpu}</td> \t\t\t\t<td>{$cpufreq}</td> \t\t\t\t<td>{$numjails}</td> \t\t\t\t<td class="edited" data-file="notes" data-type="textarea">{$notes}</td> \t\t\t</tr> EOF; $allncpu += $ncpu; $allphysmem += $physmem; $allcpufreq += $cpufreq; $alljails += $numjails; if ($cpufreq > 1) { $knownfreq++; } } } $db->close(); }
$sql = "SELECT nodename,ip FROM nodelist"; $result = $db->query($sql); //->fetchArray(SQLITE3_ASSOC); $row = array(); $i = 0; while ($res = $result->fetchArray(SQLITE3_ASSOC)) { if (!isset($res['nodename'])) { continue; } $nodename = $res['nodename']; $nodeip = $res['ip']; ++$allnodes; $path = $workdir . "/var/db/"; $postfix = ".sqlite"; $dbpath = $path . chop($nodename) . $postfix; $idle = check_locktime($nodeip); if ($idle == 0) { $offlinenodes++; } fetch_node_inv($dbpath); } if ($offlinenodes == 0) { $offlinecolor = "#FFFF99"; } else { $offlinecolor = "#FF9B77"; } if ($knownfreq > 0) { $avgfreq = round($allcpufreq / $knownfreq); } else { $avgfreq = 0; }
function show_bhyvevm($nodelist = "local") { global $workdir; $pieces = explode(" ", $nodelist); ?> <table class="images"> <thead> <tr> <th>node</th> <th>vm</th> <th>vm_ram</th> <th>vm_cpus</th> <th>vm_os_type</th> <th>status</th> <th>action</th> <th>remove</th> </tr> </thead> <tbody> <?php foreach ($pieces as $nodename) { if (!$nodename) { $nodename = $nodelist; } $db = new SQLite3("{$workdir}/var/db/{$nodename}.sqlite"); $db->busyTimeout(5000); $sql = "SELECT jname,vm_ram,vm_cpus,vm_os_type FROM bhyve;"; $result = $db->query($sql); //->fetchArray(SQLITE3_ASSOC); $row = array(); $i = 0; if ($nodename != "local") { $nodeip = get_node_info($nodename, "ip"); $idle = check_locktime($nodeip); } else { $idle = 1; } if ($idle == 0) { $hdr = '<tr style="background-color:#D6D2D0">'; } else { $hdr = '<tr>'; } while ($res = $result->fetchArray(SQLITE3_ASSOC)) { if (!isset($res['jname'])) { continue; } $jname = $res['jname']; $vm_ram = $res['vm_ram'] / 1024 / 1024; $vm_cpus = $res['vm_cpus']; $vm_os_type = $res['vm_os_type']; $status = check_vmonline($jname); $i++; if ($idle != 0) { switch ($status) { case 0: //off $statuscolor = "#EDECEA"; $action = "<form action=\"bstart.php\" method=\"post\"><input type=\"hidden\" name=\"jname\" value=\"{$jname}\"/> <input type=\"submit\" name=\"start\" value=\"Start\"></form>"; break; case 1: //running $statuscolor = "#51FF5F"; $action = "<form action=\"bstop.php\" method=\"post\"><input type=\"hidden\" name=\"jname\" value=\"{$jname}\"/> <input type=\"submit\" name=\"stop\" value=\"Stop\"></form>"; break; default: $action = "maintenance"; break; } } else { $statuscolor = "#D6D2D0"; $action = "offline"; } if ($idle != 0) { $status_td = "<td><a href=\"bstatus.php?jname={$jname}\">{$jname}</a></td>"; $remove_td = "<td><a href=\"bremove.php?jname={$jname}\">Remove</a></td>"; } else { $status_td = "<td>{$jname}</td>"; $remove_td = "<td>Remove</td>"; } $str = <<<EOF \t\t\t{$hdr} \t\t\t<td><strong>{$nodename}</strong></td> \t\t\t{$status_td} \t\t\t<td>{$vm_ram}</td><td>{$vm_cpus}</td> \t\t\t<td>{$vm_os_type}</td> \t\t\t<td style="background-color:{$statuscolor}">{$status}</td> \t\t\t<td>{$action}</td> \t\t\t{$remove_td} \t\t\t</tr> EOF; echo $str; } } echo "</tbody></table>"; }
function show_jails($nodelist = "local") { global $workdir; $pieces = explode(" ", $nodelist); ?> <table class="images"> <thead> <tr> <th>node</th> <th>jname</th> <th>ip4_addr</th> <th>status</th> <th>action</th> <th>remove</th> <th>console</th> </tr> </thead> <tbody> <?php foreach ($pieces as $nodename) { if (!$nodename) { $nodename = $nodelist; } $db = new SQLite3("{$workdir}/var/db/{$nodename}.sqlite"); $db->busyTimeout(5000); if (!$db) { return; } $sql = "SELECT jname,ip4_addr,status FROM jails WHERE emulator != \"bhyve\";"; $result = $db->query($sql); //->fetchArray(SQLITE3_ASSOC); $row = array(); $i = 0; if ($nodename != "local") { $nodeip = get_node_info($nodename, "ip"); $idle = check_locktime($nodeip); } else { $idle = 1; } if ($idle == 0) { $hdr = '<tr style="background-color:#D6D2D0">'; } else { $hdr = '<tr>'; } while ($res = $result->fetchArray(SQLITE3_ASSOC)) { if (!isset($res['jname'])) { continue; } $jname = $res['jname']; $ip4_addr = $res['ip4_addr']; $status = $res['status']; $i++; if ($idle != 0) { switch ($status) { case 0: //off $statuscolor = "#EDECEA"; $action = "<form action=\"jstart.php\" method=\"post\"><input type=\"hidden\" name=\"jname\" value=\"{$jname}\"/> <input type=\"submit\" name=\"start\" value=\"Start\"></form>"; break; case 1: //running $statuscolor = "#51FF5F"; $action = "<form action=\"jstop.php\" method=\"post\"><input type=\"hidden\" name=\"jname\" value=\"{$jname}\"/> <input type=\"submit\" name=\"stop\" value=\"Stop\"></form>"; break; default: $statuscolor = "#D6D2D0"; $action = "maintenance"; break; } } else { $statuscolor = "#D6D2D0"; $action = "offline"; } if ($idle != 0) { $status_td = "<td><a href=\"jstatus.php?jname={$jname}\">{$jname}</a></td>"; $remove_td = "<td><a href=\"jremove.php?jname={$jname}\">Remove</a></td>"; } else { $status_td = "<td>{$jname}</td>"; $remove_td = "<td>Remove</td>"; } $str = <<<EOF \t\t\t\t{$hdr} \t\t\t\t<td><strong>{$nodename}</strong></td> \t\t\t\t{$status_td} \t\t\t\t<td>{$ip4_addr}</td> \t\t\t\t<td style="background-color:{$statuscolor}">{$status}</td> \t\t\t\t<td>{$action}</td> \t\t\t\t{$remove_td} EOF; if ($status == 1) { $tmp = str_replace("/", ",", $ip4_addr); $ipw = explode(",", $tmp); $console = '<a href="http://'; $console .= $ipw[0] . ":8000"; $console .= '">Console</a>'; } else { $console = "Not running"; } $str .= <<<EOF \t\t\t\t<td>{$console}</td> \t\t\t\t</tr> EOF; echo $str; } } echo "</tbody></table>"; }