-
Notifications
You must be signed in to change notification settings - Fork 0
/
jlist.php
151 lines (130 loc) · 3.36 KB
/
jlist.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<?php
require_once("auth.php");
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>CBSD Project</title>
<link type="text/css" href="./css/all.css" rel="stylesheet" />
<style>
body {font-size:80%;font-family:Tahoma,'Sans-Serif',Arial;}
</style>
</head>
<body>
<a href="javascript:location.reload(true)">[ Refresh Page ]</a> | <a href="jcreate.php">[ New Jail ]</a>
<?php
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
${hdr}
<td><strong>$nodename</strong></td>
${status_td}
<td>$ip4_addr</td>
<td style="background-color:$statuscolor">$status</td>
<td>$action</td>
${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
<td>$console</td>
</tr>
EOF;
echo $str;
}
}
echo "</tbody></table>";
}
// MAIN
require('cbsd.php');
require('nodes.inc.php');
$db = new SQLite3("$workdir/var/db/nodes.sqlite"); $db->busyTimeout(5000);
$sql = "SELECT nodename FROM nodelist";
$result = $db->query($sql);//->fetchArray(SQLITE3_ASSOC);
$row = array();
$i = 0;
$nodelist="local";
while($res = $result->fetchArray(SQLITE3_ASSOC)){
if(!isset($res['nodename'])) continue;
$nodelist=$nodelist." ".$res['nodename'];
}
show_jails($nodelist);