mirror of
https://github.com/JRGTH/xigmanas-bastille-extension.git
synced 2025-12-11 01:10:57 +01:00
Add Linux jails basic management to the WebGUI
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
======================
|
||||
Version Description
|
||||
|
||||
1.1.07......Add Linux jails basic management to the WebGUI.
|
||||
1.1.06......Add ability to manually update bastille core files.
|
||||
1.1.05......Fix a bug to display correct VNET interface.
|
||||
1.1.04......Fix a bug that prevents VNET jail creation.
|
||||
|
||||
@@ -980,6 +980,9 @@ reset_install()
|
||||
echo "* Alternatively you can edit the '/usr/local/etc/bastille/bastille.conf' file manually. *"
|
||||
echo "*************************************************************************************************************"
|
||||
echo ""
|
||||
echo "Notice: If Linux Jail support was enabled, please execute the below command to re-enable it:"
|
||||
echo "==> sysrc -f ${CWDIR}${EXTCONF} LINUX_COMPAT_SUPPORT=\"YES\""
|
||||
echo ""
|
||||
}
|
||||
|
||||
remove_addon()
|
||||
@@ -1282,13 +1285,27 @@ bastille_init()
|
||||
|
||||
linux_compat()
|
||||
{
|
||||
# Manually enable Linux compatibility(Experimental).
|
||||
if ! sysrc -f ${CWDIR}${EXTCONF} -qn LINUX_COMPAT_SUPPORT | grep -q "YES"; then
|
||||
${CWDIR}/unionfs.sh fetch_pkg && ${CWDIR}/unionfs.sh load_kmods && ${CWDIR}/unionfs.sh unionfs_on && sysrc -f ${CWDIR}${EXTCONF} LINUX_COMPAT_SUPPORT="YES" >/dev/null 2>&1
|
||||
if ping -c1 -t5 freebsd.org > /dev/null; then
|
||||
# Manually enable Linux compatibility(Experimental).
|
||||
if ! sysrc -f ${CWDIR}${EXTCONF} -qn LINUX_COMPAT_SUPPORT | grep -q "YES"; then
|
||||
${CWDIR}/unionfs.sh fetch_pkg && ${CWDIR}/unionfs.sh load_kmods && ${CWDIR}/unionfs.sh unionfs_on && sysrc -f ${CWDIR}${EXTCONF} LINUX_COMPAT_SUPPORT="YES" >/dev/null 2>&1
|
||||
else
|
||||
echo "Already enabled."
|
||||
fi
|
||||
exit 0
|
||||
else
|
||||
echo "Already enabled."
|
||||
echo "Internet connection required to enable this feature."
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
linux_compat_disable()
|
||||
{
|
||||
if sysrc -f ${CWDIR}${EXTCONF} -qn LINUX_COMPAT_SUPPORT | grep -q "YES"; then
|
||||
echo "Disabling Linux jail compatibility support..."
|
||||
sysrc -f ${CWDIR}${EXTCONF} -x LINUX_COMPAT_SUPPORT
|
||||
echo "Done!, server reboot is recommended."
|
||||
fi
|
||||
exit 0
|
||||
}
|
||||
|
||||
@@ -1340,6 +1357,9 @@ clean|--clean)
|
||||
linux_compat)
|
||||
linux_compat
|
||||
;;
|
||||
linux_compat_disable)
|
||||
linux_compat_disable
|
||||
;;
|
||||
bastillebsd_update)
|
||||
bastille_core_update
|
||||
;;
|
||||
@@ -1368,6 +1388,11 @@ while getopts ":ospruxUvgtZh" option; do
|
||||
echo " upgrade|--upgrade Upgrade a container/release to X.Y-RELEASE."
|
||||
echo " install|--install Finish installing pending updates on container/release."
|
||||
echo " clean|--clean Cleanup the FreeBSD update/upgrade cached files/folders."
|
||||
echo ""
|
||||
echo""
|
||||
echo "Experimental:"
|
||||
echo "To enable experimental Linux jail support please execute: \"${SCRIPTNAME} linux_compat\""
|
||||
echo "To disable experimental Linux jail support please execute: \"${SCRIPTNAME} linux_compat_disable\""
|
||||
echo ""; exit 0;;
|
||||
[o]) OBI_INSTALL="ON";; # To prevent nested PHP-CGI call for installation with OBI.
|
||||
[s]) bastille_start;;
|
||||
|
||||
@@ -65,6 +65,7 @@ $zfs_activated = exec("/usr/bin/grep 'ZFS_ACTIVATED=' $configfile | /usr/bin/cut
|
||||
$tarballversion = "/usr/local/bin/bastille";
|
||||
$bastille_version_min = exec("grep 'BASTILLE_VERSION=' $tarballversion | cut -d '\"' -f2 | tr -d '.'");
|
||||
$host_version = exec("/bin/cat /etc/prd.version | tr -d '.'");
|
||||
$linux_compat_support = exec("/usr/bin/grep 'LINUX_COMPAT_SUPPORT=' $configfile | /usr/bin/cut -d'\"' -f2");
|
||||
|
||||
// Ensure the root directory is configured.
|
||||
if ($rootfolder == "")
|
||||
|
||||
@@ -79,12 +79,24 @@ if($_POST):
|
||||
$interface = $pconfig['interface'];
|
||||
endif;
|
||||
|
||||
if($release == 'Ubuntu_1804'):
|
||||
$release = "ubuntu-bionic";
|
||||
elseif($release == 'Ubuntu_2004'):
|
||||
$release = "ubuntu-focal";
|
||||
elseif($release == 'Debian9'):
|
||||
$release = "debian-stretch";
|
||||
elseif($release == 'Debian10'):
|
||||
$release = "debian-buster";
|
||||
endif;
|
||||
|
||||
if($_POST['thickjail'] && $_POST['vnetjail']):
|
||||
$options = "-T -V";
|
||||
elseif($_POST['thickjail']):
|
||||
$options = "-T";
|
||||
elseif($_POST['vnetjail']):
|
||||
$options = "-V";
|
||||
elseif($_POST['linuxjail']):
|
||||
$options = "-L";
|
||||
endif;
|
||||
|
||||
if($_POST['emptyjail']):
|
||||
@@ -134,25 +146,54 @@ $(window).on("load",function() {
|
||||
function emptyjail_change() {
|
||||
switch(document.iform.emptyjail.checked) {
|
||||
case false:
|
||||
showElementById('ipaddress_tr','show');
|
||||
showElementById('interface_tr', 'show');
|
||||
showElementById('release_tr', 'show');
|
||||
showElementById('thickjail_tr', 'show');
|
||||
showElementById('vnetjail_tr', 'show');
|
||||
showElementById('nowstart_tr', 'show');
|
||||
showElementById('autostart_tr', 'show');
|
||||
break;
|
||||
showElementById('ipaddress_tr','show');
|
||||
showElementById('interface_tr', 'show');
|
||||
showElementById('release_tr', 'show');
|
||||
showElementById('thickjail_tr', 'show');
|
||||
showElementById('vnetjail_tr', 'show');
|
||||
showElementById('nowstart_tr', 'show');
|
||||
showElementById('autostart_tr', 'show');
|
||||
showElementById('linuxjail_tr', 'show');
|
||||
break;
|
||||
case true:
|
||||
showElementById('ipaddress_tr','hide');
|
||||
showElementById('interface_tr', 'hide');
|
||||
showElementById('release_tr', 'hide');
|
||||
showElementById('thickjail_tr', 'hide');
|
||||
showElementById('vnetjail_tr', 'hide');
|
||||
showElementById('nowstart_tr', 'hide');
|
||||
showElementById('autostart_tr', 'hide');
|
||||
break;
|
||||
showElementById('ipaddress_tr','hide');
|
||||
showElementById('interface_tr', 'hide');
|
||||
showElementById('release_tr', 'hide');
|
||||
showElementById('thickjail_tr', 'hide');
|
||||
showElementById('vnetjail_tr', 'hide');
|
||||
showElementById('nowstart_tr', 'hide');
|
||||
showElementById('autostart_tr', 'hide');
|
||||
showElementById('linuxjail_tr', 'hide');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
function linuxjail_change() {
|
||||
switch(document.iform.linuxjail.checked) {
|
||||
case false:
|
||||
showElementById('ipaddress_tr','show');
|
||||
showElementById('interface_tr', 'show');
|
||||
showElementById('release_tr', 'show');
|
||||
showElementById('thickjail_tr', 'show');
|
||||
showElementById('vnetjail_tr', 'show');
|
||||
showElementById('nowstart_tr', 'show');
|
||||
showElementById('autostart_tr', 'show');
|
||||
showElementById('linuxjail_tr', 'show');
|
||||
showElementById('emptyjail_tr', 'show');
|
||||
break;
|
||||
case true:
|
||||
showElementById('ipaddress_tr','show');
|
||||
showElementById('interface_tr', 'show');
|
||||
showElementById('release_tr', 'show');
|
||||
showElementById('thickjail_tr', 'hide');
|
||||
showElementById('vnetjail_tr', 'hide');
|
||||
showElementById('nowstart_tr', 'show');
|
||||
showElementById('autostart_tr', 'show');
|
||||
showElementById('emptyjail_tr', 'hide');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//]]>
|
||||
</script>
|
||||
<?php
|
||||
@@ -205,6 +246,9 @@ $document->render();
|
||||
html_checkbox2('vnetjail',gettext('Enable VNET(VIMAGE)'),!empty($pconfig['vnetjail']) ? true : false,gettext('VNET-enabled containers are attached to a virtual bridge interface for connectivity(Advanced).'),'',false);
|
||||
endif;
|
||||
html_checkbox2('emptyjail',gettext('Create an empty container'),!empty($pconfig['emptyjail']) ? true : false,gettext('This are ideal for custom builds, experimenting with unsupported RELEASES or Linux jails.'),'',false,false,'emptyjail_change()');
|
||||
|
||||
html_checkbox2('linuxjail',gettext('Create a Linux container'),!empty($pconfig['linuxjail']) ? true : false,gettext('This will create a Linux container, this is highly experimental and for testing purposes.'),'',false,false,'linuxjail_change()');
|
||||
|
||||
endif;
|
||||
html_checkbox2('nowstart',gettext('Start after creation'),!empty($pconfig['nowstart']) ? true : false,gettext('Start the container after creation(May be overridden by later bastille releases).'),'',false);
|
||||
html_checkbox2('autostart',gettext('Auto start on boot'),!empty($pconfig['autostart']) ? true : false,gettext('Automatically start the container at boot time.'),'',false);
|
||||
@@ -222,6 +266,7 @@ $document->render();
|
||||
<script type="text/javascript">
|
||||
<!--
|
||||
emptyjail_change();
|
||||
linuxjail_change();
|
||||
//-->
|
||||
</script>
|
||||
<?php
|
||||
|
||||
@@ -50,12 +50,12 @@ function get_rel_list() {
|
||||
global $jail_dir;
|
||||
$result = [];
|
||||
if (is_dir("{$rootfolder}/releases")):
|
||||
$entries = preg_grep('/^[0-9]+\.[0-9]+\-RELEASE/', scandir("{$rootfolder}/releases"));
|
||||
$entries = preg_grep('/^[0-9]+\.[0-9]+\-RELEASE|(Debian[0-9]{1,2}$)|(Ubuntu_[0-9]{4}$)/', scandir("{$rootfolder}/releases"));
|
||||
foreach($entries as $entry):
|
||||
$a = preg_split('/\t/',$entry);
|
||||
$r = [];
|
||||
$name = $a[0];
|
||||
if(preg_match('/^[0-9]+\.[0-9]+\-RELEASE/', $name, $m)):
|
||||
if(preg_match('/^[0-9]+\.[0-9]+\-RELEASE|(Debian[0-9]{1,2}$)|(Ubuntu_[0-9]{4}$)/', $name, $m)):
|
||||
$r['name'] = $m[0];
|
||||
else:
|
||||
$r['name'] = 'unknown';
|
||||
@@ -69,6 +69,34 @@ function get_rel_list() {
|
||||
$rel_list = get_rel_list();
|
||||
$sphere_array = $rel_list;
|
||||
|
||||
if ($linux_compat_support == "YES"):
|
||||
$a_action = [
|
||||
'13.0-RELEASE' => gettext('13.0-RELEASE'),
|
||||
'12.3-RELEASE' => gettext('12.3-RELEASE'),
|
||||
'12.2-RELEASE' => gettext('12.2-RELEASE'),
|
||||
'12.1-RELEASE' => gettext('12.1-RELEASE'),
|
||||
'12.0-RELEASE' => gettext('12.0-RELEASE'),
|
||||
'11.4-RELEASE' => gettext('11.4-RELEASE'),
|
||||
'11.3-RELEASE' => gettext('11.3-RELEASE'),
|
||||
'11.2-RELEASE' => gettext('11.2-RELEASE'),
|
||||
'ubuntu-bionic' => gettext('Ubuntu-Bionic'),
|
||||
'ubuntu-focal' => gettext('Ubuntu-Focal'),
|
||||
'debian-stretch' => gettext('Debian-Stretch'),
|
||||
'debian-buster' => gettext('Debian-Buster'),
|
||||
];
|
||||
else:
|
||||
$a_action = [
|
||||
'13.0-RELEASE' => gettext('13.0-RELEASE'),
|
||||
'12.3-RELEASE' => gettext('12.3-RELEASE'),
|
||||
'12.2-RELEASE' => gettext('12.2-RELEASE'),
|
||||
'12.1-RELEASE' => gettext('12.1-RELEASE'),
|
||||
'12.0-RELEASE' => gettext('12.0-RELEASE'),
|
||||
'11.4-RELEASE' => gettext('11.4-RELEASE'),
|
||||
'11.3-RELEASE' => gettext('11.3-RELEASE'),
|
||||
'11.2-RELEASE' => gettext('11.2-RELEASE'),
|
||||
];
|
||||
endif;
|
||||
|
||||
if($_POST):
|
||||
unset($input_errors);
|
||||
unset($errormsg);
|
||||
@@ -130,9 +158,21 @@ if($_POST):
|
||||
|
||||
if (isset($_POST['Destroy']) && $_POST['Destroy']):
|
||||
if ($_POST['Destroy']):
|
||||
|
||||
$get_release = $pconfig['release_item'];
|
||||
if($get_release == 'ubuntu-bionic'):
|
||||
$get_release = "Ubuntu_1804";
|
||||
elseif($get_release == 'ubuntu-focal'):
|
||||
$get_release = "Ubuntu_2004";
|
||||
elseif($get_release == 'debian-stretch'):
|
||||
$get_release = "Debian9";
|
||||
elseif($get_release == 'debian-buster'):
|
||||
$get_release = "Debian10";
|
||||
endif;
|
||||
|
||||
$check_release = ("{$rootfolder}/releases/{$get_release}");
|
||||
$check_used = exec("/usr/bin/grep -wo {$get_release} {$jail_dir}/*/fstab 2>/dev/null");
|
||||
|
||||
$cmd = ("/usr/local/bin/bastille destroy {$get_release}");
|
||||
|
||||
if (!file_exists($check_release)):
|
||||
@@ -214,16 +254,18 @@ $document->render();
|
||||
<?php
|
||||
if (is_dir($reldir)):
|
||||
if (!is_dir_empty($reldir)):
|
||||
html_titleline2(gettext('FreeBSD Base Release Installed'));
|
||||
html_titleline2(gettext('FreeBSD/Linux Base Release Installed'));
|
||||
endif;
|
||||
foreach ($sphere_array as $sphere_record):
|
||||
if (file_exists("{$reldir}/{$sphere_record['relname']}/root/.profile")):
|
||||
html_text2('releases',gettext('Installed Base:'),htmlspecialchars($sphere_record['relname']));
|
||||
elseif (file_exists("{$reldir}/{$sphere_record['relname']}/debootstrap/debootstrap")):
|
||||
html_text2('releases',gettext('Installed Base:'),htmlspecialchars($sphere_record['relname']));
|
||||
else:
|
||||
html_text2('releases',gettext('Unknown Base:'),htmlspecialchars($sphere_record['relname']));
|
||||
endif;
|
||||
endforeach;
|
||||
endif;
|
||||
foreach ($sphere_array as $sphere_record):
|
||||
if (file_exists("{$reldir}/{$sphere_record['relname']}/root/.profile")):
|
||||
html_text2('releases',gettext('Installed Base:'),htmlspecialchars($sphere_record['relname']));
|
||||
else:
|
||||
html_text2('releases',gettext('Unknown Base:'),htmlspecialchars($sphere_record['relname']));
|
||||
endif;
|
||||
endforeach;
|
||||
?>
|
||||
<?php
|
||||
html_separator();
|
||||
@@ -232,16 +274,7 @@ $document->render();
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php
|
||||
$a_action = [
|
||||
'13.0-RELEASE' => gettext('13.0-RELEASE'),
|
||||
'12.3-RELEASE' => gettext('12.3-RELEASE'),
|
||||
'12.2-RELEASE' => gettext('12.2-RELEASE'),
|
||||
'12.1-RELEASE' => gettext('12.1-RELEASE'),
|
||||
'12.0-RELEASE' => gettext('12.0-RELEASE'),
|
||||
'11.4-RELEASE' => gettext('11.4-RELEASE'),
|
||||
'11.3-RELEASE' => gettext('11.3-RELEASE'),
|
||||
'11.2-RELEASE' => gettext('11.2-RELEASE'),
|
||||
];
|
||||
|
||||
html_combobox2('release_item',gettext('Select Base Release'),$pconfig['release_item'],$a_action,'',true,false);
|
||||
html_titleline2(gettext('Optional Distfiles (Overrides config)'));
|
||||
html_checkbox2('lib32',gettext('32-bit Compatibility'),!empty($pconfig['lib32']) ? true : false,gettext('lib32.txz'),'',false);
|
||||
|
||||
Reference in New Issue
Block a user