{% /* * Part of AREDN® -- Used for creating Amateur Radio Emergency Data Networks * Copyright (C) 2024 Tim Wilkinson * See Contributors file for additional contributors * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation version 3 of the License. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * * Additional Terms: * * Additional use restrictions exist on the AREDN® trademark and logo. * See AREDNLicense.txt for more info. * * Attributions to the AREDN® Project must be retained in the source code. * If importing this code into a new or existing project attribution * to the AREDN® project must be added to the source code. * * You must not misrepresent the origin of the material contained within. * * Modified versions must be modified to attribute to the original source * and be marked in reasonable ways as differentiate it from the original * version */ %} {% if (request.env.REQUEST_METHOD === "PUT") { configuration.prepareChanges(); if ("services" in request.args) { const services = json(request.args.services); const dhcp = configuration.getDHCP(); let f = fs.open(dhcp.services, "w"); if (f) { for (let i = 0; i < length(services); i++) { f.write(`${services[i]}\n`); } f.close(); } } if ("aliases" in request.args) { const aliases = json(request.args.aliases); const dhcp = configuration.getDHCP(); let f = fs.open(dhcp.aliases, "w"); if (f) { for (let i = 0; i < length(aliases); i++) { f.write(`${aliases[i]}\n`); } f.close(); } } if ("ports" in request.args) { const ports = json(request.args.ports); const dhcp = configuration.getDHCP(); let f = fs.open(dhcp.ports, "w"); if (f) { for (let i = 0; i < length(ports); i++) { f.write(`${ports[i]}\n`); } f.close(); } } print(_R("changes")); return; } if (request.env.REQUEST_METHOD === "DELETE") { configuration.revertModalChanges(); print(_R("changes")); return; } const types = { mail: true, router: true, switch: true, radio: true, solar: true, battery: true, power: true, weather: true, wiki: true, }; const templates = [ { name: "Generic URL" }, { name: "Simple text", link: false }, { name: "Ubiquiti camera", type: "camera", protocol: "http", port: 80, path: "snap.jpeg" }, { name: "Reolink camera", type: "camera", protocol: "http", port: 80, path: "cgi-bin/api.cgi?cmd=Snap&channel=0&rs=abcdef&user=USERNAME&password=PASSWORD" }, { name: "Axis camera", type: "camera", protocol: "http", port: 80, path: "jpg/image.jpg" }, { name: "Sunba Lite camera", type: "camera", protocol: "http", port: 80, path: "webcapture.jpg?command=snap&channel=1&user=USERNAME&password=PASSWORD" }, { name: "Sunba Performance camera", type: "camera", protocol: "http", port: 80, path: "images/snapshot.jpg" }, { name: "Sunba Smart camera", type: "camera", protocol: "http", port: 80, path: "ISAPI/Custom/snapshot?authInfo=USERNAME:PASSWORD" }, { name: "NTP Server", type: "time", protocol: "ntp", port: 123 }, { name: "Streaming video", type: "video", protocol: "rtsp", port: 554 }, { name: "Winlink Server", type: "winlink", protocol: "winlink", port: 8772 }, { name: "Phone info", type: "phone", link: false, text: "xYOUR-PHONE-EXTENSION" }, { name: "Map", type: "map", protocol: "http", port: 80 }, { name: "MeshChat", type: "chat", protocol: "http", port: 80, path: "meshchat" }, { name: "WeeWx Weather Station", type: "weather", protocol: "http", port: 80, path: "weewx" }, { name: "Proxmox Server", type: "server", protocol: "https", port: 8006 }, { name: "Generic HTTP", protocol: "http", port: 80 }, { name: "Generic HTTPS", protocol: "https", port: 443 }, ]; const services = []; const dhcp = configuration.getDHCP(); const as = iptoarr(dhcp.start); const ae = iptoarr(dhcp.end); let f = fs.open(dhcp.services); if (f) { const reService = regexp("^([^|]+)\\|1\\|([^|]+)\\|([^|]+)\\|(\\d+)\\|(.*)$"); const reLink = regexp("^([^|]+)\\|0\\|\\|([^|]+)\\|\\|$"); const reType = regexp("^(.+) \\[([a-z]+)\\]$"); for (let l = f.read("line"); length(l); l = f.read("line")) { const v = match(trim(l), reService); if (v) { let type = null; const v2 = match(v[1], reType); if (v2) { v[1] = v2[1]; type = v2[2]; } push(services, { name: v[1], type: type, link: true, protocol: v[2], hostname: v[3], port: v[4], path: v[5] }); } else { const k = match(trim(l), reLink); if (k) { let type = null; const k2 = match(k[1], reType); if (k2) { k[1] = k2[1]; type = k2[2]; } push(services, { name: k[1], type: type, link: false, hostname: k[2] }); } } } f.close(); } const hosts = [ configuration.getName() ]; const aliases = { start: dhcp.start, end: dhcp.end, leases: {}, map: [] }; f = fs.open(dhcp.reservations); if (f) { for (let l = f.read("line"); length(l); l = f.read("line")) { const v = match(trim(l), /^[^ ]+ ([^ ]+) ([^ ]+) ?(.*)/); if (v) { aliases.leases[`${as[0]}.${as[1]}.${as[2]}.${as[3] - 2 + int(v[1])}`] = v[2]; if (v[3] !== "#NOPROP") { push(hosts, v[2]); } } } f.close(); } f = fs.open(dhcp.aliases); if (f) { for (let l = f.read("line"); length(l); l = f.read("line")) { const v = match(trim(l), /^(.+) (.+)$/); if (v) { push(aliases.map, { hostname: v[2], address: v[1] }); } } f.close(); } const ports = []; f = fs.open(dhcp.ports); if (f) { for (let l = f.read("line"); length(l); l = f.read("line")) { const m = match(trim(l), /^(wan|wifi|both):(tcp|udp|both):([0-9\-]+):([.0-9]+):([0-9]+):([01])$/); if (m) { push(ports, { src: m[1], type: m[2], sports: m[3], dst: m[4], dport: m[5], enabled: m[6] === "1" }); } } f.close(); } %}
{{_R("dialog-header", "Local Services")}}
Add service
Add a service from a template
{{_H("Create a service by selecting from the templates above and hitting +. The two most generic templates are Generic URL and Simple text and can be used for any services. You can also use the other templates to help create services for specific cameras, mail servers, phones, etc. and these will pre-populate various service fields.")}}
{% for (let i = 0; i < length(services); i++) { const s = services[i]; %}
{% if (s.link === false) { %} {% } else { %}
:// : /
{% } %}
{% } %}

Host aliases
DNS hostname aliases
{{_H("Assign a hostname to an LAN IP address on this node. Multiple hostnames can be assigned to the same IP address. You are encouraged to prefix your hostnames with your callsign so it will be unique on the network.")}}
{% for (let i = 0; i < length(aliases.map); i++) { %}
{% } %}

Port Forwarding
{% if (dhcp.mode === 0) { %}
Forward WAN and Mesh ports to LAN
{% } else { %}
Forward WAN port to LAN
{% } %}
{% if (dhcp.mode === 0) { %} {{_H("For specific ports (or port ranges) from the WAN or Mesh network to the LAN network. TCP, UDP or both kinds of traffic may be included. When forwarding a port range, specify the range as start-end.")}} {% } else { %} {{_H("For specific ports (or port ranges) from the WAN network to the LAN network. TCP, UDP or both kinds of traffic may be included. When forwarding a port range, specify the range as start-end.")}} {% } %}
addresses
ports
protocol
enabled
{% for (let i = 0; i < length(ports); i++) { const p = ports[i]; %}
{% if (dhcp.mode === 0) { %} {% } else { %} {% } %}
{% } %}
{{_R("dialog-footer")}}