From ee87b29189ba464a538b35cc7aae6ffc8f0cf82c Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Thu, 5 Oct 2017 16:12:05 -0400 Subject: [PATCH] fix new gruop not being savable --- utils/generate_apache_config.pl | 104 ++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100755 utils/generate_apache_config.pl diff --git a/utils/generate_apache_config.pl b/utils/generate_apache_config.pl new file mode 100755 index 000000000..c26e99b10 --- /dev/null +++ b/utils/generate_apache_config.pl @@ -0,0 +1,104 @@ +#!/usr/bin/perl -w +use strict; + + +use Getopt::Long (); + +my $opts = {}; +Getopt::Long::GetOptions($opts, 'help', 'output=s', + 'pid_file=s', 'db_port=s', 'db_name=s', 'db_host=s', 'db_user=s', 'db_pass=s', + 'min_port=s','max_port=s', 'debug=s', + 'server_name=s','error_log=s','protocol=s', +); + +if ($opts->{help}) { + usage(); + exit 0; +} # end if + + +my %defaults = ( + error_log => '/var/log/apache2/error.log', + output => '/etc/apache2/sites-available/zoneminder.conf', + protocol => 'http', +); + +foreach my $key ( keys %defaults ) { + if ( ! $$opts{$key} ) { + $$opts{$key} = $defaults{$key}; + } +} + +my $Listen = ''; +my $VirtualHostPorts; + +if ( $$opts{protocol} eq 'https' ) { + if ( ! $$opts{server_name} ) { + die "https requires a server_name"; + } + $VirtualHostPorts = ' *:443'; +} + + +foreach my $port ( $$opts{min_port} .. $$opts{max_port} ) { + $Listen .= "Listen $port $$opts{protocol}\n"; + $VirtualHostPorts .= " *:$port"; +} + +my $template =qq` +$Listen + +DocumentRoot /usr/share/zoneminder/www +`. ( $$opts{server_name} ? ' ServerName ' . $$opts{server_name} : '' ). +qq` +ErrorLog $$opts{error_log} + +ScriptAlias /zm/cgi-bin/ /usr/lib/zoneminder/cgi-bin/ +ScriptAlias /cgi-bin/ /usr/lib/zoneminder/cgi-bin/ + + AllowOverride None + Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch + Require all granted + Satisfy Any + Order allow,deny + Allow from all + + +Alias /zm /usr/share/zoneminder/www + + + php_flag register_globals off + Options +Indexes +FollowSymLinks + AllowOverride All + + DirectoryIndex index.php + + Require all granted + Satisfy Any + Order allow,deny + Allow from all + + +`; +if ( $$opts{protocol} eq 'https' ) { + $template .= qq` +SSLCertificateFile /etc/letsencrypt/live/$$opts{server_name}/fullchain.pem +SSLCertificateKeyFile /etc/letsencrypt/live/$$opts{server_name}/privkey.pem +Include /etc/letsencrypt/options-ssl-apache.conf +`; +} +$template .= qq` + +`; + + +if ( open( F, "> $$opts{output}" ) ) { + binmode F; + print F $template; + close F; +} else { + die "Error opening $$opts{output}, Reason: $!"; +} # end if + +1; +__END__