Пример #1
0
    /**
     * Displays the form to add new server
     */
    function printForm($data = '', $action = 'add')
    {
        global $__FM_CONFIG;
        $server_id = 0;
        $server_name = $runas = $server_type = $server_update_port = null;
        $server_update_method = $server_config_file = $server_os = null;
        $ucaction = ucfirst($action);
        $server_installed = false;
        if (!empty($_POST) && !array_key_exists('is_ajax', $_POST)) {
            if (is_array($_POST)) {
                extract($_POST);
            }
        } elseif (@is_object($data[0])) {
            extract(get_object_vars($data[0]));
        }
        /** Show/hide divs */
        if (isset($server_run_as_predefined) && $server_run_as_predefined == 'as defined:') {
            $runashow = 'block';
        } else {
            $runashow = 'none';
            $server_run_as = null;
        }
        $server_update_port_style = $server_update_method == 'cron' ? 'style="display: none;"' : 'style="display: block;"';
        $disabled = $server_installed == 'yes' ? 'disabled' : null;
        if ($server_installed == 'yes') {
            if (strpos($server_update_method, 'http') === false) {
                $server_update_method_choices = array($server_update_method);
            } else {
                $server_update_method_choices = array('http', 'https');
            }
        } else {
            $server_update_method_choices = enumMYSQLSelect('fm_' . $__FM_CONFIG[$_SESSION['module']]['prefix'] . 'servers', 'server_update_method');
        }
        $available_server_types = $this->getAvailableFirewalls(enumMYSQLSelect('fm_' . $__FM_CONFIG[$_SESSION['module']]['prefix'] . 'servers', 'server_type'), $server_os);
        $server_type = buildSelect('server_type', 'server_type', $available_server_types, $server_type, 1);
        $server_update_method = buildSelect('server_update_method', 'server_update_method', $server_update_method_choices, $server_update_method, 1);
        $popup_title = $action == 'add' ? __('Add Firewall') : __('Edit Firewall');
        $popup_header = buildPopup('header', $popup_title);
        $popup_footer = buildPopup('footer');
        $alternative_help = $action == 'add' && getOption('client_auto_register') ? sprintf('<p><b>%s</b> %s</p>', __('Note:'), __('The client installer can automatically generate this entry.')) : null;
        $server_name_length = getColumnLength('fm_' . $__FM_CONFIG[$_SESSION['module']]['prefix'] . 'servers', 'server_name');
        $return_form = sprintf('<form name="manage" id="manage" method="post" action="">
		%s
			<input type="hidden" name="action" value="%s" />
			<input type="hidden" name="server_id" value="%d" />
			%s
			<table class="form-table">
				<tr>
					<th width="33&#37;" scope="row"><label for="server_name">%s</label></th>
					<td width="67&#37;"><input name="server_name" id="server_name" type="text" value="%s" size="40" placeholder="fw1.local" maxlength="%d" /></td>
				</tr>
				<tr>
					<th width="33&#37;" scope="row"><label for="server_type">%s</label></th>
					<td width="67&#37;">%s</td>
				</tr>
				<tr>
					<th width="33&#37;" scope="row"><label for="server_update_method">%s</label></th>
					<td width="67&#37;">%s<div id="server_update_port_option" %s><input type="number" name="server_update_port" value="%s" placeholder="80" onkeydown="return validateNumber(event)" maxlength="5" max="65535" /></div></td>
				</tr>
				<tr>
					<th width="33&#37;" scope="row"><label for="server_config_file">%s</label></th>
					<td width="67&#37;"><input name="server_config_file" id="server_config_file" type="text" value="%s" size="40" /></td>
				</tr>
			</table>
		%s
		</form>
		<script>
			$(document).ready(function() {
				$("#manage select").select2({
					width: "200px",
					minimumResultsForSearch: 10
				});
			});
		</script>', $popup_header, $action, $server_id, $alternative_help, __('Server Name'), $server_name, $server_name_length, __('Firewall Type'), $server_type, __('Update Method'), $server_update_method, $server_update_port_style, $server_update_port, __('Config File'), $server_config_file, $popup_footer);
        return $return_form;
    }
Пример #2
0
    /**
     * Displays the form to add new policy
     */
    function printForm($data = '', $action = 'add', $type = 'rules')
    {
        global $__FM_CONFIG;
        $policy_id = $policy_order_id = 0;
        $policy_interface = $policy_direction = $policy_time = $policy_comment = $policy_options = null;
        $policy_services = $policy_source = $policy_destination = $policy_action = null;
        $source_items = $destination_items = $services_items = null;
        $policy_source_not = $policy_destination_not = $policy_services_not = null;
        $ucaction = ucfirst($action);
        if (!empty($_POST) && !array_key_exists('is_ajax', $_POST)) {
            if (is_array($_POST)) {
                extract($_POST);
            }
        } elseif (@is_object($data[0])) {
            extract(get_object_vars($data[0]));
        }
        $server_firewall_type = getNameFromID($_POST['server_serial_no'], 'fm_' . $__FM_CONFIG[$_SESSION['module']]['prefix'] . 'servers', 'server_', 'server_serial_no', 'server_type');
        $available_policy_actions = enumMYSQLSelect('fm_' . $__FM_CONFIG[$_SESSION['module']]['prefix'] . 'policies', 'policy_action');
        if ($server_firewall_type == 'ipfilter') {
            array_pop($available_policy_actions);
        }
        $policy_interface = buildSelect('policy_interface', 'policy_interface', $this->availableInterfaces($_REQUEST['server_serial_no']), $policy_interface);
        $policy_direction = buildSelect('policy_direction', 'policy_direction', enumMYSQLSelect('fm_' . $__FM_CONFIG[$_SESSION['module']]['prefix'] . 'policies', 'policy_direction'), $policy_direction, 1);
        $policy_action = buildSelect('policy_action', 'policy_action', $available_policy_actions, $policy_action, 1);
        $source_items_assigned = getGroupItems($policy_source);
        $source_items = buildSelect('source_items', 'source_items', availableGroupItems('object', 'available'), $source_items_assigned, 1, null, true, null, null, __('Select one or more objects'));
        $destination_items_assigned = getGroupItems($policy_destination);
        $destination_items = buildSelect('destination_items', 'destination_items', availableGroupItems('object', 'available'), $destination_items_assigned, 1, null, true, null, null, __('Select one or more objects'));
        $services_items_assigned = getGroupItems($policy_services);
        $services_items = buildSelect('services_items', 'services_items', availableGroupItems('service', 'available'), $services_items_assigned, 1, null, true, null, null, __('Select one or more services'));
        $source_not_check = $policy_source_not ? 'checked' : null;
        $destination_not_check = $policy_destination_not ? 'checked' : null;
        $service_not_check = $policy_services_not ? 'checked' : null;
        $popup_title = $action == 'add' ? __('Add Policy') : __('Edit Policy');
        $popup_header = buildPopup('header', $popup_title);
        $popup_footer = buildPopup('footer');
        $return_form = <<<FORM
\t\t<form name="manage" id="manage" method="post" action="?server_serial_no={$_REQUEST['server_serial_no']}">
\t\t{$popup_header}
\t\t\t<input type="hidden" name="action" value="{$action}" />
\t\t\t<input type="hidden" name="policy_id" value="{$policy_id}" />
\t\t\t<input type="hidden" name="policy_order_id" value="{$policy_order_id}" />
\t\t\t<input type="hidden" name="policy_source_not" value="0" />
\t\t\t<input type="hidden" name="policy_destination_not" value="0" />
\t\t\t<input type="hidden" name="policy_services_not" value="0" />
FORM;
        if ($type == 'rules') {
            $return_form .= sprintf('
			<table class="form-table policy-form">
				<tr>
					<th width="33&#37;" scope="row"><label for="policy_interface">%s</label></th>
					<td width="67&#37;">%s</td>
				</tr>
				<tr>
					<th width="33&#37;" scope="row"><label for="policy_direction">%s</label></th>
					<td width="67&#37;">%s</td>
				</tr>
				<tr>
					<th width="33&#37;" scope="row">%s</th>
					<td width="67&#37;">
						<input name="policy_source_not" id="policy_source_not" value="1" type="checkbox" %s /><label for="policy_source_not"><b>%s</b></label>
						<p class="checkbox_desc">%s</p>
						%s
					</td>
				</tr>
				<tr>
					<th width="33&#37;" scope="row">%s</th>
					<td width="67&#37;">
						<input name="policy_destination_not" id="policy_destination_not" value="1" type="checkbox" %s /><label for="policy_destination_not"><b>%s</b></label>
						<p class="checkbox_desc">%s</p>
						%s
					</td>
				</tr>
				<tr>
					<th width="33&#37;" scope="row">%s</th>
					<td width="67&#37;">
						<input name="policy_services_not" id="policy_services_not" value="1" type="checkbox" %s /><label for="policy_services_not"><b>%s</b></label>
						<p class="checkbox_desc">%s</p>
						%s
					</td>
				</tr>', __('Interface'), $policy_interface, __('Direction'), $policy_direction, __('Source'), $source_not_check, __('not'), __('Use this option to invert the match'), $source_items, __('Destination'), $destination_not_check, __('not'), __('Use this option to invert the match'), $destination_items, __('Services'), $service_not_check, __('not'), __('Use this option to invert the match'), $services_items);
            if ($server_firewall_type == 'iptables') {
                $policy_time = buildSelect('policy_time', 'policy_time', $this->availableTimes(), $policy_time);
                $return_form .= sprintf('
				<tr>
					<th width="33&#37;" scope="row"><label for="policy_time">%s</label></th>
					<td width="67&#37;">%s</td>
				</tr>', __('Time Restriction'), $policy_time);
            }
            /** Parse options */
            $options = null;
            if ($server_firewall_type == 'pf') {
                array_pop($__FM_CONFIG['fw']['policy_options']);
                array_pop($__FM_CONFIG['fw']['policy_options']);
            }
            foreach ($__FM_CONFIG['fw']['policy_options'] as $opt => $opt_array) {
                $checked = $policy_options & $opt_array['bit'] ? 'checked' : null;
                $options .= '<input name="policy_options[]" id="policy_options[' . $opt_array['bit'] . ']" value="' . $opt_array['bit'] . '" type="checkbox" ' . $checked . ' /><label for="policy_options[' . $opt_array['bit'] . ']">' . $opt_array['desc'] . "</label><br />\n";
            }
            $return_form .= sprintf('
				<tr>
					<th width="33&#37;" scope="row"><label for="policy_action">%s</label></th>
					<td width="67&#37;">%s</td>
				</tr>
				<tr>
					<th width="33&#37;" scope="row">%s</th>
					<td width="67&#37;">
						%s
					</td>
				</tr>
				<tr>
					<th width="33&#37;" scope="row"><label for="policy_comment">%s</label></th>
					<td width="67&#37;"><textarea id="policy_comment" name="policy_comment" rows="4" cols="30">%s</textarea></td>
				</tr>
			</table>', __('Action'), $policy_action, __('Options'), $options, __('Comment'), $policy_comment);
        }
        $return_form .= <<<FORM
\t\t{$popup_footer}
\t\t</form>
\t\t<script>
\t\t\t\$(document).ready(function() {
\t\t\t\t\$("#manage select").select2({
\t\t\t\t\twidth: '200px',
\t\t\t\t\tminimumResultsForSearch: 10
\t\t\t\t});
\t\t\t});
\t\t</script>
FORM;
        return $return_form;
    }
Пример #3
0
if (in_array($record_type, $__FM_CONFIG['records']['require_zone_rights']) && !currentUserCan('manage_zones', $_SESSION['module'])) {
    unAuth();
}
if ($record_type == 'SOA') {
    if (getNameFromID($domain_id, 'fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'domains', 'domain_', 'domain_id', 'domain_clone_domain_id')) {
        $record_type = $default_record_type;
    } elseif (getNameFromID($domain_id, 'fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'domains', 'domain_', 'domain_id', 'domain_template_id')) {
        $record_type = $default_record_type;
    }
}
define('FM_INCLUDE_SEARCH', true);
printHeader();
@printMenu();
include ABSPATH . 'fm-modules/fmDNS/classes/class_records.php';
$search_query = createSearchSQL(array('name', 'value', 'ttl', 'class', 'text', 'comment'), 'record_');
$supported_record_types = enumMYSQLSelect('fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'records', 'record_type');
sort($supported_record_types);
$supported_record_types[] = 'SOA';
$parent_domain_ids = getZoneParentID($domain_id);
$zone_access_allowed = zoneAccessIsAllowed($parent_domain_ids);
if (!in_array($record_type, $supported_record_types)) {
    $record_type = $default_record_type;
}
$avail_types = buildRecordTypes($record_type, $parent_domain_ids, $map, $supported_record_types, $search_query);
$response = $form_data = $action = null;
if (reloadZone($domain_id)) {
    if (reloadAllowed($domain_id) && currentUserCan('reload_zones', $_SESSION['module']) && $zone_access_allowed) {
        $response = '** You need to <a href="" class="zone_reload" id="' . $domain_id . '">reload</a> this zone **';
    }
}
if (!getNSCount($domain_id)) {
Пример #4
0
 +-------------------------------------------------------------------------+
 | Processes objects management page                                       |
 | Author: Jon LaBass                                                      |
 +-------------------------------------------------------------------------+
*/
if (!isset($type)) {
    header('Location: objects-host.php');
}
if (isset($_GET['type'])) {
    header('Location: objects-' . sanitize(strtolower($_GET['type'])) . '.php');
}
if (!currentUserCan(array('manage_objects', 'view_all'), $_SESSION['module'])) {
    unAuth();
}
/** Ensure we have a valid type */
if (!in_array($type, enumMYSQLSelect('fm_' . $__FM_CONFIG[$_SESSION['module']]['prefix'] . 'objects', 'object_type'))) {
    header('Location: ' . $GLOBALS['basename']);
}
include ABSPATH . 'fm-modules/' . $_SESSION['module'] . '/classes/class_objects.php';
$response = isset($response) ? $response : null;
if (currentUserCan('manage_objects', $_SESSION['module'])) {
    $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : 'add';
    switch ($action) {
        case 'add':
            if (!empty($_POST)) {
                $result = $fm_module_objects->add($_POST);
                if ($result !== true) {
                    $response = $result;
                    $form_data = $_POST;
                } else {
                    header('Location: ' . $GLOBALS['basename'] . '?type=' . $_POST['object_type']);
Пример #5
0
    /**
     * Displays the form to add new option
     */
    function printForm($data = '', $action = 'add', $cfg_type = 'global', $cfg_type_id = null)
    {
        global $fmdb, $__FM_CONFIG, $fm_dns_zones;
        $cfg_id = $domain_id = 0;
        if (!$cfg_type_id) {
            $cfg_type_id = 0;
        }
        $cfg_name = $cfg_root_dir = $cfg_zones_dir = $cfg_comment = null;
        $ucaction = ucfirst($action);
        $server_serial_no_field = $cfg_isparent = $cfg_parent = $cfg_data = null;
        switch (strtolower($cfg_type)) {
            case 'global':
            case 'ratelimit':
                if (isset($_POST['item_sub_type'])) {
                    $cfg_id_name = sanitize($_POST['item_sub_type']);
                } else {
                    $cfg_id_name = isset($_POST['view_id']) ? 'view_id' : 'domain_id';
                }
                $data_holder = null;
                $server_serial_no = isset($_REQUEST['request_uri']['server_serial_no']) && (intval($_REQUEST['request_uri']['server_serial_no']) > 0 || $_REQUEST['request_uri']['server_serial_no'][0] == 'g') ? sanitize($_REQUEST['request_uri']['server_serial_no']) : 0;
                $server_serial_no_field = '<input type="hidden" name="server_serial_no" value="' . $server_serial_no . '" />';
                $request_uri = 'config-options.php';
                if (isset($_REQUEST['request_uri'])) {
                    $request_uri .= '?';
                    foreach ($_REQUEST['request_uri'] as $key => $val) {
                        $request_uri .= $key . '=' . sanitize($val) . '&';
                    }
                    $request_uri = rtrim($request_uri, '&');
                }
                $disabled = $action == 'add' ? null : 'disabled';
                break;
            case 'logging':
                $name_holder = 'severity';
                $name_note = null;
                $data_holder = 'dynamic';
                $data_note = null;
                break;
            case 'keys':
                $name_holder = 'key';
                $name_note = null;
                $data_holder = 'rndc-key';
                $data_note = null;
                break;
        }
        if (!empty($_POST) && !array_key_exists('is_ajax', $_POST)) {
            if (is_array($_POST)) {
                extract($_POST);
            }
        } elseif (@is_object($data[0])) {
            extract(get_object_vars($data[0]));
        }
        $cfg_isparent = buildSelect('cfg_isparent', 'cfg_isparent', enumMYSQLSelect('fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'config', 'cfg_isparent'), $cfg_isparent, 1);
        $cfg_parent = buildSelect('cfg_parent', 'cfg_parent', $this->availableParents($cfg_id, $cfg_type), $cfg_parent);
        $avail_options_array = $this->availableOptions($action, $server_serial_no, $cfg_type, $cfg_name);
        $cfg_avail_options = buildSelect('cfg_name', 'cfg_name', $avail_options_array, $cfg_name, 1, $disabled, false, 'displayOptionPlaceholder()');
        $query = "SELECT def_type FROM fm_{$__FM_CONFIG['fmDNS']['prefix']}functions WHERE def_function='{$cfg_type}' AND \n\t\t\t\tdef_option=";
        if ($action != 'add') {
            $query .= "'{$cfg_name}'";
        } else {
            $query .= "'{$avail_options_array[0]}'";
        }
        $fmdb->get_results($query);
        if ($fmdb->num_rows) {
            $results = $fmdb->last_result;
            $data_holder = $results[0]->def_type;
        }
        $cfg_data = sanitize($cfg_data);
        $popup_title = $action == 'add' ? __('Add Option') : __('Edit Option');
        $popup_header = buildPopup('header', $popup_title);
        $popup_footer = buildPopup('footer');
        $addl_options = null;
        if ($cfg_type == 'ratelimit') {
            $available_zones = $fm_dns_zones->buildZoneJSON($cfg_data);
            $addl_options = sprintf('<tr>
					<th width="33&#37;" scope="row"><label for="cfg_name">%s</label></th>
					<td width="67&#37;"><input type="hidden" name="domain_id" class="domain_name" value="%d" /><br />
					<script>
					$(".domain_name").select2({
						createSearchChoice:function(term, data) { 
							if ($(data).filter(function() { 
								return this.text.localeCompare(term)===0; 
							}).length===0) 
							{return {id:term, text:term};} 
						},
						multiple: false,
						width: "200px",
						tokenSeparators: [",", " ", ";"],
						data: %s
					});
					$(".domain_name").change(function(){
						var $swap = $(this).parent().parent().next().find("td");
						var form_data = {
							server_serial_no: getUrlVars()["server_serial_no"],
							cfg_type: getUrlVars()["option_type"],
							cfg_name: $(this).parent().parent().next().find("td").find("select").val(),
							get_available_options: true,
							item_sub_type: "domain_id",
							item_id: $(this).val(),
							view_id: getUrlVars()["view_id"],
							is_ajax: 1
						};

						$.ajax({
							type: "POST",
							url: "fm-modules/fmDNS/ajax/getData.php",
							data: form_data,
							success: function(response) {
								$swap.html(response);
								
								$("#manage select").select2({
									width: "200px",
									minimumResultsForSearch: 10
								});
							}
						});
					});
					</script>
				</tr>', __('Domain'), $domain_id, $available_zones);
        }
        $return_form = sprintf('<script>
			displayOptionPlaceholder("%s");
		</script>
		<form name="manage" id="manage" method="post" action="%s">
		%s
			<input type="hidden" name="action" value="%s" />
			<input type="hidden" name="cfg_id" value="%d" />
			<input type="hidden" name="cfg_type" value="%s" />
			<input type="hidden" name="%s" value="%s" />
			%s
			<table class="form-table">
				%s
				<tr>
					<th width="33&#37;" scope="row"><label for="cfg_name">%s</label></th>
					<td width="67&#37;">%s</td>
				</tr>
				<tr class="value_placeholder">
				</tr>
				<tr>
					<th width="33&#37;" scope="row"><label for="cfg_comment">%s</label></th>
					<td width="67&#37;"><textarea id="cfg_comment" name="cfg_comment" rows="4" cols="30">%s</textarea></td>
				</tr>
			</table>
		%s
		</form>
		<script>
			$(document).ready(function() {
				$("#manage select").select2({
					width: "200px",
					minimumResultsForSearch: 10
				});
			});
		</script>', $cfg_data, $request_uri, $popup_header, $action, $cfg_id, $cfg_type, $cfg_id_name, $cfg_type_id, $server_serial_no_field, $addl_options, __('Option Name'), $cfg_avail_options, __('Comment'), $cfg_comment, $popup_footer);
        return $return_form;
    }
Пример #6
0
    /**
     * Displays the form to add new object
     */
    function printForm($data = '', $action = 'add', $type = 'host')
    {
        global $__FM_CONFIG;
        $object_id = 0;
        $object_name = $object_address = $object_comment = null;
        $object_mask = null;
        $ucaction = ucfirst($action);
        if (!empty($_POST) && !array_key_exists('is_ajax', $_POST)) {
            if (is_array($_POST)) {
                extract($_POST);
            }
        } elseif (@is_object($data[0])) {
            extract(get_object_vars($data[0]));
        }
        /** Show/hide divs */
        $netmask_option = $type == 'host' ? 'style="display: none;"' : null;
        $object_name_length = getColumnLength('fm_' . $__FM_CONFIG[$_SESSION['module']]['prefix'] . 'objects', 'object_name');
        $object_address_length = getColumnLength('fm_' . $__FM_CONFIG[$_SESSION['module']]['prefix'] . 'objects', 'object_address');
        $object_mask_length = getColumnLength('fm_' . $__FM_CONFIG[$_SESSION['module']]['prefix'] . 'objects', 'object_mask');
        $object_type = buildSelect('object_type', 'object_type', enumMYSQLSelect('fm_' . $__FM_CONFIG[$_SESSION['module']]['prefix'] . 'objects', 'object_type'), $type, 1);
        $popup_title = $action == 'add' ? __('Add Object') : __('Edit Object');
        $popup_header = buildPopup('header', $popup_title);
        $popup_footer = buildPopup('footer');
        $return_form = sprintf('<form name="manage" id="manage" method="post" action="?type=%s">
		%s
			<input type="hidden" name="action" value="%s" />
			<input type="hidden" name="object_id" value="%s" />
			<table class="form-table">
				<tr>
					<th width="33&#37;" scope="row"><label for="object_name">%s</label></th>
					<td width="67&#37;"><input name="object_name" id="object_name" type="text" value="%s" size="40" placeholder="http" maxlength="%s" /></td>
				</tr>
				<tr>
					<th width="33&#37;" scope="row"><label for="object_type">%s</label></th>
					<td width="67&#37;">
						%s
					</td>
				</tr>
				<tr>
					<th width="33&#37;" scope="row"><label for="object_address">%s</label></th>
					<td width="67&#37;"><input name="object_address" id="object_address" type="text" value="%s" size="40" placeholder="127.0.0.1" maxlength="%s" /></td>
				</tr>
				<tr id="netmask_option" %s>
					<th width="33&#37;" scope="row"><label for="object_mask">%s</label></th>
					<td width="67&#37;"><input name="object_mask" id="object_mask" type="text" value="%s" size="40" placeholder="255.255.255.0" maxlength="%s" /></td>
				</tr>
				<tr>
					<th width="33&#37;" scope="row"><label for="object_comment">%s</label></th>
					<td width="67&#37;"><textarea id="object_comment" name="object_comment" rows="4" cols="30">%s</textarea></td>
				</tr>
			</table>
		%s
		</form>
		<script>
			$(document).ready(function() {
				$("#manage select").select2({
					width: "200px",
					minimumResultsForSearch: 10
				});
			});
		</script>', $type, $popup_header, $action, $object_id, __('Object Name'), $object_name, $object_name_length, __('Object Type'), $object_type, __('Address'), $object_address, $object_address_length, $netmask_option, __('Netmask'), $object_mask, $object_mask_length, __('Comment'), $object_comment, $popup_footer);
        return $return_form;
    }
Пример #7
0
    /**
     * Imports records from a zone file and presents a confirmation
     */
    function zoneImportWizard()
    {
        global $__FM_CONFIG, $fm_name;
        if (!currentUserCan('manage_records', $_SESSION['module'])) {
            return $this->unAuth('zone');
        }
        if (!zoneAccessIsAllowed(array($_POST['domain_id']))) {
            return $this->unAuth('zone');
        }
        $raw_contents = file_get_contents($_FILES['import-file']['tmp_name']);
        /** Strip commented lines */
        $clean_contents = preg_replace('/^;.*\\n?/m', '', $raw_contents);
        /** Strip blank lines */
        $clean_contents = preg_replace('/^\\n?/m', '', $clean_contents);
        /** Strip $GENERATE lines */
        $clean_contents = preg_replace('/^\\$GENERATE.*\\n?/m', '', $clean_contents, -1, $generate_count);
        /** Strip $ORIGIN lines */
        $clean_contents = preg_replace('/^\\$ORIGIN.*\\n?/m', '', $clean_contents, -1, $origin_count);
        /** Handle unsupported message */
        if ($generate_count || $origin_count) {
            $unsupported[] = sprintf('<h4>%s:</h4>', __('Unsupported Entries'));
            $unsupported[] = '<p class="soa_import">' . sprintf(__('%s currently does not support importing $GENERATE and $ORIGIN entries which were found in your zone file.'), $fm_name) . '</p>';
            $unsupported = implode("\n", $unsupported);
        } else {
            $unsupported = null;
        }
        $domain_name = getNameFromID($_POST['domain_id'], 'fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'domains', 'domain_', 'domain_id', 'domain_name');
        $domain_map = getNameFromID($_POST['domain_id'], 'fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'domains', 'domain_', 'domain_id', 'domain_mapping');
        $count = 1;
        /** Detect SOA */
        if (!getSOACount($_POST['domain_id']) && strpos($clean_contents, ' SOA ') !== false && (in_array('SOA', $__FM_CONFIG['records']['require_zone_rights']) && currentUserCan('manage_zones', $_SESSION['module']))) {
            $raw_soa = preg_replace("/SOA(.+?)\\)/esim", "str_replace(PHP_EOL, ' ', '\\1')", $clean_contents);
            preg_match("/SOA(.+?)\\)/esim", $clean_contents, $raw_soa);
            preg_match("/TTL(.+?)\$/esim", $clean_contents, $raw_ttl);
            if (is_array($raw_ttl)) {
                $soa_array['soa_ttl'] = trim(preg_replace('/;(.+?)+/', '', $raw_ttl[1]));
            }
            if (is_array($raw_soa)) {
                $raw_soa = preg_replace('/;(.+?)+/', '', $raw_soa[1]);
                $soa = str_replace(array("\n", "\t", '(', ')', '  '), ' ', preg_replace('/\\s\\s+/', ' ', $raw_soa));
                $soa = str_replace(' ', '|', trim($soa));
                $soa_fields = explode('|', str_replace('||', '|', $soa));
                list($soa_array['soa_master_server'], $soa_array['soa_email_address'], $tmp_serial, $soa_array['soa_refresh'], $soa_array['soa_retry'], $soa_array['soa_expire'], $tmp_neg_cache) = $soa_fields;
                if (strpos($soa_array['soa_master_server'], $domain_name) !== false) {
                    $soa_array['soa_master_server'] = str_replace('.' . trimFullStop($domain_name) . '.', '', $soa_array['soa_master_server']);
                    $soa_array['soa_email_address'] = str_replace('.' . trimFullStop($domain_name) . '.', '', $soa_array['soa_email_address']);
                    $soa_array['soa_append'] = 'yes';
                } else {
                    $soa_array['soa_append'] = 'no';
                }
            }
            $soa_row = '<h4>SOA:</h4><p class="soa_import">' . trimFullStop($domain_name) . '. IN SOA ' . $soa_array['soa_master_server'];
            if ($soa_array['soa_append'] == 'yes') {
                $soa_row .= '.' . trimFullStop($domain_name) . '.';
            }
            $soa_row .= ' ' . $soa_array['soa_email_address'];
            if ($soa_array['soa_append'] == 'yes') {
                $soa_row .= '.' . trimFullStop($domain_name) . '.';
            }
            $soa_row .= ' ( &lt;autogen_serial&gt; ' . $soa_array['soa_refresh'] . ' ' . $soa_array['soa_retry'] . ' ' . $soa_array['soa_expire'] . ' ' . $soa_array['soa_ttl'] . ' )';
            $soa_row = <<<HTML
\t\t\t\t\t\t<input type="hidden" name="create[{$count}][soa_master_server]" value="{$soa_array['soa_master_server']}" />
\t\t\t\t\t\t<input type="hidden" name="create[{$count}][soa_email_address]" value="{$soa_array['soa_email_address']}" />
\t\t\t\t\t\t<input type="hidden" name="create[{$count}][soa_refresh]" value="{$soa_array['soa_refresh']}" />
\t\t\t\t\t\t<input type="hidden" name="create[{$count}][soa_retry]" value="{$soa_array['soa_retry']}" />
\t\t\t\t\t\t<input type="hidden" name="create[{$count}][soa_expire]" value="{$soa_array['soa_expire']}" />
\t\t\t\t\t\t<input type="hidden" name="create[{$count}][soa_ttl]" value="{$soa_array['soa_ttl']}" />
\t\t\t\t\t\t<input type="hidden" name="create[{$count}][record_type]" value="SOA" />
\t\t\t\t\t\t<input type="hidden" name="create[{$count}][soa_append]" value="{$soa_array['soa_append']}" />
\t\t\t\t\t\t{$soa_row}
\t\t\t\t\t\t<span><label><input type="checkbox" name="create[{$count}][record_skip]" />Skip Import</label></span>
\t\t\t\t\t\t</p>
\t\t\t\t\t\t
\t\t\t\t\t\t<h4>Records:</h4>

HTML;
            $count++;
        } else {
            $soa_row = null;
        }
        $clean_contents = str_replace('.' . trimFullStop($domain_name) . '.', '', $clean_contents);
        $clean_contents = str_replace(trimFullStop($domain_name) . '.', '', $clean_contents);
        $available_record_types = array_filter(enumMYSQLSelect('fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'records', 'record_type'), 'removeRestrictedRR');
        sort($available_record_types);
        /** Loop through the lines */
        $lines = explode(PHP_EOL, $clean_contents);
        $failed = 0;
        $rows = null;
        $valid_hashes = array(';', '//', '#');
        foreach ($lines as $line) {
            $null_keys = array('record_ttl', 'record_priority', 'record_weight', 'record_port');
            foreach ($null_keys as $key) {
                $array[$key] = null;
            }
            if (!strlen(trim($line))) {
                continue;
            }
            foreach ($valid_hashes as $tmp_hash) {
                if (strpos($line, $tmp_hash)) {
                    $hash = $tmp_hash;
                    break;
                } else {
                    $hash = null;
                }
            }
            if ($hash == '//') {
                $hash = '\\/\\/';
            }
            /** Break up the line for comments */
            if ($hash) {
                $comment_parts = preg_split("/{$hash}+/", $line);
                $array['record_comment'] = trim($comment_parts[1]) ? trim($comment_parts[1]) : 'none';
            } else {
                $comment_parts[0] = $line;
                $array['record_comment'] = 'none';
            }
            /** Break up the line for parts */
            $parts = preg_split('/\\s+/', trim($comment_parts[0]));
            if ($domain_map == 'forward') {
                if (in_array('MX', $parts)) {
                    switch (array_search('MX', $parts)) {
                        case 3:
                            list($array['record_name'], $array['record_ttl'], $array['record_class'], $array['record_type'], $array['record_priority'], $array['record_value']) = $parts;
                            break;
                        case 2:
                            if (is_numeric($parts[0])) {
                                $array['record_name'] = isset($current_name) ? $current_name : '@';
                                list($array['record_ttl'], $array['record_class'], $array['record_type'], $array['record_priority'], $array['record_value']) = $parts;
                            } else {
                                list($array['record_name'], $array['record_class'], $array['record_type'], $array['record_priority'], $array['record_value']) = $parts;
                            }
                            break;
                        case 1:
                            $array['record_name'] = isset($current_name) ? $current_name : '@';
                            list($array['record_class'], $array['record_type'], $array['record_priority'], $array['record_value']) = $parts;
                    }
                } elseif (in_array('SRV', $parts)) {
                    switch (array_search('SRV', $parts)) {
                        case 3:
                            list($array['record_name'], $array['record_ttl'], $array['record_class'], $array['record_type'], $array['record_priority'], $array['record_weight'], $array['record_port'], $array['record_value']) = $parts;
                            break;
                        case 2:
                            if (is_numeric($parts[0])) {
                                $array['record_name'] = isset($current_name) ? $current_name : '@';
                                list($array['record_ttl'], $array['record_class'], $array['record_type'], $array['record_priority'], $array['record_weight'], $array['record_port'], $array['record_value']) = $parts;
                            } else {
                                list($array['record_name'], $array['record_class'], $array['record_type'], $array['record_priority'], $array['record_weight'], $array['record_port'], $array['record_value']) = $parts;
                            }
                            break;
                        case 1:
                            $array['record_name'] = isset($current_name) ? $current_name : '@';
                            list($array['record_class'], $array['record_type'], $array['record_priority'], $array['record_weight'], $array['record_port'], $array['record_value']) = $parts;
                    }
                } elseif (in_array('TXT', $parts)) {
                    $key = array_search('TXT', $parts);
                    $txt_record = null;
                    for ($i = $key + 1; $i < count($parts); $i++) {
                        $txt_record .= $parts[$i] . ' ';
                    }
                    $parts[$key + 1] = rtrim($txt_record);
                    switch ($key) {
                        case 3:
                            list($array['record_name'], $array['record_ttl'], $array['record_class'], $array['record_type'], $array['record_value']) = $parts;
                            break;
                        case 2:
                            if (is_numeric($parts[0])) {
                                $array['record_name'] = isset($current_name) ? $current_name : '@';
                                list($array['record_ttl'], $array['record_class'], $array['record_type'], $array['record_value']) = $parts;
                            } else {
                                list($array['record_name'], $array['record_class'], $array['record_type'], $array['record_value']) = $parts;
                            }
                            break;
                        case 1:
                            $array['record_name'] = isset($current_name) ? $current_name : '@';
                            list($array['record_class'], $array['record_type'], $array['record_value']) = $parts;
                    }
                    $array['record_value'] = str_replace('"', '', $array['record_value']);
                } elseif (in_array('A', $parts) || in_array('CNAME', $parts) || in_array('AAAA', $parts)) {
                    if (in_array('AAAA', $parts)) {
                        $key = array_search('AAAA', $parts);
                    } else {
                        $key = in_array('A', $parts) ? array_search('A', $parts) : array_search('CNAME', $parts);
                    }
                    switch ($key) {
                        case 3:
                            list($array['record_name'], $array['record_ttl'], $array['record_class'], $array['record_type'], $array['record_value']) = $parts;
                            break;
                        case 2:
                            if (is_numeric($parts[0])) {
                                $array['record_name'] = isset($current_name) ? $current_name : '@';
                                list($array['record_ttl'], $array['record_class'], $array['record_type'], $array['record_value']) = $parts;
                            } else {
                                list($array['record_name'], $array['record_class'], $array['record_type'], $array['record_value']) = $parts;
                            }
                            break;
                        case 1:
                            $array['record_name'] = isset($current_name) ? $current_name : '@';
                            list($array['record_class'], $array['record_type'], $array['record_value']) = $parts;
                    }
                }
            } else {
                if (in_array('PTR', $parts)) {
                    switch (array_search('PTR', $parts)) {
                        case 3:
                            list($array['record_name'], $array['record_ttl'], $array['record_class'], $array['record_type'], $array['record_value']) = $parts;
                            break;
                        case 2:
                            if ($parts[0] > 255) {
                                $array['record_name'] = isset($current_name) ? $current_name : '@';
                                list($array['record_ttl'], $array['record_class'], $array['record_type'], $array['record_value']) = $parts;
                            } else {
                                list($array['record_name'], $array['record_class'], $array['record_type'], $array['record_value']) = $parts;
                            }
                            break;
                        case 1:
                            $array['record_name'] = isset($current_name) ? $current_name : '@';
                            list($array['record_class'], $array['record_type'], $array['record_value']) = $parts;
                    }
                }
            }
            if (in_array('NS', $parts) && in_array('NS', $__FM_CONFIG['records']['require_zone_rights']) && currentUserCan('manage_zones', $_SESSION['module'])) {
                switch (array_search('NS', $parts)) {
                    case 3:
                        list($array['record_name'], $array['record_ttl'], $array['record_class'], $array['record_type'], $array['record_value']) = $parts;
                        break;
                    case 2:
                        if (is_numeric($parts[0])) {
                            $array['record_name'] = isset($current_name) ? $current_name : '@';
                            list($array['record_ttl'], $array['record_class'], $array['record_type'], $array['record_value']) = $parts;
                        } else {
                            list($array['record_name'], $array['record_class'], $array['record_type'], $array['record_value']) = $parts;
                        }
                        break;
                    case 1:
                        $array['record_name'] = isset($current_name) ? $current_name : '@';
                        list($array['record_class'], $array['record_type'], $array['record_value']) = $parts;
                }
            }
            if (empty($array['record_name']) && !empty($array['record_comment'])) {
                continue;
            }
            $array['record_append'] = substr($array['record_value'], -1) == '.' ? 'no' : 'yes';
            /** Set current_name to check for blanks on next run */
            $current_name = $array['record_name'];
            /** Automatically skip duplicates */
            $checked = $this->checkDuplicates($array, $_POST['domain_id']);
            $rows .= <<<ROW
\t\t\t\t\t<tr class="import_swap">
\t\t\t\t\t\t<td><span id="name{$count}" onclick="exchange(this);">{$array['record_name']}</span><input onblur="exchange(this);" type="text" id="name{$count}b" name="create[{$count}][record_name]" value="{$array['record_name']}" /></td>
\t\t\t\t\t\t<td><span id="ttl{$count}" onclick="exchange(this);">{$array['record_ttl']}</span><input onblur="exchange(this);" type="number" id="ttl{$count}b" name="create[{$count}][record_ttl]" value="{$array['record_ttl']}" /></td>
\t\t\t\t\t\t<td><input type="hidden" name="create[{$count}][record_class]" value="{$array['record_class']}" />{$array['record_class']}</td>
\t\t\t\t\t\t<td><input type="hidden" name="create[{$count}][record_type]" value="{$array['record_type']}" />{$array['record_type']}</td>
\t\t\t\t\t\t<td><span id="priority{$count}" onclick="exchange(this);">{$array['record_priority']}</span><input onblur="exchange(this);" type="number" id="priority{$count}b" name="create[{$count}][record_priority]" value="{$array['record_priority']}" /></td>
\t\t\t\t\t\t<td><span id="value{$count}" onclick="exchange(this);">{$array['record_value']}</span><input onblur="exchange(this);" type="text" id="value{$count}b" name="create[{$count}][record_value]" value="{$array['record_value']}" /></td>
\t\t\t\t\t\t<td><span id="weight{$count}" onclick="exchange(this);">{$array['record_weight']}</span><input onblur="exchange(this);" type="number" id="weight{$count}b" name="create[{$count}][record_weight]" value="{$array['record_weight']}" /></td>
\t\t\t\t\t\t<td><span id="port{$count}" onclick="exchange(this);">{$array['record_port']}</span><input onblur="exchange(this);" type="number" id="port{$count}b" name="create[{$count}][record_port]" value="{$array['record_port']}" /></td>
\t\t\t\t\t\t<td><span id="comment{$count}" onclick="exchange(this);">{$array['record_comment']}</span><input onblur="exchange(this);" type="text" id="comment{$count}b" name="create[{$count}][record_comment]" value="{$array['record_comment']}" /></td>
\t\t\t\t\t\t<td style="text-align: center;" nowrap><input type="hidden" name="create[{$count}][record_append]" value="{$array['record_append']}" />{$array['record_append']}</td>
\t\t\t\t\t\t<td style="text-align: center;"><label><input type="checkbox" name="create[{$count}][record_skip]" {$checked} />Skip Import</label></td>
\t\t\t\t\t</tr>

ROW;
            $count++;
        }
        $table_info = array('class' => 'display_results', 'id' => 'table_edits', 'name' => 'views');
        $title_array = array(__('Record'), __('TTL'), __('Class'), __('Type'), __('Priority'), __('Value'), __('Weight'), __('Port'), __('Comment'));
        $title_array[] = array('title' => __('Append Domain'), 'style' => 'text-align: center;', 'nowrap' => null);
        $title_array[] = array('title' => __('Actions'), 'class' => 'header-actions');
        $table_header = displayTableHeader($table_info, $title_array);
        $popup_header = buildPopup('header', __('Import Verification'));
        $popup_footer = buildPopup('footer', __('Import'), array('import' => 'submit', 'cancel_button' => 'cancel'));
        $body = <<<BODY
\t\t<form method="post" action="zone-records-write.php">
\t\t{$popup_header}
\t\t\t<p>Domain: {$domain_name}</p>
\t\t\t<input type="hidden" name="domain_id" value="{$_POST['domain_id']}">
\t\t\t<input type="hidden" name="map" value="{$domain_map}">
\t\t\t<input type="hidden" name="import_records" value="true">
\t\t\t<input type="hidden" name="import_file" value="{$_FILES['import-file']['name']}">
\t\t\t{$unsupported}
\t\t\t{$soa_row}
\t\t\t{$table_header}
\t\t\t\t{$rows}
\t\t\t\t</tbody>
\t\t\t</table>
\t\t\t<br />
\t\t{$popup_footer}
\t\t</form>
BODY;
        return $body;
    }
Пример #8
0
 function getServerTypes()
 {
     global $__FM_CONFIG;
     $fm_supported_servers = null;
     $db_support = enumMYSQLSelect('fm_' . $__FM_CONFIG['fmSQLPass']['prefix'] . 'servers', 'server_type');
     foreach ($db_support as $db_type) {
         $php_function = strtolower($db_type) == 'postgresql' ? 'pg' : strtolower($db_type);
         if (function_exists($php_function . '_connect') && function_exists('change' . $db_type . 'UserPassword')) {
             $fm_supported_servers[] = $db_type;
         }
     }
     return $fm_supported_servers;
 }
Пример #9
0
    /**
     * Displays the form to add new zone
     */
    function printForm($data = '', $action = 'create', $map = 'forward', $show = array('popup', 'template_menu', 'create_template'))
    {
        global $fmdb, $__FM_CONFIG, $fm_dns_acls, $fm_module_options;
        $domain_id = $domain_view = $domain_name_servers = 0;
        $domain_type = $domain_clone_domain_id = $domain_name = $template_name = null;
        $disabled = $action == 'create' ? null : 'disabled';
        if (!empty($_POST) && !array_key_exists('is_ajax', $_POST)) {
            if (is_array($_POST)) {
                $domain_id = $_POST[$action . 'Zone']['ZoneID'];
                extract($_POST[$action . 'Zone'][$domain_id]);
            }
        } elseif (@is_object($data[0])) {
            extract(get_object_vars($data[0]));
        } elseif (!empty($_POST) && array_key_exists('is_ajax', $_POST)) {
            extract($_POST);
            $domain_clone_dname = null;
            $domain_template_id = getNameFromID($domain_clone_domain_id, 'fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'domains', 'domain_', 'domain_id', 'domain_template_id');
            if ($domain_template_id) {
                $domain_name_servers = getNameFromID($domain_template_id, 'fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'domains', 'domain_', 'domain_id', 'domain_name_servers');
            } else {
                $domain_name_servers = getNameFromID($domain_clone_domain_id, 'fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'domains', 'domain_', 'domain_id', 'domain_name_servers');
            }
        }
        $domain_name = function_exists('idn_to_utf8') ? idn_to_utf8($domain_name) : $domain_name;
        /** Process multiple views */
        if (strpos($domain_view, ';')) {
            $domain_view = explode(';', rtrim($domain_view, ';'));
            if (in_array('0', $domain_view)) {
                $domain_view = 0;
            }
        }
        /** Process multiple domain name servers */
        if (strpos($domain_name_servers, ';')) {
            $domain_name_servers = explode(';', rtrim($domain_name_servers, ';'));
            if (in_array('0', $domain_name_servers)) {
                $domain_name_servers = 0;
            }
        }
        /** Get field length */
        $domain_name_length = getColumnLength('fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'domains', 'domain_name');
        $views = buildSelect('domain_view', 'domain_view', $this->availableViews(), $domain_view, 4, null, true);
        $zone_maps = buildSelect('domain_mapping', 'domain_mapping', enumMYSQLSelect('fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'domains', 'domain_mapping'), $map, 1, $disabled);
        $domain_types = buildSelect('domain_type', 'domain_type', enumMYSQLSelect('fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'domains', 'domain_type'), $domain_type, 1, $disabled);
        $clone = buildSelect('domain_clone_domain_id', 'domain_clone_domain_id', $this->availableCloneDomains($map, $domain_id), $domain_clone_domain_id, 1, $disabled);
        $name_servers = buildSelect('domain_name_servers', 'domain_name_servers', availableDNSServers('id'), $domain_name_servers, 1, null, true);
        $forwarders_show = $masters_show = 'none';
        $domain_forward_servers = $domain_master_servers = $domain_forward = null;
        $available_acls = json_encode(array());
        if ($domain_type == 'forward') {
            $forwarders_show = 'block';
            $domain_forward_servers = str_replace(';', "\n", rtrim(str_replace(' ', '', getNameFromID($domain_id, 'fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'config', 'cfg_', 'domain_id', 'cfg_data', null, "AND cfg_name='forwarders'")), ';'));
            $domain_forward = getNameFromID($domain_id, 'fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'config', 'cfg_', 'domain_id', 'cfg_data', null, "AND cfg_name='forward'");
            $available_acls = $fm_dns_acls->buildACLJSON($domain_forward_servers, 0, 'none');
        } elseif (in_array($domain_type, array('slave', 'stub'))) {
            $masters_show = 'block';
            $domain_master_servers = str_replace(';', "\n", rtrim(str_replace(' ', '', getNameFromID($domain_id, 'fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'config', 'cfg_', 'domain_id', 'cfg_data', null, "AND cfg_name='masters'")), ';'));
            $available_acls = $fm_dns_acls->buildACLJSON($domain_master_servers, 0, 'none');
        }
        /** Build forward options */
        $query = "SELECT def_type,def_dropdown FROM fm_{$__FM_CONFIG[$_SESSION['module']]['prefix']}functions WHERE def_option = 'forward'";
        $fmdb->get_results($query);
        if ($fmdb->num_rows) {
            $forward_dropdown = $fm_module_options->populateDefTypeDropdown($fmdb->last_result[0]->def_type, $domain_forward, 'domain_forward');
        }
        if ($action == 'create') {
            $domain_template_id = $this->getDefaultZone();
            $zone_show = $domain_template_id ? 'none' : 'block';
            global $fm_dns_records;
            if (!isset($fm_dns_records)) {
                include ABSPATH . 'fm-modules/' . $_SESSION['module'] . '/classes/class_records.php';
            }
            $soa_templates = '<tr id="define_soa">
					<th>SOA</th>
					<td>' . buildSelect('soa_id', 'soa_id', $fm_dns_records->availableSOATemplates($map), $fm_dns_records->getDefaultSOA()) . '</td></tr>';
        } else {
            $zone_show = 'block';
            $soa_templates = $domain_templates = null;
        }
        /** Clone options */
        if ($domain_clone_domain_id) {
            $clone_override_show = 'block';
            $clone_dname_checked = $domain_clone_dname ? 'checked' : null;
            $clone_dname_options_show = $domain_clone_dname ? 'block' : 'none';
            if (isset($no_template)) {
                $domain_template_id = 0;
                $zone_show = 'block';
            }
        } else {
            $clone_override_show = $clone_dname_options_show = 'none';
            $clone_dname_checked = null;
        }
        $clone_dname_dropdown = buildSelect('domain_clone_dname', 'domain_clone_dname', enumMYSQLSelect('fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'domains', 'domain_clone_dname'), $domain_clone_dname);
        $additional_config_link = $action == 'create' || !in_array($domain_type, array('master', 'slave')) || !currentUserCan('manage_servers', $_SESSION['module']) ? null : sprintf('<tr class="include-with-template"><td></td><td><p><a href="config-options.php?domain_id=%d">%s</a></p></td></tr>', $domain_id, __('Configure Additional Options'));
        $popup_title = $action == 'create' ? __('Add Zone') : __('Edit Zone');
        $popup_header = buildPopup('header', $popup_title);
        $popup_footer = buildPopup('footer');
        if (array_search('create_template', $show) !== false) {
            $template_name_show_hide = 'none';
            $create_template = sprintf('<tr id="create_template">
			<th>%s</th>
			<td><input type="checkbox" id="domain_create_template" name="domain_template" value="yes" /><label for="domain_create_template"> %s</label></td>
		</tr>', __('Create Template'), __('yes'));
        } else {
            $template_name_show_hide = 'table-row';
            $create_template = <<<HTML
\t\t\t<input type="hidden" id="domain_create_template" name="domain_template" value="no" />
\t\t\t<input type="hidden" name="domain_default" value="no" />
HTML;
        }
        if (array_search('template_menu', $show) !== false) {
            $classes = 'zone-form';
            $select_template = '<tr id="define_template" class="include-with-template">
					<th>' . __('Template') . '</th>
					<td>' . buildSelect('domain_template_id', 'domain_template_id', $this->availableZoneTemplates(), $domain_template_id);
            if ($action == 'edit') {
                $select_template .= sprintf('<p>%s</p>', __('Changing the template will delete all config options for this zone.'));
            }
            $select_template .= '</td></tr>';
        } else {
            $classes = 'zone-template-form';
            $select_template = null;
        }
        if (array_search('template_name', $show) !== false) {
            $default_checked = $domain_id == $this->getDefaultZone() ? 'checked' : null;
            $template_name = sprintf('<tr id="domain_template_default" style="display: %s">
			<th></th>
			<td><input type="checkbox" id="domain_default" name="domain_default" value="yes" %s /><label for="domain_default"> %s</label></td>
			<input type="hidden" id="domain_create_template" name="domain_template" value="yes" />
		</tr>', $template_name_show_hide, $default_checked, __('Make Default Template'));
        }
        $return_form = array_search('popup', $show) !== false ? '<form name="manage" id="manage" method="post" action="">' . $popup_header : null;
        $return_form .= sprintf('<input type="hidden" name="action" value="%s" />
			<input type="hidden" name="domain_id" value="%d" />
			<table class="form-table %s">
				<tr class="include-with-template">
					<th><label for="domain_name">%s</label></th>
					<td><input type="text" id="domain_name" name="domain_name" size="40" value="%s" maxlength="%d" /></td>
				</tr>
				%s
				<tr>
					<th><label for="domain_view">%s</label></th>
					<td>%s</td>
				</tr>
				<tr>
					<th><label for="domain_mapping">%s</label></th>
					<td>%s</td>
				</tr>
				<tr>
					<th><label for="domain_type">%s</label></th>
					<td>
						%s
						<div id="define_forwarders" style="display: %s">
							<p>%s</p>
							<input type="hidden" name="domain_required_servers[forwarders]" id="domain_required_servers" class="address_match_element" data-placeholder="%s" value="%s" /><br />
							( address_match_element )
						</div>
						<div id="define_masters" style="display: %s">
							<input type="hidden" name="domain_required_servers[masters]" id="domain_required_servers" class="address_match_element" data-placeholder="%s" value="%s" /><br />
							( address_match_element )
						</div>
					</td>
				</tr>
				<tr>
					<th><label for="domain_clone_domain_id">%s</label></th>
					<td>
						%s
						<div id="clone_override" style="display: %s">
							<p><input type="checkbox" id="domain_clone_dname_override" name="domain_clone_dname_override" value="yes" %s /><label for="domain_clone_dname_override"> %s</label></p>
							<div id="clone_dname_options" style="display: %s">
								%s
							</div>
						</div>
					</td>
				</tr>
				<tr>
					<th><label for="domain_name_servers">%s</label></th>
					<td>%s</td>
				</tr>
				%s
			</table>', $action, $domain_id, $classes, __('Domain Name'), $domain_name, $domain_name_length, $select_template, __('Views'), $views, __('Zone Map'), $zone_maps, __('Zone Type'), $domain_types, $forwarders_show, $forward_dropdown, __('Define forwarders'), $domain_forward_servers, $masters_show, __('Define masters'), $domain_master_servers, __('Clone Of (optional)'), $clone, $clone_override_show, $clone_dname_checked, __('Override DNAME Resource Record Setting'), $clone_dname_options_show, $clone_dname_dropdown, __('DNS Servers'), $name_servers, $soa_templates . $additional_config_link . $create_template . $template_name);
        $return_form .= array_search('popup', $show) !== false ? $popup_footer . '</form>' : null;
        $return_form .= <<<HTML
\t\t<script>
\t\t\t\$(document).ready(function() {
\t\t\t\t\$("#manage select").select2({
\t\t\t\t\twidth: '100%',
\t\t\t\t\tminimumResultsForSearch: 10,
\t\t\t\t\tallowClear: true
\t\t\t\t});
\t\t\t\t\$(".address_match_element").select2({
\t\t\t\t\tcreateSearchChoice:function(term, data) { 
\t\t\t\t\t\tif (\$(data).filter(function() { 
\t\t\t\t\t\t\treturn this.text.localeCompare(term)===0; 
\t\t\t\t\t\t}).length===0) 
\t\t\t\t\t\t{return {id:term, text:term};} 
\t\t\t\t\t},
\t\t\t\t\tmultiple: true,
\t\t\t\t\twidth: '300px',
\t\t\t\t\ttokenSeparators: [",", " ", ";"],
\t\t\t\t\tdata: {$available_acls}
\t\t\t\t});
\t\t\t\t\$("#domain_clone_dname_override").click(function() {
\t\t\t\t\tif (\$(this).is(':checked')) {
\t\t\t\t\t\t\$('#clone_dname_options').show('slow');
\t\t\t\t\t} else {
\t\t\t\t\t\t\$('#clone_dname_options').slideUp();
\t\t\t\t\t}
\t\t\t\t});
\t\t\t\t\$("#domain_create_template").click(function() {
\t\t\t\t\tif (\$(this).is(':checked')) {
\t\t\t\t\t\t\$('#domain_template_name').show('slow');
\t\t\t\t\t} else {
\t\t\t\t\t\t\$('#domain_template_name').slideUp();
\t\t\t\t\t}
\t\t\t\t});
\t\t\t\tif (\$('#domain_template_id').val() != '') {
\t\t\t\t\t\$('.zone-form > tbody > tr:not(.include-with-template, #domain_template_default)').slideUp();
\t\t\t\t} else {
\t\t\t\t\t\$('.zone-form > tbody > tr:not(.include-with-template, #domain_template_default)').show('slow');
\t\t\t\t}
\t\t\t\tif (\$('#domain_clone_domain_id').val() != '') {
\t\t\t\t\t\$('.zone-form > tbody > tr#define_soa').slideUp();
\t\t\t\t\t\$('.zone-form > tbody > tr#create_template').slideUp();
\t\t\t\t} else {
\t\t\t\t\tif(\$('#domain_template_id').val() == '') {
\t\t\t\t\t\t\$('.zone-form > tbody > tr#define_soa').show('slow');
\t\t\t\t\t\t\$('.zone-form > tbody > tr#create_template').show('slow');
\t\t\t\t\t}
\t\t\t\t}
\t\t\t});
\t\t</script>
HTML;
        return $return_form;
    }
Пример #10
0
    /**
     * Displays the form to add new server
     */
    function printForm($data = '', $action = 'add', $type = 'servers')
    {
        global $__FM_CONFIG;
        $server_id = $group_id = 0;
        $server_name = $server_root_dir = $server_zones_dir = $runas = $server_type = $server_update_port = null;
        $server_update_method = $server_key = $server_run_as = $server_config_file = $server_run_as_predefined = null;
        $server_chroot_dir = $group_name = null;
        $server_installed = false;
        if (!empty($_POST) && !array_key_exists('is_ajax', $_POST)) {
            if (is_array($_POST)) {
                extract($_POST);
            }
        } elseif (@is_object($data[0])) {
            extract(get_object_vars($data[0]));
        }
        if ($type == 'groups') {
            $server_id = $group_id;
        }
        if ($action == 'add') {
            $popup_title = $type == 'servers' ? __('Add Server') : __('Add Group');
        } else {
            $popup_title = $type == 'servers' ? __('Edit Server') : __('Edit Group');
        }
        $popup_header = buildPopup('header', $popup_title);
        $popup_footer = buildPopup('footer');
        $return_form = <<<FORM
\t\t\t<form name="manage" id="manage" method="post" action="?type={$type}">
\t\t\t{$popup_header}
\t\t\t\t<input type="hidden" name="action" value="{$action}" />
\t\t\t\t<input type="hidden" name="server_id" value="{$server_id}" />
\t\t\t\t<input type="hidden" name="sub_type" value="{$type}" />
FORM;
        if ($type == 'servers') {
            /** Show/hide divs */
            if (isset($server_run_as_predefined) && $server_run_as_predefined == 'as defined:') {
                $runashow = 'block';
            } else {
                $runashow = 'none';
                $server_run_as = null;
            }
            $server_update_port_style = $server_update_method == 'cron' ? 'style="display: none;"' : 'style="display: block;"';
            $disabled = $server_installed == 'yes' ? 'disabled' : null;
            if ($server_installed == 'yes') {
                if (strpos($server_update_method, 'http') === false) {
                    $server_update_method_choices = array($server_update_method);
                } else {
                    $server_update_method_choices = array('http', 'https');
                }
            } else {
                $server_update_method_choices = enumMYSQLSelect('fm_' . $__FM_CONFIG[$_SESSION['module']]['prefix'] . 'servers', 'server_update_method');
            }
            /** Check name field length */
            $server_name_length = getColumnLength('fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'servers', 'server_name');
            $server_config_file_length = getColumnLength('fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'servers', 'server_config_file');
            $server_root_dir_length = getColumnLength('fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'servers', 'server_root_dir');
            $server_chroot_dir_length = getColumnLength('fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'servers', 'server_chroot_dir');
            $server_zones_dir_length = getColumnLength('fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'servers', 'server_zones_dir');
            $server_type = buildSelect('server_type', 'server_type', enumMYSQLSelect('fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'servers', 'server_type'), $server_type, 1);
            $server_update_method = buildSelect('server_update_method', 'server_update_method', $server_update_method_choices, $server_update_method, 1);
            $server_key = buildSelect('server_key', 'server_key', $this->availableItems('key'), $server_key);
            $server_run_as_predefined = buildSelect('server_run_as_predefined', 'server_run_as_predefined', enumMYSQLSelect('fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'servers', 'server_run_as_predefined'), $server_run_as_predefined, 1, '', false, "showHideBox('run_as', 'server_run_as_predefined', 'as defined:')");
            $alternative_help = $action == 'add' && getOption('client_auto_register') ? sprintf('<p><b>%s</b> %s</p>', __('Note:'), __('The client installer can automatically generate this entry.')) : null;
            $return_form .= $alternative_help . sprintf('<table class="form-table">
				<tr>
					<th width="33&#37;" scope="row"><label for="server_name">%s</label></th>
					<td width="67&#37;"><input name="server_name" id="server_name" type="text" value="%s" size="40" placeholder="dns1.local" maxlength="%d" /></td>
				</tr>
				<tr>
					<th width="33&#37;" scope="row"><label for="server_key">%s</label></th>
					<td width="67&#37;">%s</td>
				</tr>
				<tr>
					<th width="33&#37;" scope="row"><label for="server_type">%s</label></th>
					<td width="67&#37;">%s</td>
				</tr>
				<tr>
					<th width="33&#37;" scope="row"><label for="server_run_as_predefined">%s</label></th>
					<td width="67&#37;">%s
					<div id="run_as" style="display: %s"><input name="server_run_as" id="server_run_as" type="text" placeholder="%s" value="%s" /></div></td>
				</tr>
				<tr>
					<th width="33&#37;" scope="row"><label for="server_update_method">%s</label></th>
					<td width="67&#37;">%s<div id="server_update_port_option" %s><input type="number" name="server_update_port" value="%s" placeholder="80" onkeydown="return validateNumber(event)" maxlength="5" max="65535" /></div></td>
				</tr>
				<tr>
					<th width="33&#37;" scope="row"><label for="server_config_file">%s</label></th>
					<td width="67&#37;"><input name="server_config_file" id="server_config_file" type="text" value="%s" size="40" placeholder="%s" maxlength="%s" /></td>
				</tr>
				<tr>
					<th width="33&#37;" scope="row"><label for="server_root_dir">%s</label></th>
					<td width="67&#37;"><input name="server_root_dir" id="server_root_dir" type="text" value="%s" size="40" placeholder="%s" maxlength="%s" /></td>
				</tr>
				<tr>
					<th width="33&#37;" scope="row"><label for="server_chroot_dir">%s</label></th>
					<td width="67&#37;"><input name="server_chroot_dir" id="server_chroot_dir" type="text" value="%s" size="40" placeholder="%s" maxlength="%s" /></td>
				</tr>
				<tr>
					<th width="33&#37;" scope="row"><label for="server_zones_dir">%s</label></th>
					<td width="67&#37;"><input name="server_zones_dir" id="server_zones_dir" type="text" value="%s" size="40" placeholder="%s" maxlength="%s" /></td>
				</tr>
			</table>
		%s
		</form>
		<script>
			$(document).ready(function() {
				$("#manage select").select2({
					minimumResultsForSearch: 10,
					allowClear: true
				});
			});
		</script>', __('Server Name'), $server_name, $server_name_length, __('Key'), $server_key, __('Server Type'), $server_type, __('Run-as Account'), $server_run_as_predefined, $runashow, __('Other run-as account'), $server_run_as, __('Update Method'), $server_update_method, $server_update_port_style, $server_update_port, __('Config File'), $server_config_file, $__FM_CONFIG['ns']['named_config_file'], $server_config_file_length, __('Server Root'), $server_root_dir, $__FM_CONFIG['ns']['named_root_dir'], $server_root_dir_length, __('Server Chroot'), $server_chroot_dir, $__FM_CONFIG['ns']['named_chroot_dir'], $server_chroot_dir_length, __('Zone File Directory'), $server_zones_dir, $__FM_CONFIG['ns']['named_zones_dir'], $server_zones_dir_length, $popup_footer);
        } elseif ($type == 'groups') {
            $group_masters = isset($group_masters) ? explode(';', $group_masters) : null;
            $group_slaves = isset($group_slaves) ? explode(';', $group_slaves) : null;
            $group_name_length = getColumnLength('fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'server_groups', 'group_name');
            $group_masters = buildSelect('group_masters', 'group_masters', $this->availableItems('server'), $group_masters, 1, null, true, null, null, __('Select master servers'));
            $group_slaves = buildSelect('group_slaves', 'group_slaves', $this->availableItems('server'), $group_slaves, 1, null, true, null, null, __('Select slave servers'));
            $return_form .= sprintf('
			<table class="form-table">
				<tr>
					<th width="33&#37;" scope="row"><label for="group_name">%s</label></th>
					<td width="67&#37;"><input name="group_name" id="group_name" type="text" value="%s" size="40" maxlength="%d" /></td>
				</tr>
				<tr>
					<th width="33&#37;" scope="row"><label for="group_masters">%s</label></th>
					<td width="67&#37;">%s</td>
				</tr>
				<tr>
					<th width="33&#37;" scope="row"><label for="group_slaves">%s</label></th>
					<td width="67&#37;">%s</td>
				</tr>
			</table>
		%s
		</form>
		<script>
			$(document).ready(function() {
				$("#manage select").select2({
					minimumResultsForSearch: 10,
					allowClear: true,
					width: "230px"
				});
			});
		</script>', __('Group Name'), $group_name, $group_name_length, __('Master Servers'), $group_masters, __('Slave Servers'), $group_slaves, $popup_footer);
        } else {
            $return_form = buildPopup('header', _('Error'));
            $return_form .= sprintf('<h3>%s</h3><p>%s</p>', __('Oops!'), __('Invalid request.'));
            $return_form .= buildPopup('footer', _('OK'), array('cancel'));
        }
        return $return_form;
    }
Пример #11
0
 function getInputForm($type, $new, $parent_domain_id, $results = null, $start = 1)
 {
     global $__FM_CONFIG, $zone_access_allowed;
     $form = $record_status = $record_class = $record_name = $record_ttl = null;
     $record_value = $record_comment = $record_priority = $record_weight = $record_port = null;
     $action = $new ? 'create' : 'update';
     $end = $new ? $start + 3 : 1;
     $show_value = true;
     $value_textarea = false;
     $append = array('CNAME', 'NS', 'MX', 'SRV', 'DNAME', 'CERT', 'RP');
     $priority = array('MX', 'SRV', 'KX');
     if ($results) {
         $results = get_object_vars($results);
         extract($results);
     }
     $yeschecked = isset($record_append) && $record_append == 'yes' ? 'checked' : '';
     $nochecked = isset($record_append) && $record_append == 'no' ? 'checked' : '';
     $statusopt[0][] = __('Active');
     $statusopt[0][] = 'active';
     $statusopt[1][] = __('Disabled');
     $statusopt[1][] = 'disabled';
     $status = BuildSelect($action . '[_NUM_][record_status]', 'status__NUM_', $statusopt, $record_status);
     $field_values['class'] = $record_status;
     $class = buildSelect($action . '[_NUM_][record_class]', 'class__NUM_', enumMYSQLSelect('fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'records', 'record_class'), $record_class);
     if ($type == 'PTR') {
         $domain_map = getNameFromID($parent_domain_id, 'fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'domains', 'domain_', 'domain_id', 'domain_mapping');
     }
     $domain = getNameFromID($parent_domain_id, 'fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'domains', 'domain_', 'domain_id', 'domain_name');
     if ((currentUserCan('manage_records', $_SESSION['module']) || currentUserCan('manage_zones', $_SESSION['module'])) && $zone_access_allowed && ($new || $domain_id == $parent_domain_id)) {
         if ($type == 'PTR') {
             $input_box = '<input ';
             $input_box .= $domain_map == 'forward' ? 'size="40"' : 'style="width: 40px;" size="4"';
             $input_box .= ' type="text" name="' . $action . '[_NUM_][record_name]" value="' . $record_name . '" />';
             if (strpos($domain, 'arpa')) {
                 $field_values['data']['Record'] = '>' . $input_box . ' .' . $domain;
             } elseif ($domain_map == 'forward') {
                 $field_values['data']['Record'] = '>' . $input_box;
             } else {
                 $field_values['data']['Record'] = '>' . $domain . '. ' . $input_box;
             }
         } else {
             $field_values['data']['Record'] = '><input size="40" type="text" name="' . $action . '[_NUM_][record_name]" value="' . $record_name . '" />';
         }
         $field_values['data']['TTL'] = '><input style="width: 35px;" type="text" name="' . $action . '[_NUM_][record_ttl]" value="' . $record_ttl . '" onkeydown="return validateNumber(event)" />';
         $field_values['data']['Class'] = '>' . $class;
         if ($type == 'CERT') {
             $field_values['data']['Type'] = '>' . buildSelect($action . '[_NUM_][record_cert_type]', '_NUM_', $__FM_CONFIG['records']['cert_types'], $record_cert_type);
             $field_values['data']['Key Tag'] = '><input style="width: 45px;" type="text" name="' . $action . '[_NUM_][record_key_tag]" value="' . $record_key_tag . '" onkeydown="return validateNumber(event)" />';
             $field_values['data']['Algorithm'] = '>' . buildSelect($action . '[_NUM_][record_algorithm]', '_NUM_', $__FM_CONFIG['records']['cert_algorithms'], $record_algorithm);
             $value_textarea = true;
         }
         if ($type == 'SSHFP') {
             $field_values['data']['Algorithm'] = '>' . buildSelect($action . '[_NUM_][record_algorithm]', '_NUM_', $__FM_CONFIG['records']['sshfp_algorithms'], $record_algorithm);
             $value_textarea = true;
         }
         if ($type == 'HINFO') {
             $field_values['data']['Hardware'] = '><input maxlength="255" type="text" name="' . $action . '[_NUM_][record_value]" value="' . $record_value . '" />';
             $field_values['data']['OS'] = '><input maxlength="255" type="text" name="' . $action . '[_NUM_][record_os]" value="' . $record_os . '" />';
             $show_value = false;
         }
         if (in_array($type, array('DNSKEY', 'KEY'))) {
             $flags = enumMYSQLSelect('fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'records', 'record_flags');
             $algorithms = $__FM_CONFIG['records']['cert_algorithms'];
             $value_textarea = true;
             if ($type == 'KEY') {
                 array_pop($flags);
                 for ($i = 1; $i <= 4; $i++) {
                     array_pop($algorithms);
                 }
             }
             $field_values['data']['Flags'] = '>' . buildSelect($action . '[_NUM_][record_flags]', '_NUM_', $flags, $record_flags);
             $field_values['data']['Algorithm'] = '>' . buildSelect($action . '[_NUM_][record_algorithm]', '_NUM_', $algorithms, $record_algorithm);
         }
         if ($show_value) {
             if ($value_textarea) {
                 $field_values['data']['Value'] = '><textarea rows="2" name="' . $action . '[_NUM_][record_value]">' . $record_value . '</textarea>';
             } else {
                 $field_values['data']['Value'] = '><input size="40" type="text" name="' . $action . '[_NUM_][record_value]" value="' . $record_value . '" />';
             }
         }
         if ($type == 'RP') {
             $field_values['data']['Text'] = '><input maxlength="255" type="text" name="' . $action . '[_NUM_][record_text]" value="' . $record_text . '" />';
         }
         if (in_array($type, $priority)) {
             $field_values['data']['Priority'] = '><input style="width: 35px;" type="text" name="' . $action . '[_NUM_][record_priority]" value="' . $record_priority . '" onkeydown="return validateNumber(event)" />';
         }
         if ($type == 'SRV') {
             $field_values['data']['Weight'] = '><input style="width: 35px;" type="text" name="' . $action . '[_NUM_][record_weight]" value="' . $record_weight . '" onkeydown="return validateNumber(event)" />';
             $field_values['data']['Port'] = '><input style="width: 35px;" type="text" name="' . $action . '[_NUM_][record_port]" value="' . $record_port . '" onkeydown="return validateNumber(event)" />';
         }
         $field_values['data']['Comment'] = '><input maxlength="200" type="text" name="' . $action . '[_NUM_][record_comment]" value="' . $record_comment . '" />';
         if (in_array($type, $append)) {
             $field_values['data']['Append Domain'] = ' align="center"><input ' . $yeschecked . ' type="radio" id="record_append[_NUM_][0]" name="' . $action . '[_NUM_][record_append]" value="yes" /><label class="radio" for="record_append[_NUM_][0]"> ' . __('yes') . '</label> <input ' . $nochecked . ' type="radio" id="record_append[_NUM_][1]" name="' . $action . '[_NUM_][record_append]" value="no" /><label class="radio" for="record_append[_NUM_][1]"> ' . __('no') . '</label>';
         }
         $field_values['data']['Status'] = '>' . $status;
         if ($new) {
             $field_values['data']['Actions'] = in_array($type, array('A')) ? ' align="center"><label><input type="checkbox" name="' . $action . '[_NUM_][PTR]" />' . __('Create PTR') . '</label>' : null;
         } else {
             $field_values['data']['Actions'] = in_array($type, array('A')) ? ' align="center"><label><input type="checkbox" name="' . $action . '[_NUM_][PTR]" />' . __('Create PTR') . '</label><br />' : ' align="center">';
             $field_values['data']['Actions'] .= '<label><input type="checkbox" id="record_delete_' . $record_id . '" name="' . $action . '[_NUM_][Delete]" />' . __('Delete') . '</label>';
         }
     } else {
         $domain = strlen($domain) > 23 ? substr($domain, 0, 20) . '...' : $domain;
         $field_values['data']['Record'] = '>' . $record_name . '<span class="grey">.' . $domain . '</span>';
         $field_values['data']['TTL'] = '>' . $record_ttl;
         $field_values['data']['Class'] = '>' . $record_class;
         if ($show_value) {
             $field_values['data']['Value'] = '>' . $record_value;
         }
         $field_values['data']['Comment'] = '>' . $record_comment;
         if (in_array($type, $priority)) {
             $field_values['data']['Priority'] = '>' . $record_priority;
         }
         if ($type == 'SRV') {
             $field_values['data']['Weight'] = '>' . $record_weight;
             $field_values['data']['Port'] = '>' . $record_port;
         }
         if (in_array($type, $append)) {
             $field_values['data']['Append Domain'] = ' style="text-align: center;">' . $record_append;
         }
         $field_values['data']['Status'] = '>' . $record_status;
         if ((currentUserCan('manage_records', $_SESSION['module']) || currentUserCan('manage_zones', $_SESSION['module'])) && $zone_access_allowed && $domain_id != $parent_domain_id) {
             $field_values['data']['Actions'] = ' align="center"><input type="hidden" name="' . $action . '[_NUM_][record_skipped]" value="off" /><label><input type="checkbox" name="' . $action . '[_NUM_][record_skipped]" ';
             if (in_array($record_id, $this->getSkippedRecordIDs($parent_domain_id))) {
                 $field_values['data']['Actions'] .= ' checked';
                 $field_values['class'] = 'disabled';
             } else {
                 $field_values['data']['Actions'] .= null;
             }
             $field_values['data']['Actions'] .= '/>' . __('Skip Import') . '</label>';
         } elseif (!currentUserCan('manage_records', $_SESSION['module']) && $zone_access_allowed && $domain_id != $parent_domain_id) {
             if (in_array($record_id, $this->getSkippedRecordIDs($parent_domain_id))) {
                 return null;
             }
         }
     }
     for ($i = $start; $i <= $end; $i++) {
         $form .= '<tr class="' . $field_values['class'] . '">' . "\n";
         foreach ($field_values['data'] as $key => $val) {
             $val = !$val ? '>' : $val;
             $num = $new ? $i : $record_id;
             $val = str_replace('_NUM_', $num, $val);
             $form .= "\t<td{$val}</td>\n";
         }
         $form .= "</tr>\n";
     }
     return $form;
 }
Пример #12
0
    /**
     * Displays the form to add new key
     */
    function printForm($data = '', $action = 'add')
    {
        global $__FM_CONFIG, $fm_dns_zones;
        include_once ABSPATH . 'fm-modules/fmDNS/classes/class_zones.php';
        $key_id = 0;
        $key_name = $key_root_dir = $key_zones_dir = $key_comment = null;
        $ucaction = ucfirst($action);
        $key_algorithm = $key_view = $key_secret = null;
        if (!empty($_POST) && !array_key_exists('is_ajax', $_POST)) {
            if (is_array($_POST)) {
                extract($_POST);
            }
        } elseif (@is_object($data[0])) {
            extract(get_object_vars($data[0]));
        }
        /** Check name field length */
        $key_name_length = getColumnLength('fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'keys', 'key_name');
        $key_secret_length = getColumnLength('fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'keys', 'key_secret');
        $key_algorithm = buildSelect('key_algorithm', 'key_algorithm', enumMYSQLSelect('fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'keys', 'key_algorithm'), $key_algorithm, 1);
        $key_view = buildSelect('key_view', 'key_view', $fm_dns_zones->availableViews(), $key_view);
        $popup_title = $action == 'add' ? __('Add Key') : __('Edit Key');
        $popup_header = buildPopup('header', $popup_title);
        $popup_footer = buildPopup('footer');
        $return_form = sprintf('<form name="manage" id="manage" method="post" action="">
		%s
			<input type="hidden" name="action" value="%s" />
			<input type="hidden" name="key_id" value="%d" />
			<table class="form-table">
				<tr>
					<th width="33&#37;" scope="row"><label for="key_name">%s</label></th>
					<td width="67&#37;"><input name="key_name" id="key_name" type="text" value="%s" size="40" maxlength="%d" /></td>
				</tr>
				<tr>
					<th width="33&#37;" scope="row"><label for="key_view">%s</label></th>
					<td width="67&#37;">%s</td>
				</tr>
				<tr>
					<th width="33&#37;" scope="row"><label for="key_algorithm">%s</label></th>
					<td width="67&#37;">%s</td>
				</tr>
				<tr>
					<th width="33&#37;" scope="row"><label for="key_secret">%s</label></th>
					<td width="67&#37;"><input name="key_secret" id="key_secret" type="text" value="%s" size="40" maxlength="%d" /></td>
				</tr>
				<tr>
					<th width="33&#37;" scope="row"><label for="key_comment">%s</label></th>
					<td width="67&#37;"><textarea id="key_comment" name="key_comment" rows="4" cols="30">%s</textarea></td>
				</tr>
			</table>
		%s
		</form>
		<script>
			$(document).ready(function() { $("#manage select").select2({minimumResultsForSearch: 10}); });
		</script>', $popup_header, $action, $key_id, __('Key Name'), $key_name, $key_name_length, __('View'), $key_view, __('Algorithm'), $key_algorithm, __('Secret'), $key_secret, $key_secret_length, __('Comment'), $key_comment, $popup_footer);
        return $return_form;
    }
Пример #13
0
    /**
     * Displays the form to add new acl
     */
    function printForm($data = '', $action = 'add')
    {
        global $__FM_CONFIG;
        $acl_id = 0;
        $acl_name = $acl_addresses = $acl_comment = null;
        $acl_predefined = 'as defined:';
        $ucaction = ucfirst($action);
        $server_serial_no = isset($_REQUEST['request_uri']['server_serial_no']) && (is_int($_REQUEST['request_uri']['server_serial_no']) && $_REQUEST['request_uri']['server_serial_no'] > 0 || $_REQUEST['request_uri']['server_serial_no'][0] == 'g') ? sanitize($_REQUEST['request_uri']['server_serial_no']) : 0;
        if (!empty($_POST) && !array_key_exists('is_ajax', $_POST)) {
            if (is_array($_POST)) {
                extract($_POST);
            }
        } elseif (@is_object($data[0])) {
            extract(get_object_vars($data[0]));
        }
        $acl_predefined = buildSelect('acl_predefined', 'acl_predefined', enumMYSQLSelect('fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'acls', 'acl_predefined'), $acl_predefined);
        $acl_addresses = str_replace(',', "\n", rtrim(str_replace(' ', '', $acl_addresses), ';'));
        /** Get field length */
        $acl_name_length = getColumnLength('fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'acls', 'acl_name');
        $popup_title = $action == 'add' ? __('Add ACL') : __('Edit ACL');
        $popup_header = buildPopup('header', $popup_title);
        $popup_footer = buildPopup('footer');
        $return_form = sprintf('<form name="manage" id="manage" method="post" action="">
		%s
			<input type="hidden" name="action" value="%s" />
			<input type="hidden" name="acl_id" value="%d" />
			<input type="hidden" name="server_serial_no" value="%s" />
			<table class="form-table">
				<tr>
					<th width="33&#37;" scope="row"><label for="acl_name">%s</label></th>
					<td width="67&#37;"><input name="acl_name" id="acl_name" type="text" value="%s" size="40" placeholder="%s" maxlength="%d" /></td>
				</tr>
				<tr>
					<th width="33&#37;" scope="row"><label for="acl_predefined">%s</label></th>
					<td width="67&#37;">%s<br />
					<textarea name="acl_addresses" rows="7" cols="28" placeholder="%s">%s</textarea></td>
				</tr>
				<tr>
					<th width="33&#37;" scope="row"><label for="acl_comment">%s</label></th>
					<td width="67&#37;"><textarea id="acl_comment" name="acl_comment" rows="4" cols="30">%s</textarea></td>
				</tr>
			</table>
		%s
		</form>
		<script>
			$(document).ready(function() {
				$("#manage select").select2({
					width: "200px",
					minimumResultsForSearch: 10
				});
			});
		</script>', $popup_header, $action, $acl_id, $server_serial_no, __('ACL Name'), $acl_name, __('internal'), $acl_name_length, __('Matched Address List'), $acl_predefined, __('Addresses and subnets delimited by space, semi-colon, or newline'), $acl_addresses, __('Comment'), $acl_comment, $popup_footer);
        return $return_form;
    }
Пример #14
0
    /**
     * Displays the form to add new service
     */
    function printForm($data = '', $action = 'add', $type = 'icmp')
    {
        global $__FM_CONFIG;
        $service_id = 0;
        $service_name = $service_tcp_flags = $service_comment = null;
        $service_icmp_type = $service_icmp_code = null;
        $ucaction = ucfirst($action);
        if (!empty($_POST) && !array_key_exists('is_ajax', $_POST)) {
            if (is_array($_POST)) {
                extract($_POST);
            }
        } elseif (@is_object($data[0])) {
            extract(get_object_vars($data[0]));
        }
        /** Show/hide divs */
        if ($type == 'icmp') {
            $icmp_option = 'block';
            $tcpudp_option = $tcp_option = 'none';
        } elseif ($type == 'tcp') {
            $icmp_option = 'none';
            $tcpudp_option = $tcp_option = 'block';
        } else {
            $icmp_option = $tcp_option = 'none';
            $tcpudp_option = 'block';
        }
        $service_name_length = getColumnLength('fm_' . $__FM_CONFIG[$_SESSION['module']]['prefix'] . 'services', 'service_name');
        $service_type = buildSelect('service_type', 'service_type', enumMYSQLSelect('fm_' . $__FM_CONFIG[$_SESSION['module']]['prefix'] . 'services', 'service_type'), $type, 1);
        @(list($port_src_start, $port_src_end) = explode(':', $service_src_ports));
        @(list($port_dest_start, $port_dest_end) = explode(':', $service_dest_ports));
        /** Process TCP Flags */
        @(list($tcp_flag_mask, $tcp_flag_settings) = explode(':', $service_tcp_flags));
        $tcp_flags_mask_form = $tcp_flags_settings_form = $tcp_flags_head = null;
        foreach ($__FM_CONFIG['tcp_flags'] as $flag => $bit) {
            $tcp_flags_head .= '<th title="' . $flag . '">' . $flag[0] . "</th>\n";
            $tcp_flags_mask_form .= '<td><input type="checkbox" name="service_tcp_flags[mask][' . $bit . ']" ';
            if ($bit & $tcp_flag_mask) {
                $tcp_flags_mask_form .= 'checked';
            }
            $tcp_flags_mask_form .= "/></td>\n";
            $tcp_flags_settings_form .= '<td><input type="checkbox" name="service_tcp_flags[settings][' . $bit . ']" ';
            if ($bit & $tcp_flag_settings) {
                $tcp_flags_settings_form .= 'checked';
            }
            $tcp_flags_settings_form .= "/></td>\n";
        }
        $popup_title = $action == 'add' ? __('Add Service') : __('Edit Service');
        $popup_header = buildPopup('header', $popup_title);
        $popup_footer = buildPopup('footer');
        $return_form = sprintf('<form name="manage" id="manage" method="post" action="?type=%s">
		%s
			<input type="hidden" name="action" value="%s" />
			<input type="hidden" name="service_id" value="%s" />
			<table class="form-table">
				<tr>
					<th width="33&#37;" scope="row"><label for="service_name">%s</label></th>
					<td width="67&#37;"><input name="service_name" id="service_name" type="text" value="%s" size="40" placeholder="http" maxlength="%d" /></td>
				</tr>
				<tr>
					<th width="33&#37;" scope="row"><label for="service_type">%s</label></th>
					<td width="67&#37;">
						%s
						<div id="icmp_option" style="display: %s;">
							<label for="service_icmp_type">Type</label> <input type="number" name="service_icmp_type" value="%s" style="width: 5em;" onkeydown="return validateNumber(event)" placeholder="0" max="40" /><br />
							<label for="service_icmp_code">Code</label> <input type="number" name="service_icmp_code" value="%s" style="width: 5em;" onkeydown="return validateNumber(event)" placeholder="0" max="15" />
						</div>
						<div id="tcpudp_option" style="display: %s;">
							<h4>%s</h4>
							<label for="port_src_start">%s</label> <input type="number" name="port_src[]" value="%s" placeholder="0" style="width: 5em;" onkeydown="return validateNumber(event)" max="65535" /> 
							<label for="port_src_end">%s</label> <input type="number" name="port_src[]" value="%s" placeholder="0" style="width: 5em;" onkeydown="return validateNumber(event)" max="65535" />
							<h4>%s</h4>
							<label for="port_dest_start">%s</label> <input type="number" name="port_dest[]" value="%s" placeholder="0" style="width: 5em;" onkeydown="return validateNumber(event)" max="65535" /> 
							<label for="port_dest_end">%s</label> <input type="number" name="port_dest[]" value="%s" placeholder="0" style="width: 5em;" onkeydown="return validateNumber(event)" max="65535" />
						</div>
						<div id="tcp_option" style="display: %s;">
							<h4>%s</h4>
							<table class="form-table tcp-flags">
								<tbody>
									<tr>
										<th></th>
										%s
									</tr>
									<tr>
										<th style="text-align: right;" title="%s">%s</th>
										%s
									</tr>
									<tr>
										<th style="text-align: right;">%s</th>
										%s
									</tr>
								</tbody>
							</table>
						</div>
					</td>
				</tr>
				<tr>
					<th width="33&#37;" scope="row"><label for="service_comment">%s</label></th>
					<td width="67&#37;"><textarea id="service_comment" name="service_comment" rows="4" cols="30">%s</textarea></td>
				</tr>
			</table>
		%s
		</form>
		<script>
			$(document).ready(function() {
				$("#manage select").select2({
					width: "200px",
					minimumResultsForSearch: 10
				});
			});
		</script>', $type, $popup_header, $action, $service_id, __('Service Name'), $service_name, $service_name_length, __('Service Type'), $service_type, $icmp_option, $service_icmp_type, $service_icmp_code, $tcpudp_option, __('Source Port Range'), __('Start'), $port_src_start, __('End'), $port_src_end, __('Destination Port Range'), __('Start'), $port_dest_start, __('End'), $port_dest_end, $tcp_option, __('TCP Flags'), $tcp_flags_head, __('Only iptables uses the Mask bit'), __('Mask'), $tcp_flags_mask_form, __('Settings'), $tcp_flags_settings_form, __('Comment'), $service_comment, $popup_footer);
        return $return_form;
    }