Correction and update of clone functionality, now also available for AFP and NFS

This commit is contained in:
bergware
2017-06-10 03:16:24 +02:00
parent d362997b1f
commit a979e5b119
4 changed files with 224 additions and 60 deletions

View File

@@ -3,8 +3,8 @@ Title="AFP Security Settings"
Cond="(($var['shareAFPEnabled']!='no') && (isset($name)?array_key_exists($name,$sec_afp):0))"
---
<?PHP
/* Copyright 2005-2016, Lime Technology
* Copyright 2012-2016, Bergware International.
/* Copyright 2005-2017, Lime Technology
* Copyright 2012-2017, 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,
@@ -14,25 +14,40 @@ Cond="(($var['shareAFPEnabled']!='no') && (isset($name)?array_key_exists($name,$
* all copies or substantial portions of the Software.
*/
?>
<script>
function checkShareSettingsAFP() {
var form = document.afp_security_form;
form.shareVolsizelimitAFP.disabled = form.shareExportAFP.value!="et";
<?
function clone_list_afp($disk) {
return strpos($disk['status'],'_NP')===false && ($disk['type']=='Data' || $disk['name']=='cache');
}
$(checkShareSettingsAFP);
</script>
?>
> This section is used to configure the security settings for the share when accessed using AFP and
> appears only when AFP is enabled on the Network Services page.
<form markdown="1" name="afp_security_form" method="POST" action="/update.htm" target="progressFrame">
> *Clone settings to* is used to copy the AFP 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="position:absolute;right:0">
<span style="font-weight:bold;margin-right:4px">Clone settings to</span>
<select id="s6" name="afpClone" size="1" multiple="multiple" style="display:none">
<option>All</option>
<?
if (isset($disks[$name])) {
foreach (array_filter($disks,'clone_list_afp') 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><input type="button" id="cloneafp" value="Clone" onclick="cloneAFP()" style="margin-left:8px">
</div>
<form markdown="1" name="afp_security_form" method="POST" action="/update.htm" target="progressFrame" onchange="$('#cloneafp').prop('disabled',true);$('#s6').dropdownchecklist('disable')">
<input type="hidden" name="shareName" value="<?=htmlspecialchars($name)?>">
Share name:
: <span class="big"><?=htmlspecialchars($name)?></span>
Export:
: <select name="shareExportAFP" size="1" onchange="checkShareSettingsAFP()">
: <select name="shareExportAFP" size="1" onchange="checkShareSettingsAFP(this.form)">
<?=mk_option($sec_afp[$name]['export'], "-", "No");?>
<?=mk_option($sec_afp[$name]['export'], "e", "Yes");?>
<?=mk_option($sec_afp[$name]['export'], "et", "Yes (TimeMachine)");?>
@@ -95,9 +110,28 @@ Security:
</form>
<?if ($sec_afp[$name]['security'] == 'secure'):?>
<form markdown="1" method="POST" action="/update.htm" target="progressFrame">
<input type="hidden" name="shareName" value="<?=htmlspecialchars($name)?>">
<div id="title" class="nocontrol"><dt>User Access</dt><i>Guests have <b>read-only</b> access.</i></div>
> *Clone settings to* 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="position:absolute;right:0">
<span style="font-weight:bold;margin-right:4px">Clone settings to</span>
<select id="s7" name="afpClone" 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_afp[$list['name']]['security']=='secure') echo mk_option("", $list['name'], my_disk($list['name']));
} else {
foreach ($shares as $list) if ($list['name']!=$name && $sec_afp[$list['name']]['security']=='secure') echo mk_option("", $list['name'], $list['name']);
}
?>
</select><input type="button" id="cloneuserafp" value="Clone" onclick="cloneUserAFP()" style="margin-left:8px">
</div>
<form markdown="1" method="POST" action="/update.htm" target="progressFrame" onchange="$('#cloneuserafp').prop('disabled',true);$('#s7').dropdownchecklist('disable')">
<input type="hidden" name="shareName" value="<?=htmlspecialchars($name)?>">
<?input_secure_users($sec_afp);?>
&nbsp;
@@ -105,12 +139,100 @@ Security:
</form>
<?elseif ($sec_afp[$name]['security'] == 'private'):?>
<form markdown="1" method="POST" action="/update.htm" target="progressFrame">
<input type="hidden" name="shareName" value="<?=htmlspecialchars($name)?>">
<div id="title" class="nocontrol"><dt>User Access</dt><i>Guests have <b>no</b> access.</i></div>
> *Clone settings to* 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="position:absolute;right:0">
<span style="font-weight:bold;margin-right:4px">Clone settings to</span>
<select id="s7" name="afpClone" size="1" multiple="multiple" style="display:none">
<option>All</option>
<?
if (isset($disks[$name])) {
foreach (array_filter($disks,'clone_list_afp') as $list) if ($list['name']!=$name && $sec_afp[$list['name']]['security']=='private') echo mk_option("", $list['name'], my_disk($list['name']));
} else {
foreach ($shares as $list) if ($list['name']!=$name && $sec_afp[$list['name']]['security']=='private') echo mk_option("", $list['name'], $list['name']);
}
?>
</select><input type="button" id="cloneuserafp" value="Clone" onclick="cloneUserAFP()" style="margin-left:8px">
</div>
<form markdown="1" method="POST" action="/update.htm" target="progressFrame" onchange="$('#cloneuserafp').prop('disabled',true);$('#s7').dropdownchecklist('disable')">
<input type="hidden" name="shareName" value="<?=htmlspecialchars($name)?>">
<?input_private_users($sec_afp);?>
&nbsp;
: <input type="submit" name="changeShareAccessAFP" value="Apply"><input type="button" value="Done" onclick="done()">
</form>
<?endif;?>
<script>
$(function() {
checkShareSettingsAFP(document.afp_security_form);
initDropdown3(false);
<?if ($tabbed):?>
$('#tab1').bind({click:function(){initDropdown3(true);}});
<?endif;?>
<?if (count($users)==1):?>
$('#cloneuserafp').prop('disabled',true);
$('#s7').dropdownchecklist('disable');
<?endif;?>
});
function checkShareSettingsAFP(form) {
form.shareVolsizelimitAFP.disabled = form.shareExportAFP.value!="et";
}
function initDropdown3(reset) {
if (reset) {
$('#s6').dropdownchecklist('destroy');
$('#s7').dropdownchecklist('destroy');
}
$("#s6").dropdownchecklist({firstItemChecksAll:true, emptyText:'select...', width:120, explicitClose:'...close'});
$("#s7").dropdownchecklist({firstItemChecksAll:true, emptyText:'select...', width:120, explicitClose:'...close'});
}
function cloneAFP() {
var data = {}, copied = false;
data.shareExportAFP = '<?=addslashes(htmlspecialchars($sec_afp[$name]['export']))?>';
data.shareVolsizelimitAFP = '<?=addslashes(htmlspecialchars($sec_afp[$name]['volsizelimit']))?>';
data.shareVoldbpathAFP = '<?=addslashes(htmlspecialchars($sec_afp[$name]['voldbpath']))?>';
data.shareSecurityAFP = '<?=addslashes(htmlspecialchars($sec_afp[$name]['security']))?>';
data.changeShareSecurityAFP = 'Apply';
$('select#s6 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:'AFP security settings are cloned to the selected shares',type:'success'},function(){refresh();});
}
function cloneUserAFP() {
var data = {}, copied = false;
data['userAccess.0'] = 'no-access';
<?
$read_list = explode(",", $sec_afp[$name]['readList']);
$write_list = explode(",", $sec_afp[$name]['writeList']);
foreach ($users as $user) {
if ($user['name'] == "root") continue;
$idx = $user['idx'];
$userAccess = null;
if ($sec_afp[$name]['security']=='secure') {
$userAccess = in_array($user['name'], $write_list) ? "read-write" : "read-only";
} elseif ($sec_afp[$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.changeShareAccessAFP = 'Apply';
$('select#s7 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>

View File

@@ -14,7 +14,30 @@ Cond="(($var['shareNFSEnabled']!='no') && (isset($name)?array_key_exists($name,$
* all copies or substantial portions of the Software.
*/
?>
<form markdown="1" method="POST" action="/update.htm" target="progressFrame">
<?
function clone_list_nfs($disk) {
return strpos($disk['status'],'_NP')===false && ($disk['type']=='Data' || $disk['name']=='cache');
}
?>
> *Clone settings to* 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="position:absolute;right:0">
<span style="font-weight:bold;margin-right:4px">Clone settings to</span>
<select id="s8" name="nfsClone" size="1" multiple="multiple" style="display:none">
<option>All</option>
<?
if (isset($disks[$name])) {
foreach (array_filter($disks,'clone_list_nfs') 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><input type="button" id="clonenfs" value="Clone" onclick="cloneNFS()" style="margin-left:8px">
</div>
<form markdown="1" method="POST" action="/update.htm" target="progressFrame" onchange="$('#clonenfs').prop('disabled',true);$('#s8').dropdownchecklist('disable')">
<input type="hidden" name="shareName" value="<?=htmlspecialchars($name)?>">
Share name:
@@ -47,3 +70,32 @@ Rule:
: <input type="submit" name="changeShareAccessNFS" value="Apply"><input type="button" value="Done" onclick="done()">
</form>
<?endif;?>
<script>
$(function() {
initDropdown4(false);
<?if ($tabbed):?>
$('<?=$var['shareAFPEnabled']=='no'?'#tab1':'#tab2'?>').bind({click:function(){initDropdown4(true);}});
<?endif;?>
});
function initDropdown4(reset) {
if (reset) {
$('#s8').dropdownchecklist('destroy');
}
$("#s8").dropdownchecklist({firstItemChecksAll:true, emptyText:'select...', width:120, explicitClose:'...close'});
}
function cloneNFS() {
var data = {}, copied = false;
data.shareExportNFS = '<?=addslashes(htmlspecialchars($sec_nfs[$name]['export']))?>';
data.shareSecurityNFS = '<?=addslashes(htmlspecialchars($sec_nfs[$name]['security']))?>';
data.changeShareSecurityNFS = 'Apply';
$('select#s8 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:'NFS security settings are cloned to the selected shares',type:'success'},function(){refresh();});
}
</script>

View File

@@ -3,8 +3,8 @@ 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.
/* Copyright 2005-2017, Lime Technology
* Copyright 2012-2017, 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,
@@ -15,32 +15,26 @@ Cond="(($var['shareSMBEnabled']!='no') && (isset($name)?array_key_exists($name,$
*/
?>
<?
function clone_list($disk) {
function clone_list_smb($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.
> *Clone settings to* 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>
<div style="position:absolute;right:0">
<span style="font-weight:bold;margin-right:4px">Clone settings to</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']));
foreach (array_filter($disks,'clone_list_smb') 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>
</select><input type="button" id="clonesmb" value="Clone" onclick="cloneSMB()" style="margin-left:8px">
</div>
<form markdown="1" method="POST" action="/update.htm" target="progressFrame" onchange="$('#clonesmb').prop('disabled',true);$('#s4').dropdownchecklist('disable')">
@@ -60,7 +54,6 @@ Export:
> 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");?>
@@ -72,7 +65,6 @@ Enhanced OS X interoperability:
> 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");?>
@@ -97,12 +89,12 @@ Security:
<?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.
> *Clone settings to* 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>
<div style="position:absolute;right:0">
<span style="font-weight:bold;margin-right:4px">Clone settings to</span>
<select id="s5" name="smbClone" size="1" multiple="multiple" style="display:none">
<option>All</option>
<?
@@ -112,11 +104,10 @@ if (isset($disks[$name])) {
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>
</select><input type="button" id="cloneusersmb" value="Clone" onclick="cloneUserSMB()" style="margin-left:8px">
</div>
<form markdown="1" method="POST" action="/update.htm" target="progressFrame" onchange="$('#cloneuser').prop('disabled',true);$('#s5').dropdownchecklist('disable')">
<form markdown="1" method="POST" action="/update.htm" target="progressFrame" onchange="$('#cloneusersmb').prop('disabled',true);$('#s5').dropdownchecklist('disable')">
<input type="hidden" name="shareName" value="<?=htmlspecialchars($name)?>">
<?input_secure_users($sec);?>
@@ -127,25 +118,25 @@ if (isset($disks[$name])) {
<?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.
> *Clone settings to* 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>
<div style="position:absolute;right:0">
<span style="font-weight:bold;margin-right:4px">Clone settings to</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']));
foreach (array_filter($disks,'clone_list_smb') 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>
</select><input type="button" id="cloneusersmb" value="Clone" onclick="cloneUserSMB()" style="margin-left:8px">
</div>
<form markdown="1" method="POST" action="/update.htm" target="progressFrame" onchange="$('#cloneuser').prop('disabled',true);$('#s5').dropdownchecklist('disable')">
<form markdown="1" method="POST" action="/update.htm" target="progressFrame" onchange="$('#cloneusersmb').prop('disabled',true);$('#s5').dropdownchecklist('disable')">
<input type="hidden" name="shareName" value="<?=htmlspecialchars($name)?>">
<?input_private_users($sec);?>
@@ -161,7 +152,8 @@ $(function() {
$('#tab'+$('input[name$="tabs"]').length).bind({click:function(){initDropdown2(true);}});
<?endif;?>
<?if (count($users)==1):?>
$('#cloneuser').prop('disabled',true);
$('#cloneusersmb').prop('disabled',true);
$('#s5').dropdownchecklist('disable');
<?endif;?>
});
function initDropdown2(reset) {
@@ -169,8 +161,8 @@ function initDropdown2(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'});
$("#s4").dropdownchecklist({firstItemChecksAll:true, emptyText:'select...', width:120, explicitClose:'...close'});
$("#s5").dropdownchecklist({firstItemChecksAll:true, emptyText:'select...', width:120, explicitClose:'...close'});
}
function cloneSMB() {
var data = {}, copied = false;
@@ -187,7 +179,7 @@ function cloneSMB() {
});
if (copied) swal({title:'Clone complete',text:'SMB security settings are cloned to the selected shares',type:'success'},function(){refresh();});
}
function cloneUser() {
function cloneUserSMB() {
var data = {}, copied = false;
data['userAccess.0'] = 'no-access';
<?

View File

@@ -56,10 +56,10 @@ $myDisks = array_filter(array_diff(array_keys($disks), explode(',',$var['shareUs
> composite view of all files and subdirectories for which that top-level directory exists on each storage device.
>
<?if (!$name):?>
> *Clone source* is used to preset the settings of the new share with the settings of an existing share.
> *Clone settings from* is used to preset the settings of the new share with the settings of an existing share.
> Select the desired share name and press **Clone** to copy the settings from that source.
<?else:?>
> *Clone destinations* is used to copy the settings of the current share to one or more other existing shares.
> *Clone settings to* is used to copy the settings of the current share to one or more other existing shares.
> Select the desired destinations and press **Clone** to copy the settings to those shares.
<?endif;?>
@@ -84,7 +84,7 @@ function initDropdown1(remove,create) {
$("#s1").dropdownchecklist({emptyText:'All', width:300, explicitClose:'...close'});
$("#s2").dropdownchecklist({emptyText:'None', width:300, explicitClose:'...close'});
<?if ($name):?>
$("#s3").dropdownchecklist({firstItemChecksAll:true, emptyText:'please select...', width:150, explicitClose:'...close'});
$("#s3").dropdownchecklist({firstItemChecksAll:true, emptyText:'select...', width:120, explicitClose:'...close'});
<?endif;?>
}
}
@@ -186,21 +186,19 @@ function cloneShare() {
}
<?endif;?>
</script>
<div style="float:right">
<div style="position:absolute;right:0">
<?if ($name):?>
<span style="display:block;font-weight:bold;margin-left:2px;margin-bottom:4px">Clone destinations</span>
<span style="font-weight:bold;margin-right:4px">Clone settings to</span>
<select id="s3" name="shareClone" size="1" multiple="multiple" style="display:none">
<option>All</option>
<?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="cloneshare" value="Clone" onclick="cloneShare()" style="margin-right:0"></div>
</select><input type="button" id="cloneshare" value="Clone" onclick="cloneShare()" style="margin-left:8px">
<?else:?>
<span style="display:block;font-weight:bold;margin-left:2px;margin-bottom:4px">Clone source</span>
<span style="font-weight:bold;margin-right:4px">Clone settings from</span>
<select name="shareClone" size="1" onchange="$('#cloneshare').prop('disabled',false)">
<option disabled selected>please select...</option>
<option disabled selected>select...</option>
<?foreach ($shares as $list) echo mk_option("", $list['name'], $list['name']);?>
</select>
<div style="margin-top:10px"><input type="button" id="cloneshare" value="Clone" onclick="cloneShare()" disabled></div>
</select><input type="button" id="cloneshare" value="Clone" onclick="cloneShare()" style="margin-left:8px" disabled>
<?endif;?>
</div>