-
Notifications
You must be signed in to change notification settings - Fork 0
/
cbsd.php
89 lines (71 loc) · 2.63 KB
/
cbsd.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
<?php
require_once("auth.php");
?>
<?php
$workdir=getenv('WORKDIR');
if (empty($workdir)) $workdir="/usr/jails";
$rp=realpath('');
$tplfile=$rp.'/jailtpl.jconf';
if (!isset($workdir)) {
echo "No such workdir. Please set in nginx: fastcgi_param WORKDIR /path/to/cbsdworkdir;";
exit(0);
}
function getJailTemplate()
{
global $jname, $host_hostname, $astart, $ip4_addr, $workdir;
global $mount_devfs, $allow_mount, $allow_devfs, $allow_nullfs;
global $mkhostsfile, $devfs_ruleset, $ver, $baserw, $mount_src, $mount_obj, $mount_kernel;
global $mount_ports, $astart, $vnet, $applytpl, $mdsize, $floatresolv;
global $pkg_bootstrap, $user_pw_root, $interface, $sysrc_enable;
global $tplfile;
$file=file_get_contents($tplfile);
if(!empty($file))
{
$file=str_replace('#jname#',$jname,$file);
$file=str_replace('#host_hostname#',$host_hostname,$file);
$file=str_replace('#astart#',$astart,$file);
$file=str_replace('#ip4_addr#',$ip4_addr,$file);
$file=str_replace('#workdir#',$workdir,$file);
$file=str_replace('#mount_devfs#',$mount_devfs,$file);
$file=str_replace('#allow_mount#',$allow_mount,$file);
$file=str_replace('#allow_devfs#',$allow_devfs,$file);
$file=str_replace('#allow_nullfs#',$allow_nullfs,$file);
$file=str_replace('#mkhostsfile#',$mkhostsfile,$file);
$file=str_replace('#devfs_ruleset#',$devfs_ruleset,$file);
$file=str_replace('#ver#',$ver,$file);
$file=str_replace('#baserw#',$baserw,$file);
$file=str_replace('#mount_obj#',$mount_obj,$file);
$file=str_replace('#mount_kernel#',$mount_kernel,$file);
$file=str_replace('#mount_ports#',$mount_ports,$file);
$file=str_replace('#mount_src#',$mount_src,$file);
$file=str_replace('#astart#',$astart,$file);
$file=str_replace('#vnet#',$vnet,$file);
$file=str_replace('#applytpl#',$applytpl,$file);
$file=str_replace('#mdsize#',$mdsize,$file);
$file=str_replace('#floatresolv#',$floatresolv,$file);
$file=str_replace('#pkg_bootstrap#',$pkg_bootstrap,$file);
$file=str_replace('#user_pw_root#',$user_pw_root,$file);
$file=str_replace('#interface#',$interface,$file);
$file=str_replace('#sysrc_enable#',$sysrc_enable,$file);
}
return $file;
}
function human_filesize($bytes, $decimals = 2) {
$sz = 'BKMGTP';
$factor = floor((strlen($bytes) - 1) / 3);
return sprintf("%.{$decimals}f ", $bytes / pow(1024, $factor)) . @$sz[$factor];
}
// $status=check_vmonline("f10a");
// if status=1 - vm online
function check_vmonline($vm) {
$exist=0;
if (!file_exists("/dev/vmm")) return 0;
if ($handle = opendir("/dev/vmm")) {
while (false !== ($entry = readdir($handle))) {
if ( "${vm}" == "${entry}" ) return 1;
}
closedir($handle);
}
return 0;
}
?>