-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathsave_auth.cgi
executable file
·75 lines (70 loc) · 1.83 KB
/
save_auth.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
#!/usr/local/bin/perl
# save_auth.cgi
# Save, create or delete an authorized key
require './ssh-lib.pl';
&ReadParse();
@auths = &list_auths();
if ($in{'new'}) {
$auth = { 'type' => $in{'type'} };
}
else {
$auth = $auths[$in{'idx'}];
}
if ($in{'delete'}) {
# Just delete this authorized key
&delete_auth($auth);
}
else {
# Validate inputs
&error_setup($text{'auth_err'});
$in{'name'} =~ /^\S+$/ || &error($text{'auth_ename'});
$auth->{'name'} = $in{'name'};
if ($auth->{'type'} == 1) {
$in{'bits'} =~ /^\d+$/ || &error($text{'auth_ebits'});
$auth->{'bits'} = $in{'bits'};
$in{'exp'} =~ /^\d+$/ || &error($text{'auth_eexp'});
$auth->{'exp'} = $in{'exp'};
}
else {
$auth->{'keytype'} = $in{'keytype'};
}
$in{'key'} =~ s/\s//g;
if ($auth->{'type'} == 1) {
$in{'key'} =~ /^\d+$/ || &error($text{'auth_ekey'});
}
else {
$in{'key'} =~ /^[a-z0-9\+\/=]+$/i || &error($text{'auth_ekey2'});
}
$auth->{'key'} = $in{'key'};
# Validate option inputs
&parse_options($auth->{'opts'}, \%opts);
if ($in{'from_def'}) {
delete($opts{'from'});
}
else {
$opts{'from'} = [ join(",", split(/\s+/, $in{'from'})) ];
}
if ($in{'command'}) {
$opts{'command'} = [ $in{'command'} ];
}
else {
delete($opts{'command'});
}
if ($in{'noport'}) { $opts{'no-port-forwarding'} = [ undef ]; }
else { delete($opts{'no-port-forwarding'}); }
if ($in{'nox11'}) { $opts{'no-x11-forwarding'} = [ undef ]; }
else { delete($opts{'no-x11-forwarding'}); }
if ($in{'noagent'}) { $opts{'no-agent-forwarding'} = [ undef ]; }
else { delete($opts{'no-agent-forwarding'}); }
if ($in{'nopty'}) { $opts{'no-pty'} = [ undef ]; }
else { delete($opts{'no-pty'}); }
$auth->{'opts'} = &join_options(\%opts);
# Create or save the authorized key
if ($in{'new'}) {
&create_auth($auth);
}
else {
&modify_auth($auth);
}
}
&redirect("list_auths.cgi");