InPanel 1.2.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (198) hide show
  1. inpanel/__init__.py +29 -0
  2. inpanel/acme.py +289 -0
  3. inpanel/aliyuncs.py +269 -0
  4. inpanel/app.py +514 -0
  5. inpanel/apt.py +223 -0
  6. inpanel/base.py +200 -0
  7. inpanel/config.py +139 -0
  8. inpanel/data/config.ini +29 -0
  9. inpanel/data/history +5 -0
  10. inpanel/data/runlogs.ini +12 -0
  11. inpanel/data/update_info.ini +4 -0
  12. inpanel/dnf.py +225 -0
  13. inpanel/lib/__init__.py +9 -0
  14. inpanel/lib/async_process.py +98 -0
  15. inpanel/lib/filelock.py +82 -0
  16. inpanel/lib/magic.py +233 -0
  17. inpanel/lib/pxssh.py +310 -0
  18. inpanel/lib/pyDes.py +867 -0
  19. inpanel/mod/__init__.py +0 -0
  20. inpanel/mod/apt.py +316 -0
  21. inpanel/mod/certificate.py +268 -0
  22. inpanel/mod/config.py +372 -0
  23. inpanel/mod/cron.py +315 -0
  24. inpanel/mod/disk.py +322 -0
  25. inpanel/mod/dnf.py +239 -0
  26. inpanel/mod/file.py +722 -0
  27. inpanel/mod/firewall.py +199 -0
  28. inpanel/mod/firewall_base.py +137 -0
  29. inpanel/mod/firewall_firewalld.py +170 -0
  30. inpanel/mod/firewall_iptables.py +176 -0
  31. inpanel/mod/firewall_macos.py +213 -0
  32. inpanel/mod/firewall_ufw.py +128 -0
  33. inpanel/mod/ftp.py +231 -0
  34. inpanel/mod/httpd.py +1205 -0
  35. inpanel/mod/lighttpd.py +26 -0
  36. inpanel/mod/login.py +98 -0
  37. inpanel/mod/mysql.py +577 -0
  38. inpanel/mod/named.py +26 -0
  39. inpanel/mod/nginx.py +2327 -0
  40. inpanel/mod/package.py +33 -0
  41. inpanel/mod/package_apt.py +62 -0
  42. inpanel/mod/package_base.py +77 -0
  43. inpanel/mod/package_dnf.py +62 -0
  44. inpanel/mod/package_map.py +366 -0
  45. inpanel/mod/package_yum.py +64 -0
  46. inpanel/mod/php.py +289 -0
  47. inpanel/mod/process.py +291 -0
  48. inpanel/mod/proftpd.py +26 -0
  49. inpanel/mod/pureftpd.py +26 -0
  50. inpanel/mod/query.py +108 -0
  51. inpanel/mod/server.py +1319 -0
  52. inpanel/mod/service.py +262 -0
  53. inpanel/mod/setting.py +228 -0
  54. inpanel/mod/shell.py +78 -0
  55. inpanel/mod/ssh.py +280 -0
  56. inpanel/mod/system.py +220 -0
  57. inpanel/mod/task.py +1337 -0
  58. inpanel/mod/ufw.py +14 -0
  59. inpanel/mod/user.py +306 -0
  60. inpanel/mod/vsftpd.py +67 -0
  61. inpanel/mod/yum.py +243 -0
  62. inpanel/plugins/__init__.py +10 -0
  63. inpanel/plugins/__pycache__/__init__.cpython-313.pyc +0 -0
  64. inpanel/plugins/acme/static/index.html +10 -0
  65. inpanel/plugins/acme/static/index.js +13 -0
  66. inpanel/plugins/shadowsocks-libev/__pycache__/info.cpython-313.pyc +0 -0
  67. inpanel/plugins/shadowsocks-libev/info.py +73 -0
  68. inpanel/plugins/shadowsocks-libev/static/index.html +70 -0
  69. inpanel/plugins/shadowsocks-libev/static/index.js +18 -0
  70. inpanel/public/css/global.css +138 -0
  71. inpanel/public/favicon.ico +0 -0
  72. inpanel/public/images/alipay.jpg +0 -0
  73. inpanel/public/images/loading.gif +0 -0
  74. inpanel/public/images/weixin.jpg +0 -0
  75. inpanel/public/index.html +94 -0
  76. inpanel/public/js/controllers/controllers.js +566 -0
  77. inpanel/public/js/controllers/database.js +590 -0
  78. inpanel/public/js/controllers/ecs.js +624 -0
  79. inpanel/public/js/controllers/file.js +940 -0
  80. inpanel/public/js/controllers/plugins.js +105 -0
  81. inpanel/public/js/controllers/service.js +1460 -0
  82. inpanel/public/js/controllers/site.js +1241 -0
  83. inpanel/public/js/controllers/utils.js +2319 -0
  84. inpanel/public/js/core.js +221 -0
  85. inpanel/public/js/directives.js +784 -0
  86. inpanel/public/js/filters.js +395 -0
  87. inpanel/public/js/services.js +257 -0
  88. inpanel/public/lib/angular/1.0.2/angular-resource.min.js +10 -0
  89. inpanel/public/lib/angular/1.0.2/angular.min.js +158 -0
  90. inpanel/public/lib/bootstrap/css/bootstrap-theme.css +587 -0
  91. inpanel/public/lib/bootstrap/css/bootstrap-theme.css.map +1 -0
  92. inpanel/public/lib/bootstrap/css/bootstrap-theme.min.css +6 -0
  93. inpanel/public/lib/bootstrap/css/bootstrap-theme.min.css.map +1 -0
  94. inpanel/public/lib/bootstrap/css/bootstrap.css +6757 -0
  95. inpanel/public/lib/bootstrap/css/bootstrap.css.map +1 -0
  96. inpanel/public/lib/bootstrap/css/bootstrap.min.css +6 -0
  97. inpanel/public/lib/bootstrap/css/bootstrap.min.css.map +1 -0
  98. inpanel/public/lib/bootstrap/fonts/glyphicons-halflings-regular.eot +0 -0
  99. inpanel/public/lib/bootstrap/fonts/glyphicons-halflings-regular.svg +288 -0
  100. inpanel/public/lib/bootstrap/fonts/glyphicons-halflings-regular.ttf +0 -0
  101. inpanel/public/lib/bootstrap/fonts/glyphicons-halflings-regular.woff +0 -0
  102. inpanel/public/lib/bootstrap/fonts/glyphicons-halflings-regular.woff2 +0 -0
  103. inpanel/public/lib/bootstrap/img/glyphicons-halflings-white.png +0 -0
  104. inpanel/public/lib/bootstrap/img/glyphicons-halflings.png +0 -0
  105. inpanel/public/lib/bootstrap/js/bootstrap.js +2377 -0
  106. inpanel/public/lib/bootstrap/js/bootstrap.min.js +7 -0
  107. inpanel/public/lib/bootstrap/js/npm.js +13 -0
  108. inpanel/public/lib/codemirror/codemirror-compressed.js +1 -0
  109. inpanel/public/lib/codemirror/codemirror.css +173 -0
  110. inpanel/public/lib/jquery/jquery-1.12.4.min.js +5 -0
  111. inpanel/public/lib/md5/md5.js +379 -0
  112. inpanel/public/lib/md5/md5.min.js +1 -0
  113. inpanel/public/partials/database/index.html +172 -0
  114. inpanel/public/partials/database/mysql/dbedit.html +462 -0
  115. inpanel/public/partials/database/mysql/dbnew.html +348 -0
  116. inpanel/public/partials/database/mysql/useredit.html +310 -0
  117. inpanel/public/partials/database/mysql/usernew.html +97 -0
  118. inpanel/public/partials/directives/message.html +20 -0
  119. inpanel/public/partials/directives/navbar.html +25 -0
  120. inpanel/public/partials/directives/selector.html +57 -0
  121. inpanel/public/partials/directives/srvbase.html +72 -0
  122. inpanel/public/partials/directives/srvext.html +34 -0
  123. inpanel/public/partials/directives/srvfile.html +23 -0
  124. inpanel/public/partials/directives/srvinstall.html +34 -0
  125. inpanel/public/partials/directives/srvlog.html +23 -0
  126. inpanel/public/partials/directives/srvminiop.html +28 -0
  127. inpanel/public/partials/directives/srvuninstall.html +38 -0
  128. inpanel/public/partials/directives/srvupdate.html +30 -0
  129. inpanel/public/partials/ecs/account.html +156 -0
  130. inpanel/public/partials/ecs/ecs.html +198 -0
  131. inpanel/public/partials/ecs/index.html +40 -0
  132. inpanel/public/partials/ecs/setings.html +459 -0
  133. inpanel/public/partials/file/file.html +501 -0
  134. inpanel/public/partials/file/trash.html +95 -0
  135. inpanel/public/partials/ftp.html +36 -0
  136. inpanel/public/partials/log.html +83 -0
  137. inpanel/public/partials/login.html +79 -0
  138. inpanel/public/partials/logout.html +22 -0
  139. inpanel/public/partials/main.html +534 -0
  140. inpanel/public/partials/plugins/index.html +55 -0
  141. inpanel/public/partials/plugins/plugins.html +13 -0
  142. inpanel/public/partials/secure.html +13 -0
  143. inpanel/public/partials/service/apache.html +147 -0
  144. inpanel/public/partials/service/cron.html +71 -0
  145. inpanel/public/partials/service/index.html +293 -0
  146. inpanel/public/partials/service/iptables.html +40 -0
  147. inpanel/public/partials/service/lighttpd.html +63 -0
  148. inpanel/public/partials/service/mariadb.html +113 -0
  149. inpanel/public/partials/service/memcache.html +36 -0
  150. inpanel/public/partials/service/minio.html +44 -0
  151. inpanel/public/partials/service/mongodb.html +44 -0
  152. inpanel/public/partials/service/mysql.html +113 -0
  153. inpanel/public/partials/service/named.html +61 -0
  154. inpanel/public/partials/service/nginx.html +296 -0
  155. inpanel/public/partials/service/ntp.html +40 -0
  156. inpanel/public/partials/service/php.html +250 -0
  157. inpanel/public/partials/service/proftpd.html +59 -0
  158. inpanel/public/partials/service/pureftpd.html +59 -0
  159. inpanel/public/partials/service/redis.html +40 -0
  160. inpanel/public/partials/service/samba.html +58 -0
  161. inpanel/public/partials/service/sendmail.html +40 -0
  162. inpanel/public/partials/service/ssh.html +186 -0
  163. inpanel/public/partials/service/tomcat.html +65 -0
  164. inpanel/public/partials/service/vsftpd.html +195 -0
  165. inpanel/public/partials/setting.html +299 -0
  166. inpanel/public/partials/site/apache/site.html +277 -0
  167. inpanel/public/partials/site/index.html +344 -0
  168. inpanel/public/partials/site/nginx/site.html +558 -0
  169. inpanel/public/partials/sorry.html +19 -0
  170. inpanel/public/partials/storage/autofm.html +103 -0
  171. inpanel/public/partials/storage/backup.html +42 -0
  172. inpanel/public/partials/storage/index.html +360 -0
  173. inpanel/public/partials/storage/migrate.html +93 -0
  174. inpanel/public/partials/storage/movedata.html +98 -0
  175. inpanel/public/partials/storage/remote.html +77 -0
  176. inpanel/public/partials/utils/cron.html +486 -0
  177. inpanel/public/partials/utils/firewall.html +266 -0
  178. inpanel/public/partials/utils/index.html +193 -0
  179. inpanel/public/partials/utils/network.html +118 -0
  180. inpanel/public/partials/utils/process.html +239 -0
  181. inpanel/public/partials/utils/repository.html +373 -0
  182. inpanel/public/partials/utils/shell.html +28 -0
  183. inpanel/public/partials/utils/ssl.html +319 -0
  184. inpanel/public/partials/utils/time.html +109 -0
  185. inpanel/public/partials/utils/user.html +359 -0
  186. inpanel/public/robots.txt +2 -0
  187. inpanel/remote.py +109 -0
  188. inpanel/templates/file/preview.html +34 -0
  189. inpanel/templates/index.html +93 -0
  190. inpanel/utils.py +282 -0
  191. inpanel/web.py +1811 -0
  192. inpanel/yum.py +756 -0
  193. inpanel-1.2.1.dist-info/METADATA +399 -0
  194. inpanel-1.2.1.dist-info/RECORD +198 -0
  195. inpanel-1.2.1.dist-info/WHEEL +5 -0
  196. inpanel-1.2.1.dist-info/entry_points.txt +2 -0
  197. inpanel-1.2.1.dist-info/licenses/LICENSE +30 -0
  198. inpanel-1.2.1.dist-info/top_level.txt +1 -0
@@ -0,0 +1,590 @@
1
+ var DatabaseCtrl = [
2
+ '$scope', 'Module', '$rootScope', 'Request', 'Message', 'Backend',
3
+ function($scope, Module, $rootScope, Request, Message, Backend) {
4
+ var module = 'database';
5
+ Module.init(module, '数据库管理');
6
+ $scope.loaded = false;
7
+
8
+ var section = Module.getSection();
9
+ $scope.has_dbserver = false;
10
+ $scope.mysql_supported = false;
11
+
12
+ $scope.load = function() {
13
+ Request.get('/api/query/service.mysqld', function(data) {
14
+ if (data['service.mysqld'] && data['service.mysqld'].status) $scope.mysql_supported = true;
15
+ $scope.has_dbserver = $scope.mysql_supported;
16
+ if ($scope.has_dbserver) {
17
+ if (section) {
18
+ if (section == 'mysqld' && $scope.mysql_supported)
19
+ Module.setSection('mysqld');
20
+ else
21
+ Module.setSection($scope.mysql_supported ? 'mysql' : 'mysql');
22
+ } else {
23
+ Module.setSection($scope.mysql_supported ? 'mysql' : 'mysql');
24
+ }
25
+ }
26
+ $scope.loaded = true;
27
+ });
28
+ };
29
+
30
+ $scope.validate_password = function() {
31
+ $scope.processing = true;
32
+ Request.post('/api/operation/mysql', {
33
+ 'action': 'checkpwd',
34
+ 'password': $rootScope.$mysql.password
35
+ }, function(data) {
36
+ if (data.code == 0) {
37
+ $rootScope.$mysql.password_validated = true;
38
+ $scope.loaddbs();
39
+ $scope.loadusers();
40
+ }
41
+ $scope.processing = false;
42
+ });
43
+ };
44
+ $scope.dbloading = true;
45
+ $scope.loaddbs = function() {
46
+ $scope.dbloading = true;
47
+ Backend.call(
48
+ $scope,
49
+ module,
50
+ '/api/backend/mysql_databases',
51
+ '/api/backend/mysql_databases', {
52
+ 'password': $rootScope.$mysql.password
53
+ }, {
54
+ 'success': function(data) {
55
+ $scope.dbs = data.data;
56
+ $scope.dbloading = false;
57
+ },
58
+ 'error': function() {
59
+ $scope.dbloading = false;
60
+ }
61
+ }
62
+ );
63
+ };
64
+ $scope.userloading = true;
65
+ $scope.loadusers = function() {
66
+ $scope.userloading = true;
67
+ Backend.call(
68
+ $scope,
69
+ module,
70
+ '/api/backend/mysql_users',
71
+ '/api/backend/mysql_users', {
72
+ 'password': $rootScope.$mysql.password
73
+ }, {
74
+ 'success': function(data) {
75
+ $scope.users = data.data;
76
+ $scope.userloading = false;
77
+ },
78
+ 'error': function() {
79
+ $scope.userloading = false;
80
+ }
81
+ }
82
+ );
83
+ };
84
+
85
+ if ($rootScope.$mysql.password_validated) {
86
+ $scope.loaddbs();
87
+ $scope.loadusers();
88
+ }
89
+ }
90
+ ];
91
+
92
+ var DatabaseMySQLNewDBCtrl = [
93
+ '$scope', 'Module', '$rootScope', '$location', 'Request', 'Message', 'Backend',
94
+ function($scope, Module, $rootScope, $location, Request, Message, Backend) {
95
+ var module = 'database.mysql.db.new';
96
+ Module.init(module, '新建数据库');
97
+ $scope.loaded = true;
98
+
99
+ $scope.collation = 'utf8_general_ci';
100
+ $scope.validate_password = function() {
101
+ $scope.processing = true;
102
+ Request.post('/api/operation/mysql', {
103
+ 'action': 'checkpwd',
104
+ 'password': $rootScope.$mysql.password
105
+ }, function(data) {
106
+ if (data.code == 0) {
107
+ $rootScope.$mysql.password_validated = true;
108
+ }
109
+ $scope.processing = false;
110
+ });
111
+ };
112
+ $scope.newdb = function() {
113
+ $scope.processing = true;
114
+ Backend.call(
115
+ $scope,
116
+ module,
117
+ '/api/backend/mysql_create',
118
+ '/api/backend/mysql_create_' + $scope.dbname, {
119
+ 'password': $rootScope.$mysql.password,
120
+ 'dbname': $scope.dbname,
121
+ 'collation': $scope.collation
122
+ }, {
123
+ 'success': function(data) {
124
+ $location.path('/database/mysql/db/edit/' + encodeURIComponent($scope.dbname));
125
+ $scope.processing = false;
126
+ },
127
+ 'error': function() {
128
+ $scope.processing = false;
129
+ }
130
+ }
131
+ );
132
+ };
133
+ }
134
+ ];
135
+
136
+ var DatabaseMySQLEditDBCtrl = [
137
+ '$scope', 'Module', '$rootScope', '$routeParams', '$location', 'Request', 'Message', 'Backend',
138
+ function($scope, Module, $rootScope, $routeParams, $location, Request, Message, Backend) {
139
+ var section = $routeParams.section;
140
+ $scope.dbname = decodeURIComponent(section);
141
+
142
+ var module = 'database.mysql.db.edit';
143
+ Module.init(module, '管理数据库 ' + $scope.dbname);
144
+ Module.initSection('users');
145
+ $scope.loaded = true;
146
+
147
+ $scope.validate_password = function() {
148
+ $scope.processing = true;
149
+ Request.post('/api/operation/mysql', {
150
+ 'action': 'checkpwd',
151
+ 'password': $rootScope.$mysql.password
152
+ }, function(data) {
153
+ if (data.code == 0) {
154
+ $rootScope.$mysql.password_validated = true;
155
+ $scope.loaddbinfo();
156
+ }
157
+ $scope.processing = false;
158
+ });
159
+ };
160
+
161
+ $scope.dbloading = true;
162
+ $scope.loaddbinfo = function() {
163
+ $scope.dbloading = true;
164
+ Backend.call(
165
+ $scope,
166
+ module,
167
+ '/api/backend/mysql_dbinfo',
168
+ '/api/backend/mysql_dbinfo_' + $scope.dbname, {
169
+ 'password': $rootScope.$mysql.password,
170
+ 'dbname': $scope.dbname
171
+ }, {
172
+ 'success': function(data) {
173
+ $scope.dbinfo = data.data;
174
+ $scope.dbloading = false;
175
+ $scope.loadusers();
176
+ },
177
+ 'error': function() {
178
+ $scope.dbloading = false;
179
+ }
180
+ }
181
+ );
182
+ };
183
+
184
+ $scope.userloading = true;
185
+ $scope.loadusers = function() {
186
+ $scope.userloading = true;
187
+ Backend.call(
188
+ $scope,
189
+ module,
190
+ '/api/backend/mysql_users',
191
+ '/api/backend/mysql_users_' + $scope.dbname, {
192
+ 'password': $rootScope.$mysql.password,
193
+ 'dbname': $scope.dbname
194
+ }, {
195
+ 'success': function(data) {
196
+ $scope.users = data.data;
197
+ $scope.userloading = false;
198
+ },
199
+ 'error': function() {
200
+ $scope.userloading = false;
201
+ }
202
+ }
203
+ );
204
+ };
205
+
206
+ $scope.setcollation = function() {
207
+ $scope.processing = true;
208
+ Request.post('/api/operation/mysql', {
209
+ 'action': 'alter_database',
210
+ 'password': $rootScope.$mysql.password,
211
+ 'dbname': $scope.dbname,
212
+ 'collation': $scope.dbinfo.collation
213
+ }, function() {
214
+ $scope.processing = false;
215
+ });
216
+ };
217
+ $scope.rename = function() {
218
+ $scope.processing = true;
219
+ Backend.call(
220
+ $scope,
221
+ module,
222
+ '/api/backend/mysql_rename',
223
+ '/api/backend/mysql_rename_' + $scope.dbname, {
224
+ 'password': $rootScope.$mysql.password,
225
+ 'dbname': $scope.dbname,
226
+ 'newname': $scope.dbinfo.name
227
+ }, {
228
+ 'success': function(data) {
229
+ $location.path('/database/mysql/db/edit/' + encodeURIComponent($scope.dbinfo.name));
230
+ $scope.processing = false;
231
+ },
232
+ 'error': function() {
233
+ $scope.processing = false;
234
+ }
235
+ }
236
+ );
237
+ };
238
+ $scope.selectexportfolder = function() {
239
+ $scope.selector.onlydir = true;
240
+ $scope.selector.onlyfile = false;
241
+ $scope.selector.load($scope.exportpath ? $scope.exportpath : '/root');
242
+ $scope.selector.selecthandler = function(path) {
243
+ $('#selector').modal('hide');
244
+ $scope.exportpath = path;
245
+ };
246
+ $('#selector').modal();
247
+ };
248
+ $scope.exportdb = function() {
249
+ $scope.processing = true;
250
+ Backend.call(
251
+ $scope,
252
+ module,
253
+ '/api/backend/mysql_export',
254
+ '/api/backend/mysql_export_' + $scope.dbname, {
255
+ 'password': $rootScope.$mysql.password,
256
+ 'dbname': $scope.dbname,
257
+ 'path': $scope.exportpath
258
+ },
259
+ function(data) {
260
+ $scope.processing = false;
261
+ }
262
+ );
263
+ };
264
+ $scope.dropdb = function() {
265
+ $scope.processing = true;
266
+ Backend.call(
267
+ $scope,
268
+ module,
269
+ '/api/backend/mysql_drop',
270
+ '/api/backend/mysql_drop_' + $scope.dbname, {
271
+ 'password': $rootScope.$mysql.password,
272
+ 'dbname': $scope.dbname
273
+ },
274
+ function(data) {
275
+ if (data.code == 0) {
276
+ $location.path('/database');
277
+ $scope.sec('mysql');
278
+ }
279
+ $scope.processing = false;
280
+ }
281
+ );
282
+ };
283
+
284
+ if ($rootScope.$mysql.password_validated) {
285
+ $scope.loaddbinfo();
286
+ }
287
+ }
288
+ ];
289
+
290
+ var DatabaseMySQLNewUserCtrl = [
291
+ '$scope', 'Module', '$rootScope', '$location', 'Request', 'Message', 'Backend',
292
+ function($scope, Module, $rootScope, $location, Request, Message, Backend) {
293
+ var module = 'database.mysql.user.new';
294
+ Module.init(module, '添加新用户');
295
+ $scope.loaded = true;
296
+
297
+ $scope.dbname = Module.getParam('dbname');
298
+
299
+ $scope.validate_password = function() {
300
+ $scope.processing = true;
301
+ Request.post('/api/operation/mysql', {
302
+ 'action': 'checkpwd',
303
+ 'password': $rootScope.$mysql.password
304
+ }, function(data) {
305
+ if (data.code == 0) {
306
+ $rootScope.$mysql.password_validated = true;
307
+ }
308
+ $scope.processing = false;
309
+ });
310
+ };
311
+ $scope.newuser = function() {
312
+ if (!$scope.emptypassword) {
313
+ if ($scope.password != $scope.passwordc) {
314
+ Message.setError('新密码和确认密码不一致!');
315
+ return;
316
+ }
317
+ }
318
+ var username = $scope.user + '@' + $scope.host;
319
+ $scope.processing = true;
320
+ Backend.call(
321
+ $scope,
322
+ module,
323
+ '/api/backend/mysql_createuser',
324
+ '/api/backend/mysql_createuser_' + username, {
325
+ 'password': $rootScope.$mysql.password,
326
+ 'user': $scope.user,
327
+ 'host': $scope.host,
328
+ 'pwd': $scope.emptypassword ? '' : $scope.password
329
+ }, {
330
+ 'success': function(data) {
331
+ $location.path('/database/mysql/user/edit/' + encodeURIComponent(username));
332
+ if ($scope.dbname) $location.search('dbname', $scope.dbname);
333
+ $scope.processing = false;
334
+ },
335
+ 'error': function() {
336
+ $scope.processing = false;
337
+ }
338
+ }
339
+ );
340
+ };
341
+ $scope.genpassword = function() {
342
+ // REF: http://stackoverflow.com/questions/9719570/generate-random-password-string-with-requirements-in-javascript
343
+ var chars = "ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
344
+ var string_length = 16;
345
+ var randomstring = '';
346
+ var charCount = 0;
347
+ var numCount = 0;
348
+ for (var i = 0; i < string_length; i++) {
349
+ // If random bit is 0, there are less than 3 digits already saved, and there are not already 5 characters saved, generate a numeric value.
350
+ if ((Math.floor(Math.random() * 2) == 0) && numCount < 3 || charCount >= 5) {
351
+ var rnum = Math.floor(Math.random() * 10);
352
+ randomstring += rnum;
353
+ numCount += 1;
354
+ } else {
355
+ // If any of the above criteria fail, go ahead and generate an alpha character from the chars string
356
+ var rnum = Math.floor(Math.random() * chars.length);
357
+ randomstring += chars.substring(rnum, rnum + 1);
358
+ charCount += 1;
359
+ }
360
+ }
361
+ $scope.randpassword = $scope.password = $scope.passwordc = randomstring;
362
+ };
363
+ }
364
+ ];
365
+
366
+ var DatabaseMySQLEditUserCtrl = [
367
+ '$scope', 'Module', '$rootScope', '$routeParams', '$location', 'Request', 'Message', 'Backend',
368
+ function($scope, Module, $rootScope, $routeParams, $location, Request, Message, Backend) {
369
+ var section = $routeParams.section;
370
+ $scope.username = decodeURIComponent(section);
371
+ var fs = $scope.username.split('@');
372
+ $scope.user = fs[0];
373
+ $scope.host = fs[1];
374
+
375
+ var module = 'database.mysql.user.edit';
376
+ Module.init(module, '管理用户 ' + $scope.username);
377
+ Module.initSection('privs');
378
+ $scope.loaded = true;
379
+
380
+ $scope.validate_password = function() {
381
+ $scope.processing = true;
382
+ Request.post('/api/operation/mysql', {
383
+ 'action': 'checkpwd',
384
+ 'password': $rootScope.$mysql.password
385
+ }, function(data) {
386
+ if (data.code == 0) {
387
+ $rootScope.$mysql.password_validated = true;
388
+ $scope.loadprivs();
389
+ $scope.loaddbs();
390
+ }
391
+ $scope.processing = false;
392
+ });
393
+ };
394
+
395
+ $scope.privsloading = true;
396
+ $scope.loadprivs = function() {
397
+ $scope.privsloading = true;
398
+ Backend.call(
399
+ $scope,
400
+ module,
401
+ '/api/backend/mysql_userprivs',
402
+ '/api/backend/mysql_userprivs_' + $scope.username, {
403
+ 'password': $rootScope.$mysql.password,
404
+ 'username': $scope.username
405
+ }, {
406
+ 'success': function(data) {
407
+ $scope.privs = data.data;
408
+ $scope.privsloading = false;
409
+ // edit or create new privs
410
+ var dbname = Module.getParam('dbname');
411
+ var privtype = Module.getParam('privtype');
412
+ if (dbname) {
413
+ $scope.privs_dbname = dbname;
414
+ $scope.editprivs(false, privtype);
415
+ }
416
+ },
417
+ 'error': function() {
418
+ $scope.privsloading = false;
419
+ }
420
+ }
421
+ );
422
+ };
423
+
424
+ $scope.$watch('selectall', function(value) {
425
+ angular.forEach($scope.curprivs, function(priv, key) {
426
+ if (key.indexOf('_priv') > 0) $scope.curprivs[key] = value ? 'Y' : 'N';
427
+ });
428
+ });
429
+ var priv_tmpl = {
430
+ 'Select_priv': 'N',
431
+ 'Insert_priv': 'N',
432
+ 'Update_priv': 'N',
433
+ 'Delete_priv': 'N',
434
+ 'Create_priv': 'N',
435
+ 'Alter_priv': 'N',
436
+ 'Index_priv': 'N',
437
+ 'Drop_priv': 'N',
438
+ 'Create_tmp_table_priv': 'N',
439
+ 'Show_view_priv': 'N',
440
+ 'Create_routine_priv': 'N',
441
+ 'Alter_routine_priv': 'N',
442
+ 'Execute_priv': 'N',
443
+ 'Create_view_priv': 'N',
444
+ 'Event_priv': 'N',
445
+ 'Trigger_priv': 'N',
446
+ 'Grant_priv': 'N',
447
+ 'Lock_tables_priv': 'N',
448
+ 'References_priv': 'N'
449
+ };
450
+ $scope.editprivs = function(privs, privtype) {
451
+ if (privtype == 'global') {
452
+ $scope.orgprivs = $scope.privs.global;
453
+ $scope.curprivs = angular.copy($scope.privs.global);
454
+ } else {
455
+ if (!privs) {
456
+ if (!$scope.privs_dbname) return;
457
+ // check if the dbname already exists
458
+ var dbfound = false;
459
+ for (var i = 0; i < $scope.privs.bydb.length; i++) {
460
+ if ($scope.privs.bydb[i].Db == $scope.privs_dbname) {
461
+ $scope.orgprivs = $scope.privs.bydb[i];
462
+ $scope.curprivs = angular.copy($scope.privs.bydb[i])
463
+ dbfound = true;
464
+ break;
465
+ }
466
+ }
467
+ if (!dbfound) {
468
+ $scope.orgprivs = null;
469
+ $scope.curprivs = angular.copy(priv_tmpl);
470
+ $scope.curprivs.Db = $scope.privs_dbname;
471
+ $scope.curprivs.flag = 'new';
472
+ }
473
+ } else {
474
+ $scope.orgprivs = privs;
475
+ $scope.curprivs = angular.copy(privs);
476
+ }
477
+ }
478
+ if (!$scope.curprivs.Db)
479
+ $scope.privsedit_title = '设置 ' + $scope.username + ' 的全局权限';
480
+ else
481
+ $scope.privsedit_title = '设置 ' + $scope.username + ' 在数据库 ' + $scope.curprivs.Db + ' 的权限';
482
+ $('#privsedit').modal();
483
+ };
484
+
485
+ $scope.updateprivs = function() {
486
+ Backend.call(
487
+ $scope,
488
+ module,
489
+ '/api/backend/mysql_updateuserprivs',
490
+ '/api/backend/mysql_updateuserprivs_' + encodeURIComponent($scope.username + ($scope.curprivs.Db ? '_' + $scope.curprivs.Db : '')), {
491
+ 'password': $rootScope.$mysql.password,
492
+ 'username': $scope.username,
493
+ 'privs': angular.toJson($scope.curprivs),
494
+ 'dbname': $scope.curprivs.Db
495
+ }, {
496
+ 'success': function(data) {
497
+ if ($scope.curprivs.flag == 'new') {
498
+ // insert to the privs list
499
+ $scope.privs.bydb.push($scope.curprivs);
500
+ } else {
501
+ // just update this item
502
+ angular.copy($scope.curprivs, $scope.orgprivs);
503
+ }
504
+ // return to database management
505
+ var dbname = Module.getParam('dbname');
506
+ if (dbname) {
507
+ $location.path('/database/mysql/db/edit/' + encodeURIComponent(dbname));
508
+ }
509
+ }
510
+ }
511
+ );
512
+ };
513
+
514
+ $scope.loaddbs = function() {
515
+ $scope.dbloading = true;
516
+ Backend.call(
517
+ $scope,
518
+ module,
519
+ '/api/backend/mysql_databases',
520
+ '/api/backend/mysql_databases', {
521
+ 'password': $rootScope.$mysql.password
522
+ }, {
523
+ 'success': function(data) {
524
+ $scope.dbs = data.data;
525
+ }
526
+ },
527
+ true
528
+ );
529
+ };
530
+
531
+ $scope.setpassword = function() {
532
+ if (!$scope.emptypassword) {
533
+ if ($scope.newpassword != $scope.newpasswordc) {
534
+ Message.setError('新密码和确认密码不一致!');
535
+ return;
536
+ }
537
+ }
538
+ $scope.processing = true;
539
+ Backend.call(
540
+ $scope,
541
+ module,
542
+ '/api/backend/mysql_setuserpassword',
543
+ '/api/backend/mysql_setuserpassword_' + $scope.username, {
544
+ 'password': $rootScope.$mysql.password,
545
+ 'username': $scope.username,
546
+ 'pwd': $scope.emptypassword ? '' : $scope.newpassword
547
+ }, {
548
+ 'success': function(data) {
549
+ $scope.processing = false;
550
+ if ($scope.username == 'root@localhost') {
551
+ // reset cached mysql password
552
+ $rootScope.$mysql = {
553
+ 'password': '',
554
+ 'password_validated': false
555
+ };
556
+ }
557
+ },
558
+ 'error': function() {
559
+ $scope.processing = false;
560
+ }
561
+ }
562
+ );
563
+ };
564
+
565
+ $scope.dropuser = function() {
566
+ $scope.processing = true;
567
+ Backend.call(
568
+ $scope,
569
+ module,
570
+ '/api/backend/mysql_dropuser',
571
+ '/api/backend/mysql_dropuser_' + $scope.username, {
572
+ 'password': $rootScope.$mysql.password,
573
+ 'username': $scope.username
574
+ },
575
+ function(data) {
576
+ if (data.code == 0) {
577
+ $location.path('/database');
578
+ $scope.sec('mysql');
579
+ }
580
+ $scope.processing = false;
581
+ }
582
+ );
583
+ };
584
+
585
+ if ($rootScope.$mysql.password_validated) {
586
+ $scope.loadprivs();
587
+ $scope.loaddbs();
588
+ }
589
+ }
590
+ ];