Browse code

read available php versions from config

Bernd Wurst authored on18/07/2018 13:32:37
Showing4 changed files
... ...
@@ -140,7 +140,14 @@ $phpoptions = "<h5>PHP</h5>
140 140
  */
141 141
 //if ($vhost['php'] == 'php54')
142 142
 //{
143
-  $options = array("none" => 'ausgeschaltet', "php56" => "PHP 5.6 (veraltet)", "fpm70" => "PHP 7.0 (auslaufend)", "fpm71" => "PHP 7.1", "fpm72" => "PHP 7.2");
143
+  $options = array("none" => 'ausgeschaltet');
144
+  $phpinfo = valid_php_versions();
145
+  foreach ($phpinfo as $tag => $info) {
146
+      $options[$tag] = 'PHP '.$info['major'].'.'.$info['minor'];
147
+      if ($info['status'] == 'deprecated') {
148
+          $options[$tag] .= ' (veraltet)';
149
+      }
150
+  }
144 151
   $phpoptions = "
145 152
   <h5>PHP</h5>
146 153
   <div style=\"margin-left: 2em;\">
... ...
@@ -23,6 +23,25 @@ require_once('class/domain.php');
23 23
 require_once("certs.php");
24 24
 
25 25
 
26
+function valid_php_versions() {
27
+    $tags = explode(',', config('php_versions'));
28
+    $ret = array();
29
+    foreach ($tags as $t) {
30
+        $key = str_replace('*', '', $t);
31
+        $ret[$key] = array('major' => null, 'minor' => null, 'status' => 'regular');
32
+        /* Wir nehmen an, dass unsere Tags immer an zweitletzter Stelle die Major-Version und 
33
+        an letzter Stelle die Minor-Version enthalten */
34
+        $ret[$key]['major'] = substr(str_replace('*', '', $t), -2, 1);
35
+        $ret[$key]['minor'] = substr(str_replace('*', '', $t), -1, 1);
36
+        if (substr($t, -1) === '*') {
37
+            $ret[$key]['status'] = 'deprecated';
38
+        }
39
+    }
40
+    DEBUG($ret);
41
+    return $ret;
42
+}
43
+
44
+
26 45
 function traffic_month($vhost_id)
27 46
 {
28 47
     $vhost_id = (int) $vhost_id;
... ...
@@ -85,7 +104,8 @@ function empty_vhost()
85 104
 
86 105
     $vhost['homedir'] = $_SESSION['userinfo']['homedir'];
87 106
     $vhost['docroot'] = null;
88
-    $vhost['php'] = 'fpm72';
107
+    $phpversions = explode(',', config('php_versions'));
108
+    $vhost['php'] = end($phpversions);
89 109
     $vhost['cgi'] = 1;
90 110
     $vhost['ssl'] = null;
91 111
     $vhost['hsts'] = -1;
... ...
@@ -88,21 +88,12 @@ if ($_GET['action'] == 'edit') {
88 88
     }
89 89
     $php = null;
90 90
     if ($_POST['vhost_type'] == 'regular' && isset($_POST['php'])) {
91
-        switch ($_POST['php']) {
92
-      case 'php56':
93
-        $php = 'php56';
94
-        break;
95
-      case 'fpm70':
96
-        $php = 'fpm70';
97
-        break;
98
-      case 'fpm71':
99
-        $php = 'fpm71';
100
-        break;
101
-      case 'fpm72':
102
-        $php = 'fpm72';
103
-        break;
104
-      /* Wenn etwas anderes kommt, ist das "kein PHP". So einfach ist das. */
105
-    }
91
+        $phpinfo = valid_php_versions();
92
+        if (array_key_exists($_POST['php'], $phpinfo)) {
93
+            $php = $_POST['php'];
94
+        } else {
95
+            $php = null;
96
+        }
106 97
     }
107 98
     $cgi = 1;
108 99
     if (isset($_POST['safemode']) && $_POST['safemode'] == 'yes') {
... ...
@@ -151,26 +151,19 @@ if (count($vhosts) > 0) {
151 151
             output('<td colspan="2"><em><strong>Sonderanwendung:</strong> Subversion-Server</em></td>');
152 152
         } else {
153 153
             $php = $vhost['php'];
154
-            switch ($php) {
155
-        /* To create new PHP icon:
156
-           convert ok.png -gravity center -draw "text 0,0 '7.2'" ok-php72.png
157
-        */
158
-        case null:
159
-          $php = icon_disabled('PHP ausgeschaltet');
160
-          break;
161
-        case 'php56':
162
-          $php = icon_enabled_phpxx('PHP in Version 5.6 eingeschaltet', 5, 6);
163
-          break;
164
-        case 'fpm70':
165
-          $php = icon_enabled_phpxx('PHP in Version 7.0 eingeschaltet', 7, 0);
166
-          break;
167
-        case 'fpm71':
168
-          $php = icon_enabled_phpxx('PHP in Version 7.1 eingeschaltet', 7, 1);
169
-          break;
170
-        case 'fpm72':
171
-          $php = icon_enabled_phpxx('PHP in Version 7.2 eingeschaltet', 7, 2);
172
-          break;
173
-      }
154
+            $phpinfo = valid_php_versions($php);
155
+            if (array_key_exists($php, $phpinfo)) {
156
+                $phpinfo = $phpinfo[$php];
157
+                /* To create new PHP icon:
158
+                   convert ok.png -gravity center -draw "text 0,0 '7.2'" ok-php72.png
159
+                */
160
+                $php = icon_enabled_phpxx('PHP in Version '.$phpinfo['major'].'.'.$phpinfo['minor'].' eingeschaltet', $phpinfo['major'], $phpinfo['minor']);
161
+                if ($phpinfo['status'] == 'deprecated') {
162
+                    $php .= ' '.icon_warning('Diese PHP-Version ist veraltet!');
163
+                }
164
+            } else {
165
+                $php = icon_disabled('PHP ausgeschaltet');
166
+            }
174 167
             output("<td>{$php}</td>");
175 168
             if ($vhost['docroot_is_default'] == 1) {
176 169
                 output("<td><span style=\"color:#777;\">{$vhost['docroot']}</span></td>");