Sprachfix und FTP-Upload-Fix
[people/pmueller/ipfire-2.x.git] / html / cgi-bin / uptime.cgi
CommitLineData
29c8a65f
MT
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
10use strict;
11# enable only the following on debugging purpose
12use warnings;
13use CGI::Carp 'fatalsToBrowser';
14
15require '/var/ipfire/general-functions.pl';
16require "${General::swroot}/lang.pl";
17require "${General::swroot}/header.pl";
18
19my %uptimesettings = ();
20my %proxysettings = ();
21my %checked = ();
22my $message = "";
23my $errormessage = "";
24my %selected= () ;
25my $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
46if ($uptimesettings{'ACTION'} eq $Lang::tr{'save'})
47{
48 &save_configuration();
49}
50elsif ($uptimesettings{'ACTION'} eq $Lang::tr{'uptime enable'})
51{
52 &save_configuration();
9833e7d8 53 system("/usr/bin/touch ${General::swroot}/uptime/enabled");
29c8a65f
MT
54 system("/usr/local/bin/yasucctrl enable");
55}
56elsif ($uptimesettings{'ACTION'} eq $Lang::tr{'uptime disable'})
57{
58 unlink "${General::swroot}/uptime/enabled";
59 system("/usr/local/bin/yasucctrl disable");
60}
61elsif ($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
69if ($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');
84print <<END
85 <table width='300px' cellspacing='0'>
86END
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>
123END
124;
125&Header::closebox();
126&Header::closebigbox();
127&Header::closepage();
128
129############################################################################################################################
130############################################################################################################################
131
132sub 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]
140user = $uptimesettings{'USER'}
141password= $uptimesettings{'PASS'}
142proxy = $uptimesettings{'PROXY'}
143debug = no
144
145[proxy]
146host = localhost
147port = $proxysettings{'PROXY_PORT'}
148
149[debug]
150path = /var/log/yasuc.log
151END
152;
153 close FILE;
154}