Skip to content
Permalink
Browse files

Add build zfs dataset for each jail

  • Loading branch information
alexey1234 committed Jul 30, 2016
1 parent 8c1901d commit 102031a9f826b86a2c1e4dd145405c023aced697
Showing with 87 additions and 14 deletions.
  1. +75 −7 conf/ext/thebrig/extensions_thebrig_edit.php
  2. +12 −7 conf/ext/thebrig/lang.inc
@@ -21,8 +21,9 @@
require("auth.inc");
require("guiconfig.inc");
//require_once("ext/thebrig/lang.inc");
require("ext/thebrig/functions.inc");
require("ext/thebrig/gui_addons.inc");
require_once("ext/thebrig/functions.inc");
require_once("ext/thebrig/gui_addons.inc");
require_once("zfs.inc");

$in_jail_allow = array (
"allow.sysvipc",
@@ -126,6 +127,9 @@
$pconfig['jailno'] = $a_jail[$cnid]['jailno'];
$pconfig['jailname'] = $a_jail[$cnid]['jailname'];
$pconfig['jail_type'] = $a_jail[$cnid]['jail_type'];
$pconfig['filesystemschem'] = $a_jail[$cnid]['filesystemschem'];
$pconfig['zfspool'] = $a_jail[$cnid]['zfspool'];
$pconfig['compression'] = $a_jail[$cnid]['compression'];
$pconfig['param'] = $a_jail[$cnid]['param'];
$pconfig['allowedip'] = $a_jail[$cnid]['allowedip']; // new entries
$pconfig['if'] = $a_jail[$cnid]['if'];
@@ -173,6 +177,7 @@
$pconfig['jailno'] = $next_jailnumber;
$pconfig['jailname'] = "jail".$next_jailnumber;
$pconfig['jail_type']="Slim";
$pconfig['filesystemschem']="simple";
$pconfig['param'] = array("allow.mount", "allow.mount.devfs");
unset ($pconfig['allowedip']);
unset ($pconfig['jail_vnet']);
@@ -344,7 +349,12 @@
// Check to make sure they are not attempting to install to a folder that thebrig uses.
if ( array_search ($pconfig['jailpath'], $thebrig_dirs ) !== FALSE)
$input_errors[] = "The specified jail location is reserved. Please choose another.";

if (false === zfs_is_valid_dataset_name($pconfig['jailname'])) {
$input_errors[] = sprintf(gtext("The attribute '%s' contains invalid characters."), gtext('Jail name'));
}
//Dataset full name construkt as pool/dataset
$datasetfullname = $pconfig['zfspool'] . "/" . $pconfig['jailname'] ;

// Check to make sure there are not any duplicate files selected
if ( count( $files_selected) > 0 ){
$base_count = 0;
@@ -427,6 +437,9 @@
$jail['jailname'] = $pconfig['jailname'];
$jail['jail_type'] = $pconfig['jail_type'];
$jail['param'] = $pconfig['param'];
$jail['filesystemschem'] = $pconfig['filesystemschem'];
$jail['zfspool'] = $pconfig['zfspool'];
$jail['compression'] = $pconfig['compression'];
$jail['jailpath'] = $pconfig['jailpath'];
$jail['allowedip'] = $pconfig['allowedip'];
$jail['jail_vnet'] = isset($pconfig['jail_vnet']) ? true : false;
@@ -460,7 +473,19 @@
$jail['zfs_enable'] = !empty($pconfig['zfs_enable']) ? true : false;
$jail['fib'] = $pconfig['fib'];
$jail['ports'] = isset( $pconfig['ports'] ) ? true : false ;

// Create zfs dataset, if it defined
if (FALSE === ($cnid = array_search_ex($uuid, $a_jail, "uuid")) && $jail['filesystemschem'] == "zfs") {
// Create new jail with zfs schem => Prepare dataset for jail
// create dataset
$result = 0;
$option = " -o mountpoint=".rtrim($jail['jailpath'], "/")." -o compression=".$jail['compression'];
$cmd = 'zfs create'. $option . ' '. $datasetfullname;
write_log($cmd);
$result |= mwexec($cmd, true);
if ($result != 0) {
write_log(sprintf('Error: Failed to create dataset %1$s', $datasetfullname));
exit;
} }
// Populate the jail. The simplest case is a full jail using tarballs.
if ( $pconfig['source'] === "tarballs" && ( count ( $files_selected ) > 0 ) && $jail['jail_type'] === "full")
thebrig_split_world($pconfig['jailpath'] , false , $files_selected );
@@ -507,6 +532,24 @@ function thebrig_get_next_jailnumber() {
}
return $jailno;
}

$l_compressionmode = [
'on' => gtext('On'),
'off' => gtext('Off'),
'lz4' => 'lz4',
'lzjb' => 'lzjb',
'gzip' => 'gzip',
'gzip-1' => 'gzip-1',
'gzip-2' => 'gzip-2',
'gzip-3' => 'gzip-3',
'gzip-4' => 'gzip-4',
'gzip-5' => 'gzip-5',
'gzip-6' => 'gzip-6',
'gzip-7' => 'gzip-7',
'gzip-8' => 'gzip-8',
'gzip-9' => 'gzip-9',
'zle' => 'zle'
];
?>
<?php include("fbegin.inc");?>
<script type="text/javascript">//<![CDATA[
@@ -613,12 +656,27 @@ function submitted() {
break;
}
});
$('#filesystemschem').change(function(){
switch ($('#filesystemschem').val()) {
case "simple":
$('#filesystemschem1_tr').hide();
$('#zfspool_tr').hide();
$('#compression_tr').hide();
break;
case "zfs":
$('#filesystemschem1_tr').hide();
$('#zfspool_tr').show();
$('#compression_tr').show();
}
});
$('#moreless').click();
$('#zfs_enable').change();
$('#jail_type').change();
$('#source').change();
$('#jail_vnet').change();
$('#filesystemschem').change();
$('#moreless').click();

});
function jail_mount_enable() {
switch (document.iform.jail_mount.checked) {
@@ -644,8 +702,8 @@ function redirect() { window.location = "extensions_thebrig_fstab.php?uuid=<?=$p
</ul>
</td></tr>
<td class="tabcont">
<form action="extensions_thebrig_edit.php" method="post" name="iform" id="iform">
<!-- <form action="test.php" method="post" name="iform" id="iform"> -->
<form action="extensions_thebrig_edit.php" method="post" name="iform" id="iform">
<!-- <form action="test.php" method="post" name="iform" id="iform">-->
<input name="jailpath" type="hidden" value="<?=$pconfig['jailpath'];?>" />
<input name="base_ver" type="hidden" value="<?=$pconfig['base_ver'];?>" />
<input name="fib" type="hidden" value="<?=$pconfig['fib'];?>" />
@@ -654,8 +712,18 @@ function redirect() { window.location = "extensions_thebrig_fstab.php?uuid=<?=$p
<?php html_titleline(_THEBRIG_JAIL_PARAMETERS);?>
<?php html_inputbox("jailno", _THEBRIG_JAIL_NUMBER, $pconfig['jailno'], _THEBRIG_JAIL_NUMBER_EXPL,true, 10, true);?>
<?php html_inputbox("jailname", _THEBRIG_TABLE1_TITLE1, $pconfig['jailname'], _THEBRIG_TABLE1_TITLE1_EXPL, true, 15,isset($uuid) && (FALSE !== $cnid) && $name_ro );?>
<?php html_combobox("jail_type", _THEBRIG_JAIL_TYPE, $pconfig['jail_type'], array('full'=> 'Full','slim' =>'Slim'), _THEBRIG_JAIL_TYPE_EXPL, true,isset($uuid) && (FALSE !== $cnid),"type_change()");?>
<?php html_combobox("jail_type", _THEBRIG_JAIL_TYPE, $pconfig['jail_type'], array('full'=> 'Full','slim' =>'Slim'), _THEBRIG_JAIL_TYPE_EXPL, true,isset($uuid) && (FALSE !== $cnid),"type_change()");
html_combobox("filesystemschem", _THEBRIG_TABLE1_TITLE_ZFS, $pconfig['filesystemschem'], array("simple" => "Simple folder","zfs"=>"zfs dataset for this"), _THEBRIG_TABLE1_TITLEZFS_EXPL, true,isset($uuid) && (FALSE !== $cnid) && $name_ro,"");
if (FALSE !== ($datasets_list1 = brig_datasets_list())) {
foreach ( $datasets_list1 as $b_dataset) {$c_dataset[] = $b_dataset[1];}

}
$a_pools = zfs_get_pool_list();?>
<?php foreach ( $a_pools as $a_pool_n => $a_pool_val) {$poolname[$a_pool_val['name']] = $a_pool_val['name'];} ?>

<?php html_combobox("zfspool", _THEBRIG_J_POOL, $pconfig['zfspool'], $poolname, _THEBRIG_J_POOL_EXPL, false,isset($uuid) && (FALSE !== $cnid) && $name_ro,""); ?>
<?php html_combobox2('compression', gtext('Compression'), $pconfig['compression'], $l_compressionmode, gtext("Controls the compression algorithm used for this dataset. The 'lzjb' compression algorithm is optimized for performance while providing decent data compression. Setting compression to 'On' uses the 'lzjb' compression algorithm. You can specify the 'gzip' level by using the value 'gzip-N', where N is an integer from 1 (fastest) to 9 (best compression ratio). Currently, 'gzip' is equivalent to 'gzip-6'."), false,isset($uuid) && (FALSE !== $cnid) && $name_ro); ?>

<?php html_checkbox("enable", _THEBRIG_TABLE1_TITLE3, !empty($pconfig['enable']) ? true : false, _THEBRIG_TABLE1_TITLE3_EXPL, "");?>
<?php html_inputbox("jailpath", _THEBRIG_ONLINETABLE_TITLE4, $pconfig['jailpath'], _THEBRIG_ONLINETABLE_TITLE4_EXPL, false, 40,isset($uuid) && (FALSE !== $cnid) && $path_ro);?>
<?php html_optionsbox("param", _THEBRIG_J_ALLOW , $pconfig['param'], $in_jail_allow, false, false); ?>
@@ -58,13 +58,18 @@
define('_THEBRIG_ADD', "Add" );
define('_THEBRIG_JAIL', "Jail" );
define ('_THEBRIG_JAIL_PARAMETERS', "Jail parameters");
define (_THEBRIG_JAIL_NUMBER, "Jail number");
define (_THEBRIG_JAIL_NUMBER_EXPL, "The jail number determines the order of the jail.");
define (_THEBRIG_TABLE1_TITLE1_EXPL, "The jail's name.");
define (_THEBRIG_JAIL_TYPE, "Jail Type \n <input type=\"button\" onclick=\"helpbox()\" value=\"Help\" />");
define (_THEBRIG_JAIL_TYPE_EXPL, "Choose jail type ");
define(_THEBRIG_TABLE1_TITLE3_EXPL,"Check it if you want start current jail automatically with main system ");
define(_THEBRIG_ONLINETABLE_TITLE4_EXPL, "Sets an alternate location for the jail. Default is {$config['thebrig']['rootfolder']}jail_name/");
define ('_THEBRIG_JAIL_NUMBER', "Jail number");
define ('_THEBRIG_JAIL_NUMBER_EXPL', "The jail number determines the order of the jail.");
define ('_THEBRIG_TABLE1_TITLE1_EXPL', "The jail's name.");
define ('_THEBRIG_JAIL_TYPE', "Jail Type \n <input type=\"button\" onclick=\"helpbox()\" value=\"Help\" />");
define ('_THEBRIG_JAIL_TYPE_EXPL', "Choose jail type ");
define('_THEBRIG_TABLE1_TITLE3_EXPL',"Check it if you want start current jail automatically with main system ");
define('_THEBRIG_ONLINETABLE_TITLE4_EXPL', "Sets an alternate location for the jail. Default is {$config['thebrig']['rootfolder']}jail_name/");
define('_THEBRIG_TABLE1_TITLE_ZFS',"Jail folder type");
define('_THEBRIG_TABLE1_TITLEZFS_EXPL',"Choice how to store the jail's world. If you want use new dataset, TherBrig will create it automatically and dataset name will as jailname");
define('_THEBRIG_J_POOL', "Pool" );
define('_THEBRIG_J_POOL_COPM', "Compression" );
define('_THEBRIG_J_POOL_EXPL', "Choise pool, where TheBrig will create dataset for jail. You can manage dataset after creation over ZFS page GUI" );
define('_THEBRIG_J_ALLOW', "In jail allow:" );
define('_THEBRIG_J_OPTION', "In jail" ); // insert into jscript page
define('_THEBRIG_J_MOUNTFSTAB', "mount/umount jail's fs");

0 comments on commit 102031a

Please sign in to comment.