/** * (re)write the web.config file to prevent browser access to the log file */ function handleWebConfig() { global $setup_site_log_dir; global $setup_site_log_file; require_once 'include/domit/xml_domit_include.php'; $prefix = $setup_site_log_dir . empty($setup_site_log_dir) ? '' : '/'; $config_array = array(array('1' => $prefix . str_replace('.', '\\.', $setup_site_log_file) . '\\.*', '2' => 'log_file_restricted.html'), array('1' => $prefix . 'install.log', '2' => 'log_file_restricted.html'), array('1' => $prefix . 'upgradeWizard.log', '2' => 'log_file_restricted.html'), array('1' => $prefix . 'emailman.log', '2' => 'log_file_restricted.html'), array('1' => 'not_imported_.*.txt', '2' => 'log_file_restricted.html'), array('1' => 'XTemplate/(.*)/(.*).php', '2' => 'index.php'), array('1' => 'data/(.*).php', '2' => 'index.php'), array('1' => 'examples/(.*).php', '2' => 'index.php'), array('1' => 'include/(.*).php', '2' => 'index.php'), array('1' => 'include/(.*)/(.*).php', '2' => 'index.php'), array('1' => 'log4php/(.*).php', '2' => 'index.php'), array('1' => 'log4php/(.*)/(.*)', '2' => 'index.php'), array('1' => 'metadata/(.*)/(.*).php', '2' => 'index.php'), array('1' => 'modules/(.*)/(.*).php', '2' => 'index.php'), array('1' => 'soap/(.*).php', '2' => 'index.php'), array('1' => 'emailmandelivery.php', '2' => 'index.php'), array('1' => 'cron.php', '2' => 'index.php')); $xmldoc = new DOMIT_Document(); //create XML declaration $xmlDecl = $xmldoc->createProcessingInstruction('xml', 'version="1.0" encoding="UTF-8"'); $xmldoc->appendChild($xmlDecl); $rootElement = $xmldoc->createElement('configuration'); $xmldoc->appendChild($rootElement); $system_webserver = $xmldoc->createElement('system.webServer'); $rewrite = $xmldoc->createElement('rewrite'); $rules = $xmldoc->createElement('rules'); for ($i = 0; $i < count($config_array); $i++) { $rule[$i] = $xmldoc->createElement('rule'); $rule[$i]->setAttribute('name', $i); $rule[$i]->setAttribute('stopProcessing', 'true'); $match[$i] = $xmldoc->createElement('match'); $match[$i]->setAttribute('url', $config_array[$i]['1']); $rule[$i]->appendChild($match[$i]); $action[$i] = $xmldoc->createElement('action'); $action[$i]->setAttribute('type', 'Redirect'); $action[$i]->setAttribute('url', $config_array[$i]['2']); $rule[$i]->appendChild($action[$i]); $rules->appendChild($rule[$i]); } $rewrite->appendChild($rules); $system_webserver->appendChild($rewrite); $rootElement->appendChild($system_webserver); // echo $xmldoc->documentElement->toNormalizedString(true); $xmldoc->saveXML('web.config', true); }
$xmldoc = new DOMIT_Document(); //var_dump($config_array); //create XML declaration $xmlDecl = $xmldoc->createProcessingInstruction('xml', 'version="1.0" encoding="UTF-8"'); $xmldoc->appendChild($xmlDecl); $rootElement = $xmldoc->createElement('configuration'); $xmldoc->appendChild($rootElement); $system_webserver = $xmldoc->createElement('system.webServer'); $rewrite = $xmldoc->createElement('rewrite'); $rules = $xmldoc->createElement('rules'); $rule = array(); $match = array(); $rule_action = array(); for ($i = 0; $i < count($config_array); $i++) { $rule[$i] = $xmldoc->createElement('rule'); $rule[$i]->setAttribute('name', $i); $rule[$i]->setAttribute('stopProcessing', 'true'); $match[$i] = $xmldoc->createElement('match'); $match[$i]->setAttribute('url', $config_array[$i]['1']); $rule[$i]->appendChild($match[$i]); $rule_action[$i] = $xmldoc->createElement('action'); $rule_action[$i]->setAttribute('type', 'Redirect'); $rule_action[$i]->setAttribute('url', $config_array[$i]['2']); $rule[$i]->appendChild($rule_action[$i]); $rules->appendChild($rule[$i]); } $rewrite->appendChild($rules); $system_webserver->appendChild($rewrite); $rootElement->appendChild($system_webserver); $xmldoc->saveXML('web.config', true);