Exemple #1
0
function rm_nfs_share($dir)
{
    global $var;
    if ($var['shareNFSEnabled'] == "yes" && get_config("Config", "nfs_export") == "yes") {
        $reload = FALSE;
        foreach (array("/etc/exports", "/etc/exports-") as $file) {
            if (exist_in_file($file, "\"{$dir}\"") && strlen($dir)) {
                $c = is_file($file) ? @file($file, FILE_IGNORE_NEW_LINES) : array();
                unassigned_log("Removing NFS share '{$dir}' from '{$file}'.");
                $c = preg_grep("@\"{$dir}\"@i", $c, PREG_GREP_INVERT);
                $c[] = "";
                file_put_contents($file, implode(PHP_EOL, $c));
                $reload = TRUE;
            }
        }
        if ($reload) {
            shell_exec("/usr/sbin/exportfs -ra 2>/dev/null");
        }
    }
    return TRUE;
}
function rm_smb_share($dir, $share_name) {
  global $paths;
  $share_conf = preg_replace("#\s+#", "_", realpath($paths['smb_usb_shares'])."/".$share_name.".conf");
  debug("Removing share definitions from '$share_conf'.");
  if (is_file($share_conf)) {
    @unlink($share_conf);
    debug("Removing share definitions from '$share_conf'.");
  }
  if (exist_in_file($paths['smb_extra'], $share_conf)) {
    debug("Removing share definitions from ".$paths['smb_extra']);
    $c = (is_file($paths['smb_extra'])) ? @file($paths['smb_extra'],FILE_IGNORE_NEW_LINES) : array();
    # Do Cleanup
    $smb_extra_includes = array_unique(preg_grep("/include/i", $c));
    foreach($smb_extra_includes as $key => $inc) if(! is_file(parse_ini_string($inc)['include'])) unset($smb_extra_includes[$key]); 
    $c = array_merge(preg_grep("/include/i", $c, PREG_GREP_INVERT), $smb_extra_includes);
    $c = preg_replace('/\n\s*\n\s*\n/s', PHP_EOL.PHP_EOL, implode(PHP_EOL, $c));
    file_put_contents($paths['smb_extra'], $c);
  }
  debug("Reloading Samba configuration. ");
  shell_exec("/usr/bin/smbcontrol $(cat /var/run/smbd.pid 2>/dev/null) close-share '${share_name}' 2>&1");
  shell_exec("/usr/bin/smbcontrol $(cat /var/run/smbd.pid 2>/dev/null) reload-config 2>&1");
  if(! is_shared($share_name)) {
    debug("Successfully removed share '${share_name}'."); return TRUE;
  } else {
    debug("Removal of share '${share_name}' failed."); return FALSE;
  }
}