Menu="Disk Share Flash"
Title="SMB Security Settings"
Cond="(($var['shareSMBEnabled']!='no') && (isset($name)?array_key_exists($name,$sec):0))"
---
<?PHP
/* Copyright 2005-2016, Lime Technology
 * Copyright 2012-2016, Bergware International.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License version 2,
 * as published by the Free Software Foundation.
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 */
?>
<?
function clone_list($disk) {
  return strpos($disk['status'],'_NP')===false && ($disk['type']=='Data' || $disk['name']=='cache');
}
?>
<style>
table.settings{width:83.3%;}
table.settings tr td:first-child{width:40%;}
</style>

> *Clone destinations* is used to copy the SMB security settings of the current selected share to one or more other existing shares.
>
> Select the desired destinations and press **Clone** to copy the SMB security settings to those shares.

<div style="float:right">
<span style="display:block;font-weight:bold;margin-left:2px;margin-bottom:4px">Clone destinations</span>
<select id="s4" name="smbClone" size="1" multiple="multiple" style="display:none">
<option>All</option>
<?
if (isset($disks[$name])) {
  foreach (array_filter($disks,'clone_list') as $list) if ($list['name']!=$name) echo mk_option("", $list['name'], my_disk($list['name']));
} else {
  foreach ($shares as $list) if ($list['name']!=$name) echo mk_option("", $list['name'], $list['name']);
}
?>
</select>
<div style="margin-top:10px;text-align:right"><input type="button" id="clonesmb" value="Clone" onclick="cloneSMB()" style="margin-right:0"></div>
</div>

<form markdown="1" method="POST" action="/update.htm" target="progressFrame" onchange="$('#clonesmb').prop('disabled',true);$('#s4').dropdownchecklist('disable')">
<input type="hidden" name="shareName" value="<?=htmlspecialchars($name)?>">

Share name:
: <span class="big"><?=htmlspecialchars($name)?></span>

Export:
: <select name="shareExport" size="1">
  <?=mk_option($sec[$name]['export'], "-", "No");?>
  <?=mk_option($sec[$name]['export'], "e", "Yes");?>
  <?=mk_option($sec[$name]['export'], "eh", "Yes (hidden)");?>
  </select>

> This setting determines whether the share is visible and/or accessible.  The 'Yes (hidden)' setting
> will *hide* the share from *browsing* but is still accessible if you know the share name.

<?if ($name !== 'flash'):?>

Enhanced OS X interoperability:
: <select name="shareFruit" size="1">
  <?=mk_option($sec[$name]['fruit'], "no", "No");?>
  <?=mk_option($sec[$name]['fruit'], "yes", "Yes");?>
  </select>

> When set to 'Yes' provides enhanced compatibility with Apple SMB clients, resulting, for example, in faster
> Finder browsing.  This may cause some issues with Windows clients, however.  Please also refer to
> the [VFS_FRUIT MAN PAGE](https://www.mankier.com/8/vfs_fruit).

<?endif;?>

Security:
: <select name="shareSecurity" size="1">
  <?=mk_option($sec[$name]['security'], "public", "Public");?>
  <?=mk_option($sec[$name]['security'], "secure", "Secure");?>
  <?=mk_option($sec[$name]['security'], "private", "Private");?>
  </select>

> Summary of security modes:
>
> **Public** All users including guests have full read/write access.
>
> **Secure** All users including guests have read access, you select which of your users
> have write access.
>
> **Private** No guest access at all, you select which of your users have read/write or
> read-only access.

&nbsp;
: <input type="submit" name="changeShareSecurity" value="Apply"><input type="button" value="Done" onclick="done()">
</form>

<?if ($sec[$name]['security'] == 'secure'):?>
<div id="title" class="nocontrol"><dt>User Access</dt><i>Guests have <b>read-only</b> access.</i></div>

> *Clone destinations* is used to copy the User access settings of the current share to one or more other existing shares.
>
> Select the desired destinations and press **Clone** to copy the  User access settings to those shares.

<div style="float:right">
<span style="display:block;font-weight:bold;margin-left:2px;margin-bottom:4px">Clone destinations</span>
<select id="s5" name="smbClone" size="1" multiple="multiple" style="display:none">
<option>All</option>
<?
if (isset($disks[$name])) {
  foreach ($disks as $list) if ($list['name']!=$name && ($list['type']=='Data' || $list['name']=='cache') && $sec[$list['name']]['security']=='secure') echo mk_option("", $list['name'], my_disk($list['name']));
} else {
  foreach ($shares as $list) if ($list['name']!=$name && $sec[$list['name']]['security']=='secure') echo mk_option("", $list['name'], $list['name']);
}
?>
</select>
<div style="margin-top:10px;text-align:right"><input type="button" id="cloneuser" value="Clone" onclick="cloneUser()" style="margin-right:0"></div>
</div>

<form markdown="1" method="POST" action="/update.htm" target="progressFrame" onchange="$('#cloneuser').prop('disabled',true);$('#s5').dropdownchecklist('disable')">
<input type="hidden" name="shareName" value="<?=htmlspecialchars($name)?>">
<?input_secure_users($sec);?>

&nbsp;
: <input type="submit" name="changeShareAccess" value="Apply"><input type="button" value="Done" onclick="done()">
</form>

<?elseif ($sec[$name]['security'] == 'private'):?>
<div id="title" class="nocontrol"><dt>User Access</dt><i>Guests have <b>no</b> access.</i></div>

> *Clone destinations* is used to copy the User access settings of the current share to one or more other existing shares.
>
> Select the desired destinations and press **Clone** to copy the  User access settings to those shares.

<div style="float:right">
<span style="display:block;font-weight:bold;margin-left:2px;margin-bottom:4px">Clone destinations</span>
<select id="s5" name="smbClone" size="1" multiple="multiple" style="display:none">
<option>All</option>
<?
if (isset($disks[$name])) {
  foreach (array_filter($disks,'clone_list') as $list) if ($list['name']!=$name && $sec[$list['name']]['security']=='private') echo mk_option("", $list['name'], my_disk($list['name']));
} else {
  foreach ($shares as $list) if ($list['name']!=$name && $sec[$list['name']]['security']=='private') echo mk_option("", $list['name'], $list['name']);
}
?>
</select>
<div style="margin-top:10px;text-align:right"><input type="button" id="cloneuser" value="Clone" onclick="cloneUser()" style="margin-right:0"></div>
</div>
<form markdown="1" method="POST" action="/update.htm" target="progressFrame" onchange="$('#cloneuser').prop('disabled',true);$('#s5').dropdownchecklist('disable')">
<input type="hidden" name="shareName" value="<?=htmlspecialchars($name)?>">
<?input_private_users($sec);?>

&nbsp;
: <input type="submit" name="changeShareAccess" value="Apply"><input type="button" value="Done" onclick="done()">
</form>
<?endif;?>

<script>
$(function() {
  initDropdown2(false);
<?if ($tabbed):?>
  $('#tab'+$('input[name$="tabs"]').length).bind({click:function(){initDropdown2(true);}});
<?endif;?>
<?if (count($users)==1):?>
  $('#cloneuser').prop('disabled',true);
<?endif;?>
});
function initDropdown2(reset) {
  if (reset) {
    $('#s4').dropdownchecklist('destroy');
    $('#s5').dropdownchecklist('destroy');
  }
  $("#s4").dropdownchecklist({firstItemChecksAll:true, emptyText:'please select...', width:150, explicitClose:'...close'});
  $("#s5").dropdownchecklist({firstItemChecksAll:true, emptyText:'please select...', width:150, explicitClose:'...close'});
}
function cloneSMB() {
  var data = {}, copied = false;
  data.shareExport = '<?=addslashes(htmlspecialchars($sec[$name]['export']))?>';
  data.shareFruit = '<?=addslashes(htmlspecialchars($sec[$name]['fruit']))?>';
  data.shareSecurity = '<?=addslashes(htmlspecialchars($sec[$name]['security']))?>';
  data.changeShareSecurity = 'Apply';
  $('select#s4 option').map(function() {
    if ($(this).prop('selected')==true) {
      data.shareName = $(this).val();
      $.post('/update.htm', data);
      copied = true;
    }
  });
  if (copied) swal({title:'Clone complete',text:'SMB security settings are cloned to the selected shares',type:'success'},function(){refresh();});
}
function cloneUser() {
  var data = {}, copied = false;
  data['userAccess.0'] = 'no-access';
<?
  $read_list = explode(",", $sec[$name]['readList']);
  $write_list = explode(",", $sec[$name]['writeList']);
  foreach ($users as $user) {
    if ($user['name'] == "root") continue;
    $idx = $user['idx'];
    $userAccess = null;
    if ($sec[$name]['security']=='secure') {
      $userAccess = in_array($user['name'], $write_list) ? "read-write" : "read-only";
    } elseif ($sec[$name]['security'] == 'private') {
      $userAccess = in_array($user['name'], $write_list) ? "read-write" : (in_array($user['name'], $read_list) ? "read-only" : "no-access");
    }
    if ($userAccess) echo "  data['userAccess.$idx'] = '$userAccess';\n";
  }
?>
  data.changeShareAccess = 'Apply';
  $('select#s5 option').map(function() {
    if ($(this).prop('selected')==true) {
      data.shareName = $(this).val();
      $.post('/update.htm', data);
      copied = true;
    }
  });
  if (copied) swal({title:'Clone complete',text:'User access settings are cloned to the selected shares',type:'success'},function(){refresh();});
}
</script>
