]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - html/cgi-bin/uptime.cgi
Source-Links gefixt.
[people/pmueller/ipfire-2.x.git] / html / cgi-bin / uptime.cgi
1 #!/usr/bin/perl
2 #
3 # IPFire CGIs
4 #
5 # This code is distributed under the terms of the GPL
6 #
7 # (c) The IPFire Team
8 #
9
10 use strict;
11 # enable only the following on debugging purpose
12 use warnings;
13 use CGI::Carp 'fatalsToBrowser';
14
15 require '/var/ipfire/general-functions.pl';
16 require "${General::swroot}/lang.pl";
17 require "${General::swroot}/header.pl";
18
19 my %uptimesettings = ();
20 my %proxysettings = ();
21 my %checked = ();
22 my $message = "";
23 my $errormessage = "";
24 my %selected= () ;
25 my $uptimefile = "/var/ipfire/uptime/yasuc.conf";
26 &General::readhash("${General::swroot}/proxy/advanced/settings", \%proxysettings);
27
28 &Header::showhttpheaders();
29
30 $uptimesettings{'ENABLE'} = 'off';
31 $uptimesettings{'USER'} = '';
32 $uptimesettings{'PASS'} = '';
33 $uptimesettings{'PROXY'} = $proxysettings{'ENABLE'};
34 ### Values that have to be initialized
35 $uptimesettings{'ACTION'} = '';
36
37 &General::readhash("${General::swroot}/uptime/settings", \%uptimesettings);
38 &Header::getcgihash(\%uptimesettings);
39
40 &Header::openpage('Uptime Client', 1, '');
41 &Header::openbigbox('100%', 'left', '', $errormessage);
42
43 ############################################################################################################################
44 ############################################################################################################################
45
46 if ($uptimesettings{'ACTION'} eq $Lang::tr{'save'})
47 {
48 &save_configuration();
49 }
50 elsif ($uptimesettings{'ACTION'} eq $Lang::tr{'uptime enable'})
51 {
52 &save_configuration();
53 system("/bin/touch ${General::swroot}/uptime/enabled");
54 system("/usr/local/bin/yasucctrl enable");
55 }
56 elsif ($uptimesettings{'ACTION'} eq $Lang::tr{'uptime disable'})
57 {
58 unlink "${General::swroot}/uptime/enabled";
59 system("/usr/local/bin/yasucctrl disable");
60 }
61 elsif ($uptimesettings{'ACTION'} eq $Lang::tr{'uptime update now'})
62 {
63 &save_configuration();
64 system("/usr/local/bin/yasucctrl");
65 }
66
67 &General::readhash("${General::swroot}/uptime/settings", \%uptimesettings);
68
69 if ($errormessage) {
70 &Header::openbox('100%', 'left', $Lang::tr{'error messages'});
71 print "<class name='base'>$errormessage\n";
72 print "&nbsp;</class>\n";
73 &Header::closebox();
74 }
75
76 $checked{'PROXY'}{'on'} = '';
77 $checked{'PROXY'}{'off'} = '';
78 $checked{'PROXY'}{"$uptimesettings{'PROXY'}"} = 'checked';
79
80 ############################################################################################################################
81 ############################################################################################################################
82
83 &Header::openbox('100%', 'center', 'Uptime Client');
84 print <<END
85 <table width='300px' cellspacing='0'>
86 END
87 ;
88 if ( $message ne "" ) {
89 print "<tr><td colspan='3' align='center'><font color='red'>$message</font>";
90 }
91
92 my $status = "";
93 my $status_color = "";
94 if ( -e "${General::swroot}/uptime/enabled" ){
95 $status_color = $Header::colourgreen;
96 $status = $Lang::tr{'running'};
97 } else {
98 $status_color = $Header::colourred;
99 $status = $Lang::tr{'stopped'};
100 }
101
102 print <<END
103 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
104 <tr><td><b>Uptime Client:</b></td><td colspan='2'>
105 <input type='submit' name='ACTION' value='$Lang::tr{'uptime enable'}' />
106 <input type='submit' name='ACTION' value='$Lang::tr{'uptime disable'}' />
107 <input type='submit' name='ACTION' value='$Lang::tr{'uptime update now'}' />
108 </td></tr></form>
109 <tr><td colspan='2' bgcolor=$status_color align='center'><font color='white'<b>$status</b></font></td></tr>
110 </table>
111 <hr>
112 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
113 <table width='500px'>
114 <tr><td colspan='2' align='left'><b>Basisoptionen</b>
115 <tr><td align='left'>Username:<td><input type='text' name='USER' value='$uptimesettings{'USER'}'>
116 <tr><td align='left'>Password:<td><input type='password' name='PASS' value='$uptimesettings{'PASS'}'>
117
118 <tr><td colspan='2' align='left'><b>Proxyeinstellungen</b>
119 <tr><td align='left'>Use proxy:<td><input type='checkbox' name='PROXY' $checked{'PROXY'}{'on'}>
120 <tr><td colspan='2' align='right'><input type='submit' name='ACTION' value=$Lang::tr{'save'}>
121 </table>
122 </form>
123 END
124 ;
125 &Header::closebox();
126 &Header::closebigbox();
127 &Header::closepage();
128
129 ############################################################################################################################
130 ############################################################################################################################
131
132 sub save_configuration {
133 # A small helper to create our configurationfile
134 &General::writehash("${General::swroot}/uptime/settings", \%uptimesettings);
135 if ($uptimesettings{'PROXY'} == "on"){ $uptimesettings{'PROXY'} = "yes";}
136 if ($uptimesettings{'PROXY'} == "off"){ $uptimesettings{'PROXY'} = "no";}
137 open( FILE, "> $uptimefile" ) or die "Unable to write $uptimefile";
138 print FILE <<END
139 [global]
140 user = $uptimesettings{'USER'}
141 password= $uptimesettings{'PASS'}
142 proxy = $uptimesettings{'PROXY'}
143 debug = no
144
145 [proxy]
146 host = localhost
147 port = $proxysettings{'PROXY_PORT'}
148
149 [debug]
150 path = /var/log/yasuc.log
151 END
152 ;
153 close FILE;
154 }