mirror of
https://github.com/unraid/webgui.git
synced 2026-01-07 10:10:05 -06:00
Merge pull request #1322 from bergware/master
Shares: enable CLEAN UP button only when unused files are present
This commit is contained in:
@@ -78,7 +78,7 @@ function addLog(logLine) {
|
||||
}
|
||||
function addCloseButton() {
|
||||
var done = location.search.split('&').pop().split('=')[1];
|
||||
addLog("<p class='centered'><button class='logLine' type='button' onclick='" + (top.Shadowbox ? "top.Shadowbox" : "window") + ".close()'>"+decodeURI(done)+"</button></p>");
|
||||
addLog("<p class='centered'><button class='logLine' type='button' onclick='" + (parent.Shadowbox ? "parent.Shadowbox" : "window") + ".close()'>"+decodeURI(done)+"</button></p>");
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
|
||||
@@ -31,7 +31,7 @@ i.fa-fw{margin-right:2px}
|
||||
<form name="share_form" method="POST" action="<?=htmlspecialchars($path)?>/Share?name=">
|
||||
<input type="button" id="compute-shares" value="_(Compute All)_" onclick="$(this).prop('disabled',true);shareList('',-1)">
|
||||
<input type="submit" value="_(Add Share)_">
|
||||
<input type="button" value="_(Clean Up)_" onclick="cleanup()">
|
||||
<input type="button" value="_(Clean Up)_" onclick="cleanup()" id="cleanup-button" disabled>
|
||||
</form>
|
||||
|
||||
:share_list_help:
|
||||
@@ -54,15 +54,13 @@ function cleanup() {
|
||||
swal({title:"_(CLEAN UP)_",text:"_(Remove unused share configurations)_",type:'info',html:true,animation:'none',showCancelButton:true,closeOnConfirm:false,confirmButtonText:"<?=_('Proceed')?>",cancelButtonText:"<?=_('Cancel')?>"},function(cleanup){
|
||||
if (!cleanup) return;
|
||||
$.post('/webGui/include/ShareList.php',{cleanup:1},function(data){
|
||||
let text = "_(No unused share configurations present)_";
|
||||
let type = "info";
|
||||
if (data > 0) {
|
||||
text = "_(Removed share configurations)_: "+data;
|
||||
type = "success";
|
||||
}
|
||||
swal({title:"_(CLEAN UP)_",text:text,type:type,html:true,confirmButtonText:"_(Ok)_"});
|
||||
swal({title:"_(CLEAN UP)_",text:"_(Removed share configurations)_: "+data,type:"success",html:true,confirmButtonText:"_(Ok)_"},function(esc){$('#cleanup-button').prop('disabled',true);});
|
||||
});
|
||||
});
|
||||
}
|
||||
$(shareList('',0));
|
||||
$(function(){
|
||||
// enable CLEAN_UP button only when unused files are present
|
||||
$.post('/webGui/include/ShareList.php',{cleanup:0},function(data){if (data>0) $('#cleanup-button').prop('disabled',false);});
|
||||
shareList('',0);
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -19,10 +19,13 @@ if (isset($_POST['scan'])) {
|
||||
if (isset($_POST['cleanup'])) {
|
||||
$n = 0;
|
||||
// active shares
|
||||
$shares = array_keys(parse_ini_file('state/shares.ini',true));
|
||||
$shares = array_map('strtolower',array_keys(parse_ini_file('state/shares.ini',true)));
|
||||
// stored shares
|
||||
foreach (glob("/boot/config/shares/*.cfg",GLOB_NOSORT) as $name) {
|
||||
if (!in_array(basename($name,'.cfg'),$shares)) {$n++; unlink($name);}
|
||||
if (!in_array(strtolower(basename($name,'.cfg')),$shares)) {
|
||||
$n++;
|
||||
if ($_POST['cleanup']==1) unlink($name);
|
||||
}
|
||||
}
|
||||
// return number of deleted files
|
||||
die((string)$n);
|
||||
|
||||
Reference in New Issue
Block a user