]> git.ipfire.org Git - ipfire-2.x.git/blame - html/cgi-bin/upnp.cgi
Ramdisk-Arbeit nahezu beendet.
[ipfire-2.x.git] / html / cgi-bin / upnp.cgi
CommitLineData
97de2cae
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 %upnpsettings = ();
20my %checked = ();
21my %netsettings = ();
22my $message = "";
23my $errormessage = "";
24my %selected= () ;
25&General::readhash("${General::swroot}/ethernet/settings", \%netsettings);
26
27my %servicenames =
28(
29 'UPnP Daemon' => 'upnpd',
30);
31
32&Header::showhttpheaders();
33
34$upnpsettings{'ENABLED'} = 'off';
35$upnpsettings{'GREEN'} = 'on';
36$upnpsettings{'BLUE'} = 'off';
37### Values that have to be initialized
38$upnpsettings{'ACTION'} = '';
39
40&General::readhash("${General::swroot}/upnp/settings", \%upnpsettings);
41&Header::getcgihash(\%upnpsettings);
42
43&Header::openpage('UPnP', 1, '');
44&Header::openbigbox('100%', 'left', '', $errormessage);
45
46############################################################################################################################
47############################################################################################################################
48
49if ($upnpsettings{'ACTION'} eq $Lang::tr{'save'})
50{
51 &General::writehash("${General::swroot}/upnp/settings", \%upnpsettings);
52}
53elsif ($upnpsettings{'ACTION'} eq 'Start')
54{
55 $upnpsettings{'ENABLED'} = 'on';
56 &General::writehash("${General::swroot}/upnp/settings", \%upnpsettings);
57 system('/usr/local/bin/upnpctrl start');
58}
59elsif ($upnpsettings{'ACTION'} eq 'Stop')
60{
61 $upnpsettings{'ENABLED'} = 'off';
62 &General::writehash("${General::swroot}/upnp/settings", \%upnpsettings);
63 system('/usr/local/bin/upnpctrl stop');
64}
65elsif ($upnpsettings{'ACTION'} eq $Lang::tr{'restart'})
66{
67 &General::writehash("${General::swroot}/upnp/settings", \%upnpsettings);
68 system('/usr/local/bin/upnpctrl restart');
69}
70
71&General::readhash("${General::swroot}/upnp/settings", \%upnpsettings);
72
73if ($errormessage) {
74 &Header::openbox('100%', 'left', $Lang::tr{'error messages'});
75 print "<class name='base'>$errormessage\n";
76 print "&nbsp;</class>\n";
77 &Header::closebox();
78}
79
80$checked{'GREEN'}{'on'} = '';
81$checked{'GREEN'}{'off'} = '';
82$checked{'GREEN'}{"$upnpsettings{'GREEN'}"} = 'checked';
83$checked{'BLUE'}{'on'} = '';
84$checked{'BLUE'}{'off'} = '';
85$checked{'BLUE'}{"$upnpsettings{'BLUE'}"} = 'checked';
86
87############################################################################################################################
88############################################################################################################################
89
90&Header::openbox('100%', 'center', 'UPnP');
91print <<END
92 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
93 <table width='400' cellspacing='0'>
94END
95;
96 if ( $message ne "" ) {
97 print "<tr><td colspan='3' align='center'><font color='red'>$message</font>";
98 }
99
100 my $lines = 0;
101 my $key = '';
102 foreach $key (sort keys %servicenames)
103 {
104 if ($lines % 2) {
105 print "<tr bgcolor='${Header::table1colour}'>\n"; }
106 else {
107 print "<tr bgcolor='${Header::table2colour}'>\n"; }
108 print "<td align='left'>$key\n";
109 my $shortname = $servicenames{$key};
110 my $status = &isrunning($shortname);
111 print "$status\n";
112 $lines++;
113 }
114 print <<END
115 <tr><td><b>Alle Dienste:</b></td><td colspan='2'>
116 <input type='submit' name='ACTION' value='Start' />
117 <input type='submit' name='ACTION' value='Stop' />
118 <input type='submit' name='ACTION' value='$Lang::tr{'restart'}' />
119 </table>
120 </form>
121 <hr />
122 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
123 <table width='500'>
124 <tr><td colspan='2' align='left'><b>$Lang::tr{'options'}</b>
125 <tr><td align='left'>$Lang::tr{'interfaces'}
126 <td align='left'>&nbsp;<td><input type='checkbox' name='GREEN' $checked{'GREEN'}{'on'} /> <font size='2' color='$Header::colourgreen'><b>$Lang::tr{'green'} - $netsettings{'GREEN_DEV'}</b></font>
127END
128;
129 if (&Header::blue_used()){
130 print <<END
131 <tr><td align='left'>&nbsp;<td><input type='checkbox' name='BLUE' $checked{'BLUE'}{'on'} /> <font size='2' color='$Header::colourblue'><b>$Lang::tr{'wireless'} - $netsettings{'BLUE_DEV'}</b></font>
132END
133;
134 }
135 print <<END
136 <tr><td colspan='2' align='right'><input type='submit' name='ACTION' value=$Lang::tr{'save'} />
137 </table>
138 </form>
139END
140;
141&Header::closebox();
142
143&Header::closebigbox();
144&Header::closepage();
145
146############################################################################################################################
147############################################################################################################################
148
149sub isrunning
150{
151 my $cmd = $_[0];
152 my $status = "<td bgcolor='${Header::colourred}'><font color='white'><b>$Lang::tr{'stopped'}</b></font></td>";
153 my $pid = '';
154 my $testcmd = '';
155 my $exename;
156
157 $cmd =~ /(^[a-z]+)/;
158 $exename = $1;
159
160 if (open(FILE, "/var/run/${cmd}.pid"))
161 {
162 $pid = <FILE>; chomp $pid;
163 close FILE;
164 if (open(FILE, "/proc/${pid}/status"))
165 {
166 while (<FILE>)
167 {
168 if (/^Name:\W+(.*)/) {
169 $testcmd = $1; }
170 }
171 close FILE;
172 if ($testcmd =~ /$exename/)
173 {
174 $status = "<td bgcolor='${Header::colourgreen}'><font color='white'><b>$Lang::tr{'running'}</b></font></td>";
175 }
176 }
177 }
178
179 return $status;
180}
181