Forráskód Böngészése

added support for secure config files

Piotr Labudda 8 éve
szülő
commit
80ea97b506
1 módosított fájl, 33 hozzáadás és 0 törlés
  1. 33 0
      SE/se-lib/Config.php

+ 33 - 0
SE/se-lib/Config.php

@@ -22,6 +22,8 @@
  *
  * TODO: dziedziczenie plikow na podstawie hosta - kropki? dla hosta www2.biall.com.pl i www.biall.com.pl dziedziczy po: biall.com.pl
  *
+ * If conf file not found '.cnf*.ini.php' then try to find file '.cnf*.inc.php'
+ *
  * Struktura pliku .cnf*.ini.php
 ;<?php
 ;die(); // For further security
@@ -39,6 +41,17 @@ Array
             [foo1] => bar1
         )
 )
+ *
+ * Struktura pliku .cnf*.inc.php
+<?php
+return function ($secret = '') {
+	if ('secret-p5-password' !== $secret) return null;
+	$conf = [
+		'host' => "",
+		// ...
+	];
+	return $conf;
+};
  */
 
 class Config {
@@ -120,6 +133,26 @@ class Config {
 			}
 		}
 
+		try {
+			if (empty($_cnf[$conf_file])) {
+				$file_suffix = '.inc.php';
+				$search_for_files[] = APP_PATH_CONFIG . DS . $file_prefix . '-' . $host . $file_suffix;
+				$search_for_files[] = APP_PATH_CONFIG . DS . $file_prefix . '-' . $host_parent . $file_suffix;
+				$search_for_files[] = APP_PATH_CONFIG . DS . $file_prefix . $file_suffix;
+				foreach ($search_for_files as $f) {
+					if (1 == V::get('DBG_CNF', '', $_GET)) { echo "f(" . end(explode('/',$f)) . ")=(" . file_exists($f) . ")"; }
+					if (file_exists($f)) {
+						$fun = include $f;
+						if (!is_callable($fun)) throw new Exception("Config func is not callable");
+						$_cnf[$conf_file] = $fun('secret-p5-password');
+						break;
+					}
+				}
+			}
+		} catch (Exception $e) {
+			DBG::log($e);
+		}
+
 		return $_cnf[$conf_file];
 	}