mirror of
https://github.com/unraid/webgui.git
synced 2026-01-14 05:30:07 -06:00
194 lines
8.1 KiB
Plaintext
194 lines
8.1 KiB
Plaintext
Menu="UserList"
|
|
Title="Add User"
|
|
Tag="user"
|
|
---
|
|
<?PHP
|
|
/* Copyright 2005-2020, Lime Technology
|
|
* Copyright 2012-2020, 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.
|
|
*/
|
|
?>
|
|
|
|
<?
|
|
$void = "<img src='/webGui/images/user.png' width='48' height='48' onclick='$("#drop").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}
|
|
i#showPass.checked{opacity:0.5}
|
|
.usage-disk.sys{display:inline-block;width:10rem;top:<?=$themes2?'1.2':'.7'?>rem;margin-left:12px;border-radius:4px}
|
|
</style>
|
|
|
|
<script src="<?autov('/webGui/javascript/jquery.filedrop.js')?>"></script>
|
|
<script src="<?autov('/webGui/javascript/jquery.base64.js')?>"></script>
|
|
<script src="<?autov('/webGui/javascript/jquery.zxcvbn.js')?>" async></script>
|
|
<script>
|
|
var path = '/boot/config/plugins/dynamix/users';
|
|
var filename = '';
|
|
|
|
function showPassword() {
|
|
if ($('#showPass').hasClass('checked')) {
|
|
$('#showPass').removeClass('checked');
|
|
var type = 'password';
|
|
} else {
|
|
$('#showPass').addClass('checked');
|
|
var type = 'text';
|
|
}
|
|
$('input[name="userPasswordGUI"]').attr('type',type);
|
|
$('input[name="userPasswordConfGUI"]').attr('type',type);
|
|
}
|
|
|
|
function checkUsername(form) {
|
|
var username = form.userName.value.trim();
|
|
if (!username.match('^[a-z_][a-z0-9_-]*[$]?$')) {
|
|
swal({title:"Invalid user name",text:"Use only lowercase letters, digits, underscores and dashes",type:"error"});
|
|
return false;
|
|
}
|
|
if (username.match('^(disk[0-9]+|cache[0-9]*|parity[0-9]*|flash)$')) {
|
|
swal({title:"Invalid user name",text:"Do not use reserved names",type:"error"});
|
|
return false;
|
|
}
|
|
if (form.userPasswordGUI.value.length > 128 || form.userPasswordConfGUI.value.length > 128) {
|
|
swal({title:"Password too long",text:"Use a password up to 128 characters",type:"error"});
|
|
return false;
|
|
}
|
|
if (filename) {
|
|
$.post("/webGui/include/FileUpload.php",{cmd:'save',path:path,filename:filename,output:username+'.png'});
|
|
}
|
|
form.userPassword.value = base64(form.userPasswordGUI.value);
|
|
form.userPasswordConf.value = base64(form.userPasswordConfGUI.value);
|
|
form.userPasswordGUI.disabled = true;
|
|
form.userPasswordConfGUI.disabled = true;
|
|
return true;
|
|
}
|
|
|
|
function validatePassword(input) {
|
|
var custom = ['unraid','limetech','lime-technology','bergware','squidly'];
|
|
var strength = ['Worst','Bad','Weak','Good','Strong'];
|
|
var emoji = ['😵','😩','😔','😀','😎'];
|
|
if (!input) {
|
|
$('#strength-bar').css('background-color','transparent');
|
|
$('#strength-text').html('');
|
|
$('.usage-disk.sys').addClass('none');
|
|
} else {
|
|
var bar = zxcvbn(input,custom);
|
|
switch (bar.score) {
|
|
case 0: $('#strength-bar').css('background-color','red'); break;
|
|
case 1: $('#strength-bar').css('background-color','yellow'); break;
|
|
case 2: $('#strength-bar').css('background-color','orange'); break;
|
|
case 3: $('#strength-bar').css('background-color','blue'); break;
|
|
case 4: $('#strength-bar').css('background-color','green'); break;
|
|
}
|
|
$('#strength-bar').css('width',Math.min(input.length*100/64,100)+'%');
|
|
$('#strength-text').html(emoji[bar.score]+' '+strength[bar.score]+'. '+bar.feedback.warning);
|
|
$('.usage-disk.sys').removeClass('none');
|
|
}
|
|
}
|
|
|
|
function restore() {
|
|
// restore original image
|
|
$('#dropbox').html("<?=$void?>");
|
|
filename = '';
|
|
}
|
|
|
|
$(function(){
|
|
var dropbox = $('#dropbox');
|
|
// attach the drag-n-drop feature to the 'dropbox' element
|
|
dropbox.filedrop({
|
|
maxfiles:1,
|
|
maxfilesize:95, // KB
|
|
url:'/webGui/include/FileUpload.php',
|
|
data:{path:path,"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 95 kB (97,280 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) $(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>
|
|
|
|
<form markdown="1" name="user_edit" method="POST" action="/update.htm" target="progressFrame" onsubmit="return checkUsername(this)">
|
|
User name:
|
|
: <input type="text" name="userName" maxlength="32" onKeyUp="this.form.cmdUserEdit.disabled=(this.form.userName.value=='')" pattern="^[a-z_][a-z0-9_-]*[$]?$">
|
|
|
|
> Usernames may be up to 32 characters long and must start with a **lower case letter** or an underscore,
|
|
> followed by **lower case letters**, digits, underscores, or dashes. They can end with a dollar sign.
|
|
|
|
Description:
|
|
: <input type="text" name="userDesc" maxlength="64" pattern='[^&:"]*'>
|
|
|
|
> Up to 64 characters. The characters ampersand (&) quote (") and colon (:) are not allowed.
|
|
|
|
Custom image:
|
|
: <span id="dropbox"><?=$void?></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 95 kB (97,280 bytes).
|
|
|
|
Password:
|
|
<input type="hidden" name="userPassword" value="">
|
|
: <input type="password" name="userPasswordGUI" maxlength="129" onKeyUp="validatePassword(this.value);this.form.cmdUserEdit.disabled=(this.form.userName.value=='' || this.form.userPasswordGUI.value!=this.form.userPasswordConfGUI.value)">
|
|
<i id="showPass" class="fa fa-eye" style="cursor:pointer" title="Show / Hide password" onclick="showPassword()"></i><span><span class="usage-disk sys none"><span id="strength-bar" style="width:0"></span><span></span></span><span id="strength-text"></span></span>
|
|
|
|
> Up to 128 characters.
|
|
|
|
Retype password:
|
|
<input type="hidden" name="userPasswordConf" value="">
|
|
: <input type="password" name="userPasswordConfGUI" maxlength="129" onKeyUp="this.form.cmdUserEdit.disabled=(this.form.userName.value=='' || this.form.userPasswordGUI.value!=this.form.userPasswordConfGUI.value)">
|
|
|
|
|
|
: <input type="submit" name="cmdUserEdit" value="Add" disabled><input type="button" value="Done" onclick="done('UserAdd')">
|
|
</form>
|