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 if (reply.runtime.instances) {
109 Object.values(reply.runtime.instances).forEach((element) => {
116 element.command.forEach((param, index, arr) => {
117 if (param === "-r") resolver = arr[index + 1];
118 if (param === "-a") address = arr[index + 1];
119 if (param === "-p") port = arr[index + 1];
121 resolver = resolver || "Unknown";
122 address = address || "127.0.0.1";
123 port = port || "Unknown";
124 reply.providers.forEach((prov) => {
125 let regexp = pkg.templateToRegexp(prov.template);
126 if (!found && regexp.test(resolver)) {
128 name = _(prov.title);
129 let match = resolver.match(regexp);
130 if (match[1] != null) {
133 prov.params.option &&
134 prov.params.option.options
136 prov.params.option.options.forEach((opt) => {
137 if (opt.value === match[1]) option = _(opt.description);
139 name += " (" + option + ")";
141 if (match[1] !== "") name += " (" + match[1] + ")";
146 rows.push([name, address, port, forceDnsText]);
149 cbi_update_table(table, rows, E("em", _("There are no active instances.")));