function proceedConfig(&$array, $key, $value) { $helper = new ConfigHelper(); $endsWith = function ($v, $end) use($helper) { return $helper->endsWith($v, $end); }; if ($endsWith($key, 'class')) { if (!class_exists($value)) { throw new \Exception("Class not found {$value}"); } } else { if ($endsWith($key, 'conf')) { $file = $helper->getPath($value); //----------------------------------------------------- // Must end with json extension //----------------------------------------------------- if (!$endsWith($file, '.json')) { throw new \Exception("File '{$file}' is not a '.json' file"); } //----------------------------------------------------- // Must exist //----------------------------------------------------- $realPath = realpath($file); if (!$realPath) { throw new \Exception("File not found {$file}"); } //----------------------------------------------------- // Must be in one of this directories //----------------------------------------------------- if ($this->directories) { $throwException = true; foreach ($this->directories as $dir) { if (strpos($realPath, $dir) == 0) { $throwException = false; break; } } if ($throwException) { throw new \Exception("File '{$realPath}' is not in allowed directories"); } } //----------------------------------------------------- // Must be valid //----------------------------------------------------- $this->testJSONValidity(@file_get_contents($file)); $array['conf'] = $helper->getJSon($value); } elseif ($endsWith($key, 'url')) { // $components = parse_url($value); // if ( array_key_exists('scheme', $components) && ! in_array($components['scheme'], array('http','https'))) { // throw new \Exception("Invalid URL $value. Scheme is u"); // } // if ( ! array_key_exists('scheme', $components) && ! array_key_exists('path', $components)){ // throw new \Exception("Invalid URL $value"); // } // else if ( ! filter_var($value, FILTER_VALIDATE_URL) ) { // } } } }
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE * License as published by the Free Software Foundation; either * version 3 of the License, or any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU AFFERO GENERAL PUBLIC LICENSE for more details. * * You should have received a copy of the GNU Affero General Public * License along with this library. If not, see <http://www.gnu.org/licenses/>. * */ /** * This PHP scripts is used by AppInfo\App to register an admin panel. * It sets a bunch of var and calls a template. * */ use OCA\User_servervars2\Lib\ConfigHelper; $appName = 'user_servervars2'; $helper = new ConfigHelper(); $tmpl = new OCP\Template($appName, 'settings-admin'); $array = array('sso_url', 'slo_url', 'auto_create_user', 'update_user_data', 'update_groups', 'stop_if_empty', 'tokens_class', 'tokens_conf', 'group_naming_conf', 'group_naming_class', 'button_name'); foreach ($array as $key) { $parm = OCP\Config::getAppValue($appName, $key); $tmpl->assign($key, $parm); if ($helper->endsWith($key, 'conf') && $parm) { $tmpl->assign($key . '_data', $helper->getJSon($parm)); } } return $tmpl->fetchPage();