#!/usr/bin/perl ############################################################################### # # # IPFire.org - A linux based firewall # # Copyright (C) 2005-2013 IPFire Team # # # # This program is free software: you can redistribute it and/or modify # # it under the terms of the GNU General Public License as published by # # the Free Software Foundation, either version 3 of the License, or # # (at your option) any later version. # # # # This program is distributed in the hope that it will be useful, # # but WITHOUT ANY WARRANTY; without even the implied warranty of # # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # # GNU General Public License for more details. # # # # You should have received a copy of the GNU General Public License # # along with this program. If not, see . # # # ############################################################################### use strict; # enable only the following on debugging purpose #use warnings; #use CGI::Carp 'fatalsToBrowser'; require '/var/ipfire/general-functions.pl'; require "${General::swroot}/lang.pl"; require "${General::swroot}/header.pl"; my %sambasettings = (); my %cgisettings = (); my %checked = (); my %netsettings = (); my %ovpnsettings = (); my %color = (); my %mainsettings = (); my $message = ""; my $errormessage = ""; my @Logs = qx(ls /var/log/samba/); my $Log =$Lang::tr{'no log selected'}; my $Status = qx(/usr/local/bin/sambactrl smbstatus); $Status=~s/\n/
/g; my $userentry = ""; my @user = (); my @userline = (); my $userfile = "${General::swroot}/samba/private/smbpasswd"; my %selected= () ; my $defaultoption= "[Share]\npath = /var/ipfire/samba/share1\ncomment = Share - Public Access\nbrowseable = yes\nwriteable = yes\ncreate mask = 0777\ndirectory mask = 0777\npublic = yes\nforce user = samba"; my $defaultprinter= "[Printer]\ncomment = Printer public\npath = /var/spool/cups\nprinting = sysvn\nprintcap = lpstat\npublic = yes\nwritable = no\nprintable = yes"; my %printer = (); my %shares = (); &General::readhash("${General::swroot}/ethernet/settings", \%netsettings); &General::readhash("${General::swroot}/ovpn/settings", \%ovpnsettings); &General::readhash("${General::swroot}/main/settings", \%mainsettings); &General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color); my @ovpnnetwork = split(/\//,$ovpnsettings{'DOVPN_SUBNET'}); my @ovpnip = split(/\./,$ovpnnetwork[0]); $ovpnip[3]=$ovpnip[3]+1; ############################################################################################################################ ############################################# Samba Dienste fr Statusberprfung ########################################## my %servicenames = ('SMB Daemon' => 'smbd', 'NetBIOS Nameserver' => 'nmbd', 'Winbind Daemon' => 'winbindd'); &Header::showhttpheaders(); ############################################################################################################################ #################################### Initialisierung von Samba Variablen fr global Settings ############################### $sambasettings{'WORKGRP'} = 'homeip.net'; $sambasettings{'NETBIOSNAME'} = 'IPFire'; $sambasettings{'SRVSTRING'} = 'Samba running on IPFire 2.x'; $sambasettings{'INTERFACES'} = ''; $sambasettings{'SECURITY'} = 'share'; $sambasettings{'OSLEVEL'} = '33'; $sambasettings{'GREEN'} = 'on'; $sambasettings{'BLUE'} = 'off'; $sambasettings{'ORANGE'} = 'off'; $sambasettings{'VPN'} = 'off'; $sambasettings{'WINSSRV'} = ''; $sambasettings{'WINSSUPPORT'} = 'on'; $sambasettings{'REMOTEANNOUNCE'} = ''; $sambasettings{'REMOTESYNC'} = ''; $sambasettings{'PASSWORDSYNC'} = 'off'; $sambasettings{'OTHERINTERFACES'} = '127.0.0.1'; $sambasettings{'GUESTACCOUNT'} = 'samba'; $sambasettings{'MAPTOGUEST'} = 'Bad User'; $sambasettings{'LOGLEVEL'} = '3 passdb:5 auth:5 winbind:2'; $sambasettings{'SYSLOGLEVEL'} = '1'; $sambasettings{'SYSLOGONLY'} = 'on'; $sambasettings{'DOSCHARSET'} = 'CP850'; $sambasettings{'UNIXCHARSET'} = 'UTF8'; $sambasettings{'DISPLAYCHARSET'} = 'CP850'; $sambasettings{'SOCKETOPTIONS'} = 'TCP_NODELAY SO_RCVBUF=819200 SO_SNDBUF=819200 SO_KEEPALIVE'; $sambasettings{'WIDELINKS'} = 'on'; $sambasettings{'UNIXEXTENSION'} = 'off'; $sambasettings{'SMB2'} = 'off'; ### Values that have to be initialized $sambasettings{'ACTION'} = ''; ### Samba CUPS Variablen $sambasettings{'LOADPRINTERS'} = 'Yes'; $sambasettings{'PRINTING'} = 'cups'; $sambasettings{'PRINTCAPNAME'} = 'cups'; my $LOGLINES = '50'; ################################################## Samba PDC Variablen ##################################################### $sambasettings{'LOCALMASTER'} = 'off'; $sambasettings{'DOMAINMASTER'} = 'off'; $sambasettings{'PREFERREDMASTER'} = 'off'; my $PDCOPTIONS = `cat ${General::swroot}/samba/pdc`; ############################################################################################################################ &General::readhash("${General::swroot}/samba/settings", \%sambasettings); &Header::getcgihash(\%sambasettings); sub refreshpage{&Header::openbox( 'Waiting', 1, "" );print "

$Lang::tr{'pagerefresh'}
";&Header::closebox();} if (($sambasettings{'WIDELINKS'} eq 'on') & ($sambasettings{'UNIXEXTENSION'} eq 'on')) {$errormessage = "$errormessage
Don't enable 'Wide links' and 'Unix extension' at the same time"; } &Header::openpage('Samba', 1, ''); &Header::openbigbox('100%', 'left', '', $errormessage); ############################################################################################################################ ############################################# Samba Rootskript aufrufe fr SU-Actions ####################################### if ($sambasettings{'ACTION'} eq 'smbuserdisable'){system("/usr/local/bin/sambactrl smbuserdisable $sambasettings{'NAME'}");refreshpage();} if ($sambasettings{'ACTION'} eq 'smbuserenable'){system("/usr/local/bin/sambactrl smbuserenable $sambasettings{'NAME'}");refreshpage();} if ($sambasettings{'ACTION'} eq 'smbuseradd'){system("/usr/local/bin/sambactrl smbuseradd $sambasettings{'USERNAME'} $sambasettings{'PASSWORD'} $sambasettings{'GROUP'} $sambasettings{'SHELL'}");refreshpage();} if ($sambasettings{'ACTION'} eq 'smbpcadd'){system("/usr/local/bin/sambactrl smbpcadd $sambasettings{'PCNAME'} $sambasettings{'GROUP'} $sambasettings{'SHELL'}");refreshpage();} if ($sambasettings{'ACTION'} eq 'smbchangepw'){system("/usr/local/bin/sambactrl smbchangepw $sambasettings{'USERNAME'} $sambasettings{'PASSWORD'}");refreshpage();} if ($sambasettings{'ACTION'} eq 'smbrestart'){system("/usr/local/bin/sambactrl smbrestart");refreshpage();} if ($sambasettings{'ACTION'} eq 'smbstart'){system("/usr/local/bin/sambactrl smbstart");refreshpage();} if ($sambasettings{'ACTION'} eq 'smbstop'){system("/usr/local/bin/sambactrl smbstop");refreshpage();} if ($sambasettings{'ACTION'} eq 'smbreload'){system("/usr/local/bin/sambactrl smbreload");refreshpage();} if ($sambasettings{'ACTION'} eq 'globalresetyes') { system("/usr/local/bin/sambactrl smbglobalreset"); $sambasettings{'WORKGRP'} = 'homeip.net'; $sambasettings{'NETBIOSNAME'} = 'IPFire'; $sambasettings{'SRVSTRING'} = 'Samba running on IPFire 2.x'; $sambasettings{'INTERFACES'} = ''; $sambasettings{'SECURITY'} = 'share'; $sambasettings{'OSLEVEL'} = '65'; $sambasettings{'GREEN'} = 'on'; $sambasettings{'BLUE'} = 'off'; $sambasettings{'ORANGE'} = 'off'; $sambasettings{'VPN'} = 'off'; $sambasettings{'WINSSRV'} = ''; $sambasettings{'WINSSUPPORT'} = 'on'; $sambasettings{'REMOTEANNOUNCE'} = ''; $sambasettings{'REMOTESYNC'} = ''; $sambasettings{'PASSWORDSYNC'} = 'off'; $sambasettings{'OTHERINTERFACES'} = '127.0.0.1'; $sambasettings{'GUESTACCOUNT'} = 'samba'; $sambasettings{'MAPTOGUEST'} = 'Bad User'; $sambasettings{'LOGLEVEL'} = '3 passdb:5 auth:5 winbind:2'; $sambasettings{'SYSLOGLEVEL'} = '1'; $sambasettings{'SYSLOGONLY'} = 'on'; $sambasettings{'DOSCHARSET'} = 'CP850'; $sambasettings{'UNIXCHARSET'} = 'UTF8'; $sambasettings{'DISPLAYCHARSET'} = 'CP850'; ### Samba CUPS Variablen $sambasettings{'LOADPRINTERS'} = 'Yes'; $sambasettings{'PRINTING'} = 'cups'; $sambasettings{'PRINTCAPNAME'} = 'cups'; $sambasettings{'PRINTERNAME'} = 'Printer'; ### Values that have to be initialized $sambasettings{'WIDELINKS'} = 'on'; $sambasettings{'UNIXEXTENSION'} = 'off'; $sambasettings{'ACTION'} = ''; $sambasettings{'LOCALMASTER'} = 'off'; $sambasettings{'DOMAINMASTER'} = 'off'; $sambasettings{'PREFERREDMASTER'} = 'off'; $sambasettings{'SOCKETOPTIONS'} = 'TCP_NODELAY SO_RCVBUF=819200 SO_SNDBUF=819200 SO_KEEPALIVE'; $sambasettings{'WIDELINKS'} = 'on'; $sambasettings{'UNIXEXTENSION'} = 'off'; $sambasettings{'SMB2'} = 'off'; $PDCOPTIONS = `cat ${General::swroot}/samba/pdc`; system("/usr/local/bin/sambactrl smbreload"); refreshpage(); } if ($sambasettings{'ACTION'} eq 'join') { $message .= &joindomain($sambasettings{'USERNAME'}, $sambasettings{'PASSWORD'}); } ############################################################################################################################ ################################################ Sicherheitsabfrage für den Reset ########################################## if ($sambasettings{'ACTION'} eq 'globalreset') { print <
$Lang::tr{'resetglobals'}
$Lang::tr{'yes'}
$Lang::tr{'no'}
END ; } if ($sambasettings{'ACTION'} eq 'sharesreset') { print <
$Lang::tr{'resetshares'}
$Lang::tr{'yes'}
$Lang::tr{'no'}
END ; } ############################################################################################################################ ########################################### Samba Benutzer oder PC l�chen ################################################# if ($sambasettings{'ACTION'} eq 'userdelete'){system("/usr/local/bin/sambactrl smbuserdelete $sambasettings{'NAME'}");refreshpage();} ############################################################################################################################ ##################################### Umsetzen der Werte von Checkboxen und Dropdowns ###################################### if ($sambasettings{'ACTION'} eq $Lang::tr{'save'}) { $sambasettings{'INTERFACES'} = ''; if ($sambasettings{'GREEN'} eq 'on'){ $sambasettings{'INTERFACES'} .= " $netsettings{'GREEN_DEV'}";} if ($sambasettings{'BLUE'} eq 'on'){ $sambasettings{'INTERFACES'} .= " $netsettings{'BLUE_DEV'}";} if ($sambasettings{'ORANGE'} eq 'on'){ $sambasettings{'INTERFACES'} .= " $netsettings{'ORANGE_DEV'}";} if ($sambasettings{'VPN'} eq 'on'){$sambasettings{'INTERFACES'} .= " ";} if ($sambasettings{'OTHERINTERFACES'} ne ''){ $sambasettings{'INTERFACES'} .= " $sambasettings{'OTHERINTERFACES'}";} ############################################################################################################################ ##################################### Schreiben settings und bersetzen fr smb.conf ####################################### delete $sambasettings{'__CGI__'};delete $sambasettings{'x'};delete $sambasettings{'y'}; &General::writehash("${General::swroot}/samba/settings", \%sambasettings); if ($sambasettings{'PASSWORDSYNC'} eq 'on'){ $sambasettings{'PASSWORDSYNC'} = "true";} else { $sambasettings{'PASSWORDSYNC'} = "false";} if ($sambasettings{'WINSSUPPORT'} eq 'on'){ $sambasettings{'WINSSUPPORT'} = "true";$sambasettings{'WINSSRV'} = "";} else { $sambasettings{'WINSSUPPORT'} = "false";} if ($sambasettings{'LOCALMASTER'} eq 'on'){ $sambasettings{'LOCALMASTER'} = "true";} else { $sambasettings{'LOCALMASTER'} = "false";} if ($sambasettings{'DOMAINMASTER'} eq 'on'){ $sambasettings{'DOMAINMASTER'} = "true";} else { $sambasettings{'DOMAINMASTER'} = "false";} if ($sambasettings{'PREFERREDMASTER'} eq 'on'){ $sambasettings{'PREFERREDMASTER'} = "true";} else { $sambasettings{'PREFERREDMASTER'} = "false";} if ($sambasettings{'SYSLOGONLY'} eq 'on'){ $sambasettings{'SYSLOGONLY'} = "yes";} else { $sambasettings{'SYSLOGONLY'} = "no";} if ($sambasettings{'WIDELINKS'} eq 'on'){ $sambasettings{'WIDELINKS'} = "yes";} else { $sambasettings{'WIDELINKS'} = "no";} if ($sambasettings{'UNIXEXTENSION'} eq 'on'){ $sambasettings{'UNIXEXTENSION'} = "yes";} else { $sambasettings{'UNIXEXTENSION'} = "no";} ############################################################################################################################ ############################################# Schreiben der Samba globals ################################################## open (FILE, ">${General::swroot}/samba/global") or die "Can't save the global settings: $!"; flock (FILE, 2); print FILE <>${General::swroot}/samba/global") or die "Can't save the global cups settings: $!"; flock (FILE, 2); print FILE <${General::swroot}/samba/pdc") or die "Can't save the pdc settings: $!"; flock (FILE, 2); chomp $sambasettings{'PDCOPTIONS'}; $sambasettings{'PDCOPTIONS'} =~ s/\r\n/\n/gi; $sambasettings{'PDCOPTIONS'} =~ s/^\n//gi; $sambasettings{'PDCOPTIONS'} =~ s/^\r//gi; $sambasettings{'PDCOPTIONS'} =~ s/^.\n//gi; $sambasettings{'PDCOPTIONS'} =~ s/^.\r//gi; print FILE <$errormessage\n"; print " \n"; &Header::closebox(); } if ($message) { $message = &Header::cleanhtml($message); $message =~ s/\n/
/g; &Header::openbox('100%', 'left', $Lang::tr{'messages'}); print "$message\n"; &Header::closebox(); } ############################################################################################################################ ########################################## Aktivieren von Checkboxen und Dropdowns ######################################### $checked{'SYSLOGONLY'}{'off'} = ''; $checked{'SYSLOGONLY'}{'on'} = ''; $checked{'SYSLOGONLY'}{$sambasettings{'SYSLOGONLY'}} = "checked='checked'"; $checked{'WINSSUPPORT'}{'off'} = ''; $checked{'WINSSUPPORT'}{'on'} = ''; $checked{'WINSSUPPORT'}{$sambasettings{'WINSSUPPORT'}} = "checked='checked'"; $checked{'PASSWORDSYNC'}{'off'} = ''; $checked{'PASSWORDSYNC'}{'on'} = ''; $checked{'PASSWORDSYNC'}{$sambasettings{'PASSWORDSYNC'}} = "checked='checked'"; $checked{'LOCALMASTER'}{'off'} = ''; $checked{'LOCALMASTER'}{'on'} = ''; $checked{'LOCALMASTER'}{$sambasettings{'LOCALMASTER'}} = "checked='checked'"; $checked{'DOMAINMASTER'}{'off'} = ''; $checked{'DOMAINMASTER'}{'on'} = ''; $checked{'DOMAINMASTER'}{$sambasettings{'DOMAINMASTER'}} = "checked='checked'"; $checked{'PREFERREDMASTER'}{'off'} = ''; $checked{'PREFERREDMASTER'}{'on'} = ''; $checked{'PREFERREDMASTER'}{$sambasettings{'PREFERREDMASTER'}} = "checked='checked'"; $checked{'WIDELINKS'}{'off'} = ''; $checked{'WIDELINKS'}{'on'} = ''; $checked{'WIDELINKS'}{$sambasettings{'WIDELINKS'}} = "checked='checked'"; $checked{'UNIXEXTENSION'}{'off'} = ''; $checked{'UNIXEXTENSION'}{'on'} = ''; $checked{'UNIXEXTENSION'}{$sambasettings{'UNIXEXTENSION'}} = "checked='checked'"; $checked{'SMB2'}{'off'} = ''; $checked{'SMB2'}{'on'} = ''; $checked{'SMB2'}{$sambasettings{'SMB2'}} = "checked='checked'"; $checked{'GREEN'}{'off'} = ''; $checked{'GREEN'}{'on'} = ''; $checked{'GREEN'}{$sambasettings{'GREEN'}} = "checked='checked'"; $checked{'BLUE'}{'off'} = ''; $checked{'BLUE'}{'on'} = ''; $checked{'BLUE'}{$sambasettings{'BLUE'}} = "checked='checked'"; $checked{'ORANGE'}{'off'} = ''; $checked{'ORANGE'}{'on'} = ''; $checked{'ORANGE'}{$sambasettings{'ORANGE'}} = "checked='checked'"; $checked{'VPN'}{'off'} = ''; $checked{'VPN'}{'on'} = ''; $checked{'VPN'}{$sambasettings{'VPN'}} = "checked='checked'"; if ( $sambasettings{'MAPTOGUEST'} eq "Never" ) { $sambasettings{'MAPTOGUEST'}="Bad User"; } $selected{'MAPTOGUEST'}{$sambasettings{'MAPTOGUEST'}} = "selected='selected'"; $selected{'SECURITY'}{$sambasettings{'SECURITY'}} = "selected='selected'"; ############################################################################################################################ ################################### Aufbau der HTML Seite fr globale Sambaeinstellungen ################################### &Header::openbox('100%', 'center', $Lang::tr{'samba'}); print <
$Lang::tr{'all services'}
END ; my $key = ''; foreach $key (sort keys %servicenames) { print ""; my $shortname = $servicenames{$key}; my $status = &isrunning($shortname); print "$status"; } print <
$key

END ; if (&Header::blue_used()) { print < END ; } if (&Header::orange_used()) { print < END ; } print < END ; # print < END ; if ($sambasettings{'WINSSUPPORT'} eq 'off') {print"";} print < END ; if ($sambasettings{'SECURITY'} eq 'user') { print < END ; } if ($sambasettings{'SECURITY'} eq 'user' && $sambasettings{'DOMAINMASTER'} eq 'on') { print < END ; } if ( -e "/var/ipfire/cups/enable") { print < END ; } print <
$Lang::tr{'basic options'}
$Lang::tr{'workgroup'}
$Lang::tr{'netbios name'}
$Lang::tr{'dos charset'}
$Lang::tr{'unix charset'}
$Lang::tr{'display charset'}
$Lang::tr{'server string'}
$Lang::tr{'log level'}
Sys$Lang::tr{'log level'}
Syslog onlyon / off
$Lang::tr{'interfaces'}on / off | OpenVpn - $ovpnip[0].$ovpnip[1].$ovpnip[2].$ovpnip[3]/$ovpnnetwork[1]
on / off | $Lang::tr{'green'} - $netsettings{'GREEN_DEV'}
on / off | $Lang::tr{'wireless'} - $netsettings{'BLUE_DEV'}
on / off | $Lang::tr{'dmz'} - $netsettings{'ORANGE_DEV'}
$Lang::tr{'more'}

Wide linkson / off
Unix extensionon / off
SMB2 $Lang::tr{'protocol'}on / off

$Lang::tr{'security options'}
$Lang::tr{'security'}
$Lang::tr{'map to guest'}
$Lang::tr{'unix password sync'}on / # off

$Lang::tr{'network options'}
$Lang::tr{'os level'}
$Lang::tr{'socket options'}
$Lang::tr{'remote announce'}
$Lang::tr{'remote browse sync'}
$Lang::tr{'wins server'}
$Lang::tr{'wins support'}on / off
$Lang::tr{'local master'}on / off
$Lang::tr{'domain master'}on / off
$Lang::tr{'prefered master'}on / off

$Lang::tr{'pdc options'}


$Lang::tr{'printing options'}
$Lang::tr{'load printer'}
$Lang::tr{'printing'}
$Lang::tr{'printcap name'}
END ; if ($sambasettings{'ACTION'} eq 'globalcaption') { print <
$Lang::tr{'caption'}
$Lang::tr{'save settings'}
$Lang::tr{'restore settings'}
END ; } &Header::closebox(); ############################################################################################################################ ########################################## Benutzerverwaltung fr Usersecurity ############################################# if ($sambasettings{'SECURITY'} eq 'user') { if ($sambasettings{'DOMAINMASTER'} eq 'off') { &Header::openbox('100%', 'center', $Lang::tr{'accounting user nonpdc'}); } else { &Header::openbox('100%', 'center', $Lang::tr{'accounting user pdc'}); } print <
END ; if ($sambasettings{'DOMAINMASTER'} eq 'off') { print ""; } else { print ""; } print ""; system('/usr/local/bin/sambactrl readsmbpasswd'); open(FILE, "<${General::swroot}/samba/private/smbpasswd") or die "Can't read user file: $!"; @user = ; close(FILE); system('/usr/local/bin/sambactrl locksmbpasswd'); my $lines = 0; foreach $userentry (sort @user) { @userline = split( /\:/, $userentry ); if ($lines % 2) {print "";} else {print "";} print " END ; } else { print < END ; } if ($userline[0] =~ /\$/) { print ""; } else { print <
END ; } if ($sambasettings{'DOMAINMASTER'} eq 'on' && $userline[0] =~ /\$/) { print <
END ; } else { print <
END ; } $lines++; } print <
$Lang::tr{'accounting'}
$Lang::tr{'username'}$Lang::tr{'password'}$Lang::tr{'type'}$Lang::tr{'status'}$Lang::tr{'options'}
$userline[0]"; if ($userline[4] =~ /N/) { print "$Lang::tr{'not set'}"; } else { print "$Lang::tr{'set'}"; } if ($sambasettings{'DOMAINMASTER'} eq 'off') { print ""; } else { if ($userline[0] =~ /\$/) { print "$Lang::tr{'pc'}"; } else { print "$Lang::tr{'user'}"; } } if ($userline[4] =~ /D/) { print <
END ; if ($sambasettings{'DOMAINMASTER'} eq 'on') { print <
END ; } print <
END ; if ($sambasettings{'ACTION'} eq 'usercaption') { print <
$Lang::tr{'caption'}
$Lang::tr{'add user'}
$Lang::tr{'pc add'}
$Lang::tr{'delete user'}
$Lang::tr{'delete pc'}
$Lang::tr{'activate user'}
$Lang::tr{'deactivate user'}
$Lang::tr{'change passwords'}
$Lang::tr{'save config'}
END ; } if ($sambasettings{'ACTION'} eq 'userchangepw') { my $username = "$sambasettings{'NAME'}"; my $password = 'samba'; print <
$Lang::tr{'change passwords'}
$Lang::tr{'username'}
$Lang::tr{'password'}
END ; } if ($sambasettings{'ACTION'} eq 'useradd') { my $username = "user"; my $password = "samba"; chomp $username; $username=~s/\s//g; chomp $password; $password=~s/\s//g; print <
$Lang::tr{'add user'}
$Lang::tr{'username'}
$Lang::tr{'password'}
$Lang::tr{'unix group'}
$Lang::tr{'unix shell'}
END ; } if ($sambasettings{'ACTION'} eq 'pcadd') { my $pcname = "client\$"; chomp $pcname; $pcname=~s/\s//g; print <
$Lang::tr{'pc add'}
$Lang::tr{'client'}
$Lang::tr{'unix group'}
$Lang::tr{'unix shell'}
END ; } &Header::closebox(); } if ($sambasettings{'SECURITY'} eq "ADS") { &Header::openbox('100%', 'center', $Lang::tr{'samba join a domain'}); my $AD_DOMAINNAME = uc($mainsettings{'DOMAINNAME'}); print <
$Lang::tr{'domain'} $AD_DOMAINNAME
$Lang::tr{'administrator username'}
$Lang::tr{'administrator password'}
END &Header::closebox(); } ############################################################################################################################ ############################################### Verwalten von Freigaben #################################################### &Header::openbox('100%', 'center', $Lang::tr{'shares'}); my %shares = config("${General::swroot}/samba/shares"); print <
END ; my @Shares = keys(%shares); my $lines = 0; my $col=""; foreach my $shareentry (sort @Shares) { chomp $shareentry; if ($lines % 2) { print ""; $col="bgcolor='$color{'color20'}'"; } else { print ""; $col="bgcolor='$color{'color22'}'"; } print <$shareentry END ; $lines++; } print <
$Lang::tr{'manage shares'}
$Lang::tr{'sharename'}$Lang::tr{'options'}
END ; if ($sambasettings{'ACTION'} eq 'sharecaption') { print <
$Lang::tr{'caption'}
$Lang::tr{'add share'}
$Lang::tr{'edit share'}
$Lang::tr{'save config'}
$Lang::tr{'reset shares'}
$Lang::tr{'delete share'}
END ; } if ($sambasettings{'ACTION'} eq 'shareadd' || $sambasettings{'ACTION'} eq 'optioncaption' ) { print <
$Lang::tr{'add share'}
$Lang::tr{'show share options'}

END ; } if ($sambasettings{'ACTION'} eq 'sharechange' || $sambasettings{'ACTION'} eq 'optioncaption2' ) { my $shareoption = $shares{$sambasettings{'NAME'}}; print <
$Lang::tr{'edit share'}
$Lang::tr{'show share options'}

END ; } if ($sambasettings{'ACTION'} eq 'sharesresetyes') { system('/usr/local/bin/sambactrl smbsharesreset'); my $shares = config("${General::swroot}/samba/shares"); system("/usr/local/bin/sambactrl smbreload"); } if ($sambasettings{'ACTION'} eq 'smbshareadd') { $shares{'xvx'}= "$sambasettings{'SHAREOPTION'}"; save("shares"); my $shares = config("${General::swroot}/samba/shares"); } if ($sambasettings{'ACTION'} eq 'smbsharedel') { delete $shares{$sambasettings{'NAME'}}; save("shares"); my %shares = config("${General::swroot}/samba/shares"); } if ($sambasettings{'ACTION'} eq 'smbsharechange') { $shares{$sambasettings{'NAME'}} = $sambasettings{'SHAREOPTION'}; save("shares"); my %shares = config("${General::swroot}/samba/shares"); } &Header::closebox(); ############################################################################################################################ ################################################ Verwalten von Druckern #################################################### my %printer = config("${General::swroot}/samba/printer"); if ( -e "/var/ipfire/cups/enable") { &Header::openbox('100%', 'center', $Lang::tr{'printer'}); my @Printers = keys(%printer); print <
END ; foreach my $printerentry (sort @Printers) { chomp $printerentry; print < END ; } print <
$Lang::tr{'manage printers'}
$Lang::tr{'printername'}$Lang::tr{'options'}
$printerentry
END ; if ($sambasettings{'ACTION'} eq 'printeradd' || $sambasettings{'ACTION'} eq 'printercaption' ) { print <
$Lang::tr{'add printer'}
$Lang::tr{'show share options'}

END ; } if ($sambasettings{'ACTION'} eq 'printerchange' || $sambasettings{'ACTION'} eq 'printercaption2' ) { my $printeroption = $printer{$sambasettings{'NAME'}}; print <
$Lang::tr{'edit printer'}
$Lang::tr{'show share options'}

END ; } if ($sambasettings{'ACTION'} eq 'smbprinteradd') { $printer{'xvx'}= "$sambasettings{'PRINTEROPTION'}"; save("printer"); my %printer = config("${General::swroot}/samba/printer"); } if ($sambasettings{'ACTION'} eq 'smbprinterdel') { delete $printer{$sambasettings{'NAME'}}; save("printer"); my %printer = config("${General::swroot}/samba/printer"); } if ($sambasettings{'ACTION'} eq 'smbprinterchange') { $printer{$sambasettings{'NAME'}} = $sambasettings{'PRINTEROPTION'}; save("printer"); my %printer = config("${General::swroot}/samba/printer"); } &Header::closebox(); } ############################################################################################################################ ############################################### Anzeige des Sambastatus #################################################### &Header::openbox('100%', 'center', 'Status'); print <
$Lang::tr{'samba status'}
$Status
END ; &Header::closebox(); ############################################################################################################################ ############################################### Anzeige der Sambalogs ###################################################### if ($sambasettings{'ACTION'} eq 'showlog') { $Log = qx(tail -n $sambasettings{'LOGLINES'} /var/log/samba/$sambasettings{'LOG'}); $Log=~s/\n/
/g; } &Header::openbox('100%', 'center', $Lang::tr{'log'}); print <
$Lang::tr{'log view'}

$Lang::tr{'show last x lines'}

$Log

$sambasettings{'LOG'}
END ; &Header::closebox(); &Header::closebigbox(); &Header::closepage(); ############################################################################################################################ ############################################ Subfunktion fr Sambadienste ################################################### sub config { my $file = shift; my @allarray = `grep -n '^\\[' $file`; my @linesarray = (); my @namearray = (); my %hash = (); my $options = (); my $EOF = qx(cat $file | wc -l); foreach my $allarrayentry (@allarray) { my @allarrayline = split( /\:/, $allarrayentry ); push(@linesarray,$allarrayline[0]);$allarrayline[1]=~s/\[//g;$allarrayline[1]=~s/\]//g;push(@namearray,$allarrayline[1]); } for(my $i = 0; $i <= $#namearray; $i++) { chomp $namearray[$i]; $namearray[$i]=~s/\[//g;$namearray[$i]=~s/\]//g; if ( $i eq $#namearray ) { my $lineend = $EOF-$linesarray[$i]+1; $options=qx(tail -$lineend $file); } else { my $linestart = $EOF-$linesarray[$i]+1; my $lineend = $linesarray[$i+1]-$linesarray[$i]; $options=qx(tail -$linestart $file | head -$lineend); } $hash{$namearray[$i]} = "$options"; #print"
$namearray[$i]\n$options\n
"; # enable only for debuging } return(%hash); } sub save { my $smb = shift; open (FILE, ">${General::swroot}/samba/$smb") or die "Can't $smb settings $!"; flock (FILE, 2); if ( $smb eq 'printer') {while (my ($name, $option) = each %printer){chomp $option;$option =~ s/\r\n/\n/gi;$option =~ s/^\n//gi;$option =~ s/^\r//gi;$option =~ s/^.\n//gi;$option =~ s/^.\r//gi;print FILE "$option\n";}} if ( $smb eq 'shares') {while (my ($name, $option) = each %shares){chomp $option;$option =~ s/\r\n/\n/gi;$option =~ s/^\n//gi;$option =~ s/^\r//gi;$option =~ s/^.\n//gi;$option =~ s/^.\r//gi;print FILE "$option\n";} } close FILE; if ( -e "/var/ipfire/cups/enable") { if ( $sambasettings{'SECURITY'} eq 'user' && $sambasettings{'DOMAINMASTER'} eq 'true' ){system("/usr/local/bin/sambactrl smbsafeconfpdccups");} else {system("/usr/local/bin/sambactrl smbsafeconfcups");} } else { if ( $sambasettings{'SECURITY'} eq 'user' && $sambasettings{'DOMAINMASTER'} eq 'true' ){system("/usr/local/bin/sambactrl smbsafeconfpdc");} else{system("/usr/local/bin/sambactrl smbsafeconf");} } system("/usr/local/bin/sambactrl smbreload"); refreshpage(); } sub isrunning { my $cmd = $_[0]; my $status = "$Lang::tr{'stopped'}"; my $pid = ''; my $testcmd = ''; my $exename; $cmd =~ /(^[a-z]+)/; $exename = $1; if (open(FILE, "/var/run/${cmd}.pid")) { $pid = ; chomp $pid; close FILE; if (open(FILE, "/proc/${pid}/status")) { while () { if (/^Name:\W+(.*)/) { $testcmd = $1; } } close FILE; if ($testcmd =~ /$exename/) { $status = "$Lang::tr{'running'}"; } } } return $status; } sub joindomain { my $username = shift; my $password = shift; my @options = ("/usr/local/bin/sambactrl", "join", $username, $password); my $output = qx(@options); return $output; }