[%# ts_conf - REQUIRED ts_texts tweakmodule tweakcfg conf nocontainers changed_settings (optional for tweaksettings only right now) -%] [% USE ServerRoles -%] [% USE JSON -%] [% USE Whostmgr -%] [% USE CPHash -%] [% USE CPScalar -%] [% USE CPSort -%] [% USE Encoder -%] [%# could not get scrolling tabs to behave in IE6 -%] [% SET this_is_ie6 = CPANEL.ua_is_ie().match('^6'); -%] [% bootstrap = bootstrap; %] [% UNLESS nocontainers -%]
[% locale.maketext("Find") %] 
[% END -%] [% SET extrascript = ''; IF tweakcfg.extra_settings; FOR settings_key = tweakcfg.extra_settings.keys; ts_conf.$settings_key = tweakcfg.extra_settings.$settings_key; END; END; SET TS_display = ts_display || ts_texts.TS_display; SET make_tabs = TS_display.size > 1; SET hide_group = {}; FOR group_item = TS_display; SET group_shown = 0; FOR setting_name = group_item.1; SET cur_settings = ts_conf.$setting_name; # Sometimes ts_conf is pre-filtered to have removed # role-restricted settings. This handles those cases. IF !cur_settings; NEXT; END; # Check if this setting should be shown (not skipped) SET setting_should_be_shown = 1; # Skip if skipif condition evaluates to true IF cur_settings.exists( 'skipif' ) && ref( \cur_settings.skipif ) == 'CODE' && cur_settings.skipif( conf ); SET setting_should_be_shown = 0; END; # Skip if role restrictions aren't met IF setting_should_be_shown && cur_settings.needs_role && !ServerRoles.are_roles_enabled(cur_settings.needs_role); SET setting_should_be_shown = 0; END; # If at least one setting in the group should be shown, show the group IF setting_should_be_shown; group_shown = 1; LAST; END; END; IF !group_shown; hide_group.${group_item.0} = 1; END; END; IF make_tabs; UNLESS this_is_ie6; '
<
'; '
>
'; '
'; '
'; END; '
    '; FOR group_item = TS_display; SET group = group_item.0; IF !hide_group.$group; SET groupkey = group.replace('[^A-Za-z0-9]',''); SET class_html = loop.last ? ' class="last"' : ''; "\t${group}\n"; END; END; '
' _ "\n"; UNLESS this_is_ie6; '
'; '
'; END; END; '
' _ "\n\n"; FOR group_item = TS_display; SET group = group_item.0; IF hide_group.$group; NEXT; END; SET groupkey = group.replace('[^A-Za-z0-9]',''); SET header_text = ts_headers ? ts_headers.$group ? ts_headers.$group.txt : '' : '' ; '
'; WRAPPER '_brick.tmpl' bootstrap = bootstrap norow=1 bricktitle = group _ ( header_text ? " $header_text" : '' ) brickid = "group_" _ groupkey brickclass = "settingsgroup" ; #do this because we do NEXT IF to some of the rows, which would give #two rows with the same color using loop.index SET row_index = 0; SET sorted_keys = group_item.1; IF tweakcfg.extra_texts && tweakcfg.extra_texts.$group; SET extra_keys = tweakcfg.extra_texts.$group.keys.sort(); SET sorted_keys = sorted_keys.merge( extra_keys ); FOR extra_key = extra_keys; SET ts_texts.$extra_key = tweakcfg.extra_texts.$group.$extra_key; END; END; FOR key = sorted_keys; "\n\n"; SET cur_settings = ts_conf.$key; # Sometimes ts_conf is pre-filtered to have removed # role-restricted settings. This handles those cases. IF !cur_settings; NEXT; END; SET cur_texts = ts_texts.$key; SET cur_label = cur_texts.label || cur_settings.label; NEXT IF cur_settings.exists( 'skipif' ) && ref( \cur_settings.skipif ) == 'CODE' && cur_settings.skipif( conf ) ; SET row_index = row_index + 1; SET tclass = row_index % 2 ? 'tdshade1_noborder' : 'tdshade2_noborder'; ''; IF ! conf.$key.defined; ''; END; IF cur_settings.needs_role && !ServerRoles.are_roles_enabled(cur_settings.needs_role); NEXT; END; SET this_is_a_button = cur_settings && cur_settings.type == 'button'; IF this_is_a_button; IF cur_settings && cur_settings.popup; SET button_html = "${cur_texts.button}"; ELSE; SET button_html = "${cur_texts.button}"; END; #if no label, put the button on the left and then go to the next setting IF !cur_texts.label; ""; button_html; ''; NEXT; END; END; SET newoption_title = ''; IF changed_settings && changed_settings.exists(key); SET newoption = !this_is_a_button; IF newoption; SET newoption_title = locale.maketext('The setting, [_1], has changed since the last time you saved this page.',key); END; ELSE; SET newoption = !this_is_a_button && !conf.exists( key ) && (!cur_settings.save_location || cur_settings.save_location == 'cpanel.config'); IF newoption; SET newoption_title = locale.maketext('The setting, [_1], was not set in the configuration file, so the default has been used.',key); IF cur_settings.exists('default'); SET conf.$key = cur_settings.default; END; END; END; IF cur_settings.requires_test; extrascript = extrascript _ "register_requires_test( '$key', '" _ cur_settings.requires_test.join("','") _ "')\n" ; END; IF cur_settings.excludes; SET excludes = ref ( cur_settings.excludes ) == 'ARRAY' ? cur_settings.excludes : cur_settings.excludes.split(',') ; FOR exclusion = excludes; IF exclusion != key; #cannot exclude self extrascript = extrascript _ "register_exclude('$key','$exclusion');\n"; END; END; END; IF cur_settings.requires; SET requirements = ref ( cur_settings.requires ) == 'ARRAY' ? cur_settings.requires : cur_settings.requires.split(',') ; FOR requirement = requirements; IF requirements != key; #cannot require self extrascript = extrascript _ "register_requires('$key','$requirement');\n"; END; END; END; IF cur_settings.depends; FOR dep = cur_settings.depends; extrascript = extrascript _ "register_depends('$key','$dep');\n"; END; END; IF cur_settings.exists('value'); #ignore the value in the config file and use the value supplied conf.$key = cur_settings.value(conf); END; SET unformatted_value = conf.$key; SET formatted_value = cur_settings.exists( 'format' ) && ref( \cur_settings.format ) == 'CODE' ? cur_settings.format( unformatted_value ) : unformatted_value ; SET formatted_value_enc = formatted_value.cpanel_safe_html_encode_str(); IF newoption || this_is_a_button || cur_settings.type == 'multiselect'; SET is_invalid = 0; ELSE; #undef values are "special" IF cur_settings.type == 'number' && !formatted_value.length; SET formatted_value = UNDEF; SET is_invalid = 0; END; IF formatted_value.defined(); TRY; SET is_invalid = cur_settings.exists( 'checkval' ) && ref( \cur_settings.checkval ) == 'CODE' && ! cur_settings.only_validate_on_change && ! cur_settings.checkval( formatted_value ).defined(); CATCH; SET is_invalid = 1; END; ELSE; #if undef but setting can't disable, then that's invalid SET is_invalid = !cur_settings.can_undef; END; END; IF is_invalid; SET tclass = tclass _ ' invalid'; END; SET range_html = []; IF cur_settings.exists('minimum'); SET minimum = cur_settings.minimum; # If a special formatter is being applied to the displayed value, the same # needs to be done to the displayed minimum, if any. IF cur_settings.exists( 'format' ) && ref( \cur_settings.format ) == 'CODE'; minimum = cur_settings.format( minimum ); END; range_html.push( locale.maketext('Minimum: [numf,_1]',minimum) ); END; IF cur_settings.exists('maximum'); SET maximum = cur_settings.maximum; IF cur_settings.exists( 'format' ) && ref( \cur_settings.format ) == 'CODE'; maximum = cur_settings.format( maximum ); END; range_html.push( locale.maketext('Maximum: [numf,_1]',maximum) ); END; SET range_html = ( range_html.size > 0 ) ? ' (' _ range_html.join('; ') _ ')' : UNDEF ; SET newoption_html = ''; IF newoption; SET newoption_html = '  '; END; SET cur_help = cur_texts.help || cur_settings.help; IF tweakcfg.display_label; IF !cur_help; SET display_html = "
${newoption_html}${cur_label}${range_html}
"; ELSIF tweakcfg.always_show_help; SET display_html = "
${newoption_html}${cur_label}${range_html}
" _ "
" _ "
$cur_help
" _ '
'; ELSE; SET display_html = "
${newoption_html}${cur_label}${range_html}" _ " [?]" _ '
' _ "
" _ "" _ '
' ; END; ELSE; # Adding an alert warning to inform users that their website stats are not available because of # the 'common' setting as LOGSTYLE. IF key == "LOGSTYLE" && formatted_value == "common"; SET common_setting_warning = "
" _ locale.maketext("Your “[_1]” uses the “[_2]” setting. Your website’s stats may not function.", "LOGSTYLE", "COMMON") _ "
"; SET display_html = common_setting_warning _ cur_help; ELSE; SET display_html = cur_help _ range_html; END; END; "\n"; "" _ (debug ? "$key " : '' ) _ display_html _ ( is_invalid ? '

The current value for this field is invalid. You must update it.' : '' ) _ "\n" ; ""; SWITCH cur_settings.type; CASE [ 'button' ]; button_html; #assembled earlier CASE [ 'path' 'text' 'number' 'size' 'password' ]; SET text_type = cur_settings.type == 'password' ? 'password' : 'text' ; SET input_maxlength = cur_settings.exists('maxlength') ? " maxlength='${cur_settings.maxlength}'" : '' ; IF cur_settings.exists('maxlength') && cur_settings.maxlength && cur_settings.exists('size') && cur_settings.size; SET input_size = " size='${cur_settings.size}'"; ELSIF cur_settings.exists('maxlength') && cur_settings.maxlength; SET input_size = " size='${cur_settings.maxlength}'"; ELSIF cur_settings.exists('width') && cur_settings.width; SET input_size = " size='${cur_settings.width}'"; ELSE; SET input_size = ''; END; SET buttons = []; SET use_radio_buttons = cur_settings.options || cur_settings.can_undef || cur_settings.defined( 'default' ); SET cur_radios = cur_settings.options; IF !cur_radios && (cur_settings.can_undef || cur_settings.defined( 'default' )); cur_radios = []; # Note: order in which we push items to the list matters, so we can't # collapse the if logic nicely here. IF cur_settings.can_undef && cur_settings.item( 'default' ).length != 0; cur_radios.push(UNDEF); END; IF cur_settings.defined( 'default' ); cur_radios.push(cur_settings.default); END; IF cur_settings.defined( 'pci' ); cur_radios.push(cur_settings.pci); END; END; IF cur_radios; ""; SET selected_radio = ''; FOR cur_radio = cur_radios; IF !cur_radio.defined; SET undef_is_default = cur_settings.exists( 'default' ) && ! cur_settings.defined( 'default' ) ; IF ( undef_is_default ); SET extrascript = extrascript _ "default_values['$key'] = null;\n"; END; IF is_invalid; SET check_undef = undef_is_default; ELSE; SET check_undef = !formatted_value.defined(); END; IF check_undef; selected_radio = 'undef'; END; buttons.push( '' ); ELSIF cur_radio == cur_settings.default; #in case any Javascript tests on the value SET js_default = cur_settings.default.match('\A\d+(?:\.\d+)\z') ? cur_settings.default + 0 : "'${cur_settings.default}'" ; SET extrascript = extrascript _ "default_values['$key'] = $js_default;\n"; SET cur_default = cur_settings.default; SET default_text = cur_settings.default_text || cur_default; SET cur_radio_checked = is_invalid || formatted_value == cur_default; IF cur_radio_checked; selected_radio = 'default'; END; buttons.push( '' ); ELSIF cur_radio == cur_settings.pci; SET pci_text = cur_settings.pci_text || cur_settings.pci; SET cur_radio_checked = (formatted_value == cur_settings.pci); IF cur_radio_checked; selected_radio = 'pci'; END; buttons.push( '' ); ELSE; SET text_key = "custom_${cur_radio}"; SET cur_radio_text = cur_texts.custom.$cur_radio; SET cur_radio_text = cur_radio_text.html(); IF !cur_radio_text; cur_radio_text = cur_radio.html(); cur_radio_text = cur_radio _ ( cur_settings.exists( 'unit' ) ? " ${cur_settings.unit}" : '' ); END; SET cur_radio_checked = (formatted_value == cur_radio); IF cur_radio_checked; selected_radio = "custom_$cur_radio"; END; cur_radio_html = cur_radio.html(); buttons.push( '' ); END; END; SET custom_selected = !selected_radio; SET disabled_html = custom_selected ? '' : ' disabled="disabled"' ; SET checked_html = custom_selected ? ' checked="checked"' : '' ; SET default_input_value = formatted_value.defined() ? formatted_value_enc : cur_settings.default ; buttons.push( ( bootstrap ? "
" _ "
" _ "" _ "
" _ "" _ "
" : "" _ "" _ ( key.match('TTL$') ? '

' _ locale.maketext('Required') _ '' : '' ) ) _ ( cur_settings.exists( 'unit' ) ? " ${cur_settings.unit}" : '' ) ); ELSE; #no buttons, simple text field SET disabled_html = cur_settings.can_undef && ! formatted_value.defined() ? 'disabled="disabled"' : '' ; "" _ ( cur_settings.unit.defined() ? " ${cur_settings.unit}" : '' ) ; IF key == 'ADDR'; '

' _ locale.maketext('Required') _ ''; END; END; '
'; #weird hack to achieve centering... "
    "; "
  • " _ buttons.join('
  • ') _ '
  • '; '
'; CASE 'textarea'; ""; CASE 'multiselect'; '
'; FOR opt = cur_settings.options; SET checked_html = conf.$key.$opt ? 'checked="checked"' : ''; # NB: If every option is hidden then the user will see # no controls, which is awkward. If that’s ever a # possibility, we’ll need to make this smarter. IF cur_settings.hidden.grep("$opt").size(); IF checked_html; ""; END; NEXT; ELSE; SET label = cur_texts.optionlabels.$opt || cur_settings.optionlabels.$opt || opt; IF cur_settings.default.$opt; label = label _ " default"; END; IF cur_settings.pci.$opt; label = label _ " PCI Recommended"; END; "
"; END; END; '
'; CASE [ 'select', 'locale' ]; IF cur_settings.sorter; SET select_options = cur_settings.sorter( cur_settings.options ); ELSE; SET select_options = cur_settings.options.sort(); END; SET cur_option_in_options = 0; SET select_html = "'; select_html = select_html _ '
'; IF cur_settings.exists('default'); IF cur_settings.type == 'locale'; SET cur_default = locale.get_locale_name(cur_settings.default); ELSE; SET cur_default = cur_settings.default; END; select_html = select_html _ '
' _ locale.maketext('System Default: [_1]',cur_default); END; IF cur_settings.exists('pci'); select_html = select_html _ '
' _ locale.maketext('PCI Recommendation: [_1]',cur_settings.pci); END; select_html = select_html _ '
'; SET use_radio_buttons = cur_settings.allow_other; IF use_radio_buttons; ""; '
'; #weird hack to achieve centering... "
    "; "
  • " _ "' _ select_html _ '
  • ' ; IF cur_settings.exists('maxlength') && cur_settings.maxlength; SET input_size = " size='${cur_settings.maxlength}'"; ELSIF cur_settings.exists('width') && cur_settings.width; SET input_size = " size='${cur_settings.width}'"; ELSE; SET input_size = ''; END; "
  • " _ '' _ ' ' _ "" _ '
  • ' _ ( key == 'ETHDEV' ? '
    ' _ locale.maketext('Required') _ '' : '' ) ; '
'; ELSE; select_html; END; CASE [ 'radio' 'binary' 'inversebinary' ]; #radio buttons, with values specified in "options" SET is_binary = cur_settings.type == 'binary' || cur_settings.type == 'inversebinary'; '
'; #weird hack to achieve centering... '
    ' ; SET cur_optionlabels = cur_texts.optionlabels || cur_settings.optionlabels; IF cur_settings.exists( 'options' ) && cur_optionlabels; FOREACH cur_option=cur_settings.options; IF ref( cur_option ) != 'ARRAY' && CPHash.vmethod('exists',cur_optionlabels, cur_option); SET cur_settings.options.${loop.index} = [ cur_optionlabels.$cur_option, cur_option, ]; END; END; END; SET radio_options = cur_settings.options || ( cur_settings.type == 'inversebinary' ? [ [ 'On', 0 ], ['Off', 1 ] ] : [ [ 'On', 1 ], ['Off', 0 ] ] ) ; FOR cur_option = radio_options; IF ref( cur_option ) == 'ARRAY'; SET real_option = cur_option.1; SET disp_option = cur_option.0; ELSE; SET real_option = cur_option; SET disp_option = cur_option; END; IF cur_settings.exists( 'default' ) && real_option == cur_settings.default; IF bootstrap; SET spacer = ' '; ELSE; SET spacer = is_binary ? '
    ' : ' '; END; SET disp_option = disp_option _ "$spacerdefault"; END; IF cur_settings.exists( 'pci' ) && real_option == cur_settings.pci; SET spacer = is_binary ? '
    ' : ' '; SET disp_option = disp_option _ "$spacerPCI recommended"; END; radio_onclick_fn = "checktweaks()"; IF (key == "LOGSTYLE" && real_option == "common"); radio_onclick_fn = "promptBeforeSelection('" _ key _ "', '" _ formatted_value _ "')"; END; "
  • ' _ '
  • ' ; END; '
'; END; ""; "\n"; END; END; '
'; END; IF make_tabs; '
'; END; '
'; -%] [% UNLESS nocontainers -%]

 
[% END -%]