Enhanced Read/Write operations for easy cloning of user shares and disk shares

This commit is contained in:
bergware
2017-06-10 18:51:31 +02:00
parent e2d8f1aa0c
commit b5aa1cc7c2
7 changed files with 548 additions and 287 deletions

View File

@@ -1,8 +1,8 @@
Type="xmenu"
---
<?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,
@@ -12,8 +12,10 @@ Type="xmenu"
* all copies or substantial portions of the Software.
*/
?>
<?
function clone_list($disk) {
return strpos($disk['status'],'_NP')===false && ($disk['type']=='Data' || $disk['name']=='cache');
}
if (count($pages)==2) $tabbed = false;
$refs = []; $n = 0;
@@ -28,9 +30,28 @@ $end = count($refs)-1;
$prev = $i>0 ? $refs[$i-1] : $refs[$end];
$next = $i<$end ? $refs[$i+1] : $refs[0];
?>
<style>
div.clone1{position:absolute;right:0;margin-top:0}
div.clone2{position:absolute;right:0;margin-top:48px}
select.clone{min-width:144px;margin-right:0}
input.clone{margin-left:8px;margin-right:0}
span.clone,i.clone{margin-right:4px}
</style>
<script>
var ctrl = "<span class='ctrl2 status vhshift'><a href='/Shares/Disk?name=<?=$prev?>' title='previous disk share'><button type='button' style='margin-right:4px'><i class='fa fa-chevron-left'></i></button></a><a href='/Shares/Disk?name=<?=$next?>' title='next disk share'><button type='button'><i class='fa fa-chevron-right'></i></button></a></span>";
function toggleButton(button,id) {
var disabled = true;
switch (id) {
case false:
case true:
disabled = id;
break;
default:
$('select#'+id+' option').each(function(){if ($(this).prop('selected')==true) disabled = false;});
}
$('input#'+button).prop('disabled',disabled);
}
$(function() {
<?if ($tabbed):?>
$('.tabs').append(ctrl);

View File

@@ -14,33 +14,47 @@ Cond="(($var['shareAFPEnabled']!='no') && (isset($name)?array_key_exists($name,$
* all copies or substantial portions of the Software.
*/
?>
<?
function clone_list_afp($disk) {
return strpos($disk['status'],'_NP')===false && ($disk['type']=='Data' || $disk['name']=='cache');
}
?>
> 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.
> *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 AFP security settings to those shares.
> *Read settings from* is used to preset the AFP security settings of the current selected share with the settings of an existing share.
>
> Select the desired share name and press **Read** to copy the AFP security settings from the selected source.
>
> *Write 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 **Write** to copy the AFP security settings to the selected shares.
<div style="position:absolute;right:0">
<span style="margin-right:4px">Clone settings to</span><i class="fa fa-arrow-right" style="margin-right:4px"></i>
<select id="s6" name="afpClone" size="1" multiple="multiple" style="display:none">
<option>All</option>
<div class="clone1">
<span class="clone">Read settings from</span><i class="fa fa-arrow-left clone"></i>
<select name="readafp" size="1" class="clone" onchange="toggleButton('readafp',false)">
<option disabled selected>select...</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']));
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><input type="button" id="cloneafp" value="Clone" onclick="cloneAFP()" style="margin-left:8px">
</select><input type="button" id="readafp" value="Read" class="clone" onclick="readAFP()" disabled>
</div>
<div class="clone2">
<span class="clone">Write settings to</span><i class="fa fa-arrow-right clone"></i>
<select id="afp1" name="writeafp" size="1" multiple="multiple" style="display:none" onchange="toggleButton('writeafp',this.id)">
<?
$rows = [];
if (isset($disks[$name])) {
foreach (array_filter($disks,'clone_list') as $list) if ($list['name']!=$name) $rows[] = mk_option("", $list['name'], my_disk($list['name']));
} else {
foreach ($shares as $list) if ($list['name']!=$name) $rows[] = mk_option("", $list['name'], $list['name']);
}
if ($rows) echo "<option>All</option>";
foreach ($rows as $row) echo $row;
?>
</select><input type="button" id="writeafp" value="Write" class="clone" onclick="writeAFP()" disabled>
</div>
<form markdown="1" name="afp_security_form" method="POST" action="/update.htm" target="progressFrame" onchange="$('#cloneafp').prop('disabled',true);$('#s6').dropdownchecklist('disable')">
<form markdown="1" name="afp_edit" method="POST" action="/update.htm" target="progressFrame" onchange="toggleButton('writeafp',true);$('#afp1').dropdownchecklist('disable')">
<input type="hidden" name="shareName" value="<?=htmlspecialchars($name)?>">
Share name:
@@ -112,25 +126,44 @@ Security:
<?if ($sec_afp[$name]['security'] == 'secure'):?>
<div id="title" class="nocontrol"><dt>AFP User Access</dt><i>Guests have <b>read-only</b> access.</i></div>
> *Clone settings to* is used to copy the AFP User Access settings of the current share to one or more other existing shares.
> *Read settings from* is used to preset the AFP User Access settings of the current selected share with the settings of an existing share.
>
> Select the desired destinations and press **Clone** to copy the AFP User access settings to those shares.
> Select the desired share name and press **Read** to copy the AFP security settings from the selected source.
>
> *Write settings to* is used to copy the AFP User Access settings of the current share to one or more other existing shares.
>
> Select the desired destinations and press **Write** to copy the AFP User access settings to the selected shares.
<div style="position:absolute;right:0">
<span style="margin-right:4px">Clone settings to</span><i class="fa fa-arrow-right" style="margin-right:4px"></i>
<select id="s7" name="afpClone" size="1" multiple="multiple" style="display:none">
<option>All</option>
<div class="clone1">
<span class="clone">Read settings from</span><i class="fa fa-arrow-left clone"></i>
<select name="readuserafp" size="1" class="clone" onchange="toggleButton('readuserafp',false)">
<option disabled selected>select...</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']));
foreach (array_filter($disks,'clone_list') as $list) if ($list['name']!=$name && $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">
</select><input type="button" id="readuserafp" value="Read" class="clone" onclick="readUserAFP()" disabled>
</div>
<div class="clone2">
<span class="clone">Write settings to</span><i class="fa fa-arrow-right clone"></i>
<select id="afp2" name="writeuserafp" size="1" multiple="multiple" style="display:none" onchange="toggleButton('writeuserafp',this.id)">
<?
$rows = [];
if (isset($disks[$name])) {
foreach (array_filter($disks,'clone_list') as $list) if ($list['name']!=$name && $sec_afp[$list['name']]['security']=='secure') $rows[] = mk_option("", $list['name'], my_disk($list['name']));
} else {
foreach ($shares as $list) if ($list['name']!=$name && $sec_afp[$list['name']]['security']=='secure') $rows[] = mk_option("", $list['name'], $list['name']);
}
if ($rows) echo "<option>All</option>";
foreach ($rows as $row)echo $row;
?>
</select><input type="button" id="writeuserafp" value="Write" class="clone" onclick="writeUserAFP()" disabled>
</div>
<form markdown="1" method="POST" action="/update.htm" target="progressFrame" onchange="$('#cloneuserafp').prop('disabled',true);$('#s7').dropdownchecklist('disable')">
<form markdown="1" name="afp_user_edit" method="POST" action="/update.htm" target="progressFrame" onchange="toggleButton('writeuserafp',true);$('#afp2').dropdownchecklist('disable')">
<input type="hidden" name="shareName" value="<?=htmlspecialchars($name)?>">
<?input_secure_users($sec_afp);?>
@@ -141,25 +174,44 @@ if (isset($disks[$name])) {
<?elseif ($sec_afp[$name]['security'] == 'private'):?>
<div id="title" class="nocontrol"><dt>AFP User Access</dt><i>Guests have <b>no</b> access.</i></div>
> *Clone settings to* is used to copy the AFP User Access settings of the current share to one or more other existing shares.
> *Read settings from* is used to preset the AFP User Access settings of the current selected share with the settings of an existing share.
>
> Select the desired destinations and press **Clone** to copy the AFP User access settings to those shares.
> Select the desired share name and press **Read** to copy the AFP security settings from the selected source.
>
> *Write settings to* is used to copy the AFP User Access settings of the current share to one or more other existing shares.
>
> Select the desired destinations and press **Write** to copy the AFP User access settings to the selected shares.
<div style="position:absolute;right:0">
<span style="margin-right:4px">Clone settings to</span><i class="fa fa-arrow-right" style="margin-right:4px"></i>
<select id="s7" name="afpClone" size="1" multiple="multiple" style="display:none">
<option>All</option>
<div class="clone1">
<span class="clone">Read settings from</span><i class="fa fa-arrow-left clone"></i>
<select name="readuserafp" size="1" class="clone" onchange="toggleButton('readuserafp',false)">
<option disabled selected>select...</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']));
foreach (array_filter($disks,'clone_list') 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">
</select><input type="button" id="readuserafp" value="Read" class="clone" onclick="readUserAFP()" disabled>
</div>
<div class="clone2">
<span class="clone">Write settings to</span><i class="fa fa-arrow-right clone"></i>
<select id="afp2" name="writeuserafp" size="1" multiple="multiple" style="display:none" onchange="toggleButton('writeuserafp',this.id)">
<?
$rows = [];
if (isset($disks[$name])) {
foreach (array_filter($disks,'clone_list') as $list) if ($list['name']!=$name && $sec_afp[$list['name']]['security']=='private') $rows[] = mk_option("", $list['name'], my_disk($list['name']));
} else {
foreach ($shares as $list) if ($list['name']!=$name && $sec_afp[$list['name']]['security']=='private') $rows[] = mk_option("", $list['name'], $list['name']);
}
if ($rows) echo "<option>All</option>";
foreach($rows as $row) echo $row;
?>
</select><input type="button" id="writeuserafp" value="Write" class="clone" onclick="writeUserAFP()" disabled>
</div>
<form markdown="1" method="POST" action="/update.htm" target="progressFrame" onchange="$('#cloneuserafp').prop('disabled',true);$('#s7').dropdownchecklist('disable')">
<form markdown="1" name="afp_user_edit" method="POST" action="/update.htm" target="progressFrame" onchange="toggleButton('writeuserafp',true);$('#afp2').dropdownchecklist('disable')">
<input type="hidden" name="shareName" value="<?=htmlspecialchars($name)?>">
<?input_private_users($sec_afp);?>
@@ -170,44 +222,77 @@ if (isset($disks[$name])) {
<script>
$(function() {
checkShareSettingsAFP(document.afp_security_form);
initDropdown3(false);
checkShareSettingsAFP(document.afp_edit);
initDropdownAFP(false);
<?if ($tabbed):?>
$('#tab1').bind({click:function(){initDropdown3(true);}});
$('#tab2').bind({click:function(){initDropdownAFP(true);}});
<?endif;?>
<?if (count($users)==1):?>
$('#cloneuserafp').prop('disabled',true);
$('#s7').dropdownchecklist('disable');
toggleButton('readuserafp',true);
toggleButton('writeuserafp',true);
$('#afp2').dropdownchecklist('disable');
<?endif;?>
});
function checkShareSettingsAFP(form) {
form.shareVolsizelimitAFP.disabled = form.shareExportAFP.value!="et";
}
function initDropdown3(reset) {
function initDropdownAFP(reset) {
if (reset) {
$('#s6').dropdownchecklist('destroy');
$('#s7').dropdownchecklist('destroy');
$('#afp1').dropdownchecklist('destroy');
$('#afp2').dropdownchecklist('destroy');
}
$("#s6").dropdownchecklist({firstItemChecksAll:true, emptyText:'select...', width:120, explicitClose:'...close'});
$("#s7").dropdownchecklist({firstItemChecksAll:true, emptyText:'select...', width:120, explicitClose:'...close'});
$("#afp1").dropdownchecklist({firstItemChecksAll:true, emptyText:'select...', width:120, explicitClose:'...close'});
$("#afp2").dropdownchecklist({firstItemChecksAll:true, emptyText:'select...', width:120, explicitClose:'...close'});
}
function cloneAFP() {
function readAFP() {
var form = document.afp_edit;
var name = $('select[name="readafp"]').val();
$.get('/webGui/include/ProtocolData.php',{protocol:'afp',name:name},function(json) {
var data = $.parseJSON(json);
form.shareExportAFP.value = data.export;
form.shareVolsizelimitAFP.value = data.volsizelimit;
form.shareVoldbpathAFP.value = data.voldbpath;
form.shareSecurityAFP.value = data.security;
});
$(form).find('select').trigger('change');
}
function writeAFP() {
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() {
$('select#afp1 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();});
if (copied) swal({title:'Clone complete',text:'AFP security settings are written to the selected shares',type:'success'},function(){refresh();});
}
function cloneUserAFP() {
function readUserAFP() {
var form = document.afp_user_edit;
var name = $('select[name="readuserafp"]').val();
var users = {};
<?
foreach ($users as $user) {
if ($user['name'] == "root") continue;
echo "users['{$user['name']}'] = {$user['idx']};\n";
}
?>
$.get('/webGui/include/ProtocolData.php',{protocol:'afp',name:name},function(json) {
var data = $.parseJSON(json);
var readList = data.readList.split(',');
var writeList = data.writeList.split(',');
$(form).find('select[name^="userAccess."]').each(function(){$(this).val('no-access');});
for (var i=0; i < readList.length; i++) $(form).find('select[name="userAccess.'+users[readList[i]]+'"]').val('read-only');
for (var i=0; i < writeList.length; i++) $(form).find('select[name="userAccess.'+users[writeList[i]]+'"]').val('read-write');
});
$(form).find('select').trigger('change');
}
function writeUserAFP() {
var data = {}, copied = false;
data['userAccess.0'] = 'no-access';
<?
@@ -226,13 +311,13 @@ function cloneUserAFP() {
}
?>
data.changeShareAccessAFP = 'Apply';
$('select#s7 option').map(function() {
$('select#afp2 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();});
if (copied) swal({title:'Clone complete',text:'AFP User Access settings are written to the selected shares',type:'success'},function(){refresh();});
}
</script>

View File

@@ -14,30 +14,44 @@ Cond="(($var['shareNFSEnabled']!='no') && (isset($name)?array_key_exists($name,$
* all copies or substantial portions of the Software.
*/
?>
<?
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 NFS security settings of the current selected share to one or more other existing shares.
> *Read settings from* is used to preset the NFS security settings of the current selected share with the settings of an existing share.
>
> Select the desired destinations and press **Clone** to copy the NFS security settings to those shares.
> Select the desired share name and press **Read** to copy the NFS security settings from the selected source.
>
> *Write settings to* is used to copy the NFS security settings of the current selected share to one or more other existing shares.
>
> Select the desired destinations and press **Write** to copy the NFS security settings to the selected shares.
<div style="position:absolute;right:0">
<span style="margin-right:4px">Clone settings to</span><i class="fa fa-arrow-right" style="margin-right:4px"></i>
<select id="s8" name="nfsClone" size="1" multiple="multiple" style="display:none">
<option>All</option>
<div class="clone1">
<span class="clone">Read settings from</span><i class="fa fa-arrow-left clone"></i>
<select name="readnfs" size="1" class="clone" onchange="toggleButton('readnfs',false)">
<option disabled selected>select...</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']));
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><input type="button" id="clonenfs" value="Clone" onclick="cloneNFS()" style="margin-left:8px">
</select><input type="button" id="readnfs" value="Read" class="clone" onclick="readNFS()" disabled>
</div>
<div class="clone2">
<span class="clone">Write settings to</span><i class="fa fa-arrow-right clone"></i>
<select id="nfs1" name="writenfs" size="1" multiple="multiple" style="display:none" onchange="toggleButton('writenfs',this.id)">
<?
$rows = [];
if (isset($disks[$name])) {
foreach (array_filter($disks,'clone_list') as $list) if ($list['name']!=$name) $rows[] = mk_option("", $list['name'], my_disk($list['name']));
} else {
foreach ($shares as $list) if ($list['name']!=$name) $rows[] = mk_option("", $list['name'], $list['name']);
}
if ($rows) echo "<option>All</option>";
foreach ($rows as $row) echo $row;
?>
</select><input type="button" id="writenfs" value="Write" class="clone" onclick="writeNFS()" disabled>
</div>
<form markdown="1" method="POST" action="/update.htm" target="progressFrame" onchange="$('#clonenfs').prop('disabled',true);$('#s8').dropdownchecklist('disable')">
<form markdown="1" name="nfs_edit" method="POST" action="/update.htm" target="progressFrame" onchange="toggleButton('writenfs',true);$('#nfs1').dropdownchecklist('disable')">
<input type="hidden" name="shareName" value="<?=htmlspecialchars($name)?>">
Share name:
@@ -73,29 +87,39 @@ Rule:
<script>
$(function() {
initDropdown4(false);
initDropdownNFS(false);
<?if ($tabbed):?>
$('<?=$var['shareAFPEnabled']=='no'?'#tab1':'#tab2'?>').bind({click:function(){initDropdown4(true);}});
$('<?=$var['shareAFPEnabled']=='no'?'#tab2':'#tab3'?>').bind({click:function(){initDropdownNFS(true);}});
<?endif;?>
});
function initDropdown4(reset) {
function initDropdownNFS(reset) {
if (reset) {
$('#s8').dropdownchecklist('destroy');
$('#nfs1').dropdownchecklist('destroy');
}
$("#s8").dropdownchecklist({firstItemChecksAll:true, emptyText:'select...', width:120, explicitClose:'...close'});
$("#nfs1").dropdownchecklist({firstItemChecksAll:true, emptyText:'select...', width:120, explicitClose:'...close'});
}
function cloneNFS() {
function readNFS() {
var form = document.nfs_edit;
var name = $('select[name="readnfs"]').val();
$.get('/webGui/include/ProtocolData.php',{protocol:'nfs',name:name},function(json) {
var data = $.parseJSON(json);
form.shareExportNFS.value = data.export;
form.shareSecurityNFS.value = data.security;
});
$(form).find('select').trigger('change');
}
function writeNFS() {
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() {
$('select#nfs1 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();});
if (copied) swal({title:'Clone complete',text:'NFS security settings are written to the selected shares',type:'success'},function(){refresh();});
}
</script>

View File

@@ -14,30 +14,44 @@ Cond="(($var['shareSMBEnabled']!='no') && (isset($name)?array_key_exists($name,$
* all copies or substantial portions of the Software.
*/
?>
<?
function clone_list_smb($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.
> *Read settings from* is used to preset the SMB security settings of the current selected share with the settings of an existing share.
>
> Select the desired destinations and press **Clone** to copy the SMB security settings to those shares.
> Select the desired share name and press **Read** to copy the SMB security settings from the selected source.
>
> *Write 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 **Write** to copy the SMB security settings to the selected shares.
<div style="position:absolute;right:0">
<span style="margin-right:4px">Clone settings to</span><i class="fa fa-arrow-right" style="margin-right:4px"></i>
<select id="s4" name="smbClone" size="1" multiple="multiple" style="display:none">
<option>All</option>
<div class="clone1">
<span class="clone">Read settings from</span><i class="fa fa-arrow-left clone"></i>
<select name="readsmb" size="1" class="clone" onchange="toggleButton('readsmb',false)">
<option disabled selected>select...</option>
<?
if (isset($disks[$name])) {
foreach (array_filter($disks,'clone_list_smb') as $list) if ($list['name']!=$name) echo mk_option("", $list['name'], my_disk($list['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><input type="button" id="clonesmb" value="Clone" onclick="cloneSMB()" style="margin-left:8px">
</select><input type="button" id="readsmb" value="Read" class="clone" onclick="readSMB()" disabled>
</div>
<div class="clone2">
<span class="clone">Write settings to</span><i class="fa fa-arrow-right clone"></i>
<select id="smb1" name="writesmb" size="1" multiple="multiple" style="display:none" onchange="toggleButton('writesmb',this.id)">
<?
$rows = [];
if (isset($disks[$name])) {
foreach (array_filter($disks,'clone_list') as $list) if ($list['name']!=$name) $rows[] = mk_option("", $list['name'], my_disk($list['name']));
} else {
foreach ($shares as $list) if ($list['name']!=$name) $rows[] = mk_option("", $list['name'], $list['name']);
}
if ($rows) echo "<option>All</option>";
foreach ($rows as $row) echo $row;
?>
</select><input type="button" id="writesmb" value="Write" class="clone" onclick="writeSMB()" disabled>
</div>
<form markdown="1" method="POST" action="/update.htm" target="progressFrame" onchange="$('#clonesmb').prop('disabled',true);$('#s4').dropdownchecklist('disable')">
<form markdown="1" name="smb_edit" method="POST" action="/update.htm" target="progressFrame" onchange="toggleButton('writesmb',true);$('#smb1').dropdownchecklist('disable')">
<input type="hidden" name="shareName" value="<?=htmlspecialchars($name)?>">
Share name:
@@ -89,25 +103,44 @@ Security:
<?if ($sec[$name]['security'] == 'secure'):?>
<div id="title" class="nocontrol"><dt>SMB User Access</dt><i>Guests have <b>read-only</b> access.</i></div>
> *Clone settings to* is used to copy the SMB User Access settings of the current share to one or more other existing shares.
> *Read settings from* is used to preset the SMB User Access settings of the current selected share with the settings of an existing share.
>
> Select the desired destinations and press **Clone** to copy the SMB User access settings to those shares.
> Select the desired share name and press **Read** to copy the SMB security settings from the selected source.
>
> *Write settings to* is used to copy the SMB User Access settings of the current share to one or more other existing shares.
>
> Select the desired destinations and press **Write** to copy the SMB User access settings to the selected shares.
<div style="position:absolute;right:0">
<span style="margin-right:4px">Clone settings to</span><i class="fa fa-arrow-right" style="margin-right:4px"></i>
<select id="s5" name="smbClone" size="1" multiple="multiple" style="display:none">
<option>All</option>
<div class="clone1">
<span class="clone">Read settings from</span><i class="fa fa-arrow-left clone"></i>
<select name="readusersmb" size="1" class="clone" onchange="toggleButton('readusersmb',false)">
<option disabled selected>select...</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']));
foreach (array_filter($disks,'clone_list') as $list) if ($list['name']!=$name && $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><input type="button" id="cloneusersmb" value="Clone" onclick="cloneUserSMB()" style="margin-left:8px">
</select><input type="button" id="readusersmb" value="Read" class="clone" onclick="readUserSMB()" disabled>
</div>
<div class="clone2">
<span class="clone">Write settings to</span><i class="fa fa-arrow-right clone"></i>
<select id="smb2" name="writeusersmb" size="1" multiple="multiple" style="display:none" onchange="toggleButton('writeusersmb',this.id)">
<?
$rows = [];
if (isset($disks[$name])) {
foreach (array_filter($disks,'clone_list') as $list) if ($list['name']!=$name && $sec[$list['name']]['security']=='secure') $rows[] = mk_option("", $list['name'], my_disk($list['name']));
} else {
foreach ($shares as $list) if ($list['name']!=$name && $sec[$list['name']]['security']=='secure') $rows[] = mk_option("", $list['name'], $list['name']);
}
if ($rows) echo "<option>All</option>";
foreach ($rows as $row) echo $row;
?>
</select><input type="button" id="writeusersmb" value="Write" class="clone" onclick="writeUserSMB()" disabled>
</div>
<form markdown="1" method="POST" action="/update.htm" target="progressFrame" onchange="$('#cloneusersmb').prop('disabled',true);$('#s5').dropdownchecklist('disable')">
<form markdown="1" name="smb_user_edit" method="POST" action="/update.htm" target="progressFrame" onchange="toggleButton('writeusersmb',true);$('#smb2').dropdownchecklist('disable')">
<input type="hidden" name="shareName" value="<?=htmlspecialchars($name)?>">
<?input_secure_users($sec);?>
@@ -118,25 +151,44 @@ if (isset($disks[$name])) {
<?elseif ($sec[$name]['security'] == 'private'):?>
<div id="title" class="nocontrol"><dt>SMB User Access</dt><i>Guests have <b>no</b> access.</i></div>
> *Clone settings to* is used to copy the SMB User Access settings of the current share to one or more other existing shares.
> *Read settings from* is used to preset the SMB User Access settings of the current selected share with the settings of an existing share.
>
> Select the desired destinations and press **Clone** to copy the SMB User access settings to those shares.
> Select the desired share name and press **Read** to copy the SMB security settings from the selected source.
>
> *Write settings to* is used to copy the SMB User Access settings of the current share to one or more other existing shares.
>
> Select the desired destinations and press **Write** to copy the SMB User access settings to the selected shares.
<div style="position:absolute;right:0">
<span style="margin-right:4px">Clone settings to</span><i class="fa fa-arrow-right" style="margin-right:4px"></i>
<select id="s5" name="smbClone" size="1" multiple="multiple" style="display:none">
<option>All</option>
<div class="clone1">
<span class="clone">Read settings from</span><i class="fa fa-arrow-left clone"></i>
<select name="readusersmb" size="1" class="clone" onchange="toggleButton('readusersmb',false)">
<option disabled selected>select...</option>
<?
if (isset($disks[$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']));
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><input type="button" id="cloneusersmb" value="Clone" onclick="cloneUserSMB()" style="margin-left:8px">
</select><input type="button" id="readusersmb" value="Read" class="clone" onclick="readUserSMB()" disabled>
</div>
<div class="clone2">
<span class="clone">Write settings to</span><i class="fa fa-arrow-right clone"></i>
<select id="smb2" name="writeusersmb" size="1" multiple="multiple" style="display:none" onchange="toggleButton('writeusersmb',this.id)">
<?
$rows = [];
if (isset($disks[$name])) {
foreach (array_filter($disks,'clone_list') as $list) if ($list['name']!=$name && $sec[$list['name']]['security']=='private') $rows[] = mk_option("", $list['name'], my_disk($list['name']));
} else {
foreach ($shares as $list) if ($list['name']!=$name && $sec[$list['name']]['security']=='private') $rows[] = mk_option("", $list['name'], $list['name']);
}
if ($rows) echo "<option>All</option>";
foreach ($rows as $row) echo $row;
?>
</select><input type="button" id="writeusersmb" value="Write" class="clone" onclick="writeUserSMB()" disabled>
</div>
<form markdown="1" method="POST" action="/update.htm" target="progressFrame" onchange="$('#cloneusersmb').prop('disabled',true);$('#s5').dropdownchecklist('disable')">
<form markdown="1" name="smb_user_edit" method="POST" action="/update.htm" target="progressFrame" onchange="toggleButton('writeusersmb',true);$('#smb2').dropdownchecklist('disable')">
<input type="hidden" name="shareName" value="<?=htmlspecialchars($name)?>">
<?input_private_users($sec);?>
@@ -147,39 +199,71 @@ if (isset($disks[$name])) {
<script>
$(function() {
initDropdown2(false);
initDropdownSMB(false);
<?if ($tabbed):?>
$('#tab'+$('input[name$="tabs"]').length).bind({click:function(){initDropdown2(true);}});
$('#tab'+$('input[name$="tabs"]').length).bind({click:function(){initDropdownSMB(true);}});
<?endif;?>
<?if (count($users)==1):?>
$('#cloneusersmb').prop('disabled',true);
$('#s5').dropdownchecklist('disable');
toggleButton('readusersmb',true);
toggleButton('writeusersmb',true);
$('#smb2').dropdownchecklist('disable');
<?endif;?>
});
function initDropdown2(reset) {
function initDropdownSMB(reset) {
if (reset) {
$('#s4').dropdownchecklist('destroy');
$('#s5').dropdownchecklist('destroy');
$('#smb1').dropdownchecklist('destroy');
$('#smb2').dropdownchecklist('destroy');
}
$("#s4").dropdownchecklist({firstItemChecksAll:true, emptyText:'select...', width:120, explicitClose:'...close'});
$("#s5").dropdownchecklist({firstItemChecksAll:true, emptyText:'select...', width:120, explicitClose:'...close'});
$("#smb1").dropdownchecklist({firstItemChecksAll:true, emptyText:'select...', width:120, explicitClose:'...close'});
$("#smb2").dropdownchecklist({firstItemChecksAll:true, emptyText:'select...', width:120, explicitClose:'...close'});
}
function cloneSMB() {
function readSMB() {
var form = document.smb_edit;
var name = $('select[name="readsmb"]').val();
$.get('/webGui/include/ProtocolData.php',{protocol:'smb',name:name},function(json) {
var data = $.parseJSON(json);
form.shareExport.value = data.export;
form.shareFruit.value = data.fruit;
form.shareSecurity.value = data.security;
});
$(form).find('select').trigger('change');
}
function writeSMB() {
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.shareSecurity = '<?=addslashes(htmlspecialchars($sec[$name]['shareSecurity']))?>';
data.changeShareSecurity = 'Apply';
$('select#s4 option').map(function() {
$('select#smb1 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();});
if (copied) swal({title:'Clone complete',text:'SMB security settings are written to the selected shares',type:'success'},function(){refresh();});
}
function cloneUserSMB() {
function readUserSMB() {
var form = document.smb_user_edit;
var name = $('select[name="readusersmb"]').val();
var users = {};
<?
foreach ($users as $user) {
if ($user['name'] == "root") continue;
echo "users['{$user['name']}'] = {$user['idx']};\n";
}
?>
$.get('/webGui/include/ProtocolData.php',{protocol:'smb',name:name},function(json) {
var data = $.parseJSON(json);
var readList = data.readList.split(',');
var writeList = data.writeList.split(',');
$(form).find('select[name^="userAccess."]').each(function(){$(this).val('no-access');});
for (var i=0; i < readList.length; i++) $(form).find('select[name="userAccess.'+users[readList[i]]+'"]').val('read-only');
for (var i=0; i < writeList.length; i++) $(form).find('select[name="userAccess.'+users[writeList[i]]+'"]').val('read-write');
});
$(form).find('select').trigger('change');
}
function writeUserSMB() {
var data = {}, copied = false;
data['userAccess.0'] = 'no-access';
<?
@@ -198,13 +282,13 @@ function cloneUserSMB() {
}
?>
data.changeShareAccess = 'Apply';
$('select#s5 option').map(function() {
$('select#smb2 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();});
if (copied) swal({title:'Clone complete',text:'SMB User Access settings are written to the selected shares',type:'success'},function(){refresh();});
}
</script>

View File

@@ -1,8 +1,8 @@
Type="xmenu"
---
<?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,
@@ -12,25 +12,48 @@ Type="xmenu"
* all copies or substantial portions of the Software.
*/
?>
<?if ($name):?>
<?
$refs = []; $n = 0;
// Natural sorting of share names
uksort($shares,'strnatcasecmp');
foreach ($shares as $ref) {
$sname = $ref['name'];
$refs[] = $sname;
if ($sname==$name) $i = $n;
$n++;
function clone_list($disk) {
return strpos($disk['status'],'_NP')===false && ($disk['type']=='Data' || $disk['name']=='cache');
}
if ($name) {
$refs = []; $n = 0;
// Natural sorting of share names
uksort($shares,'strnatcasecmp');
foreach ($shares as $ref) {
$sname = $ref['name'];
$refs[] = $sname;
if ($sname==$name) $i = $n;
$n++;
}
$end = count($refs)-1;
$prev = urlencode($i>0 ? $refs[$i-1] : $refs[$end]);
$next = urlencode($i<$end ? $refs[$i+1] : $refs[0]);
} else {
$tabbed = false;
}
$end = count($refs)-1;
$prev = urlencode($i>0 ? $refs[$i-1] : $refs[$end]);
$next = urlencode($i<$end ? $refs[$i+1] : $refs[0]);
?>
<style>
div.clone1{position:absolute;right:0;margin-top:0}
div.clone2{position:absolute;right:0;margin-top:48px}
select.clone{min-width:144px;margin-right:0}
input.clone{margin-left:8px;margin-right:0}
span.clone,i.clone{margin-right:4px}
</style>
<script>
function toggleButton(button,id) {
var disabled = true;
switch (id) {
case false:
case true:
disabled = id;
break;
default:
$('select#'+id+' option').each(function(){if ($(this).prop('selected')==true) disabled = false;});
}
$('input#'+button).prop('disabled',disabled);
}
<?if ($name):?>
var ctrl = "<span class='ctrl1 status vhshift'><a href='/Shares/Share?name=<?=$prev?>' title='previous user share'><button type='button' style='margin-right:4px'><i class='fa fa-chevron-left'></i></button></a><a href='/Shares/Share?name=<?=$next?>' title='next user share'><button type='button'><i class='fa fa-chevron-right'></i></button></a></span>";
$(function() {
@@ -40,7 +63,5 @@ $(function() {
$('div[id=title]:not(".nocontrol")').each(function(){$(this).append(ctrl);});
<?endif;?>
});
</script>
<?else:?>
<?$tabbed = false;?>
<?endif;?>
</script>

View File

@@ -13,7 +13,6 @@ Title="Share Settings"
* all copies or substantial portions of the Software.
*/
?>
<?
if ($name == "") {
/* default values when adding new share */
@@ -50,159 +49,44 @@ function globalInclude($name) {
$disks = array_filter($disks,'my_disks');
$myDisks = array_filter(array_diff(array_keys($disks), explode(',',$var['shareUserExclude'])), 'globalInclude');
?>
> A *Share*, also called a *User Share*, is simply the name of a top-level directory that exists on one or more of your
> storage devices (array and cache). Each share can be exported for network access. When browsing a share, we return the
> composite view of all files and subdirectories for which that top-level directory exists on each storage device.
>
<?if (!$name):?>
> *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 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.
> *Read 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 **Read** to copy the settings from the selected source.
<?if ($name):?>
>
> *Write 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 **Write** to copy the settings to the selected shares.
<?endif;?>
<script>
$(function() {
initDropdown1(false,true);
<?if ($tabbed):?>
$('#tab1').bind({click:function(){initDropdown1(true,true);}});
<?endif;?>
setDiskList(document.share_edit.shareUseCache.value);
presetSpace(document.share_edit.shareFloor);
});
function initDropdown1(remove,create) {
if (remove) {
$('#s1').dropdownchecklist('destroy');
$('#s2').dropdownchecklist('destroy');
<?if ($name):?>
$('#s3').dropdownchecklist('destroy');
<?endif;?>
}
if (create) {
$("#s1").dropdownchecklist({emptyText:'All', width:300, explicitClose:'...close'});
$("#s2").dropdownchecklist({emptyText:'None', width:300, explicitClose:'...close'});
<?if ($name):?>
$("#s3").dropdownchecklist({firstItemChecksAll:true, emptyText:'select...', width:120, explicitClose:'...close'});
<?endif;?>
}
}
function setDiskList(cache) {
var onOff = cache=='only' ? 'disable' : 'enable';
$("#s1").dropdownchecklist(onOff);
$("#s2").dropdownchecklist(onOff);
}
function presetSpace(shareFloor) {
var unit = ['KB','MB','GB','TB','PB'];
var scale = shareFloor.value;
if (scale.replace(/[0-9.,\s]/g,'').length>0) return;
var base = scale>0 ? Math.floor(Math.log(scale)/Math.log(1000)) : 0;
if (base>=unit.length) base = unit.length-1;
shareFloor.value = (scale/Math.pow(1000, base))+unit[base];
}
// Compose input fields
function prepareEdit(form) {
// Test share name validity
var share = form.shareName.value.trim();
if (share.length==0) {
swal('Missing share name', 'Enter a name for the share', 'error');
return false;
}
if (share.match('^(disk[0-9]+|cache[0-9]*|flash)$')) {
swal('Invalid share name', 'Do not use reserved names', 'error');
return false;
}
form.shareName.value = share;
// Adjust minimum free space value to selected unit
var unit = 'KB,MB,GB,TB,PB';
var scale = form.shareFloor.value;
var index = unit.indexOf(scale.replace(/[0-9.,\s]/g,'').toUpperCase());
form.shareFloor.value = scale.replace(/[A-Z\s]/gi,'') * Math.pow(1000, (index>0 ? index/3 : 0))
// Return include as single line input
var include = '';
for (var i=0,item; item=form.shareInclude.options[i]; i++) {
if (item.selected) {
if (include.length) include += ',';
include += item.value;
item.selected = false;
}
}
item = form.shareInclude.options[0];
item.value = include;
item.selected = true;
// Return exclude as single line input
var exclude = '';
for (var i=0,item; item=form.shareExclude.options[i]; i++) {
if (item.selected) {
if (exclude.length) exclude += ',';
exclude += item.value;
item.selected = false;
}
}
item = form.shareExclude.options[0];
item.value = exclude;
item.selected = true;
return true;
}
<?if ($name):?>
function cloneShare() {
var data = {}, copied = false;
data.shareAllocator = '<?=addslashes(htmlspecialchars($share['allocator']))?>';
data.shareFloor = '<?=addslashes(htmlspecialchars($share['floor']))?>';
data.shareSplitLevel = '<?=addslashes(htmlspecialchars($share['splitLevel']))?>';
data.shareInclude = '<?=addslashes(htmlspecialchars($share['include']))?>';
data.shareExclude = '<?=addslashes(htmlspecialchars($share['exclude']))?>';
data.shareUseCache = '<?=addslashes(htmlspecialchars($share['useCache']))?>';
data.cmdEditShare = 'Apply';
$('select#s3 option').map(function() {
if ($(this).prop('selected')==true) {
data.shareNameOrig = $(this).val();
data.shareName = $(this).val();
$.post('/update.htm', data);
copied = true;
}
});
if (copied) swal({title:'Clone complete',text:'Share settings are cloned to the selected shares',type:'success'},function(){refresh();});
}
<?else:?>
function cloneShare() {
var form = document.share_edit;
var name = $('select[name="shareClone"]').val();
initDropdown1(true,false);
$.get('/webGui/include/ShareData.php',{name:name},function(json) {
var data = $.parseJSON(json);
form.shareAllocator.value = data.allocator;
form.shareFloor.value = data.floor;
form.shareSplitLevel.value = data.splitLevel;
form.shareInclude.value = data.include;
form.shareExclude.value = data.exclude;
form.shareUseCache.value = data.useCache;
form.shareCOW.value = data.cow;
for (var i=0,disk; disk=data.include.split(',')[i]; i++) for (var j=0,include; include=form.shareInclude.options[j]; j++) if (include.value==disk) include.selected=true;
for (var i=0,disk; disk=data.exclude.split(',')[i]; i++) for (var j=0,exclude; exclude=form.shareExclude.options[j]; j++) if (exclude.value==disk) exclude.selected=true;
initDropdown1(false,true);
});
}
<?endif;?>
</script>
<div style="position:absolute;right:0">
<?if ($name):?>
<span style="margin-right:4px">Clone settings to</span><i class="fa fa-arrow-right" style="margin-right:4px"></i>
<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><input type="button" id="cloneshare" value="Clone" onclick="cloneShare()" style="margin-left:8px">
<?else:?>
<span style="margin-right:4px">Clone settings from</span><i class="fa fa-arrow-left" style="margin-right:4px"></i>
<select name="shareClone" size="1" onchange="$('#cloneshare').prop('disabled',false)">
<div id="" class="clone1">
<span class="clone">Read settings from</span><i class="fa fa-arrow-left clone"></i>
<select name="readshare" size="1" class="clone" onchange="toggleButton('readshare',false)">
<option disabled selected>select...</option>
<?foreach ($shares as $list) echo mk_option("", $list['name'], $list['name']);?>
</select><input type="button" id="cloneshare" value="Clone" onclick="cloneShare()" style="margin-left:8px" disabled>
<?endif;?>
<?
foreach ($shares as $list) if ($list['name']!=$name || !$name) echo mk_option("", $list['name'], $list['name']);
?>
</select><input type="button" id="readshare" value="Read" class="clone" onclick="readShare()" disabled>
</div>
<?if ($name):?>
<div id="" class="clone2">
<span class="clone">Write settings to</span><i class="fa fa-arrow-right clone"></i>
<select id="s3" name="writeshare" size="1" multiple="multiple" style="display:none" onchange="toggleButton('writeshare',this.id)">
<?
$rows = [];
foreach ($shares as $list) if ($list['name']!=$name) $rows[] = mk_option("", $list['name'], $list['name']);
if ($rows) echo "<option>All</option>";
foreach ($rows as $row) echo $row;
?>
</select><input type="button" id="writeshare" value="Write" class="clone" onclick="writeShare()" disabled>
</div>
<?endif;?>
<form markdown="1" name="share_edit" method="POST" action="/update.htm" target="progressFrame" onsubmit="return prepareEdit(this)" onchange="$('#cloneshare').prop('disabled',true);$('#s3').dropdownchecklist('disable')">
<form markdown="1" name="share_edit" method="POST" action="/update.htm" target="progressFrame" onsubmit="return prepareEdit(this)"<?=$name?" onchange=\"toggleButton('writeshare',true);$('#s3').dropdownchecklist('disable')\">":">"?>
<input type="hidden" name="shareNameOrig" value="<?=htmlspecialchars($share['nameOrig'])?>">
Share name:
@@ -368,3 +252,125 @@ Share status:
: <input type="submit" name="cmdEditShare" value="Apply"><input type="button" value="Done" onclick="done()">
<?endif;?>
</form>
<script>
$(function() {
initDropdown(false,true);
<?if ($tabbed):?>
$('#tab1').bind({click:function(){initDropdown(true,true);}});
<?endif;?>
setDiskList(document.share_edit.shareUseCache.value);
presetSpace(document.share_edit.shareFloor);
});
function initDropdown(remove,create) {
if (remove) {
$('#s1').dropdownchecklist('destroy');
$('#s2').dropdownchecklist('destroy');
<?if ($name):?>
$('#s3').dropdownchecklist('destroy');
<?endif;?>
}
if (create) {
$("#s1").dropdownchecklist({emptyText:'All', width:300, explicitClose:'...close'});
$("#s2").dropdownchecklist({emptyText:'None', width:300, explicitClose:'...close'});
<?if ($name):?>
$("#s3").dropdownchecklist({firstItemChecksAll:true, emptyText:'select...', width:120, explicitClose:'...close'});
<?endif;?>
}
}
function setDiskList(cache) {
var onOff = cache=='only' ? 'disable' : 'enable';
$("#s1").dropdownchecklist(onOff);
$("#s2").dropdownchecklist(onOff);
}
function presetSpace(shareFloor) {
var unit = ['KB','MB','GB','TB','PB'];
var scale = shareFloor.value;
if (scale.replace(/[0-9.,\s]/g,'').length>0) return;
var base = scale>0 ? Math.floor(Math.log(scale)/Math.log(1000)) : 0;
if (base>=unit.length) base = unit.length-1;
shareFloor.value = (scale/Math.pow(1000, base))+unit[base];
}
// Compose input fields
function prepareEdit(form) {
// Test share name validity
var share = form.shareName.value.trim();
if (share.length==0) {
swal('Missing share name', 'Enter a name for the share', 'error');
return false;
}
if (share.match('^(disk[0-9]+|cache[0-9]*|flash)$')) {
swal('Invalid share name', 'Do not use reserved names', 'error');
return false;
}
form.shareName.value = share;
// Adjust minimum free space value to selected unit
var unit = 'KB,MB,GB,TB,PB';
var scale = form.shareFloor.value;
var index = unit.indexOf(scale.replace(/[0-9.,\s]/g,'').toUpperCase());
form.shareFloor.value = scale.replace(/[A-Z\s]/gi,'') * Math.pow(1000, (index>0 ? index/3 : 0))
// Return include as single line input
var include = '';
for (var i=0,item; item=form.shareInclude.options[i]; i++) {
if (item.selected) {
if (include.length) include += ',';
include += item.value;
item.selected = false;
}
}
item = form.shareInclude.options[0];
item.value = include;
item.selected = true;
// Return exclude as single line input
var exclude = '';
for (var i=0,item; item=form.shareExclude.options[i]; i++) {
if (item.selected) {
if (exclude.length) exclude += ',';
exclude += item.value;
item.selected = false;
}
}
item = form.shareExclude.options[0];
item.value = exclude;
item.selected = true;
return true;
}
function readShare() {
var form = document.share_edit;
var name = $('select[name="readshare"]').val();
initDropdown(true,false);
$.get('/webGui/include/ShareData.php',{name:name},function(json) {
var data = $.parseJSON(json);
form.shareAllocator.value = data.allocator;
form.shareFloor.value = data.floor;
form.shareSplitLevel.value = data.splitLevel;
form.shareInclude.value = data.include;
form.shareExclude.value = data.exclude;
form.shareUseCache.value = data.useCache;
form.shareCOW.value = data.cow;
for (var i=0,disk; disk=data.include.split(',')[i]; i++) for (var j=0,include; include=form.shareInclude.options[j]; j++) if (include.value==disk) include.selected=true;
for (var i=0,disk; disk=data.exclude.split(',')[i]; i++) for (var j=0,exclude; exclude=form.shareExclude.options[j]; j++) if (exclude.value==disk) exclude.selected=true;
initDropdown(false,true);
});
$(form).find('select').trigger('change');
}
function writeShare() {
var data = {}, copied = false;
data.shareAllocator = '<?=addslashes(htmlspecialchars($share['allocator']))?>';
data.shareFloor = '<?=addslashes(htmlspecialchars($share['floor']))?>';
data.shareSplitLevel = '<?=addslashes(htmlspecialchars($share['splitLevel']))?>';
data.shareInclude = '<?=addslashes(htmlspecialchars($share['include']))?>';
data.shareExclude = '<?=addslashes(htmlspecialchars($share['exclude']))?>';
data.shareUseCache = '<?=addslashes(htmlspecialchars($share['useCache']))?>';
data.cmdEditShare = 'Apply';
$('select#s3 option').map(function() {
if ($(this).prop('selected')==true) {
data.shareNameOrig = $(this).val();
data.shareName = $(this).val();
$.post('/update.htm', data);
copied = true;
}
});
if (copied) swal({title:'Clone complete',text:'Share settings are cloned to the selected shares',type:'success'},function(){refresh();});
}
</script>

View File

@@ -0,0 +1,20 @@
<?PHP
/* 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,
* 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.
*/
?>
<?
switch ($_GET['protocol']) {
case 'smb': $data = parse_ini_file('state/sec.ini',true); break;
case 'afp': $data = parse_ini_file('state/sec_afp.ini',true); break;
case 'nfs': $data = parse_ini_file('state/sec_nfs.ini',true); break;
}
echo json_encode($data[$_GET['name']]);
?>