]>
Commit | Line | Data |
---|---|---|
ac1cfefa MT |
1 | #!/usr/bin/perl |
2 | # | |
3 | # SmoothWall CGIs | |
4 | # | |
5 | # This code is distributed under the terms of the GPL | |
6 | # | |
7 | # (c) The SmoothWall Team | |
8 | # | |
9 | # $Id: dial.cgi,v 1.4.2.3 2005/02/22 22:21:55 gespinasse Exp $ | |
10 | # | |
11 | ||
12 | use strict; | |
13 | ||
14 | # enable only the following on debugging purpose | |
15 | #use warnings; | |
16 | #use CGI::Carp 'fatalsToBrowser'; | |
17 | ||
18 | require 'CONFIG_ROOT/general-functions.pl'; | |
19 | require "${General::swroot}/lang.pl"; | |
20 | require "${General::swroot}/header.pl"; | |
21 | ||
22 | my %cgiparams=(); | |
23 | ||
24 | $cgiparams{'ACTION'} = ''; | |
25 | &Header::getcgihash(\%cgiparams); | |
26 | ||
10a04d70 MT |
27 | if ($cgiparams{'ACTION'} eq $Lang::tr{'dial profile'}) |
28 | { | |
29 | my $profile = $cgiparams{'PROFILE'}; | |
30 | my %tempcgiparams = (); | |
31 | $tempcgiparams{'PROFILE'} = ''; | |
32 | &General::readhash("${General::swroot}/ppp/settings-$cgiparams{'PROFILE'}", | |
33 | \%tempcgiparams); | |
34 | ||
35 | # make a link from the selected profile to the "default" one. | |
36 | unlink("${General::swroot}/ppp/settings"); | |
37 | link("${General::swroot}/ppp/settings-$cgiparams{'PROFILE'}", | |
38 | "${General::swroot}/ppp/settings"); | |
39 | system ("/bin/touch", "${General::swroot}/ppp/updatesettings"); | |
40 | ||
41 | # read in the new params "early" so we can write secrets. | |
42 | %cgiparams = (); | |
43 | &General::readhash("${General::swroot}/ppp/settings", \%cgiparams); | |
44 | $cgiparams{'PROFILE'} = $profile; | |
45 | $cgiparams{'BACKUPPROFILE'} = $profile; | |
46 | &General::writehash("${General::swroot}/ppp/settings-$cgiparams{'PROFILE'}", | |
47 | \%cgiparams); | |
48 | ||
49 | # write secrets file. | |
50 | open(FILE, ">/${General::swroot}/ppp/secrets") or die "Unable to write secrets file."; | |
51 | flock(FILE, 2); | |
52 | my $username = $cgiparams{'USERNAME'}; | |
53 | my $password = $cgiparams{'PASSWORD'}; | |
54 | print FILE "'$username' * '$password'\n"; | |
55 | chmod 0600, "${General::swroot}/ppp/secrets"; | |
56 | close FILE; | |
57 | ||
58 | &General::log("$Lang::tr{'profile made current'} $tempcgiparams{'PROFILENAME'}"); | |
59 | $cgiparams{'ACTION'} = "$Lang::tr{'dial'}"; | |
60 | } | |
61 | ||
ac1cfefa MT |
62 | if ($cgiparams{'ACTION'} eq $Lang::tr{'dial'}) { |
63 | system('/etc/rc.d/rc.red','start') == 0 | |
64 | or &General::log("Dial failed: $?"); } | |
65 | elsif ($cgiparams{'ACTION'} eq $Lang::tr{'hangup'}) { | |
66 | system('/etc/rc.d/rc.red','stop') == 0 | |
67 | or &General::log("Hangup failed: $?"); } | |
68 | sleep 1; | |
69 | ||
70 | print "Status: 302 Moved\nLocation: /cgi-bin/index.cgi\n\n"; |