9 return "https-dns-proxy";
12 return "https://docs.openwrt.melmac.net/" + pkg.Name + "/";
14 templateToRegexp: function (template) {
20 let placeholder = part.match(/^\{(\w+)\}$/);
21 if (placeholder) return `(?<${placeholder[1]}>.*?)`;
22 else return part.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
30 var getInitStatus = rpc.declare({
31 object: "luci." + pkg.Name,
32 method: "getInitStatus",
36 var getPlatformSupport = rpc.declare({
37 object: "luci." + pkg.Name,
38 method: "getPlatformSupport",
42 var getProviders = rpc.declare({
43 object: "luci." + pkg.Name,
44 method: "getProviders",
48 var getRuntime = rpc.declare({
49 object: "luci." + pkg.Name,
54 return baseclass.extend({
55 title: _("HTTPS DNS Proxy Instances"),
59 getInitStatus(pkg.Name),
60 getProviders(pkg.Name),
65 render: function (data) {
67 status: (data[0] && data[0][pkg.Name]) || {
70 force_dns_active: null,
73 providers: (data[1] && data[1][pkg.Name]) || { providers: [] },
74 runtime: (data[2] && data[2][pkg.Name]) || { instances: [] },
76 reply.providers.sort(function (a, b) {
77 return _(a.title).localeCompare(_(b.title));
79 reply.providers.push({
82 params: { option: { type: "text" } },
85 var forceDnsText = "";
86 if (reply.status.force_dns_active) {
87 reply.status.force_dns_ports.forEach((element) => {
88 forceDnsText += element + " ";
96 { class: "table", id: "https-dns-proxy_status_table" },
98 E("tr", { class: "tr table-titles" }, [
99 E("th", { class: "th" }, _("Name / Type")),
100 E("th", { class: "th" }, _("Listen Address")),
101 E("th", { class: "th" }, _("Listen Port")),
102 E("th", { class: "th" }, _("Force DNS Ports")),
108 Object.values(reply.runtime.instances).forEach((element) => {
115 element.command.forEach((param, index, arr) => {
116 if (param === "-r") resolver = arr[index + 1];
117 if (param === "-a") address = arr[index + 1];
118 if (param === "-p") port = arr[index + 1];
120 resolver = resolver || "Unknown";
121 address = address || "127.0.0.1";
122 port = port || "Unknown";
123 reply.providers.forEach((prov) => {
124 let regexp = pkg.templateToRegexp(prov.template);
125 if (!found && regexp.test(resolver)) {
127 name = _(prov.title);
128 let match = resolver.match(regexp);
129 if (match[1] != null) {
132 prov.params.option &&
133 prov.params.option.options
135 prov.params.option.options.forEach((opt) => {
136 if (opt.value === match[1]) option = _(opt.description);
138 name += " (" + option + ")";
140 if (match[1] !== "") name += " (" + match[1] + ")";
145 rows.push([name, address, port, forceDnsText]);
148 cbi_update_table(table, rows, E("em", _("There are no active instances.")));