From e2c18a4b78abff53b87cf7b01b1f32677fbd2e48 Mon Sep 17 00:00:00 2001
From: Daniel Berteaud <daniel@firewall-services.com>
Date: Thu, 13 Jul 2017 17:14:23 +0200
Subject: [PATCH] Use php71

---
 root/etc/e-smith/templates/etc/e-smith/sql/init/dl |  2 +-
 .../templates/etc/httpd/conf/httpd.conf/98Dl       | 29 ++++++++++----
 .../etc/opt/remi/php71/php-fpm.d/www.conf/10All    | 45 ++++++++++++++++++++++
 3 files changed, 67 insertions(+), 9 deletions(-)
 create mode 100644 root/etc/e-smith/templates/etc/opt/remi/php71/php-fpm.d/www.conf/10All

diff --git a/root/etc/e-smith/templates/etc/e-smith/sql/init/dl b/root/etc/e-smith/templates/etc/e-smith/sql/init/dl
index eda06c3..f408e9d 100644
--- a/root/etc/e-smith/templates/etc/e-smith/sql/init/dl
+++ b/root/etc/e-smith/templates/etc/e-smith/sql/init/dl
@@ -11,7 +11,7 @@ if [ ! -d /var/lib/mysql/$db ]; then
         /usr/bin/mysql -e 'create database $db'
         /usr/bin/mysql $db < $dbstruct
 else
-        su -s /bin/bash - www -c "cd /usr/share/dl/include/scripts && /usr/bin/php ./dbupgrade.php"
+        su -s /bin/bash - www -c "cd /usr/share/dl/include/scripts && /usr/bin/php71 ./dbupgrade.php"
 fi
 
 /usr/bin/mysql <<EOF
diff --git a/root/etc/e-smith/templates/etc/httpd/conf/httpd.conf/98Dl b/root/etc/e-smith/templates/etc/httpd/conf/httpd.conf/98Dl
index de2e3dd..bdc2ae1 100644
--- a/root/etc/e-smith/templates/etc/httpd/conf/httpd.conf/98Dl
+++ b/root/etc/e-smith/templates/etc/httpd/conf/httpd.conf/98Dl
@@ -23,15 +23,8 @@ EOF
 }
 if ($dl{'status'} eq 'enabled'){
 
-$OUT .=<<"END"
-
-# dl Configuration
-$alias
-
-<Directory  /usr/share/dl>
-    AllowOverride Limit
+  my $php =<<_EOF;
     AddType application/x-httpd-php .php
-    php_admin_value open_basedir /usr/share/dl:/etc/dl.php:/var/lib/dl:/var/log/dl.log
     php_admin_flag file_uploads On
     php_admin_flag magic_quotes Off
     php_admin_flag magic_quotes_gpc Off
@@ -43,6 +36,26 @@ $alias
     php_admin_value upload_tmp_dir /var/lib/dl/tmp
     php_admin_value session.save_path /var/lib/dl/tmp
     php_admin_value session.gc_maxlifetime 86400
+_EOF
+  if ($fastcgi_mod eq 'mod_fastcgi'){
+    $php = "    AddHandler phpdl-fastcgi .php\n";
+  }
+  elsif ($fascgi_mod eq 'mod_proxy_fcgi'){
+    $php =<<'_EOF';
+     <FilesMatch \.php$>
+         SetHandler "proxy:unix:/var/run/php-fpm/php71-dl.sock|fcgi://localhost"
+     </FilesMatch>
+_EOF
+  }
+
+$OUT .=<<"END"
+
+# dl Configuration
+$alias
+
+<Directory  /usr/share/dl>
+    AllowOverride Limit
+$php
     order deny,allow
     deny from all
     allow from $allow
diff --git a/root/etc/e-smith/templates/etc/opt/remi/php71/php-fpm.d/www.conf/10All b/root/etc/e-smith/templates/etc/opt/remi/php71/php-fpm.d/www.conf/10All
new file mode 100644
index 0000000..da6e270
--- /dev/null
+++ b/root/etc/e-smith/templates/etc/opt/remi/php71/php-fpm.d/www.conf/10All
@@ -0,0 +1,45 @@
+{
+
+if (($dl{status'} || 'disabled) eq 'enabled'){
+  $OUT .=<<_EOF;
+[php71-dl]
+user = www
+group = www
+listen.owner = root
+listen.group = www
+listen.mode = 0660
+listen = /var/run/php-fpm/php71-dl.sock
+pm = dynamic
+pm.max_children = 15
+pm.start_servers = 3
+pm.min_spare_servers = 3
+pm.max_spare_servers = 4
+pm.max_requests = 5000
+php_admin_value[session.save_path] = /var/lib/php/dl/session
+php_admin_value[opcache.file_cache]  = /var/lib/php/dl/opcache
+php_admin_value[upload_tmp_dir] = /var/lib/php/dl/tmp
+php_admin_value[error_log] = /var/log/php/dl/error.log
+slowlog = /var/log/php/dl/slow.log
+php_admin_value[sendmail_path] = /usr/sbin/sendmail -t -i -f php@{ $DomainName }
+php_admin_flag[display_errors] = off
+php_admin_flag[log_errors] = on
+php_admin_value[error_log] = syslog
+php_admin_value[memory_limit] = 128M
+php_admin_value[max_execution_time] = 0
+php_admin_value[post_max_size] = { $dl{MaxUploadSize} || '4096' }M
+php_admin_value[upload_max_filesize] = { $dl{MaxUploadSize} || '4096' }M
+php_admin_value[disable_functions] = system, show_source, symlink, exec, dl, shell_exec, passthru, phpinfo, escapeshellarg, escapeshellcmd
+php_admin_value[open_basedir] = /usr/share/dl:/etc/dl.php:/var/lib/dl:/var/log/dl.log
+php_admin_flag[allow_url_fopen] = off
+php_admin_flag[file_upload] = on
+php_admin_flag[session.cookie_httponly] = on
+php_admin_flag[allow_url_include] = off
+php_admin_value[session.save_handler] = files
+php_admin_value[output_buffering] = off
+_EOF
+}
+else{
+  $OUT .= '; Dl is disabled';
+}
+
+}