function zfs_dataset_display_properties() { mwexec2("zfs list -H -o name -t filesystem 2>&1", $rawdata); $vols = implode(" ", $rawdata); mwexec2("zfs get all {$vols} 2>&1", $rawdata2); return implode("\n", $rawdata2); }
function zfs_volume_display_properties() { mwexec2("zfs list -H -o name -t volume 2>&1", $rawdata); $vols = implode(" ", $rawdata); mwexec2("zfs get all {$vols} 2>&1", $rawdata2); return implode("\n", $rawdata2); }
function get_zfs_snapshots() { $result = array(); mwexec2("zfs list -H -o name,used,creation -t snapshot 2>&1", $rawdata); foreach ($rawdata as $line) { $a = preg_split("/\t/", $line); $r = array(); $name = $a[0]; $r['snapshot'] = $name; if (preg_match('/^([^\\/\\@]+)(\\/([^\\@]+))?\\@(.*)$/', $name, $m)) { $r['pool'] = $m[1]; $r['name'] = $m[4]; $r['path'] = $m[1] . $m[2]; } else { $r['pool'] = 'unknown'; // XXX $r['name'] = 'unknown'; // XXX $r['path'] = $name; } $r['used'] = $a[1]; $r['creation'] = $a[2]; $result[] = $r; } return $result; }
function get_all_hast() { $a = array(); $a[''] = gettext("Must choose one"); mwexec2("hastctl dump | grep resource", $rawdata); foreach ($rawdata as $line) { $hast = preg_split("/\\s/", $line); $name = $hast[1]; $file = "/dev/hast/{$name}"; if (file_exists($file)) { $diskinfo = disks_get_diskinfo($file); $size = $diskinfo[mediasize_mbytes]; if ($size > 1024) { $size = (int) ($size / 1024); $size .= "GB"; } else { $size .= "MB"; } } else { $size = "(secondary)"; } $a[$file] = htmlspecialchars("{$name}: {$size}"); } return $a; }
function zfs_snapshot_display_properties() { mwexec2("zfs list -H -o name -t snapshot 2>&1", $rawdata); $snaps = implode(" ", $rawdata); $rawdata2 = array(); if (!empty($snaps)) { mwexec2("zfs get all {$snaps} 2>&1", $rawdata2); } return implode("\n", $rawdata2); }
function zfs_zpool_get_iostat() { // Get zpool I/O statistic informations $cmd = "zpool iostat -v 2>&1"; if (isset($_GET['pool'])) { $cmd .= " {$_GET['pool']}"; } mwexec2($cmd, $rawdata); return implode("\n", $rawdata); }
function hast_get_status() { global $config; if (!isset($config['hast']['enable'])) { return gettext("HAST disabled"); } $cmd = "/sbin/hastctl status"; if (isset($_GET['name'])) { $cmd .= " {$_GET['name']}"; } $cmd .= " 2>&1"; mwexec2($cmd, $rawdata); return implode("\n", $rawdata); }
function zfs_zpool_get_status() { global $config; array_sort_key($config['zfs']['pools']['pool'], "name"); array_sort_key($config['zfs']['vdevices']['vdevice'], "name"); $a_pool = $config['zfs']['pools']['pool']; $a_vdevice = $config['zfs']['vdevices']['vdevice']; // Get zpool status informations $cmd = "zpool status -v"; if (isset($_GET['pool'])) { $cmd .= " {$_GET['pool']}"; } mwexec2($cmd, $rawdata); return implode("\n", $rawdata); }
function ismounted_or_dataset($path) { if (disks_ismounted_ex($path, "mp")) { return true; } mwexec2("/sbin/zfs list -H -o mountpoint", $rawdata); foreach ($rawdata as $line) { $mp = trim($line); if ($mp == "-") { conitnue; } if ($path == $mp) { return true; } } return false; }
function get_zfs_paths() { $result = array(); mwexec2("zfs list -H -o name -t filesystem,volume 2>&1", $rawdata); foreach ($rawdata as $line) { $a = preg_split("/\t/", $line); $r = array(); $name = $a[0]; $r['path'] = $name; if (preg_match('/^([^\\/\\@]+)(\\/([^\\@]+))?$/', $name, $m)) { $r['pool'] = $m[1]; } else { $r['pool'] = 'unknown'; // XXX } $result[] = $r; } return $result; }
function rcconf_process_updatenotification($mode, $data) { global $config; $retval = 0; switch ($mode) { case UPDATENOTIFY_MODE_NEW: case UPDATENOTIFY_MODE_MODIFIED: break; case UPDATENOTIFY_MODE_DIRTY: if (is_array($config['system']['rcconf']['param'])) { $index = array_search_ex($data, $config['system']['rcconf']['param'], "uuid"); if (false !== $index) { mwexec2("/usr/local/sbin/rconf attribute remove {$config['system']['rcconf']['param'][$index]['name']}"); unset($config['system']['rcconf']['param'][$index]); write_config(); } } break; } return $retval; }
function get_mount_info($path) { if (file_exists($path) === FALSE) { return FALSE; } // get all mount points $a_mounts = array(); mwexec2('/sbin/mount -p', $rawdata); foreach ($rawdata as $line) { list($dev, $dir, $fs, $opt, $dump, $pass) = preg_split('/\\s+/', $line); $a_mounts[] = array('dev' => $dev, 'dir' => $dir, 'fs' => $fs, 'opt' => $opt, 'dump' => $dump, 'pass' => $pass); } if (empty($a_mounts)) { return FALSE; } // check path with mount list do { foreach ($a_mounts as $mountv) { if (strcmp($mountv['dir'], $path) == 0) { // found mount point return $mountv; } } // path don't have parent? if (strpos($path, '/') === FALSE) { break; } // retry with parent $pathinfo = pathinfo($path); $path = $pathinfo['dirname']; } while (1); return FALSE; }
function get_all_hast($a_extent, $uuid) { $a = array(); $a[''] = gettext("Must choose one"); mwexec2("hastctl dump | grep resource", $rawdata); foreach ($rawdata as $line) { $hast = preg_split("/\\s/", $line); $name = $hast[1]; $file = "/dev/hast/{$name}"; if (file_exists($file)) { $diskinfo = disks_get_diskinfo($file); $size = $diskinfo[mediasize_mbytes]; if ($size > 1024) { $size = (int) ($size / 1024); $size .= "GB"; } else { $size .= "MB"; } } else { $size = "(secondary)"; } $index = array_search_ex($file, $a_extent, "path"); if (FALSE !== $index) { if (!isset($uuid)) { continue; } if ($a_extent[$index]['uuid'] != $uuid) { continue; } } $a[$file] = htmlspecialchars("{$name}: {$size}"); } return $a; }
function execCmd($cmd) { mwexec2("{$cmd} 2>&1", $output, $status); return implode("\n", $output); }
if (is_array($config['bhyve'])) { unset($config['bhyve']); write_config(); header("Location: /"); exit; } } elseif (!is_file("/tmp/bhyve.install")) { unlink_if_exists("/tmp/extensions_bhyve_config.php"); $connected = @fsockopen("www.github.com", 80); if ($connected) { fclose($connected); unset($gitconfigfile); $gitconfigfile = file_get_contents("https://raw.githubusercontent.com/alexey1234/vmbhyve_nas4free/master/conf/ext/extensions_bhyve_config.php"); $git_ver = preg_split("/bhyve_VERSION,/", $gitconfigfile); $git_ver = 0 + $git_ver[1]; mwexec2("fetch -o /tmp/install.sh https://raw.githubusercontent.com/alexey1234/vmbhyve_nas4free/master/bhyve_install.sh", $garbage, $fetch_ret_val); if (is_file("/tmp/install.sh")) { // Fetch of install.sh succeeded mwexec("chmod a+x /tmp/install.sh"); } else { $input_errors[] = "There seems to be a networking issue. I can't reach GitHub to retrieve the file. <br />Please check <a href='/system.php'>DNS</a> and other <a href='/interfaces_lan.php'>networking settings</a>. <br />Alternatively, try it again to see if there was some transient network problem."; } // end of failed install.sh fetch } // end of successful internet connectivity test } out: include "fbegin.inc"; ?> <script type="text/javascript">//<![CDATA[ $(document).ready(function(){
$cronjob['uuid'] = $_POST['uuid']; $cronjob['desc'] = $_POST['desc']; $cronjob['minute'] = !empty($_POST['minute']) ? $_POST['minute'] : null; $cronjob['hour'] = !empty($_POST['hour']) ? $_POST['hour'] : null; $cronjob['day'] = !empty($_POST['day']) ? $_POST['day'] : null; $cronjob['month'] = !empty($_POST['month']) ? $_POST['month'] : null; $cronjob['weekday'] = !empty($_POST['weekday']) ? $_POST['weekday'] : null; $cronjob['all_mins'] = $_POST['all_mins']; $cronjob['all_hours'] = $_POST['all_hours']; $cronjob['all_days'] = $_POST['all_days']; $cronjob['all_months'] = $_POST['all_months']; $cronjob['all_weekdays'] = $_POST['all_weekdays']; $cronjob['who'] = $_POST['who']; $cronjob['command'] = $_POST['command']; if (stristr($_POST['Submit'], gettext("Run now"))) { mwexec2(escapeshellcmd($_POST['command']), $output, $retval); if (0 == $retval) { $execmsg = gettext("The cron job has been executed successfully."); write_log("The cron job '{$_POST['command']}' has been executed successfully."); } else { $execfailmsg = gettext("Failed to execute cron job."); write_log("Failed to execute cron job '{$_POST['command']}'."); } } else { if (isset($uuid) && FALSE !== $cnid) { $a_cronjob[$cnid] = $cronjob; $mode = UPDATENOTIFY_MODE_MODIFIED; } else { $a_cronjob[] = $cronjob; $mode = UPDATENOTIFY_MODE_NEW; }
continue; } if (strpos($fname, '/') === false) { $zfs['pools']['pool'][$index]['used'] = $used; $zfs['pools']['pool'][$index]['avail'] = $avail; } } $rawdata = null; $spa = @exec("sysctl -q -n vfs.zfs.version.spa"); if ($spa == '') { mwexec2("zpool list -H -o name,root,size,allocated,free,capacity,health", $rawdata); } else { if ($spa < 21) { mwexec2("zpool list -H -o name,altroot,size,allocated,free,capacity,health", $rawdata); } else { mwexec2("zpool list -H -o name,altroot,size,allocated,free,capacity,health,dedup", $rawdata); } } foreach ($rawdata as $line) { if ($line == 'no pools available') { continue; } list($pool, $root, $size, $alloc, $free, $cap, $health, $dedup) = explode("\t", $line); if (false === ($index = array_search_ex($pool, $zfs['pools']['pool'], 'name'))) { continue; } if ($root != '-') { $zfs['pools']['pool'][$index]['root'] = $root; } $zfs['pools']['pool'][$index]['size'] = $size; $zfs['pools']['pool'][$index]['alloc'] = $alloc;
function zfs_zpool_get_status() { global $config; array_sort_key($config['zfs']['pools']['pool'], "name"); array_sort_key($config['zfs']['vdevices']['vdevice'], "name"); $a_pool = $config['zfs']['pools']['pool']; $a_vdevice = $config['zfs']['vdevices']['vdevice']; // Get zpool status informations $cmd = "zpool status -v"; if (isset($_GET['pool'])) { $cmd .= " {$_GET['pool']}"; } mwexec2($cmd, $rawdata); // Modify and render status informations $result = ""; foreach ($rawdata as $line) { if (preg_match("/(\\s+)(?:pool\\:)(\\s+)(.*)/", $line, $match)) { $pool = trim($match[3]); $index = array_search_ex($pool, $a_pool, "name"); if (0 && $index !== false) { $href = "<a href='disks_zfs_zpool_edit.php?uuid={$a_pool[$index]['uuid']}'>{$pool}</a>"; $result .= "{$match[1]}pool:{$match[2]}{$href}"; } else { $result .= htmlspecialchars($line); } } else { if (preg_match("/(\\s+)(?:scrub\\:)(\\s+)(.*)/", $line, $match)) { if (0 && isset($pool)) { $href = "<a href='disks_zfs_zpool_tools.php?action=scrub&option=s&pool={$pool}' title=\"" . sprintf(gettext("Start scrub on '%s'."), $pool) . "\">scrub</a>:"; } else { $href = "scrub"; } $result .= "{$match[1]}{$href}{$match[2]}{$match[3]}"; } else { if (0 && isset($pool)) { $a_disk = get_conf_disks_filtered_ex("fstype", "zfs"); $found = false; if (count($a_disk) > 0 && false !== ($index = array_search_ex($pool, $a_pool, "name"))) { $pool_conf = $a_pool[$index]; if (is_array($pool_conf['vdevice'])) { foreach ($pool_conf['vdevice'] as $vdevicev) { if (false !== ($index = array_search_ex($vdevicev, $a_vdevice, "name"))) { $vdevice = $a_vdevice[$index]; if (is_array($vdevice['device'])) { foreach ($vdevice['device'] as $devicev) { $index = array_search_ex($devicev, $a_disk, "devicespecialfile"); if ($index === false) { continue 2; } $disk = $a_disk[$index]; $string = "/(\\s+)(?:" . $disk['name'] . ")(\\s+)(\\w+)(.*)/"; if (preg_match($string, $line, $match)) { $href = "<a href='disks_zfs_zpool_tools.php'>{$disk['name']}</a>"; if (0 && $match[3] == "ONLINE") { $href1 = "<a href='disks_zfs_zpool_tools.php?action=offline&option=d&pool={$pool}&device={$disk[name]}'>{$match[3]}</a>"; } else { if (0 && $match[3] == "OFFLINE") { $href1 = "<a href='disks_zfs_zpool_tools.php?action=online&option=d&pool={$pool}&device={$disk[name]}'>{$match[3]}</a>"; } else { $href1 = ""; } } $result .= "{$match[1]}{$href}{$match[2]}{$href1}{$match[4]}"; $found = true; continue 2; } } } } } } } if (!$found) { $result .= htmlspecialchars($line); } } else { $result .= htmlspecialchars($line); } } } $result .= "<br />"; } return $result; }
function get_logmirror($pool, $dev) { mwexec2("zpool status {$pool}", $rawdata); $type = ""; $mirror = ""; $dev = preg_replace('/^\\/dev\\//', "", $dev); foreach ($rawdata as $line) { if ($line[0] != "\t") { continue; } if (preg_match('/^\\t(\\S+)/', $line, $m)) { $mirror = ""; if ($m[1] == "logs") { $type = "log"; } else { $type = ""; } continue; } else { if ($type != "log") { continue; } } if (preg_match('/^\\t(\\s+)(mirror-(\\S+))/', $line, $m)) { $mirror = $m[2]; } else { if ($mirror == "") { continue; } } if (preg_match('/^\\t\\s+([a-z]+[0-9]+)/', $line, $dev)) { break; } } return $mirror; }
function do_change(&$pconfig) { $address = $pconfig['media_uctladdress']; $port = $pconfig['media_uctlport']; $user = $pconfig['media_uctluser']; $secret = $pconfig['media_uctlsecret']; $muser = $pconfig['media_uctlmuser']; $msecret = $pconfig['media_uctlmsecret']; $target = $pconfig['target']; $lun = 0; $path = $pconfig['path']; $size = $pconfig['size']; $sizeunit = $pconfig['sizeunit']; $flags = $pconfig['flags']; $uctl = "/usr/local/bin/istgtcontrol"; $args = "-q -c /var/etc/iscsi/istgtcontrol.conf"; $args .= " -h " . escapeshellarg($address); $args .= " -p " . escapeshellarg($port); $args .= " -t " . escapeshellarg($target); $args .= " -l " . escapeshellarg($lun); $args .= " -U " . escapeshellarg($user); $args .= " -S " . escapeshellarg($secret); $args .= " -M " . escapeshellarg($muser); $args .= " -R " . escapeshellarg($msecret); $args .= " -s " . escapeshellarg("{$size}{$sizeunit}"); $args .= " -f " . escapeshellarg($flags); $file = escapeshellarg($path); $cmd = "{$uctl} {$args} change {$file} 2>&1"; unset($rawdata, $rc, $pconfig['error']); mwexec2($cmd, $rawdata, $rc); if ($rc != 0) { $pconfig['error'] = $rawdata[0]; return -1; } return 0; }
function get_all_zvol($a_extent, $uuid) { $a = array(); $a[''] = gettext("Must choose one"); mwexec2("zfs list -H -t volume -o name,volsize,sharenfs,org.freebsd:swap", $rawdata); foreach ($rawdata as $line) { $zvol = explode("\t", $line); $name = $zvol[0]; $file = "/dev/zvol/{$name}"; $size = $zvol[1]; $sharenfs = $zvol[2]; $swap = $zvol[3]; if ($sharenfs !== "-") { continue; } if ($swap !== "-") { continue; } $index = array_search_ex($file, $a_extent, "path"); if (FALSE !== $index) { if (!isset($uuid)) { continue; } if ($a_extent[$index]['uuid'] != $uuid) { continue; } } $a[$file] = htmlspecialchars("{$name}: {$size}"); } return $a; }
function get_volused($pool, $name) { mwexec2("zfs get -H -o value used {$pool}/{$name} 2>&1", $rawdata); return $rawdata[0]; }
list($pool, $root, $size, $cap, $health, $dedup) = explode("\t", $line); if ($root != '-') { $zfs['pools']['pool'][$pool]['root'] = $root; } $zfs['extra']['pools']['pool'][$pool]['size'] = $size; $zfs['extra']['pools']['pool'][$pool]['cap'] = $cap; $zfs['extra']['pools']['pool'][$pool]['health'] = $health; $zfs['extra']['pools']['pool'][$pool]['dedup'] = $dedup; } $pool = null; $vdev = null; $type = null; $i = 0; $vdev_type = array('mirror', 'raidz1', 'raidz2', 'raidz3'); $rawdata = null; mwexec2('zpool status', $rawdata); foreach ($rawdata as $line) { if (empty($line[0]) || $line[0] != "\t") { continue; } if (!is_null($vdev) && preg_match('/^\\t (\\S+)/', $line, $m)) { $dev = $m[1]; if (preg_match("/^(.+)\\.nop\$/", $dev, $m)) { $zfs['vdevices']['vdevice'][$vdev]['device'][] = "/dev/{$m[1]}"; $zfs['vdevices']['vdevice'][$vdev]['aft4k'] = true; } else { if (preg_match("/^(.+)\\.eli\$/", $dev, $m)) { //$zfs['vdevices']['vdevice'][$vdev]['device'][] = "/dev/{$m[1]}"; $zfs['vdevices']['vdevice'][$vdev]['device'][] = "/dev/{$dev}"; } else { $zfs['vdevices']['vdevice'][$vdev]['device'][] = "/dev/{$dev}";
//Set new line $hr = ""; //Set horizontal line $bs = ""; //Set bold start $be = ""; //Set bold end $cs = "Error or code:"; //Set code end $ce = ""; //Set code end // Get system and hardware informations $cpuinfo = system_get_cpu_info(); $meminfo = system_get_ram_info(); $hwinfo = trim(exec("/sbin/sysctl -a | /usr/bin/awk -F:\\ '/controller|interface/ &&! /AT|VGA|Key|inet|floppy/{!u[\$2]++}END{for(i in u) a=a OFS i;print a}'")); mwexec2("sysctl -n dev.acpi.0.%desc", $mbinfo); $sys_summary = sprintf("%s %s (revision %s) %s; %s %s %sMiB RAM", get_product_name(), get_product_version(), get_product_revision(), get_platform_type(), $mbinfo[0], $cpuinfo['model'], round($meminfo['real'] / 1024 / 1024)); ?> <form action="<?php echo $_SERVER['SCRIPT_NAME']; ?> " method="post" enctype="multipart/form-data" name="iform"> <table> <tr> <td class="label" align="right"><?php echo gettext("Info"); ?> </td> <td class="text" align="left"><?php echo $sys_summary; ?>
} list($fname, $used, $avail) = explode("\t", $line); if (false === ($index = array_search_ex($fname, $zfs['pools']['pool'], 'name'))) { continue; } if (strpos($fname, '/') === false) { $zfs['pools']['pool'][$index]['used'] = $used; $zfs['pools']['pool'][$index]['avail'] = $avail; } } $rawdata = null; $spa = @exec("sysctl -q -n vfs.zfs.version.spa"); if ($spa == '') { mwexec2("zpool list -H -o name,root,size,capacity,health", $rawdata); } else { mwexec2("zpool list -H -o name,altroot,size,capacity,health", $rawdata); } foreach ($rawdata as $line) { if ($line == 'no pools available') { continue; } list($pool, $root, $size, $cap, $health) = explode("\t", $line); if (false === ($index = array_search_ex($pool, $zfs['pools']['pool'], 'name'))) { continue; } if ($root != '-') { $zfs['pools']['pool'][$index]['root'] = $root; } $zfs['pools']['pool'][$index]['size'] = $size; $zfs['pools']['pool'][$index]['cap'] = $cap; $zfs['pools']['pool'][$index]['health'] = $health;
function zfs_dataset_display_properties() { mwexec2("zfs get all 2>&1", $rawdata); return implode("\n", $rawdata); }
if ($index != false) { $config['system']['usermanagement']['user'][$index]['extraoptions'] = $opt; } write_config(); $retval = 0; config_lock(); $retval |= rc_exec_service("userdb"); config_unlock(); if ($dir != "/nonexistent" && file_exists($dir)) { // adjust permission chmod($dir, 0755); chown($dir, $user); chgrp($dir, $group); // update auth method $cmd = "/usr/local/bin/sudo -u {$user} /usr/local/bin/VBoxManage setproperty websrvauthlibrary null"; mwexec2("{$cmd} 2>&1", $rawdata, $result); if (!file_exists($d_sysrebootreqd_path)) { config_lock(); $retval |= rc_update_service("vbox"); config_unlock(); } } $savemsg = get_std_save_message($retval); } } include "fbegin.inc"; ?> <script type="text/javascript">//<![CDATA[ $(document).ready(function(){ function enable_change(enable_change) { var endis = !($('#enable').prop('checked') || enable_change);
function get_vbox_vminfo($user, $uuid) { $vminfo = array(); unset($rawdata); mwexec2("/usr/local/bin/sudo -u {$user} /usr/local/bin/VBoxManage showvminfo --machinereadable {$uuid}", $rawdata); foreach ($rawdata as $line) { if (preg_match("/^([^=]+)=(\"([^\"]+)\"|[^\"]+)/", $line, $match)) { $a = array(); $a['raw'] = $match[0]; $a['key'] = $match[1]; $a['value'] = isset($match[3]) ? $match[3] : $match[2]; $vminfo[$a['key']] = $a; } } return $vminfo; }
} if (!isset($config['thebrig']['rootfolder']) || !is_dir($config['thebrig']['rootfolder'] . "work")) { $input_errors[] = _THEBRIG_NOT_CONFIRMED; } // end of elseif if ($_POST) { $cmd = "touch " . $config['thebrig']['rootfolder'] . "thebrigerror.txt"; mwexec($cmd); unset($input_errors); // clear out the input errors array $pconfig = $_POST; mwexec2("uname -m", $arch); // Obtain the machine architecture $arch = $arch[0]; // Extract the first string from the array mwexec2("uname -r | cut -d- -f1-2", $rel); // Obtain the current kernel release $rel = $rel[0]; // Extract the first string from the array // This first error check is verifying that at least one file was selected for deletion. // If the "Delete" button was pressed, then we need to check for that, and then grab // the list of files selected, and see how big that array is (count). If the size is less than // one (implying that it is 0), then nothing has been selected, and we need to let the user know. if (isset($_POST['delete']) && count($_POST['formFiles']) < 1) { $input_errors[] = _THEBRIG_DELETE_ERROR; } // This first error check is verifying that at least one file was selected for fetching. // If the "Fetch" button was pressed, then we need to check for that, and then grab // the list of files selected, and see how big that array is (count). If the size is less than // one (implying that it is 0), then nothing has been selected, and we need to let the user know. if (isset($_POST['fetch']) && count($_POST['formPackages']) < 1) {
function get_spare_list($pool) { $result = array(); mwexec2("zpool status {$pool}", $rawdata); $req_level = -1; $key = ""; $devs = array(); foreach ($rawdata as $line) { if ($line[0] != "\t") { continue; } if (preg_match('/^\\t(\\s+)(spare-\\S+)/', $line, $m)) { $req_level = strlen($m[1]) + 2; $key = $m[2]; continue; } if (preg_match('/^\\t(\\s+)(\\S+)/', $line, $m)) { $level = strlen($m[1]); if ($level == $req_level) { $devs[] = "/dev/{$m[2]}"; continue; } } if ($key != "") { $result[$key] = $devs; } $key = ""; $devs = array(); $req_level = -1; } return $result; }