/**
     * Performs syntax checks with named-check* utilities
     *
     * @since 1.0
     * @package fmDNS
     *
     * @param array $files_array Array containing named files and contents
     * @return string
     */
    function namedSyntaxChecks($files_array)
    {
        global $__FM_CONFIG;
        if (!array_key_exists('server_serial_no', $files_array)) {
            return;
        }
        if (getOption('enable_named_checks', $_SESSION['user']['account_id'], 'fmDNS') != 'yes') {
            return;
        }
        $die = false;
        $named_checkconf = findProgram('named-checkconf');
        $uname = php_uname('n');
        if (!$named_checkconf) {
            return sprintf('<div id="named_check" class="info"><p>%s</p></div>', sprintf(__('The named utilities (specifically named-checkconf and named-checkzone) cannot be found on %s. If they were installed, these configs and zones could be checked for syntax.'), $uname));
        }
        $fm_temp_directory = '/' . ltrim(getOption('fm_temp_directory'), '/');
        $tmp_dir = rtrim($fm_temp_directory, '/') . '/' . $_SESSION['module'] . '_' . date("YmdHis") . '/';
        system('rm -rf ' . $tmp_dir);
        $debian_system = isDebianSystem($files_array['server_os_distro']);
        $named_conf_contents = null;
        /** Create temporary directory structure */
        foreach ($files_array['files'] as $file => $contents) {
            if (!is_dir(dirname($tmp_dir . $file))) {
                if (!@mkdir(dirname($tmp_dir . $file), 0777, true)) {
                    $class = 'class="info"';
                    $message = sprintf(__('%s is not writeable by %s so the named checks cannot be performed.'), $fm_temp_directory, $__FM_CONFIG['webserver']['user_info']['name']);
                    $die = true;
                    break;
                }
            }
            file_put_contents($tmp_dir . $file, $contents);
            if ($debian_system && (strpos($file, 'named.conf.options') || strpos($file, 'named.conf.local'))) {
                $named_conf_contents .= $contents;
            }
            /** Create temporary directory from named.conf's 'directory' line */
            if (strpos($contents, 'directory')) {
                preg_match('/directory(.+?)+/', $contents, $directory_line);
                if (count($directory_line)) {
                    $line_array = explode('"', $directory_line[0]);
                    @mkdir($tmp_dir . $line_array[1], 0777, true);
                    $named_conf = $file;
                }
            }
            /** Build array of zone files to check */
            if (preg_match('/\\/zones\\.conf\\.(.+?)/', $file)) {
                $view = preg_replace('/(.+?)zones\\.conf\\.+/', '', $file);
                $tmp_contents = preg_replace('/^\\/\\/(.+?)+/', '', $contents);
                $tmp_contents = explode("};\n", trim($tmp_contents));
                foreach ($tmp_contents as $zone_def) {
                    if (strpos($zone_def, 'type master;') !== false) {
                        preg_match('/^zone "(.+?)+/', $zone_def, $tmp_zone_def);
                        $tmp_zone_def = explode('"', $tmp_zone_def[0]);
                        preg_match('/file "(.+?)+/', trim($zone_def), $tmp_zone_def_file);
                        $tmp_zone_def_file = explode('"', $tmp_zone_def_file[0]);
                        if (!empty($tmp_zone_def_file[1])) {
                            $zone_files[$view][$tmp_zone_def[1]] = $tmp_zone_def_file[1];
                        }
                    }
                }
            }
        }
        if ($debian_system) {
            file_put_contents($tmp_dir . $named_conf, $named_conf_contents);
        }
        if (!$die) {
            /** Run named-checkconf */
            $named_checkconf_cmd = findProgram('sudo') . ' ' . findProgram('named-checkconf') . ' -t ' . $tmp_dir . ' ' . $named_conf . ' 2>&1';
            exec($named_checkconf_cmd, $named_checkconf_results, $retval);
            if ($retval) {
                $class = 'class="error"';
                $named_checkconf_results = implode("\n", $named_checkconf_results);
                if (strpos($named_checkconf_results, 'sudo') !== false) {
                    $class = 'class="info"';
                    $message = sprintf(__('The webserver user (%s) on %s does not have permission to run the following command:%sThe following error ocurred:%s'), $__FM_CONFIG['webserver']['user_info']['name'], $uname, '<br /><pre>' . $named_checkconf_cmd . '</pre><p>', '<pre>' . $named_checkconf_results . '</pre>');
                } else {
                    $message = __('Your named configuration contains one or more errors:') . '<br /><pre>' . $named_checkconf_results . '</pre>';
                }
                /** Run named-checkzone */
            } else {
                $named_checkzone_results = null;
                if (array($zone_files)) {
                    foreach ($zone_files as $view => $zones) {
                        foreach ($zones as $zone_name => $zone_file) {
                            $named_checkzone_cmd = findProgram('sudo') . ' ' . findProgram('named-checkzone') . ' -t ' . $tmp_dir . ' ' . $zone_name . ' ' . $zone_file . ' 2>&1';
                            exec($named_checkzone_cmd, $results, $retval);
                            if ($retval) {
                                $class = 'class="error"';
                                $named_checkzone_results .= implode("\n", $results);
                                if (strpos($named_checkzone_results, 'sudo') !== false) {
                                    $class = 'class="info"';
                                    $message = sprintf(__('The webserver user (%s) on %s does not have permission to run the following command:%sThe following error ocurred:%s'), $__FM_CONFIG['webserver']['user_info']['name'], $uname, '<br /><pre>' . $named_checkzone_cmd . '</pre><p>', '<pre>' . $named_checkzone_results . '</pre>');
                                    break 2;
                                }
                            }
                        }
                    }
                }
                if ($named_checkzone_results) {
                    if (empty($message)) {
                        $message = __('Your zone configuration files contain one or more errors:') . '<br /><pre>' . $named_checkzone_results . '</pre>';
                    }
                } else {
                    $class = null;
                    $message = __('Your named configuration and zone files are loadable.');
                }
            }
        }
        /** Remove temporary directory */
        system('rm -rf ' . $tmp_dir);
        return <<<HTML
\t\t\t<div id="named_check" {$class}>
\t\t\t\t<p>{$message}</p>
\t\t\t</div>

HTML;
    }
Beispiel #2
0
/**
 * Sets default override configuration options based on OS distro
 *
 * @since 1.2
 * @package facileManager
 * @subpackage fmDNS
 */
function setDefaultOverrideOptions()
{
    global $fm_module_options;
    $config = null;
    $server_os_distro = isDebianSystem($_POST['server_os_distro']) ? 'debian' : strtolower($_POST['server_os_distro']);
    switch ($server_os_distro) {
        case 'debian':
            $config = array(array('cfg_type' => 'global', 'server_serial_no' => $_POST['SERIALNO'], 'cfg_name' => 'pid-file', 'cfg_data' => '/var/run/named/named.pid'));
    }
    if (is_array($config)) {
        if (!isset($fm_module_options)) {
            include ABSPATH . 'fm-modules/fmDNS/classes/class_options.php';
        }
        foreach ($config as $config_data) {
            $fm_module_options->add($config_data);
        }
    }
}