node-red-contrib-unifi
Version:
Node for Node-RED to connect to a UniFi Controller
286 lines (272 loc) • 19.2 kB
HTML
<script type="text/javascript">
RED.nodes.registerType('unificonfig', {
category: 'config',
defaults: {
name: { value: "" },
ip: { value: "", required: true },
port: { value: 443, validate: RED.validators.number() },
site: { value: "default" },
unifios: { value: true },
ssl: { value: false },
},
credentials: {
username: { type: "text" },
password: { type: "password" }
},
label: function () {
return this.name || "Unifi Server";
}
});
</script>
<script type="text/x-red" data-template-name="unificonfig">
<div class="form-row">
<label for="node-config-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-config-input-name" placeholder="Name">
</div>
<div class="form-row">
<label for="node-config-input-ip"><i class="fa fa-globe"></i> Server</label>
<input class="input-append-left" type="text" id="node-config-input-ip" placeholder="IP Address" style="width: 40%;" >
<label for="node-config-input-port" style="margin-left: 10px; width: 35px; "> Port</label>
<input type="text" id="node-config-input-port" placeholder="Port" style="width:45px">
</div>
<div class="form-row">
<label> </label>
<input type="checkbox" id="node-config-input-unifios" placeholder="Unifi OS" style="display: inline-block; width: auto; vertical-align: top;">
<label for="node-config-input-unifios" style="width: 70%;">Unifi OS</label>
<br>
<label> </label>
<input type="checkbox" id="node-config-input-ssl" placeholder="SSL Verification" style="display: inline-block; width: auto; vertical-align: top;">
<label for="node-config-input-ssl" style="width: 70%;">SSL Verification</label>
</div>
<div class="form-row">
<label for="node-config-input-site"><i class="fa fa-list"></i> Site</label>
<input type="text" id="node-config-input-site" placeholder="Site Name">
</div>
<div class="form-row">
<label for="node-config-input-username"><i class="fa fa-user"></i> Username</label>
<input type="text" id="node-config-input-username" placeholder="Username">
</div>
<div class="form-row">
<label for="node-config-input-password"><i class="fa fa-lock"></i> Password</label>
<input type="password" id="node-config-input-password" placeholder="Password">
</div>
</script>
<script type="text/x-red" data-help-name="unificonfig">
<p>Shared configuration for the unifi controllers</p>
</script>
<script type="text/javascript">
RED.nodes.registerType('Unifi', {
category: 'output',
color: '#C0DEED',
defaults: {
name: { value: "" },
server: { type: "unificonfig", required: true },
command: { value: 1, required: true },
debug: { value: false },
},
inputs: 1,
outputs: 2,
outputLabels: ["data", "error"],
icon: "bridge.png",
label: function () {
if (this.name) {
return this.name;
}
switch (this.command.toString()) {
case '1':
return 'Unifi: getSitesStats';
case '10':
return 'Unifi: getSiteSysinfo';
case '20':
return 'Unifi: getClientDevices';
case '30':
return 'Unifi: getAllUsers';
case '35':
return 'Unifi: getBlockedUsers';
case '40':
return 'Unifi: getUserGroups';
case '50':
return 'Unifi: getHealth';
case '60':
return 'Unifi: getDashboard';
case '70':
return 'Unifi: getAccessDevices';
case '80':
return 'Unifi: getRogueAccessPoints';
case '90':
return 'Unifi: getEvents';
case '100':
return 'Unifi: getAlarms';
case '110':
return 'Unifi: getWLanSettings';
case '120':
return 'Unifi: getPortConfig';
case '130':
return 'Unifi: getPortForwardSettings';
default:
return 'Unifi';
}
}
});
</script>
<script type="text/javascript">
RED.nodes.registerType('UnifiWS', {
category: 'output',
color: '#C0DEED',
defaults: {
name: { value: "" },
server: { type: "unificonfig", required: true },
},
inputs: 0,
outputs: 1,
icon: "bridge.png",
label: function () {
if (this.name) {
return this.name;
}
}
});
</script>
<script type="text/x-red" data-template-name="Unifi">
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
<div class="form-row">
<label for="node-input-server"><i class="fa fa-server"></i> Server</label>
<input type="text" id="node-input-server" placeholder="">
</div>
<div class="form-row">
<label for="node-input-command"><i class="fa fa-dot-circle-o"></i> Command</label>
<select id="node-input-command">
<option value="1">SitesStats</option>
<option value="10">SiteSysinfo</option>
<option value="20">ClientDevices</option>
<option value="30">AllUsers</option>
<option value="35">AllBlockedUsers</option>
<option value="40">UserGroups</option>
<option value="50">Health</option>
<option value="60">Dashboard</option>
<option value="70">AccessDevices</option>
<option value="80">RogueAccessPoints</option>
<option value="90">Events</option>
<option value="100">Alarms</option>
<option value="110">WLanSettings</option>
<option value="120">ListPortProfiles</option>
<option value="130">PortForwardSettings</option>
</select>
</div>
<div class="form-row">
<label for="node-input-debug"><i class="fa fa-bug"></i> Debug</label>
<input type="checkbox" id="node-input-debug" placeholder="Debug" style="display: inline-block; width: auto; vertical-align: top;">
</div>
</script>
<script type="text/x-red" data-template-name="UnifiWS">
<div class="form-row">
Alpha version: At this point anything could change or not work.
</div>
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
<div class="form-row">
<label for="node-input-server"><i class="fa fa-server"></i> Server</label>
<input type="text" id="node-input-server" placeholder="">
</div>
</script>
<script type="text/x-red" data-help-name="Unifi">
<p>Connects to a Unifi Controller and query/control UniFi devices.</p>
<p><code>msg.payload.command</code> is used to override the command selected in the node.<br> Example how to send a command from a function Node<br> <code>msg.payload = { command: "ClientDevices"};</code></p>
<p>Available Commands:</p>
<ul>
<li><code>SitesStats</code> : Site stats</li>
<li><code>SiteSysinfo</code> : Site sysinfo</li>
<li><code>ClientDevices</code> : Online client device(s)</li>
<li><code>AllUsers</code> : All client devices ever connected to the site</li>
<li><code>AllBlockedUsers</code> : All blocked client devices ever connected to the site</li>
<li><code>UserGroups</code> : User groups</li>
<li><code>Health</code> : Health metrics</li>
<li><code>Dashboard</code> : Dashboard metrics</li>
<li><code>AccessDevices</code> : Access points</li>
<li><code>RogueAccessPoints</code> : Rogue access points</li>
<li><code>Events</code> : Events</li>
<li><code>Alarms</code> : Alarms</li>
<li><code>WLanSettings</code> : WLan Settings</li>
<li><code>ListPortProfiles</code> : List Port Profiles</li>
<li><code>PortForwardSettings</code> : Port Forward Settings</li>
</ul>
<p>Special Commands: (No GUI)</p>
<ul>
<li><code>DisableWLan</code> : Disable/Enable WLan { command: "disableWLan", wlan_id: "use _id from command WLanSettings", disable: true }</li>
<li><code>DisablePortForward</code> : Disable/Enable PortForward { command: "disablePortForward", portforward_id: "use _id from command PortForwardSettings", disable: true }</li>
<li><code>blockClient</code> : Block Client { command: "blockClient", mac: "client MAC address" }</li>
<li><code>unblockClient</code> : Unblock Client { command: "unblockClient", mac: "client MAC address" }</li>
<li><code>reconnectClient</code> : Reconnect Client { command: "reconnectClient", mac: "client MAC address" }</li>
<li><code>authorizeGuest</code> : Authorize Client { command: "authorizeGuest", mac: "client MAC address", minutes: "minutes until authorization expires" }</li>
<li><code>unauthorizeGuest</code> : Unauthorize Client { command: "unauthorizeGuest", mac: "client MAC address" }</li>
<li><code>restartAP</code> : Reboot an Access point { command: "restartAP", mac: "device MAC address" }</li>
<li><code>enableAP</code> : Enable an Access point { command: "enableAP", device_id: "24 char device id" }</li>
<li><code>disableAP</code> : Disable an Access point { command: "disableAP", device_id: "24 char device id" }</li>
<li><code>setAPLed</code> : Set LED for Access point { command: "setapled", device_id: "24 char device id", mode: "off/on/default" }</li>
<li><code>setSiteLed</code> : Set LED for Site { command: "setsiteled", mode: true/false }</li>
<li><code>site</code> : Connect to site name { site: "site name"}</li>
<li><code>getFirewallGroups</code> : Get list of firewall groups { command: "getFirewallGroups" }</li>
<li><code>addFirewallGroup</code> : Add firewall group { command: "addFirewallGroup", group_name: "group-name", group_type: "address-group|ipv6-address-group|port-group", group_members: ["CIDRs", "IPs"] }</li>
<li><code>editFirewallGroup</code> : Edit firewall group { command: "editFirewallGroup", group_id: "group id", group_name: "group-name", group_type: "address-group|ipv6-address-group|port-group", group_members: ["CIDRs", "IPs"] }</li>
<li><code>deleteFirewallGroup</code> : Delete firewall group { command: "deleteFirewallGroup", group_id: "group id" }</li>
<li><code>getFirewallRules</code> : Get a list of firewall rules { command: "getFirewallRules" }</li>
<li><code>getFirewallRule</code> : Get a firewall rule { command: "getFirewallRule, rule_id: "id" }</li>
<li><code>getFirewallRuleByName</code> : Get a firewall rule by its name{ command: "getFirewallRuleByName, rule_name: "name" }</li>
<li><code>enableFirewallRule</code> : Enable a firewall rule { command: "enableFirewallRule", rule_id: "id" }</li>
<li><code>disableFirewallRule</code> : Disable a firewall rule { command: "disableFirewallRule", rule_id: "id" }</li>
<li><code>getPoePortState</code> : Get the PoE state of port x { command: "getPoePortState", device_id: "id", port: "port number" }</li>
<li><code>enablePoePort</code> : Enable POE on port x { command: "enablePoePort", device_id: "id", port: "port number", poe_mode: "off|auto|pasv24|passthrough" }</li>
<li><code>disablePoePort</code> : Disable POE on port x { command: "disablePoePort", device_id: "id", port: "port number" }</li>
<li><code>forceProvision</code> : Force provision { command: "forceProvision", mac: "device MAC address" }</li>
<li><code>setPortProfiles</code> : setPortProfiles: Set overrides for multiple ports of a device { command: "setPortProfiles", device_id: "24 char device id", port_overrides: [ {"port_idx": 1, "portconf_id": "id of the port profile", "name": "friendly name of the port", "poe_mode": "off|auto" }, ... ] }</li>
<li><code>setLocate</code> : Enable flash device LED (or other indication based on device) { command: "setLocate", mac: "device MAC address" }</li>
<li><code>unsetLocate</code> : Disable flash device LED (or other indication based on device) { command: "unsetLocate", mac: "device MAC address" }</li>
<li><code>setWLanPassword</code> : Change WLan password { command: "setWLanPassword", wlan_id: "SSID ID", x_passphrase: "New password" }</li>
<li><code>getVouchers</code> : Get available Vouchers from Guest Portal { command: "getVouchers" }</li>
<li><code>createVouchers</code> : Create new Vouchers for Guest Usage { command: "createVouchers", minutes: "expiration time in minutes", count: "number of vouchers", quota: "'0' is for multi-use, '1' is for single-use", note: "note added to voucher", up: "upload speed limit in kbps (remove if not used)", down: "download speed limit in kbps (remove if not used)", mbytes: "data transfer limit in MB (remove if not used)"}</li>
<li><code>revokeVouchers</code> : Revoke voucher { command: "revokeVouchers", voucher_id : "24 char _id of the voucher" }</li>
<li><code>clientDevices</code> : Returns a single client device { command: "clientDevices", mac: "device MAC address" }</li>
<li><code>enableTrafficManagementRule</code> : Enable a traffic management rule { command: "enableTrafficManagementRule", rule_id: "id" }</li>
<li><code>disableTrafficManagementRule</code> : Disable a traffic management rule { command: "disableTrafficManagementRule", rule_id: "id" }</li>
<li><code>getTrafficManagementRule</code> : Get traffic management rules, optional add rule_id { command: "getTrafficManagementRule", rule_id: "id" }</li>
<li><code>enableTrafficRouteRule</code> : Enable a traffic route rule { command: "enableTrafficRouteRule", rule_id: "id" }</li>
<li><code>disableTrafficRouteRule</code> : Disable a traffic route rule { command: "disableTrafficRouteRule", rule_id: "id" }</li>
<li><code>getTrafficRouteRule</code> : Get traffic route rules, optional add rule_id { command: "getTrafficRouteRule", rule_id: "id" }</li>
<li><code>getWLanSetting</code> : Get WLan setting for selected WLan { command: "getWLanSetting", wlan_id: "id" }</li>
<li><code>setWLanFilter</code> : Set Device Access Filtering { command: "setWLanFilter", wlan_id: "id", policy: "allow|deny", mac: ['MAC Address'] }</li>
<li><code>setDNSServer</code> : Set DHCP DNS Server 1 and 2 { command: "setDNSServer", network_id: "id", dns1: "x.x.x.x", dns2: "x.x.x.x" }</li>
<li><code>getNetworkConf</code> : Get network configuration { command: "getNetworkConf" }</li>
<li><code>setAPLedColor</code> : Set LED color for Access point { command: "setapledcolor", device_id: "24 char device id", color: "Color Hex code", brightness: 1-100 }</li>
<li><code>getRadiusUsers</code> : Get all radius users { command: "getRadiusUsers" }</li>
<li><code>getRadiusProfiles</code> : Get all radius profiles { command: "getRadiusProfiles" }</li>
<li><code>createRadiusUser</code> : Create radius user { command: "createRadiusUser", name: "account name", x_password: "password", tunnel_type: "optional 1-13", tunnel_medium_type: "optional 1-15", vlan: "optional vlan id" }</li>
<li><code>updateRadiusUser</code> : Update radius user { command: "updateRadiusUser", user_id: "24 char string _id of the user", name: "optional account name", x_password: "optional password", tunnel_type: "optional 1-13", tunnel_medium_type: "optional 1-15", vlan: "optional vlan id" }</li>
<li><code>deleteRadiusUser</code> : Delete radius user { command: "deleteRadiusUser", user_id: "24 char string _id of the user" }</li>
<li><code>getDPIstats</code> : Get array of DPI stats { command: "getDPIstats" }</li>
<li><code>getCustomDNS</code> : Get array of Custom DNS entries { command: "getCustomDNS" }</li>
<li><code>setCustomDNS</code> : Create new Custom DNS entry { command: "setCustomDNS", record_type: "A|AAAA|MX|TXT|SRV", value: "IP address|Text|Domain name", key: "Domain name", priority: 0-65535, weight: 0-65535, ttl: 1-86400, port: 1-65535, enabled: true|false, _id: "_id of current Custom DNS entry if you want to update" }</li>
<li><code>getFirewallZones</code> : Get array of Firewall Zones { command: "getFirewallZones" }</li>
<li><code>getNetworks</code> : Get array of Networks { command: "getNetworks" }</li>
<li><code>setFirewallZone</code> : Create, Update or Delete Firewall Zone { command: "setFirewallZone", name: "Zone name - create or update", network_ids: "Network Id - create or update", _id: "Zone id - update or delete", remove: "true - delete" }</li>
<li><code>getFirewallPolicies</code> : Get array of Firewall Policies { command: "getFirewallPolicies" }</li>
<li><code>setFirewallPolicy</code> : Set status of Firewall Policy { command: "setFirewallPolicy", enabled: "true | false", _id: "Firewall Policy Id" }</li>
<li><code>powerCyclePoEPort</code> : Power-Cycle Switch PoE port { command: "powerCyclePoEPort", port: "Port Id", mac: "Switch MAC address" }</li>
<li><code>startPingDevice</code> : Send 30 ping requests to a specific device { command: "startPingDevice", mac: "Device MAC address" }</li>
<li><code>stopPingDevice</code> : Stop pinging a specific device { command: "stopPingDevice", mac: "Device MAC address" }</li>
<p>Returns all data in JSON parsable strings/objects</p>
</ul>
<p>For more information see the <a href="https://github.com/Isaksson/node-red-contrib-unifi" target="_blank">GitHub</a> site.</p>
<p>Version 0.3.22</p>
</script>
<script type="text/x-red" data-help-name="UnifiWS">
<p><u>BETA</u></p>
<p>Connects to a Unifi Controller</p>
<p>Returns all data in JSON parsable strings/objects</p>
<p>For more information see the <a href="https://github.com/Isaksson/node-red-contrib-unifi" target="_blank">GitHub</a> site.</p>
<p>Version 0.3.22</p>
</script>