forked from unraid/webgui
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserAdd.page
More file actions
148 lines (132 loc) · 5.78 KB
/
UserAdd.page
File metadata and controls
148 lines (132 loc) · 5.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
Menu="UserList"
Title="Add User"
Tag="user"
---
<?PHP
/* Copyright 2005-2018, Lime Technology
* Copyright 2012-2018, 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;}
</style>
<script src="<?autov('/webGui/javascript/jquery.filedrop.js')?>"></script>
<script>
var path = '/boot/config/plugins/dynamix/users';
var filename = '';
function restore() {
// restore original image
$('#dropbox').html("<?=$void?>");
filename = '';
}
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.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;
}
if (filename) {
$.post("/webGui/include/FileUpload.php",{cmd:'save',path:path,filename:filename,output:username+'.png'});
}
return true;
}
$(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=='')">
> 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.
> In regular expression terms: `[a-z_][a-z0-9_-]*[$]?`
Description:
: <input type="text" name="userDesc" maxlength="64">
> Up to 64 characters.
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="password" name="userPassword" maxlength="129" onKeyUp="this.form.cmdUserEdit.disabled=(this.form.userName.value=='' || 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.userName.value=='' || this.form.userPassword.value!=this.form.userPasswordConf.value)">
: <input type="submit" name="cmdUserEdit" value="Add" disabled><input type="button" value="Done" onclick="done('UserAdd')">
</form>