-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpure-users.cgi
executable file
·566 lines (468 loc) · 28.2 KB
/
pure-users.cgi
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
#!/usr/bin/perl
# Edit Pure-FTPd users.
do '../web-lib.pl';
&init_config(); &ReadParse();
&header($text{'pure-users_title'}, undef, "users", 1, 1, undef, $text{'index_mail'});
# Check if there is CSS styles
if ($config{'conf_pureCSS'}) { print "<STYLE type=\"text/css\">
$config{'conf_pureCSS'}\n</STYLE>\n\n"; }
# Check if pure-pw is installed.
if (!-x $config{'conf_pureftpdpw'}) {
print "<p><hr><center><h2>",
&text('pure-users_conf',
"<tt>$config{'conf_pureftpdpw'}</tt>",
"/config.cgi?$module_name"),
"</h2></center><p>\n<hr>\n";
&footer("/", $text{'index'});
exit;
}
sub Pureparse() {
$action .= "-u \"$in{'uid'}\" -g \"$in{'gid'}\" -c \"$in{'gecos'}\" ".
"$in{'chroot'} \"$in{'home'}\" -T \"$in{'upload_band'}\" ".
"-t \"$in{'download_band'}\" -q \"$in{'upload_ratio'}\" ".
"-Q \"$in{'download_ratio'}\" -y \"$in{'max_sessions'}\" ".
"-z \"$in{'time'}\" -y \"$in{'max_sessions'}\" ".
"-n \"$in{'max_files'}\" -N \"$in{'max_size'}\" ".
"-i \"$in{'allow_local_IP'}\" -I \"$in{'deny_local_IP'}\" ".
"-r \"$in{'allow_client_IP'}\" -R \"$in{'deny_client_IP'}\" ";
}
sub sort_as_wanted {
# retrieve sort preferences
if($in{'sort'} ne "") { $sort=$in{'sort'}; }else{ $sort=$config{'conf_sort'}; }
# retrieve User 1 informations
local ($logina, $passwd, $uida, $gida, $gecosa, $homea,
$upload_band, $download_band, $upload_ratio, $download_ratio,
$max_sessions, $max_files, $max_size,
$allow_local_IP, $deny_local_IP,
$allow_client_IP, $deny_client_IP, $time) = split(/:/,$a);
# retrieve User 2 informations
local ($loginb, $passwd, $uidb, $gidb, $gecosb, $homeb,
$upload_band, $download_band, $upload_ratio, $download_ratio,
$max_sessions, $max_files, $max_size,
$allow_local_IP, $deny_local_IP,
$allow_client_IP, $deny_client_IP, $time) = split(/:/,$b);
# Then compare to match the sort preferences
if($sort eq "uid") { "\U$uida" cmp "\U$uidb"
|| "\U$logina" cmp "\U$loginb" }
elsif($sort eq "gecos") { "\U$gecosa" cmp "\U$gecosb"
|| "\U$logina" cmp "\U$loginb" }
elsif($sort eq "home") { "\U$homea" cmp "\U$homeb"
|| "\U$logina" cmp "\U$loginb" }
elsif($sort eq "gid") { "\U$gida" cmp "\U$gidb"
|| "\U$uida" cmp "\U$uidb"
|| "\U$logina" cmp "\U$loginb" }
# Otherwise, sort by login
else { "\U$logina" cmp "\U$loginb" }
}
sub Newuser() {
$action .= "-u $in{'uid'} -g $in{'gid'} ".
"-c \"$in{'gecos'}\" $in{'chroot'} \"$in{'home'}\" ";
# Parse the new user's information
if($in{'allow_local_IP'}) { $action .= "-i \"$in{'allow_local_IP'}\" "; }
if($in{'deny_local_IP'}) { $action .= "-I \"$in{'deny_local_IP'}\" "; }
if($in{'max_files'}) { $action .= "-n \"$in{'max_files'}\" "; }
if($in{'max_size'}) { $action .= "-N \"$in{'max_size'}\" "; }
if($in{'upload_ratio'}) { $action .= "-q \"$in{'upload_ratio'}\" "; }
if($in{'download_ratio'}) { $action .= "-Q \"$in{'download_ratio'}\" "; }
if($in{'allow_client_IP'}) { $action .= "-r \"$in{'allow_client_IP'}\" "; }
if($in{'deny_client_IP'}) { $action .= "-R \"$in{'deny_client_IP'}\" "; }
if($in{'upload_band'}) { $action .= "-T \"$in{'upload_band'}\" "; }
if($in{'download_band'}) { $action .= "-t \"$in{'download_band'}\" "; }
if($in{'max_sessions'}) { $action .= "-y \"$in{'max_sessions'}\" "; }
if($in{'time'}) { $action .= "-z \"$in{'time'}\" "; }
}
sub Setdisplay() { # Subroutine to parse, change and set users display
# Check if form sent to overide configuration preferences
if($in{'d_login'} eq "0") { $config{'conf_displaylogin'} = ""; $displ{'login'}=1;}
elsif($in{'d_login'} ne "") { $config{'conf_displaylogin'} = $in{'d_login'}; $displ{'login'}=1;}
elsif($config{'conf_displaylogin'} ne "") { $displ{'login'}=1;}
if($in{'d_gecos'} eq "0") { $config{'conf_displaygecos'} = ""; $displ{'gecos'}=1; }
elsif($in{'d_gecos'} ne "") { $config{'conf_displaygecos'} = $in{'d_gecos'}; $displ{'gecos'}=1; }
elsif($config{'conf_displaygecos'} ne "") { $displ{'gecos'}=1;}
if($in{'d_home'} eq "0") { $config{'conf_displayhome'} = ""; $displ{'home'}=1; }
elsif($in{'d_home'} ne "") { $config{'conf_displayhome'} = $in{'d_home'}; $displ{'home'}=1; }
elsif($config{'conf_displayhome'} ne "") { $displ{'login'}=1;}
if($in{'d_uid'} eq "0") { $config{'conf_displayuid'} = ""; $displ{'uid'}=1; }
elsif($in{'d_uid'} ne "") { $config{'conf_displayuid'} = $in{'d_uid'}; $displ{'uid'}=1; }
elsif($config{'conf_displayuid'} ne "") { $displ{'uid'}=1;}
if($in{'d_gid'} eq "0") { $config{'conf_displaygid'} = ""; $displ{'gid'}=1; }
elsif($in{'d_gid'} ne "") { $config{'conf_displaygid'} = $in{'d_gid'}; $displ{'gid'}=1; }
elsif($config{'conf_displaygid'} ne "") { $displ{'gid'}=1;}
if($in{'d_upband'} eq "0") { $config{'conf_displayupband'} = ""; $displ{'upband'}=1; }
elsif($in{'d_upband'} ne "") { $config{'conf_displayupband'} = $in{'d_upband'}; $displ{'upband'}=1; }
elsif($config{'conf_displayupband'} ne "") { $displ{'upband'}=1;}
if($in{'d_dwband'} eq "0") { $config{'conf_displaydwband'} = ""; $displ{'dwband'}=1; }
elsif($in{'d_dwband'} ne "") { $config{'conf_displaydwband'} = $in{'d_dwband'}; $displ{'dwband'}=1; }
elsif($config{'conf_displaydwband'} ne "") { $displ{'dwband'}=1;}
if($in{'d_upratio'} eq "0") { $config{'conf_displayupratio'} = ""; $displ{'upratio'}=1; }
elsif($in{'d_upratio'} ne "") { $config{'conf_displayupratio'} = $in{'d_upratio'}; $displ{'upratio'}=1; }
elsif($config{'conf_displayupratio'} ne "") { $displ{'upratio'}=1;}
if($in{'d_dwratio'} eq "0") { $config{'conf_displaydwratio'} = ""; $displ{'dwratio'}=1; }
elsif($in{'d_dwratio'} ne "") { $config{'conf_displaydwratio'} = $in{'d_dwratio'}; $displ{'dwratio'}=1; }
elsif($config{'conf_displaydwratio'} ne "") { $displ{'dwratio'}=1;}
if($in{'d_mxfile'} eq "0") { $config{'conf_displaymxfile'} = ""; $displ{'mxfile'}=1; }
elsif($in{'d_mxfile'} ne "") { $config{'conf_displaymxfile'} = $in{'d_mxfile'}; $displ{'mxfile'}=1; }
elsif($config{'conf_displaymxfile'} ne "") { $displ{'mxfile'}=1;}
if($in{'d_mxsize'} eq "0") { $config{'conf_displaymxsize'} = ""; $displ{'mxsize'}=1; }
elsif($in{'d_mxsize'} ne "") { $config{'conf_displaymxsize'} = $in{'d_mxsize'}; $displ{'mxsize'}=1; }
elsif($config{'conf_displaymxsize'} ne "") { $displ{'mxsize'}=1;}
if($in{'d_percfile'} eq "0"){ $config{'conf_displaypercfile'} = ""; $displ{'percfile'}=1; }
elsif($in{'d_percfile'} ne "") { $config{'conf_displaypercfile'} = $in{'d_percfile'}; $displ{'percfile'}=1; }
elsif($config{'conf_displaypercfile'} ne "") { $displ{'percfile'}=1;}
if($in{'d_percsize'} eq "0"){ $config{'conf_displaypercsize'} = ""; $displ{'percsize'}=1; }
elsif($in{'d_percsize'} ne "") { $config{'conf_displaypercsize'} = $in{'d_percsize'}; $displ{'percsize'}=1; }
elsif($config{'conf_displaypercsize'} ne "") { $displ{'percsize'}=1;}
if($in{'d_sess'} eq "0") { $config{'conf_displaysession'} = ""; $displ{'session'}=1; }
elsif($in{'d_sess'} ne "") { $config{'conf_displaysession'} = $in{'d_sess'}; $displ{'session'}=1; }
elsif($config{'conf_displaysession'} ne "") { $displ{'session'}=1;}
if($in{'d_chroot'} eq "2" || $config{'conf_displaychroot'} eq "2")
{ $config{'conf_displaychroot'} = "2"; $displ{'chroot'}=1; }
elsif( $in{'d_chroot'} ne "") { $config{'conf_displaychroot'} = $in{'d_chroot'}; $displ{'chroot'}=1; }
elsif($config{'conf_displaychroot'} ne "") { $displ{'chroot'}=1;}
# Parse the display configuration preferences
($minuid,$maxuid) = split(/-/, $config{'conf_displayuid'});
($mingid,$maxgid) = split(/-/, $config{'conf_displaygid'});
($minupb,$maxupb) = split(/-/, $config{'conf_displayupband'});
($mindlb,$maxdlb) = split(/-/, $config{'conf_displaydwband'});
($minupr,$maxupr) = split(/-/, $config{'conf_displayupratio'});
($mindlr,$maxdlr) = split(/-/, $config{'conf_displaydwratio'});
($minfil,$maxfil) = split(/-/, $config{'conf_displaymxfile'});
($minsiz,$maxsiz) = split(/-/, $config{'conf_displaymxsize'});
($minprf,$maxprf) = split(/-/, $config{'conf_displaypercfile'});
($minprs,$maxprs) = split(/-/, $config{'conf_displaypercsize'});
($minses,$maxses) = split(/-/, $config{'conf_displaysession'});
# Build the display form
# Values with regexp expression
if($displ{'login'} ne "" || $displ{'gecos'} ne "" || $displ{'home'} ne "")
{ $display.= "<br><br><b>".$text{'pure-users_criteriaregexp'}."</b><br>\n"; }
if($displ{'login'} ne "") { $display.= " ".$text{'pure-users_criterialogin'}.
" <input type=text name=d_login size=10 value=\"$config{'conf_displaylogin'}\">\n"; }
if($displ{'gecos'} ne "") { $display.= " ".$text{'pure-users_criteriagecos'}.
" <input type=text name=d_gecos size=10 value=\"$config{'conf_displaygecos'}\">\n"; }
if($displ{'home'} ne "") { $display.= " ".$text{'pure-users_criteriahome'}.
" <input type=text name=d_home size=10 value=\"$config{'conf_displayhome'}\">\n"; }
# Values from 000-000
if($displ{'uid'} ne "" || $displ{'gid'} ne ""
|| $displ{'upband'} ne "" || $displ{'dwband'} ne ""
|| $displ{'upratio'} ne "" || $displ{'dwratio'} ne ""
|| $displ{'mxfile'} ne "" || $displ{'mxsize'} ne ""
|| $displ{'percfile'} ne "" || $displ{'percsize'} ne ""
|| $displ{'session'} ne "" ) { $display.= "<br><br><b>".$text{'pure-users_criteriavalues'}."</b><br>\n"; }
if($displ{'uid'} ne "") { $display.= " ".$text{'pure-users_criteriauid'}.
" <input type=text name=d_uid size=10 value=\"$config{'conf_displayuid'}\">\n"; }
if($displ{'gid'} ne "") { $display.= " ".$text{'pure-users_criteriagid'}.
" <input type=text name=d_gid size=10 value=\"$config{'conf_displaygid'}\">\n"; }
if($displ{'upband'} ne "") { $display.= " ".$text{'pure-users_criteriaupband'}.
" <input type=text name=d_upband size=10 value=\"$config{'conf_displayupband'}\">\n"; }
if($displ{'dwband'} ne "") { $display.= " ".$text{'pure-users_criteriadwband'}.
" <input type=text name=d_dwband size=10 value=\"$config{'conf_displaydwband'}\">\n"; }
if($displ{'upratio'} ne "") { $display.= " ".$text{'pure-users_criteriaupratio'}.
" <input type=text name=d_upratio size=10 value=\"$config{'conf_displayupratio'}\">\n"; }
if($displ{'dwratio'} ne "") { $display.= " ".$text{'pure-users_criteriadwratio'}.
" <input type=text name=d_dwratio size=10 value=\"$config{'conf_displaydwratio'}\">\n"; }
if($displ{'mxfile'} ne "") { $display.= " ".$text{'pure-users_criteriamax_files'}.
" <input type=text name=d_mxfile size=10 value=\"$config{'conf_displaymxfile'}\">\n"; }
if($displ{'mxsize'} ne "") { $display.= " ".$text{'pure-users_criteriamax_size'}.
" <input type=text name=d_mxsize size=10 value=\"$config{'conf_displaymxsize'}\">\n"; }
if($displ{'percfile'} ne "") { $display.= " ".$text{'pure-users_criteriaper_files'}.
" <input type=text name=d_percfile size=10 value=\"$config{'conf_displaypercfile'}\">\n"; }
if($displ{'percsize'} ne "") { $display.= " ".$text{'pure-users_criteriaper_size'}.
" <input type=text name=d_percsize size=10 value=\"$config{'conf_displaypercsize'}\">\n"; }
if($displ{'session'} ne "") { $display.= " ".$text{'pure-users_criteriamax_sessions'}.
" <input type=text name=d_sess size=10 value=\"$config{'conf_displaysession'}\">\n"; }
if ($displ{'chroot'} ne "") {
$display.= " <br><br>".$text{'pure-users_criteriachroot'}.
" <input type=radio name=d_chroot value=0";
$display.= " checked" if($config{'conf_displaychroot'} == "0");
$display.= ">$text{'No'} <input type=radio name=d_chroot value=1";
$display.= " checked" if($config{'conf_displaychroot'} == "1");
$display.= ">$text{'Yes'}\n";
$display.= " <input type=radio name=d_chroot value=2";
$display.= " checked" if($config{'conf_displaychroot'} == "2");
$display.= ">$text{'Whatever'}\n";
} if ($config{'conf_displaychroot'} == "2" ) { $config{'conf_displaychroot'} = ""; }
# Return value if display's preferences are set
if ( $display ) { return 1; } else { return 0; }
}
if ($in{'action'} eq $text{'delete'}) {
# Delete one user
$action="$config{'conf_pureftpdpw'} userdel \"$in{'login'}\" -m";
open (FIC, "$action |");
@results=<FIC>; close(FIC);
if(!$results[0])
{ printf "<center><h1>$text{'pure-users_deleteOK'}</h1></center>\n\n",
$in{'login'}; } else { printf "<center><h1>$text{'pure-users_notdelete'}
<br>$results[0]</h1></center>\n\n",$in{'login'}; } }
elsif ($in{'action'} eq $text{'pure-users_quotasupdate'}) {
# Check if pure-quotacheck is installed.
if (!-x $config{'conf_purequotas'}) {
print "<p><hr><center><h2>",&text('pure-users_quotasconf',
"<tt>$config{'conf_purequotas'}</tt>",
"/config.cgi?$module_name"),
"</h2></center><p>\n<hr>\n";
} else {
# Update quotas from home directory
$action="$config{'conf_purequotas'} -u $in{'uid'} -d \"$in{'home'}\" -g $in{'gid'}";
open (FIC, "$action |");
@results=<FIC>; close(FIC);
if(!$results[0])
{ printf "<center><h1>$text{'pure-users_quotasOK'}</h1></center>\n\n",
$in{'login'}; } else { printf "<center><h1>$text{'pure-users_notquotas'}
<br>$results[0]</h1></center>\n\n",$in{'login'}; } } }
elsif ($in{'action'} eq $text{'save'}) {
# Modify one user
$action ="$config{'conf_pureftpdpw'} usermod \"$in{'login'}\" ";
&Pureparse(); $action.="-m";
open (FIC, "$action |");
@results=<FIC>; close(FIC);
# Changing user results
if(!$results[0]) { printf "<center><h1>$text{'pure-users_modifyOK'}
</h1></center>\n\n",$in{'login'}; } else { printf "<center><h1>
$text{'pure-users_notmodify'}<br>$results[0]</h1></center>\n\n",
$in{'login'}; }
# Change user's password
if(!$in{'change'} && $in{'action'} eq $text{'save'}) {
$action ="(echo \"$in{'passwd2'}\"; echo \"$in{'passwd2'}\") ";
$action.="| $config{'conf_pureftpdpw'} passwd \"$in{'login'}\" -m";
open (FIC, "$action |");
@results=<FIC>; close(FIC);
# Changing password results
if($results[0])
{ printf "<center><h1>$text{'pure-users_passwdOK'}</h1>
</center>\n\n",$in{'login'}; } else { printf "<h1><center>
$text{'pure-users_notpasswd'}</h1></center>\n\n",$in{'login'}; }}
}
elsif ($in{'action'} eq $text{'add'}) {
$error=""; # Check if all the basic info for new user are present
if(!$in{'login'}) { $error=$text{'pure-users_loginmissing'}; }
elsif(!$in{'home'}) { $error=$text{'pure-users_homemissing'}; }
elsif(!$in{'uid'}) { $error=$text{'pure-users_uidmissing'}; }
elsif(!$in{'gid'}) { $error=$text{'pure-users_gidmissing'}; }
elsif(!$in{'passwd'}) { $error=$text{'pure-users_passwdmissing'}; }
else { # Everything is ok, Add user
$action ="(echo \"$in{'passwd'}\"; echo \"$in{'passwd'}\") ";
$action.="| $config{'conf_pureftpdpw'} useradd \"$in{'login'}\" ";
&Newuser();
$action.="-m";
open (FIC, "$action|");
@results=<FIC>; close(FIC); }
# Adding results
if($results[0] && !$error)
{ printf "<center><h1>$text{'pure-users_addOK'}</h1></center>\n\n",
$in{'login'}; } else { printf "<center><h1>$text{'pure-users_notadd'}
<br>$error</h1></center>\n\n",$in{'login'}; }
}
print "<center>".&text('pure-users_displaywarning',"#display")."</center><br><br>" if &Setdisplay();
$sure = $text{'pure-users_areyousure'};
print "\n\n<hr>\n<center><table border width=60%>\n\n";
print "<tr $tb> <td><b>$text{'pure-users_header'}</b></td></tr>\n";
print "<tr $cb> <td><table>\n\n";
# Are new users Chroot or not ?
if($config{'conf_newchroot'}) { $new2=" checked";
$new1=""; } else{ $new1=" checked"; $new2=""; }
# New user form
print <<EOF;
<tr><td valign=top>\
<form action=pure-users.cgi method=POST>
<h2><b>$text{'pure-users_NEWUSER'}</b></h2>
<a href="/config.cgi?pureftpd">$text{'pure-users_defaultsettings'}</a>
</td><td><table border width=100%>
<tr $tb><td colspan=2 align=center><b>$text{'pure-users_NEWUSER'}</b>
</td></tr>
<tr><td><table>
<tr><td nowrap><b>$text{'login'}</b></td><td>
<input name=login size=40 value="$config{'conf_newlogin'}"></td></tr>
<tr><td nowrap><b>$text{'gecos'}</b></td><td>
<input name=gecos size=40 value="$config{'conf_newgecos'}"></td></tr>
<tr><td nowrap><b>$text{'home'}</b></td><td>
<input name=home size=35 value="$config{'conf_newpath'}">
<input type=button onClick='ifield=document.forms[0].home; chooser=window.open("/chooser.cgi?type=1&chroot=/&file="+ifield.value,"chooser","toolbar=no,menubar=no,scrollbar=no,width=400,height=300"); chooser.ifield=ifield; window.ifield=ifield;' value="...
">
</td></tr>
<tr><td nowrap><b>$text{'upload_band'}</b></td><td>
<input name=upload_band size=10 value='$config{'conf_newupload'}'> $text{'speed'}</td></tr>
<tr><td nowrap><b>$text{'download_band'}</b></td><td>
<input name=download_band size=10 value='$config{'conf_newdownload'}'> $text{'speed'}</td></tr>
<tr><td nowrap><b>$text{'upload_ratio'}</b></td><td>
<input name=upload_ratio size=10 value='$config{'conf_ratioupload'}'> $text{'Mb'}</td></tr>
<tr><td nowrap><b>$text{'download_ratio'}</b></td><td>
<input name=download_ratio size=10 value='$config{'conf_ratiodownload'}'> $text{'Mb'}</td></tr>
<tr><td nowrap><b>$text{'max_files'}</b></td><td>
<input name=max_files size=10 value='$config{'conf_newmaxfiles'}'> $text{'items'}</td></tr>
<tr><td nowrap><b>$text{'max_size'}</b></td><td>
<input name=max_size size=10 value='$config{'conf_newmaxsize'}'> $text{'Mb'}</td></tr>
<tr><td nowrap><b>$text{'allow_local_IP'} </b></td><td>
<input name=allow_local_IP size=40 value='$config{'conf_newallowlocal'}'></td></tr>
<tr><td nowrap><b>$text{'deny_local_IP'} </b></td><td>
<input name=deny_local_IP size=40 value='$config{'conf_newdenylocal'}'></td></tr>
<tr><td nowrap><b>$text{'allow_client_IP'} </b></td><td>
<input name=allow_client_IP size=40 value='$config{'conf_newallowclient'}'></td></tr>
<tr><td nowrap><b>$text{'deny_client_IP'} </b></td><td>
<input name=deny_client_IP size=40 value='$config{'conf_newdenyclient'}'></td></tr>
<tr><td nowrap><b>$text{'time'} </b></td><td>
<input name=time size=10 value='$config{'conf_newtime'}'> hhmm-hhmm</td></tr>
<tr><td nowrap><b>$text{'max_sessions'} </b></td><td>
<input name=max_sessions size=10 value='$config{'conf_maxsession'}'></td></tr>
<tr><td nowrap><b>$text{'chroot'} </b></td><td>
<input type=radio name=chroot value="-d"$new1> $text{'Yes'}
<input type=radio name=chroot value="-D"$new2> $text{'No'}</td></tr>
<tr><td nowrap><b>$text{'passwd'} </b></td><td>
<input size=30 name=passwd value=''></td></tr>
<tr><td><input type=submit class=submit name=action value="$text{'add'}">
</td><td><b>$text{'uid'}</b>
<input name=uid size=10 value='$config{'conf_newuid'}'>
<input type=button onClick='ifield=document.forms[0].uid;chooser=window.open("/user_chooser.cgi?multi=0&user="+escape(ifield.value),"chooser","toolbar=no,menubar=no,scrollbars=yes,width=300,height=200"); chooser.ifield=ifield;window.ifield=ifield' value="
...">
<b>$text{'gid'}</b>
<input name=gid size=10 value='$config{'conf_newgid'}'>
<input type=button onClick='ifield=document.forms[0].gid;chooser=window.open("/group_chooser.cgi?multi=0&group="+escape(ifield.value),"chooser","toolbar=no,menubar=no,scrollbars=yes,width=300,height=200"); chooser.ifield=ifield;window.ifield=ifield;' valu
e="...">
</td></tr></table>
</center></td></tr></table></form><br></td></tr>
EOF
$lines = &read_file_lines("$config{'conf_pureftpdldap'}");
$j=0;$k=0; $percent_size=""; $percent_file="";
# Loop to parse each user from the pureftpd.passwd
foreach $i ( sort sort_as_wanted(@$lines) ) {
# parse the user's line and split each values
local ($login, $passwd, $uid, $gid, $gecos, $home,
$upload_band, $download_band, $upload_ratio, $download_ratio,
$max_sessions, $max_files, $max_size,
$allow_local_IP, $deny_local_IP,
$allow_client_IP, $deny_client_IP, $time) = split(/:/, $i);
# Check if the user is chrooted
if ($home =~ /^(.*)\.\/$/) { $home = $1;
$chroot = 1; } else { $chroot = 0; }
# compute the proper value of Mb and bandwith
if($max_size){ $max_size = ($max_size/1048576); }
if($upload_band){ $upload_band = int($upload_band/1024); }
if($download_band){ $download_band = int($download_band/1024); }
# Check quotas if "max_size" or "max_files" are set
if($max_files || $max_size ) { $quotas="<br><br>\n";
if(-e "$home/.ftpquota") {
$files = &read_file_lines("$home/.ftpquota");
$files = $file_cache{"$home/.ftpquota"}[0];
($file_quotas,$size_quotas) = split(/ /, $files);
$size_quotas=int($size_quotas/1048576);
if($max_files){ # if max_files set then compute
$percent_size=int(($file_quotas/$max_files)*100);
$quotas.=" $text{'file_quotas'}: <b>". $percent_size .
"%</b> ($file_quotas ".$text{'items'}.")";}
if($max_size){ # if max_size set then compute
$percent_file=int(($size_quotas/$max_size)*100);
$quotas.=" $text{'size_quotas'}: <b>". $percent_file .
"%</b> ($size_quotas ".$text{'Mb'}.")";}
} else { $quotas.=$text{'pure-users_quotasnone'};
$percent_size=""; $percent_file=""; }
$quotas.="<br>\n<input type=submit class=submit ".
"name=action value=\"$text{'pure-users_quotasupdate'}\">\n";
if(($max_files && $max_files<=$file_quotas)
|| ($max_size && $max_size<=$size_quotas))
{ $exceeded="<b>$text{'pure-users_quotaexceeded'}</b>"; }
else { $exceeded=""; }
} else { $quotas=""; $exceeded=""; $percent_size=""; $percent_file=""; }
if ( # Test if the current user matches the display configuration preferences
($config{'conf_displaylogin'} eq "" || $login =~ /$config{'conf_displaylogin'}/)
&& ($config{'conf_displaygecos'} eq "" || $gecos =~ /$config{'conf_displaygecos'}/)
&& ($config{'conf_displayhome'} eq "" || $home =~ /$config{'conf_displayhome'}/)
&& ($config{'conf_displaychroot'} eq "" || $chroot eq $config{'conf_displaychroot'})
&& ($minuid eq "" || $uid >= $minuid) && ($maxuid eq "" || $uid <= $maxuid)
&& ($mingid eq "" || $gid >= $mingid) && ($maxgid eq "" || $gid <= $maxgid)
&& ($minupb eq "" || $upload_band >= $mingid) && ($maxupb eq "" || $upload_band <= $maxupb)
&& ($mindlb eq "" || $download_band >= $mindlb) && ($maxdlb eq "" || $download_band <= $maxdlb)
&& ($minupr eq "" || $upload_ratio >= $minupr) && ($maxupr eq "" || $upload_ratio <= $maxupr)
&& ($mindlr eq "" || $download_ratio >= $mindlr) && ($maxdlr eq "" || $download_ratio <= $maxdlr)
&& ($minfil eq "" || $max_files >= $minfil) && ($maxfil eq "" || $max_files <= $maxfil)
&& ($minsiz eq "" || $max_size >= $minsiz) && ($maxsiz eq "" || $max_size <= $maxsiz)
&& ($minprf eq "" || $percent_size >= $minprf) && ($maxprf eq "" || $percent_size <= $maxprf)
&& ($minprs eq "" || $percent_file >= $minprs) && ($maxprs eq "" || $percent_file <= $maxprs)
&& ($minses eq "" || $max_sessions >= $minses) && ($maxses eq "" || $max_sessions <= $maxses)
) { $j++; } else { $k++; next; }
# Display the current user's form
print "<tr><td valign=top>\n";
print "<form action=pure-users.cgi method=POST>\n";
print "<input type=hidden name=login value=\"$login\">\n";
print "<h2><b>$login</b></h2>\n";
print "<input type=submit class=submit name=action value=\"$text{'save'}\">\n";
print "<input type=submit class=submit name=action value=\"$text{'delete'}\" ";
print "onClick=\"if (window.confirm('$sure $login ?')) { return true; } else { return false; }\">";
print "<br><br><font color=red>$exceeded</font></td><td><table border width=100%>\n";
# Fix the looping problem by correcting the type error (change "," to ";")
# print "<tr $tb><td colspan=2 align=center><b>$login</b></td></tr>",
print "<tr $tb><td colspan=2 align=center><b>$login</b></td></tr>";
print "<tr><td><table>\n";
print "<tr><td nowrap><b>$text{'gecos'}</b></td><td>",
"<input name=gecos size=40 value=\"$gecos\"></td></tr>\n";
print "<tr><td nowrap><b>$text{'home'}</b></td><td>",
"<input name=home size=35 value=\"$home\">",
"<input type=button onClick='ifield=document.forms[$j].home; chooser=window.open(\"/chooser.cgi?",
"type=1&chroot=/&file=\"+ifield.value,\"chooser\",\"toolbar=no,menubar=no,scrollbar=no,width=400,",
"height=300\"); chooser.ifield=ifield; window.ifield=ifield;' value=\"...\">";
print "</td></tr>\n<tr><td nowrap><b>$text{'upload_band'}</b></td><td>",
"<input name=upload_band size=10 value=\"$upload_band\"> $text{'speed'}</td></tr>\n";
print "<tr><td nowrap><b>$text{'download_band'}</b></td><td>",
"<input name=download_band size=10 value=\"$download_band\"> $text{'speed'}</td></tr>\n";
print "</td></tr>\n<tr><td nowrap><b>$text{'upload_ratio'}</b></td><td>",
"<input name=upload_ratio size=10 value=\"$upload_ratio\"> $text{'Mb'}</td></tr>\n";
print "<tr><td nowrap><b>$text{'download_ratio'}</b></td><td>",
"<input name=download_ratio size=10 value=\"$download_ratio\"> $text{'Mb'}</td></tr>\n";
print "<tr><td nowrap><b>$text{'max_files'}</b></td><td>",
"<input name=max_files size=10 value=\"$max_files\"> $text{'items'}</td></tr>\n";
print "<tr><td nowrap><b>$text{'max_size'}</b></td><td>",
"<input name=max_size size=10 value=\"$max_size\"> $text{'Mb'}</td></tr>\n";
print "<tr><td nowrap><b>$text{'allow_local_IP'}</b></td><td>",
"<input name=allow_local_IP size=40 value=\"$allow_local_IP\"></td></tr>\n";
print "<tr><td nowrap><b>$text{'deny_local_IP'}</b></td><td>",
"<input name=deny_local_IP size=40 value=\"$deny_local_IP\"></td></tr>\n";
print "<tr><td nowrap><b>$text{'allow_client_IP'}</b></td><td>",
"<input name=allow_client_IP size=40 value=\"$allow_client_IP\"></td></tr>\n";
print "<tr><td nowrap><b>$text{'deny_client_IP'}</b></td><td>",
"<input name=deny_client_IP size=40 value=\"$deny_client_IP\"></td></tr>\n";
print "<tr><td nowrap><b>$text{'time'}</b></td><td>",
"<input name=time size=10 value=\"$time\"> hhmm-hhmm</td></tr>\n";
print "<tr><td nowrap><b>$text{'max_sessions'}</b></td><td>",
"<input name=max_sessions size=10 value=\"$max_sessions\"></td></tr>\n";
print "<tr><td nowrap><b>$text{'chroot'}</b></td><td>",
"<input type=radio name=chroot value=\"-d\"",
$chroot ? " checked> $text{'Yes'} " : "> $text{'Yes'} ",
"<input type=radio name=chroot value=\"-D\"",
$chroot ? "> $text{'No'}</td></tr>" : " checked> $text{'No'}</td></tr>";
print " </table><center><b>$text{'uid'}</b> <input name=uid size=10 value='$uid'>\n";
print " <input type=button onClick='ifield=document.forms[$j].uid;chooser=window.open",
"(\"/user_chooser.cgi?multi=0&user=\"+escape(ifield.value),\"chooser\",\"toolbar=no,",
"menubar=no,scrollbars=yes,width=300,height=200\"); chooser.ifield=ifield;window.ifield=ifield' value=\"...\"> \n";
print " <b>$text{'gid'}</b> <input name=gid size=10 value='$gid'> \n";
print " <input type=button onClick='ifield=document.forms[$j].gid;chooser=window.open",
"(\"/group_chooser.cgi?multi=0&group=\"+escape(ifield.value),\"chooser\",\"toolbar=no,",
"menubar=no,scrollbars=yes,width=300,height=200\"); chooser.ifield=ifield;window.ifield=ifield;' value=\"...\"> \n";
print " <br><b>$text{'passwd'}</b> <input type=radio name=change value=1 checked> ";
print "$text{'change'} | <input type=radio name=change value=0>";
print "<input name=passwd2 size=30 value=''>\n";
print " $quotas\n";
print "</center></td></tr></table></form></td></tr>\n\n\n";
}
# Now display the "Display form"
print "<tr><td colspan=2><a name='display'></a><br><br><center>";
print &text('pure-users_displayresult',$j,$k)."<br>";
print "<br><font color=red>$text{'pure-users_displaynone'}</font>" if ($j==0 && $k>0) ;
print "<form action=pure-users.cgi method=GET>\n";
print "$text{'pure-users_display'}<br>";
print "<input type=radio name=sort value=login";
print " checked" if($sort eq "login" || $sort eq "");
print "> $text{'pure-users_criterialogin'} \n";
print "<input type=radio name=sort value=gecos";
print " checked" if($sort eq "gecos");
print "> $text{'pure-users_criteriagecos'} \n";
print "<input type=radio name=sort value=home";
print " checked" if($sort eq "home");
print "> $text{'pure-users_criteriahome'} \n";
print "<input type=radio name=sort value=uid";
print " checked" if($sort eq "uid");
print "> $text{'pure-users_criteriauid'} \n";
print "<input type=radio name=sort value=gid";
print " checked" if($sort eq "gid");
print "> $text{'pure-users_criteriauid'}<br><br>\n";
print "<input type=submit value=\"$text{'pure-users_displayagain'}\">";
print "$display</form>";
print "</center></td></tr></table>\n\n</td></tr></table></center>\n\n";
&footer("", $text{'index_return'});