]> git.ipfire.org Git - ipfire-2.x.git/commitdiff
samba: Allow rewriting configuration from CLI
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 13 Oct 2020 16:04:46 +0000 (17:04 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 13 Oct 2020 16:06:19 +0000 (17:06 +0100)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
html/cgi-bin/samba.cgi
src/paks/samba/install.sh

index ec1237134691f84f03dd1a83d509fa4ac5bedb9a..be670a95efff0ae576d1a3fef98174ee22b61c8e 100644 (file)
@@ -50,11 +50,6 @@ my %shares = ();
 &General::readhash("${General::swroot}/main/settings", \%mainsettings);
 &General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color);
 
-############################################################################################################################
-############################################# Samba Dienste fr Statusberprfung ##########################################
-
-&Header::showhttpheaders();
-
 ############################################################################################################################
 #################################### Initialisierung von Samba Variablen fr global Settings ###############################
 
@@ -72,7 +67,17 @@ my $LOGLINES = '50';
 ############################################################################################################################
 
 &General::readhash("${General::swroot}/samba/settings", \%sambasettings);
+
+# Hook to regenerate the configuration files.
+if ($ENV{"REMOTE_ADDR"} eq "") {
+       &writeconfiguration();
+       exit(0);
+}
+
+&Header::showhttpheaders();
+
 &Header::getcgihash(\%sambasettings);
+delete $sambasettings{'__CGI__'};delete $sambasettings{'x'};delete $sambasettings{'y'};
 
 &Header::openpage('Samba', 1, '');
 &Header::openbigbox('100%', 'left', '', $errormessage);
@@ -100,81 +105,19 @@ if ($sambasettings{'ACTION'} eq 'userdelete'){system("/usr/local/bin/sambactrl s
 ############################################################################################################################
 ##################################### Umsetzen der Werte von Checkboxen und Dropdowns ######################################
 
-if ($sambasettings{'ACTION'} eq $Lang::tr{'save'})
-{
 ############################################################################################################################
 ##################################### Schreiben settings und bersetzen fr smb.conf #######################################
 
-delete $sambasettings{'__CGI__'};delete $sambasettings{'x'};delete $sambasettings{'y'};
-&General::writehash("${General::swroot}/samba/settings", \%sambasettings);
-
-############################################################################################################################
-############################################# Schreiben der Samba globals ##################################################
-
-       open (FILE, ">${General::swroot}/samba/global") or die "Can't save the global settings: $!";
-       flock (FILE, 2);
-       
-print FILE <<END
-# global.settings by IPFire Project
-
-[global]
-server string = Samba on IPFire
+if ($sambasettings{'ACTION'} eq $Lang::tr{'save'}) {
+       &General::writehash("${General::swroot}/samba/settings", \%sambasettings);
 
-workgroup = $sambasettings{'WORKGRP'}
-realm = $mainsettings{'DOMAINNAME'}
-passdb backend = smbpasswd
+       # Write configuration to file
+       &writeconfiguration();
 
-map to guest = $sambasettings{'MAPTOGUEST'}
-
-guest account = $sambasettings{'GUESTACCOUNT'}
-unix password sync = no
-
-bind interfaces only = true
-interfaces = green0 blue0 127.0.0.0/8
-remote announce = $sambasettings{'REMOTEANNOUNCE'}
-remote browse sync = $sambasettings{'REMOTESYNC'}
-
-winbind separator = +
-winbind uid = 10000-20000
-winbind gid = 10000-20000
-winbind use default domain = yes
-
-# Log to syslog
-logging = syslog
-
-# Enable support for Apple
-vfs objects = catia fruit streams_xattr recycle
-
-# Enable following symlinks
-wide links = yes
-
-END
-;
-
-# Server Role
-if ($sambasettings{'ROLE'} eq "standalone") {
-       print FILE "server role = standalone\n";
-} elsif ($sambasettings{'ROLE'} eq "member") {
-       print FILE "server role = member server\n";
-}
-
-if ($sambasettings{'ENCRYPTION'} =~ m/(desired|required)/) {
-       print FILE "smb encrypt = $1\n";
+       system("/usr/local/bin/sambactrl smbreload");
 }
 
-print FILE <<END;
-# Export all printers
-[printers]
-path = /var/spool/samba/
-printable = yes
-
-END
-close FILE;
-
-system("/usr/local/bin/sambactrl smbsafeconf");
-system("/usr/local/bin/sambactrl smbreload");
-}
-  &General::readhash("${General::swroot}/samba/settings", \%sambasettings);
+&General::readhash("${General::swroot}/samba/settings", \%sambasettings);
   
 
 if ($errormessage)
@@ -838,6 +781,69 @@ sub isrunning
        return $status;
        }
 
+sub writeconfiguration() {
+       open (FILE, ">${General::swroot}/samba/global") or die "Can't save the global settings: $!";
+       flock (FILE, 2);
+       
+       print FILE <<END;
+# global.settings by IPFire Project
+
+[global]
+server string = Samba on IPFire
+
+workgroup = $sambasettings{'WORKGRP'}
+realm = $mainsettings{'DOMAINNAME'}
+passdb backend = smbpasswd
+
+map to guest = $sambasettings{'MAPTOGUEST'}
+
+guest account = $sambasettings{'GUESTACCOUNT'}
+unix password sync = no
+
+bind interfaces only = true
+interfaces = green0 blue0 127.0.0.0/8
+remote announce = $sambasettings{'REMOTEANNOUNCE'}
+remote browse sync = $sambasettings{'REMOTESYNC'}
+
+winbind separator = +
+winbind uid = 10000-20000
+winbind gid = 10000-20000
+winbind use default domain = yes
+
+# Log to syslog
+logging = syslog
+
+# Enable support for Apple
+vfs objects = catia fruit streams_xattr recycle
+
+# Enable following symlinks
+wide links = yes
+
+END
+
+# Server Role
+if ($sambasettings{'ROLE'} eq "standalone") {
+       print FILE "server role = standalone\n";
+} elsif ($sambasettings{'ROLE'} eq "member") {
+       print FILE "server role = member server\n";
+}
+
+if ($sambasettings{'ENCRYPTION'} =~ m/(desired|required)/) {
+       print FILE "smb encrypt = $1\n";
+}
+
+print FILE <<END;
+# Export all printers
+[printers]
+path = /var/spool/samba/
+printable = yes
+
+END
+close FILE;
+
+       system("/usr/local/bin/sambactrl smbsafeconf");
+}
+
 sub joindomain {
        my $username = shift;
        my $password = shift;
index 22d74b93a6ab0e84b5f3f50dbcee84923cdbf306..06a5b0358d7aea1a38a0184110f8ab3ca442da28 100644 (file)
@@ -33,15 +33,6 @@ fi
 extract_files
 restore_backup ${NAME}
 
-# Migrate configuration from Samba 3.6 to 4.x
-sed -i /var/ipfire/samba/smb.conf \
-       -e "/^display charset =/d" \
-       -e "/^encrypt passwords =/d" \
-       -e "/^null passwords =/d" \
-       -e "/^socket options =/d" \
-       -e "/^syslog/d" \
-       -e "s/^security = share$/security = user/"
-
 # Migrate SECURITY to ROLE
 sed -i /var/ipfire/samba/settings \
        -e "s/^SECURITY=ADS/ROLE=member/" \
@@ -49,5 +40,8 @@ sed -i /var/ipfire/samba/settings \
        -e "s/^SECURITY=share/ROLE=standalone/" \
        -e "s/^SECURITY=user/ROLE=standalone/"
 
+# Rewrite configuration files
+sudo -u nobody /srv/web/ipfire/cgi-bin/samba.cgi
+
 # Start the service
 /usr/local/bin/sambactrl smbstart