]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - html/cgi-bin/samba.cgi
Geaendert:
[people/pmueller/ipfire-2.x.git] / html / cgi-bin / samba.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 %sambasettings = ();
20 my %checked = ();
21 my %netsettings = ();
22 my $message = "";
23 my $errormessage = "";
24 my $shareentry = "";
25 my @shares = ();
26 my @shareline = ();
27 my @proto = ();
28 my %selected= () ;
29 my $sharefile = "/var/ipfire/samba/shares";
30 &General::readhash("${General::swroot}/ethernet/settings", \%netsettings);
31
32 my %servicenames =
33 (
34 'SMB Daemon' => 'smbd',
35 'NetBIOS Nameserver' => 'nmbd',
36 'Winbind Daemon' => 'winbindd'
37 );
38
39 &Header::showhttpheaders();
40
41 $sambasettings{'ENABLED'} = 'off';
42 $sambasettings{'EDIT'} = 'no';
43 $sambasettings{'VALID'} = 'yes';
44 $sambasettings{'WORKGRP'} = 'homeip.net';
45 $sambasettings{'NETBIOSNAME'} = 'IPFIRE';
46 $sambasettings{'SRVSTRING'} = 'Samba Server %v running on IPFire 2.0';
47 $sambasettings{'INTERFACES'} = '';
48 $sambasettings{'SECURITY'} = 'share';
49 $sambasettings{'OSLEVEL'} = '20';
50 $sambasettings{'PDC'} = 'off';
51 $sambasettings{'WINSSERV'} = '';
52 $sambasettings{'WINS'} = 'off';
53 ### Values that have to be initialized
54 $sambasettings{'ACTION'} = '';
55
56 &General::readhash("${General::swroot}/samba/settings", \%sambasettings);
57 &Header::getcgihash(\%sambasettings);
58
59 &Header::openpage('Samba', 1, '');
60 &Header::openbigbox('100%', 'left', '', $errormessage);
61
62 ############################################################################################################################
63 ############################################################################################################################
64
65 if ($sambasettings{'ACTION'} eq $Lang::tr{'save'})
66 {
67 &General::writehash("${General::swroot}/samba/settings", \%sambasettings);
68 }
69
70 &General::readhash("${General::swroot}/samba/settings", \%sambasettings);
71
72 if ($errormessage) {
73 &Header::openbox('100%', 'left', $Lang::tr{'error messages'});
74 print "<class name='base'>$errormessage\n";
75 print "&nbsp;</class>\n";
76 &Header::closebox();
77 }
78
79 $checked{'PDC'}{'on'} = '';
80 $checked{'PDC'}{'off'} = '';
81 $checked{'PDC'}{"$sambasettings{'PDC'}"} = 'checked';
82 $checked{'WINS'}{'on'} = '';
83 $checked{'WINS'}{'off'} = '';
84 $checked{'WINS'}{"$sambasettings{'WINS'}"} = 'checked';
85
86 ############################################################################################################################
87 ############################################################################################################################
88
89 &Header::openbox('100%', 'center', 'Samba');
90 print <<END
91 <table width='400px' cellspacing='0'>
92 END
93 ;
94 if ( $message ne "" ) {
95 print "<tr><td colspan='3' align='center'><font color='red'>$message</font>";
96 }
97
98 my $lines = 0;
99 my $key = '';
100 foreach $key (sort keys %servicenames)
101 {
102 if ($lines % 2) {
103 print "<tr bgcolor='${Header::table1colour}'>\n"; }
104 else {
105 print "<tr bgcolor='${Header::table2colour}'>\n"; }
106 print "<td align='left'>$key</td>\n";
107 my $shortname = $servicenames{$key};
108 my $status = &isrunning($shortname);
109 print "$status\n";
110 print <<END
111 <td><form method='post' action='$ENV{'SCRIPT_NAME'}'>
112 <input type='hidden' name='ACTION' value='restart $shortname'>
113 <input type='image' src='/images/reload.gif'>
114 </form></td>
115 END
116 ;
117 print "</tr>\n";
118 $lines++;
119 }
120 print <<END
121 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
122 <tr><td><b>Alle Dienste:</b></td><td colspan='2'>
123 <input type='submit' name='ACTION' value='Start' />
124 <input type='submit' name='ACTION' value='Stop' />
125 <input type='submit' name='ACTION' value='$Lang::tr{'restart'}' />
126 </td></tr></form>
127 </table>
128 <hr>
129 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
130 <table width='500px'>
131 <tr><td colspan='2' align='left'><b>Basisoptionen</b>
132 <tr><td align='left'>Workgroup:<td><input type='text' name='WORKGRP' value='$sambasettings{'WORKGRP'}'>
133 <tr><td align='left'>NetBIOS-Name:<td><input type='text' name='NETBIOSNAME' value='$sambasettings{'NETBIOSNAME'}'>
134 <tr><td align='left'>Server-String:<td><input type='text' name='SRVSTRING' value='$sambasettings{'SRVSTRING'}'>
135 <tr><td align='left'>Interfaces:<td><select name='INTERFACES'>
136 <option value='$netsettings{'GREEN_DEV'}'>GREEN</option>
137 END
138 ;
139 if (&Header::blue_used()){
140 print <<END
141 <option value='$netsettings{'BLUE_DEV'}'>BLUE</option>
142 <option value='$netsettings{'GREEN_DEV'},$netsettings{'BLUE_DEV'}'>GREEN & BLUE</option>
143 END
144 ;
145 }
146 print <<END
147 </select>
148
149 <tr><td colspan='2' align='left'><b>Sicherheitsoptionen</b>
150 <tr><td align='left'>Security:<td><select name='SECURITY'>
151 <option value='share'>SHARE</option>
152 <option value='user'>USER</option>
153 <option value='server'>SERVER</option>
154 <option value='domain'>DOMAIN</option>
155 </select>
156
157 <tr><td colspan='2' align='left'><b>Browsingoptionen</b>
158 <tr><td align='left'>OS Level:<td><input type='text' name='OSLEVEL' value='$sambasettings{'OSLEVEL'}'>
159 <tr><td align='left'>Primary Domain Controller:<td>on <input type='radio' name='PDC' value='on' $checked{'PDC'}{'on'}>/
160 <input type='radio' name='PDC' value='off' $checked{'PDC'}{'off'}> off
161
162 <tr><td colspan='2' align='left'><b>WINS-Optionen</b>
163 <tr><td align='left'>WINS-Server:<td><input type='text' name='WINSSRV' value='$sambasettings{'WINSSRV'}'>
164 <tr><td align='left'>WINS-Support:<td>on <input type='radio' name='WINS' value='on' $checked{'WINS'}{'on'}>/
165 <input type='radio' name='WINS' value='off' $checked{'WINS'}{'off'}> off
166
167 <tr><td colspan='2' align='right'><input type='submit' name='ACTION' value=$Lang::tr{'save'}>
168 </table>
169 </form>
170 END
171 ;
172 &Header::closebox();
173
174 &Header::openbox('100%', 'center', 'Shares');
175
176 print <<END
177 <table width='500'>
178 <tr><th width='40%'>Name der Freigabe<th width='40%'>Pfad<th width='20%'>Optionen
179 END
180 ;
181 open( FILE, "< $sharefile" ) or die "Unable to read $sharefile";
182 @shares = <FILE>;
183 close FILE;
184 foreach $shareentry (sort @shares)
185 {
186 @shareline = split( /\;/, $shareentry );
187 print <<END
188 <tr><td align='center' bgcolor='#EAEAEA'><b>$shareline[0]</b>
189 <td align='center' bgcolor='#EAEAEA'>$shareline[2]
190 <td align='right' bgcolor='#EAEAEA'>
191 <table border='0'><tr>
192 END
193 ;
194 if ($shareline[1] eq 'enabled') {
195 print <<END
196 <td><form method='post' action='$ENV{'SCRIPT_NAME'}'>
197 <input type='hidden' name='NAME' value='shareline[0]'>
198 <input type='hidden' name='ACTION' value='disable'>
199 <input type='image' alt='Ausschalten' src='/images/on.gif'>
200 </form>
201 END
202 ;
203 } elsif ($shareline[1] eq 'disabled') {
204 print <<END
205 <td><form method='post' action='$ENV{'SCRIPT_NAME'}'>
206 <input type='hidden' name='NAME' value='shareline[0]'>
207 <input type='hidden' name='ACTION' value='enable'>
208 <input type='image' alt='Einschalten' src='/images/off.gif'>
209 </form>
210 END
211 ;
212 }
213 print <<END
214 <td><form method='post' action='$ENV{'SCRIPT_NAME'}'>
215 <input type='hidden' name='NAME' value='shareline[0]'>
216 <input type='hidden' name='ACTION' value='Bearbeiten'>
217 <input type='image' alt='Bearbeiten' src='/images/edit.gif'>
218 </form>
219 <td><form method='post' action='$ENV{'SCRIPT_NAME'}'>
220 <input type='hidden' name='NAME' value='shareline[0]'>
221 <input type='hidden' name='ACTION' value='Loeschen'>
222 <input type='image' alt='Loeschen' src='/images/delete.gif'>
223 </form>
224 </table>
225 END
226 ;
227 }
228 print <<END
229 <tr><td colspan='8' align='right' valign='middle'><b>Legende:</b>&nbsp;&nbsp;<img src='/images/edit.gif'>&nbsp;Freigabe bearbeiten | <img src='/images/delete.gif'>&nbsp;Freigabe loeschen &nbsp;
230 </table>
231 END
232 ;
233
234 &Header::closebox();
235
236 &Header::closebigbox();
237 &Header::closepage();
238
239 ############################################################################################################################
240 ############################################################################################################################
241
242 sub isrunning
243 {
244 my $cmd = $_[0];
245 my $status = "<td bgcolor='${Header::colourred}'><font color='white'><b>$Lang::tr{'stopped'}</b></font></td>";
246 my $pid = '';
247 my $testcmd = '';
248 my $exename;
249
250 $cmd =~ /(^[a-z]+)/;
251 $exename = $1;
252
253 if (open(FILE, "/var/run/${cmd}.pid"))
254 {
255 $pid = <FILE>; chomp $pid;
256 close FILE;
257 if (open(FILE, "/proc/${pid}/status"))
258 {
259 while (<FILE>)
260 {
261 if (/^Name:\W+(.*)/) {
262 $testcmd = $1; }
263 }
264 close FILE;
265 if ($testcmd =~ /$exename/)
266 {
267 $status = "<td bgcolor='${Header::colourgreen}'><font color='white'><b>$Lang::tr{'running'}</b></font></td>";
268 }
269 }
270 }
271
272 return $status;
273 }
274