Skip to content

Commit 3bf07b4

Browse files
author
mergar
committed
wip
0 parents  commit 3bf07b4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+33255
-0
lines changed

INSTALLING.eng

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
For install scripts:
2+
3+
1) Have CBSD installed
4+
2) Add 'web' user, from which will work nginx/php-fpm
5+
3) Add 'web' user into cbsd group (see group file in current dir as sample of line)
6+
4) Create directory for WEB docroot: mkdir -p /home/web/cbsd.localhost/public_html
7+
5) Move directory with scripts and change owner: cp -a jaction ~web/cbsd.localhost/public_html && chown -R web:www ~web
8+
6) Have correct NGINX settings as nginx directory . When workdir of CBSD is not /usr/jails, correct this path in WORKDIR variable in vhosts file.
9+
7) Add or change in /usr/local/etc/{php-fpm.conf,php.ini} those parameters which is sets in php-fpm.conf and php.ini in current dir
10+
8) mkdir /var/log/httpd
11+
9) touch /var/log/httpd/php.err
12+
10) chown web:www /var/log/httpd/php.err
13+
11) sysrc php-fpm_enable="YES"; sysrc nginx_enable="YES"
14+
12) In yout /usr/local/etc/rc.d/sudoers.d put web file from ~/sudoers.d to allow CBSD privileges command.
15+
13) service php-fpm start; service nginx start
16+
14) put into /etc/hosts IP of you NGINX for cbsd.localhost
17+
18+
After that, the browser should open at least something to http://cbsd.localhost/jaction/

INSTALLING.rus

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Для инсталляции PHP скриптов:
2+
3+
1) иметь CBSD
4+
2) завести пользователя web, от которого будет работать nginx/php-fpm
5+
3) добавить в группу cbsd пользователя web (как в файле group)
6+
4) создать каталог для скриптов: mkdir -p /home/web/cbsd.localhost/public_html
7+
5) Перенести туда каталог со скриптами: cp -a jaction ~web/cbsd.localhost/public_html && chown -R web:www ~web
8+
6) иметь структуру/конфигурацию nginx как в каталоге nginx. Если workdir CBSD не в /usr/jails, исправить путь в vhosts переменной WORKDIR
9+
7) добавить или изменить в /usr/local/etc/{php-fpm.conf,php.ini} те параметры, которые установлены в php-fpm.conf, php.ini
10+
8) mkdir /var/log/httpd
11+
9) touch /var/log/httpd/php.err
12+
10) chown web:www /var/log/httpd/php.err
13+
11) sysrc php-fpm_enable="YES"; sysrc nginx_enable="YES"
14+
12) в /usr/local/etc/rc.d/sudoers.d положить файлик web из каталога sudoers.d
15+
13) service php-fpm start; service nginx start
16+
14) /etc/hosts прописать cbsd.localhost на соотв ip
17+
18+
После чего, должно в броузере открыться хоть что-то по http://cbsd.localhost/jaction/

LICENSE

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
Copyright (c) 2015, Oleg Ginzburg
2+
All rights reserved.
3+
4+
Redistribution and use in source and binary forms, with or without
5+
modification, are permitted provided that the following conditions are met:
6+
7+
* Redistributions of source code must retain the above copyright notice, this
8+
list of conditions and the following disclaimer.
9+
10+
* Redistributions in binary form must reproduce the above copyright notice,
11+
this list of conditions and the following disclaimer in the documentation
12+
and/or other materials provided with the distribution.
13+
14+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
18+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
20+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
21+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
22+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24+

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# cbsd-websample
2+
Sample of WEB interface for earlier CBSD. No any style, frameworks etc, just for test action via browser.
3+
4+

group

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
cbsd:*:150:web

jaction/README.txt

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Jail action sample via cbsd
2+

jaction/addnode-fromargs.php

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
require('cbsd.php');
3+
4+
if (isset($_POST['address'])) {
5+
$address = $_POST['address'];
6+
}
7+
8+
if (isset($_POST['password'])) {
9+
$password = $_POST['password'];
10+
}
11+
12+
if (isset($_POST['sshport'])) {
13+
$sshport = $_POST['sshport'];
14+
} else {
15+
$sshport = 22222;
16+
}
17+
18+
if ((strlen($address)<2)) {
19+
echo "No address";
20+
die;
21+
}
22+
23+
if ((strlen($password)<2)) {
24+
echo "No password";
25+
die;
26+
}
27+
28+
if ((strlen($sshport)<2)) {
29+
echo "No sshport";
30+
die;
31+
}
32+
33+
$handle=popen("env NOCOLOR=1 /usr/local/bin/sudo /usr/local/bin/cbsd task owner=cbsdweb mode=new /usr/local/bin/cbsd node inter=0 mode=add node=$address pw=$password port=$sshport", "r");
34+
$read = fgets($handle, 4096);
35+
echo "Job Queued: $read";
36+
pclose($handle);
37+
header( 'Location: nodes.php' ) ;
38+
?>

jaction/addnode.php

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
require('cbsd.php');
3+
?>
4+
5+
<html>
6+
<head>
7+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
8+
<title>CBSD Project</title>
9+
10+
<style>
11+
body {
12+
font-size:14px;
13+
}
14+
</style>
15+
16+
</head>
17+
<body>
18+
<form action="addnode-fromargs.php" method="post">
19+
<div class="main">
20+
<div class="field">
21+
<label for="address">Node IP or Hostname:</label>
22+
<input type="text" name="address" />
23+
</div>
24+
<div class="field">
25+
<label for="password">CBSD User Password:</label>
26+
<input type="text" name="password" />
27+
</div>
28+
<div class="field">
29+
<label for="sshport">SSH Port:</label>
30+
<input type="text" name="sshport" value="22222" maxlength="5" size="5" />
31+
</div>
32+
<p><input type="submit" name="create" value="Connect" ></p>
33+
</div>
34+
</form>
35+
</body>
36+
</html>

jaction/bases.php

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<html>
2+
<head>
3+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
4+
<title>CBSD Project</title>
5+
<link type="text/css" href="./css/all.css" rel="stylesheet" />
6+
<style>
7+
body {
8+
font-size:14px;
9+
}
10+
</style>
11+
</head>
12+
<body>
13+
<a href="javascript:location.reload(true)">[ Refresh Page ]</a>
14+
<script>
15+
</script>
16+
17+
<?php
18+
require('cbsd.php');
19+
?>
20+
<table class="images">
21+
<thead>
22+
<tr>
23+
<th>arch</th>
24+
<th>target_arch</th>
25+
<th>ver</th>
26+
</tr>
27+
</thead><tbody>
28+
<?php
29+
30+
$fp=popen("env NOCOLOR=1 /usr/local/bin/sudo /usr/local/bin/cbsd basels", "r");
31+
if ($fp) {
32+
while(!feof($fp)) {
33+
34+
echo "<tr>";
35+
$data=fgets($fp, 2048);
36+
37+
if (strlen($data)>3 ) {
38+
list($base, $arch, $target_arch, $ver ) = explode('_', "${data}");
39+
if (!isset($arch)) $arch="unknown";
40+
if (!isset($target_arch)) $targeT_arch="unknown";
41+
if (!isset($ver)) $ver="unknown";
42+
43+
$str = <<<EOF
44+
<td>$arch</td>
45+
<td>$target_arch</td>
46+
<td>$ver</td>
47+
</tr>
48+
EOF;
49+
echo $str;
50+
}
51+
52+
}
53+
}
54+
55+
echo "\n";

jaction/blist.php

+138
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
<html>
2+
<head>
3+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
4+
<title>CBSD Project</title>
5+
<link type="text/css" href="./css/all.css" rel="stylesheet" />
6+
<style>
7+
body {
8+
font-size:14px;
9+
}
10+
</style>
11+
</head>
12+
<body>
13+
<a href="javascript:location.reload(true)">[ Refresh Page ]</a> | <a href="bcreate.php">[ New VM ]</a>
14+
<script>
15+
</script>
16+
17+
18+
<?php
19+
function show_bhyvevm($nodelist="local")
20+
{
21+
global $workdir;
22+
23+
$pieces = explode(" ", $nodelist);
24+
25+
?>
26+
27+
<table class="images">
28+
<thead>
29+
<tr>
30+
<th>node</th>
31+
<th>vm</th>
32+
<th>vm_ram</th>
33+
<th>vm_cpus</th>
34+
<th>vm_os_type</th>
35+
<th>status</th>
36+
<th>action</th>
37+
<th>remove</th>
38+
</tr>
39+
</thead>
40+
<tbody>
41+
<?php
42+
43+
foreach ($pieces as $nodename) {
44+
if (!$nodename) {
45+
$nodename=$nodelist;
46+
}
47+
$db = new SQLite3("$workdir/var/db/$nodename.sqlite"); $db->busyTimeout(5000);
48+
$sql = "SELECT jname,vm_ram,vm_cpus,vm_os_type FROM bhyve;";
49+
$result = $db->query($sql);//->fetchArray(SQLITE3_ASSOC);
50+
$row = array();
51+
$i = 0;
52+
53+
if ( $nodename != "local" ) {
54+
$nodeip=get_node_info($nodename,"ip");
55+
$idle=check_locktime($nodeip);
56+
} else {
57+
$idle=1;
58+
}
59+
60+
if ($idle == 0 ) {
61+
$hdr = '<tr style="background-color:#D6D2D0">';
62+
} else {
63+
$hdr = '<tr>';
64+
}
65+
66+
while($res = $result->fetchArray(SQLITE3_ASSOC)){
67+
if(!isset($res['jname'])) continue;
68+
$jname = $res['jname'];
69+
$vm_ram = $res['vm_ram'] / 1024 / 1024 ;
70+
$vm_cpus = $res['vm_cpus'];
71+
$vm_os_type = $res['vm_os_type'];
72+
$status=check_vmonline($jname);
73+
$i++;
74+
75+
if ( $idle != 0 ) {
76+
switch ($status) {
77+
case 0:
78+
//off
79+
$statuscolor="#EDECEA";
80+
$action="<form action=\"bstart.php\" method=\"post\"><input type=\"hidden\" name=\"jname\" value=\"$jname\"/> <input type=\"submit\" name=\"start\" value=\"Start\"></form>";
81+
break;
82+
case 1:
83+
//running
84+
$statuscolor="#51FF5F";
85+
$action="<form action=\"bstop.php\" method=\"post\"><input type=\"hidden\" name=\"jname\" value=\"$jname\"/> <input type=\"submit\" name=\"stop\" value=\"Stop\"></form>";
86+
break;
87+
default:
88+
$action="maintenance";
89+
break;
90+
}
91+
} else {
92+
$statuscolor="#D6D2D0";
93+
$action="offline";
94+
}
95+
96+
if ( $idle != 0 ) {
97+
$status_td="<td><a href=\"bstatus.php?jname=$jname\">$jname</a></td>";
98+
$remove_td="<td><a href=\"bremove.php?jname=$jname\">Remove</a></td>";
99+
} else {
100+
$status_td="<td>$jname</td>";
101+
$remove_td="<td>Remove</td>";
102+
}
103+
104+
$str = <<<EOF
105+
${hdr}
106+
<td><strong>$nodename</strong></td>
107+
${status_td}
108+
<td>$vm_ram</td><td>$vm_cpus</td>
109+
<td>$vm_os_type</td>
110+
<td style="background-color:$statuscolor">$status</td>
111+
<td>$action</td>
112+
${remove_td}
113+
</tr>
114+
EOF;
115+
echo $str;
116+
}
117+
}
118+
echo "</tbody></table>";
119+
}
120+
121+
// MAIN
122+
require('cbsd.php');
123+
require('nodes.inc.php');
124+
125+
$db = new SQLite3("$workdir/var/db/nodes.sqlite"); $db->busyTimeout(5000);
126+
$sql = "SELECT nodename FROM nodelist";
127+
$result = $db->query($sql);//->fetchArray(SQLITE3_ASSOC);
128+
$row = array();
129+
$i = 0;
130+
131+
$nodelist="local";
132+
133+
while($res = $result->fetchArray(SQLITE3_ASSOC)){
134+
if(!isset($res['nodename'])) continue;
135+
$nodelist=$nodelist." ".$res['nodename'];
136+
}
137+
138+
show_bhyvevm($nodelist);

0 commit comments

Comments
 (0)