Files
webgui/plugins/dynamix/UserEdit.page
2019-08-20 07:27:42 +02:00

262 lines
9.8 KiB
Plaintext

Menu="UserList"
Title="Edit User"
Tag="user"
---
<?PHP
/* Copyright 2005-2019, Lime Technology
* Copyright 2012-2019, 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.
*/
?>
<?if (!array_key_exists($name, $users)):?>
<p class="notice">User <?=htmlspecialchars($name)?> has been deleted.</p><br>
<input type="button" value="Done" onClick="done()">
<?return;?>
<?endif;?>
<?
$user = "/boot/config/plugins/dynamix/users/$name.png";
$void = "<img src='/webGui/images/user.png' width='48' height='48' id='image' onclick='$(&quot;#drop&quot;).click()' style='cursor:pointer' title='Click to select PNG file'>";
$icon = "<i class='fa fa-trash top' title='Restore default image' onclick='restore()'></i>";
?>
<style>
<?if ($display['theme']=='gray'):?>
span#dropbox{border:1px solid #606E7F;border-radius:5px;background:#121510;padding:28px 12px;line-height:72px;margin-right:16px;}
<?elseif ($display['theme']=='azure'):?>
span#dropbox{border:1px solid #606E7F;border-radius:5px;background:#EDEAEF;padding:28px 12px;line-height:72px;margin-right:16px;}
<?elseif ($display['theme']=='black'):?>
span#dropbox{border:1px solid #f2f2f2;border-radius:5px;background:#262626;padding:28px 12px;line-height:72px;margin-right:16px;}
<?else:?>
span#dropbox{border:1px solid #1c1c1c;border-radius:5px;background:#e8e8e8;padding:28px 12px;line-height:72px;margin-right:16px;}
<?endif;?>
i.top{position:absolute;padding-top:4px;cursor:pointer;}
</style>
<script src="<?autov('/webGui/javascript/jquery.filedrop.js')?>"></script>
<script>
var path = '/boot/config/plugins/dynamix/users';
var filename = '';
function checkPassword(form) {
if (form.userPassword.value.length > 128 || form.userPasswordConf.value.length > 128) {
swal({title:"Password too long",text:"Use a password up to 128 characters",type:"error"});
return false;
}
return true;
}
function restore() {
// restore original image and activate APPLY button
$('#dropbox').html("<?=$void?>");
$('input[name="userDesc"]').trigger('change');
filename = 'reset';
}
function upload(remove) {
// save or delete upload when APPLY is pressed
if (remove || filename=='reset') {
$.post("/webGui/include/FileUpload.php",{cmd:'delete',path:path,filename:'<?=addslashes(htmlspecialchars($name))?>.png'});
} else if (filename) {
$.post("/webGui/include/FileUpload.php",{cmd:'save',path:path,filename:filename,output:'<?=addslashes(htmlspecialchars($name))?>.png'});
}
}
$(function(){
var dropbox = $('#dropbox');
// attach the drag-n-drop feature to the 'dropbox' element
dropbox.filedrop({
maxfiles:1,
maxfilesize:512, // KB
url:'/webGui/include/FileUpload.php',
data:{"csrf_token":"<?=$var['csrf_token']?>"},
beforeEach:function(file) {
if (!file.type.match(/^image\/png/)) {
swal({title:"Warning",text:"Only PNG images are allowed!",type:"warning"});
return false;
}
},
error: function(error, file, i) {
switch (error) {
case 'BrowserNotSupported':
swal({title:"Browser error",text:"Your browser does not support HTML5 file uploads!",type:"error"});
break;
case 'TooManyFiles':
swal({title:"Too many files",text:"Please select one file only!",type:"error"});
break;
case 'FileTooLarge':
swal({title:"File too large",text:"Maximum file upload size is 512 kB (524,288 bytes)",type:"error"});
break;
}
},
uploadStarted:function(i,file,count) {
var image = $('img', $(dropbox));
var reader = new FileReader();
image.width = 48;
image.height = 48;
reader.onload = function(e){image.attr('src',e.target.result);};
reader.readAsDataURL(file);
},
uploadFinished:function(i,file,response) {
if (response == 'OK 200') {
if (!filename || filename=='reset') $(dropbox).append("<?=$icon?>");
$('input[name="userDesc"]').trigger('change');
filename = file.name;
} else {
swal({title:"Upload error",text:response,type:"error"});
}
}
});
// simulate a drop action when manual file selection is done
$('#drop').bind('change', function(e) {
var files = e.target.files;
if ($('#dropbox').triggerHandler({type:'drop',dataTransfer:{files:files}})==false) e.stopImmediatePropagation();
});
});
</script>
<div class="spinner fixed"></div>
<form markdown="1" method="POST" action="/update.htm" target="progressFrame" onsubmit="upload(<?=$name=="root" ? 'false' : 'this.confirmDelete.checked'?>)">
<input type="hidden" name="userName" value="<?=htmlspecialchars($name)?>">
User name:
: <?=htmlspecialchars($name)?>
Description:
: <input type="text" name="userDesc" maxlength="64" value="<?=htmlspecialchars($users[$name]['desc'])?>">
> Up to 64 characters.
Custom image:
: <span id="dropbox">
<?if (file_exists($user)):?>
<img src="<?=autov($user)?>" id="image" width="48" height="48" onclick="$('#drop').click()" style="cursor:pointer" title="Click to select PNG file"><?=$icon?>
<?else:?>
<?=$void?>
<?endif;?>
</span><em>Drag-n-drop a PNG file or click the image at the left.</em><input type="file" id="drop" accept=".png" style="display:none">
> The image will be scaled to 48x48 pixels in size. The maximum image file upload size is 512 kB (524,288 bytes).
<?if ($name=="root"):?>
&nbsp;
<?else:?>
Delete<input type="checkbox" name="confirmDelete" onChange="chkDelete(this.form, this.form.cmdUserEdit)">
<?endif;?>
: <input type="submit" name="cmdUserEdit" value="Apply" disabled><input type="button" value="Done" onclick="done('UserEdit')">
</form>
<br><br>
<form markdown="1" method="POST" action="/update.htm" target="progressFrame" onsubmit="return checkPassword(this)">
<input type="hidden" name="userName" value="<?=htmlspecialchars($name)?>">
Password:
: <input type="password" name="userPassword" maxlength="129" onKeyUp="this.form.cmdUserEdit.disabled=(this.form.userPassword.value != this.form.userPasswordConf.value);">
> Up to 128 characters.
Retype password:
: <input type="password" name="userPasswordConf" maxlength="129" onKeyUp="this.form.cmdUserEdit.disabled=(this.form.userPassword.value != this.form.userPasswordConf.value);">
&nbsp;
: <input type="submit" name="cmdUserEdit" value="Change" disabled><input type="button" value="Done" onclick="done('UserEdit')">
</form>
<?if ($name != 'root' && $var['shareSMBEnabled'] != 'no'):?>
<script>
var users = {};
var security = {};
var readList = {};
var writeList = {};
<?
$rw = 'read-write';
$ro = 'read-only';
$no = 'no-access';
foreach ($users as $user) {
$idx = $user['idx'];
if ($idx) echo "users[\"{$user['name']}\"]='$idx';\n";
}
foreach ($shares as $share => $data) {
echo "security[\"$share\"]=\"{$sec[$share]['security']}\";\n";
echo "readList[\"$share\"]=\",{$sec[$share]['readList']},\";\n";
echo "writeList[\"$share\"]=\",{$sec[$share]['writeList']},\";\n";
}
?>
function updateAccess(form,data,n,i) {
var name = ",<?=$name?>,";
if (data) {
if (n<i) {
$.post('/update.htm',data[n], function(){setTimeout(function(){updateAccess(form,data,++n,i);},1000);});
} else {
$('div.spinner').html(unraid_logo).hide();
$('input[value="Reset"]').val('Done').prop('disabled',false).prop('onclick',null).off('click').click(function(){done('UserEdit');});
}
} else {
var data = [];
var i = 0;
$(form).find('select').each(function(){
if ($(this).prop('id')) {
var share = decodeURI($(this).prop('id'));
var access = '';
data[i] = {};
data[i]['userAccess.0'] = '<?=$no?>';
for (var user in users) {
var idx = users[user];
switch (security[share]) {
case 'public':
access = '<?=$rw?>';
break;
case 'secure':
if (','+user+',' == name) access = $(this).val();
else access = writeList[share].indexOf(name)!==-1 ? '<?=$rw?>' : '<?=$ro?>';
break;
case 'private':
if (','+user+',' == name) access = $(this).val();
else access = writeList[share].indexOf(name)!==-1 ? '<?=$rw?>' : (readList[share].indexOf(name)!==-1 ? '<?=$ro?>' : '<?=$no?>');
break;
}
data[i]['userAccess.'+idx] = access;
}
data[i]['shareName'] = share;
data[i]['changeShareAccess'] = 'Apply';
i++;
}
});
$(form).find('input').prop('disabled',true);
$('div.spinner').html(unraid_logo).show();
updateAccess(form,data,0,i);
}
}
</script>
<form markdown="1" method="POST">
<?
echo "<table class='share_status' style='margin-top:20px'>";
echo "<thead><tr><td>Share</td><td>Security</td><td>User Access</td></tr></thead>";
echo "<tbody>";
foreach ($shares as $share => $data) {
if ($sec[$share]['export']=='-') continue;
$security = $sec[$share]['security'];
$read = in_array($name,explode(',',$sec[$share]['readList']));
$write = in_array($name,explode(',',$sec[$share]['writeList']));
switch ($security) {
case 'public' : $access = $rw; break;
case 'secure' : $access = $write ? $rw : $ro; break;
case 'private': $access = $write ? $rw : ($read ? $ro : $no); break;}
echo "<tr><td>$share</td><td>$security</td><td><select onchange='$(this).prop(\"id\",\"".rawurlencode($share)."\")'>";
echo mk_option($access,$rw,'Read/Write');
if ($security!='public') echo mk_option($access,$ro,'Read-only');
if ($security=='private') echo mk_option($access,$no,'No Access');
echo "</select></td></tr>";
}
echo "</tbody>";
echo "</table>";
?>
&nbsp;
: <input type="button" value="Apply" onclick="updateAccess(this.form)" disabled><input type="button" value="Done" onclick="done('UserEdit')">
</form>
<?endif;?>