/* Pi-hole: A black hole for Internet advertisements * (c) 2023 Pi-hole, LLC (https://pi-hole.net) * Network-wide ad blocking via your own hardware. * * This file is copyright under the latest version of the EUPL. * Please see LICENSE file for your rights under this license. */ /* global utils:false, apiFailure: false, applyCheckboxRadioStyle: false, saveSettings:false */ /* exported createDynamicConfigTabs */ function addAllowedValues(allowed) { if (typeof allowed === "object") { return ( "

Available options:

" ); } else if (typeof allowed === "string") { return "

Allowed value: " + utils.escapeHtml(allowed) + "

"; } } function generateRow(topic, key, value) { // If the value is an object, we need to recurse if (!("description" in value)) { Object.keys(value).forEach(function (subkey) { var subvalue = value[subkey]; generateRow(topic, key + "." + subkey, subvalue); }); return; } // else: we have a setting we can display var box = '
' + '
' + '

' + key + (value.modified ? '  ' : "") + (value.flags.advanced ? '  ' : "") + "

" + "

" + utils.escapeHtml(value.description).replace("\n", "
") + "

" + "
" + '
' + '
'; var defaultValueHint = ""; if (value.modified) { defaultValueHint = ""; if (value.default !== null) { var defVal = utils.escapeHtml(JSON.stringify(value.default)); switch (defVal) { case "true": { defVal = "enabled"; break; } case "false": { defVal = "disabled"; break; } case '""': case "[]": { defVal = "empty"; break; } // No default } defaultValueHint = "

Default Value: " + defVal + "

"; } } switch (value.type) { case "IPv4 address": case "IPv6 address": case "string": { box += '' + '
' + ' ' + defaultValueHint + addAllowedValues(value.allowed) + "
"; break; } case "boolean": { box += '
" + "
"; break; } case "double": { box += '' + '
' + ' ' + defaultValueHint + "
"; break; } case "integer": { box += '' + '
' + ' ' + defaultValueHint + "
"; break; } case "unsigned integer": { box += '' + '
' + ' ' + defaultValueHint + "
"; break; } case "unsigned integer (16 bit)": { box += '' + '
' + ' ' + defaultValueHint + "
"; break; } case "string array": { box += '' + '
' + ' " + defaultValueHint + addAllowedValues(value.allowed) + "
"; break; } case "enum (string)": { box += '' + '
' + ' " + defaultValueHint + "
" + '
' + addAllowedValues(value.allowed) + "
"; break; } case "password (write-only string)": { box += '' + '
' + ' ' + defaultValueHint + addAllowedValues(value.allowed) + "
"; break; } default: { box += "TYPE " + value.type + " NOT DEFINED"; } } box += "
"; var topKey = key.split(".")[0]; var elem = $("#advanced-content-" + topKey + "-flex"); elem.append(box); } function createDynamicConfigTabs() { $.ajax({ url: "/api/config?detailed=true", }) .done(function (data) { // Create the content for the advanced dynamic config topics Object.keys(data.topics).forEach(function (n) { var topic = data.topics[n]; $("#advanced-content").append( '
' + '
' + '
' + '

' + topic.description + " (" + topic.name + ")" + "

" + "
" + '
' + '
' + '
' + "
" + "
" + "
" + "
" ); }); Object.keys(data.config).forEach(function (topic) { var value = data.config[topic]; generateRow(topic, topic, value, data); }); $("#advanced-overlay").hide(); $("#advanced-content").append( '
' + '' + "
" ); $("button[id='save']").on("click", function () { saveSettings(); }); applyCheckboxRadioStyle(); }) .fail(function (data) { apiFailure(data); }); } $(document).ready(function () { createDynamicConfigTabs(); });