tips:airos

This is an old revision of the document!


AirOS

<?php
 
// airOS-getFile_HTTP() from Omniflux:
// https://community.ubnt.com/t5/airMAX-AC/Login-to-web-interface-with-PHP/m-p/2291860#M29858
 
// an example of fetching status.cgi from an AF24 (and probably any other UBNT radio)
// the output is a bunch of JSON with the current radio stats
 
// airOS_getFile_HTTP ($username, $password, $file, $address, $schema)
 
#$out = airOS_getFile_HTTP ("root", "xxx", "status.cgi", "10.210.48.2", "https"); // CPE mng
#$out = airOS_getFile_HTTP ("galileo", "xxx", "status.cgi", "10.210.12.247", "http"); // settore
$out = airOS_getFile_HTTP ("root", "xxx", "status.cgi", "109.104.240.187:8008", "http"); // CPE
print $out;
 
function airOS_getFile_HTTP ($username, $password, $file, $address, $schema)
 
{
        $ch = curl_init();
 
        // Setup CURL
        curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
        curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
        curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt ($ch, CURLOPT_COOKIEJAR, null);
        curl_setopt ($ch, CURLOPT_HTTPHEADER, Array ('Expect: '));
 
        // Login AirOS >= 8.5.0+ OR get cookie with session ID for AirOS < 8.5.0
        curl_setopt ($ch, CURLOPT_URL, "$schema://$address/api/auth");
        curl_setopt ($ch, CURLOPT_POST, 1);
        curl_setopt ($ch, CURLOPT_POSTFIELDS, Array ('username' => $username, 'password' => $password));
        curl_setopt ($ch, CURLOPT_HEADER, 1);
        $response = curl_exec ($ch);
// uncomment to see raw response
//print "resp: $response\n";
        curl_setopt ($ch, CURLOPT_HEADER, 0); 
 
        // AirOS >= 8.5.0 request and return file
 
        if (curl_getinfo ($ch, CURLINFO_HTTP_CODE) == 200)
        {
                // Get X-CSRF-ID value
                preg_match ('/X-CSRF-ID: .*/', substr ($response, 0, curl_getinfo ($ch, CURLINFO_HEADER_SIZE)), $XCSRFID);
 
                curl_setopt ($ch, CURLOPT_URL, "$schema://$address/$file");
                curl_setopt ($ch, CURLOPT_POST, 0);
                $retfile = curl_exec ($ch);
 
                curl_setopt ($ch, CURLOPT_URL, "$schema://$address/logout.cgi");
                curl_setopt ($ch, CURLOPT_HTTPHEADER, Array (trim ($XCSRFID[0]), 'X-AIROS-LUA: 1'));
                curl_setopt ($ch, CURLOPT_POST, 1);
                curl_setopt ($ch, CURLOPT_POSTFIELDS, Array());
                curl_exec ($ch);
        }
 
        // Login failed, try AirOS < 8.5.0 login, request, and return file
        else
        {
                curl_setopt ($ch, CURLOPT_URL, "$schema://$address/login.cgi");
                curl_setopt ($ch, CURLOPT_POST, 1);
                curl_setopt ($ch, CURLOPT_POSTFIELDS, Array ('username' => $username, 'password' => $password));
                curl_exec ($ch);
 
                curl_setopt ($ch, CURLOPT_URL, "$schema://$address/$file");
                curl_setopt ($ch, CURLOPT_POST, 0);
                $retfile = curl_exec ($ch);
        }
 
        curl_close ($ch);
 
        return $retfile;
}
?>
{
  "chain_names": [
    {
      "number": 1,
      "name": "Chain 0"
    },
    {
      "number": 2,
      "name": "Chain 1"
    }
  ],
  "host": {
    "hostname": "cpe-188192-gal-lab",
    "uptime": 667685,
    "time": "2018-01-26 08:29:59",
    "timestamp": 828344250,
    "fwversion": "v8.5.0-cs.36727.180118.1402",
    "devmodel": "Rocket Prism 5AC Gen2",
    "netrole": "bridge",
    "loadavg": 0.129883,
    "totalram": 129982464,
    "freeram": 89100288,
    "temperature": 50,
    "cpuload": 39.603962
  },
  "genuine": "/images/genuine.png",
  "services": {
    "dhcpc": false,
    "dhcpd": false,
    "dhcp6d_stateful": false,
    "pppoe": false,
    "airview": 2
  },
  "firewall": {
    "iptables": false,
    "ebtables": false,
    "ip6tables": false,
    "eb6tables": false
  },
  "portfw": false,
  "wireless": {
    "essid": "lessinianet.net",
    "mode": "sta-ptmp",
    "compat_11n": 0,
    "hide_essid": 0,
    "apmac": "80:2A:A8:A4:2F:9D",
    "frequency": 5655,
    "center1_freq": 5655,
    "dfs": 1,
    "distance": 14850,
    "security": "WPA2",
    "noisef": -90,
    "txpower": 22,
    "aprepeater": false,
    "rstatus": 5,
    "chanbw": 20,
    "rx_chainmask": 3,
    "tx_chainmask": 3,
    "cac_state": 0,
    "rx_idx": 4,
    "rx_nss": 2,
    "tx_idx": 6,
    "tx_nss": 2,
    "count": 1,
    "polling": {
      "dcap": 57720,
      "ucap": 95680,
      "use": 2,
      "tx_use": 1,
      "rx_use": 1,
      "atpc_status": 0,
      "fixed_frame": false,
      "gps_sync": false
    },
    "sta": [
      {
        "mac": "80:2A:A8:A4:2F:9D",
        "lastip": "0.0.0.0",
        "signal": -66,
        "rssi": 30,
        "noisefloor": -90,
        "chainrssi": [
          28,
          26,
          0
        ],
        "tx_idx": 6,
        "rx_idx": 4,
        "tx_nss": 2,
        "rx_nss": 2,
        "tx_latency": 0,
        "distance": 14850,
        "tx_packets": 0,
        "tx_lretries": 0,
        "tx_sretries": 0,
        "uptime": 157916,
        "tx_ratedata": [
          3,
          0,
          0,
          176,
          14327,
          102196,
          156745,
          178340,
          0,
          0
        ],
        "stats": {
          "rx_bytes": 83701813,
          "rx_packets": 588950,
          "rx_pps": 11,
          "tx_bytes": 98347739,
          "tx_packets": 292160,
          "tx_pps": 0
        },
        "remote": {
          "hostname": "santuario-SudOvest",
          "platform": "Rocket 5AC Prism",
          "version": "XC.qca955x.v8.5.11.39842.190109.1449",
          "uptime": 240246,
          "time": "2019-01-12 10:33:00",
          "cpuload": 7,
          "temperature": 51,
          "totalram": 129961984,
          "freeram": 81661952,
          "netrole": "bridge",
          "mode": "ap-ptmp",
          "compat_11n": 1,
          "signal": -64,
          "rssi": 32,
          "noisefloor": -87,
          "tx_power": 22,
          "distance": 14850,
          "rx_chainmask": 3,
          "chainrssi": [
            30,
            28,
            0
          ],
          "tx_ratedata": [
            2,
            5,
            220,
            3920,
            294380,
            0,
            0,
            0,
            0,
            0
          ],
          "tx_bytes": 139113407571,
          "rx_bytes": 9806798900,
          "ethlist": [
            {
              "ifname": "eth0",
              "enabled": true,
              "plugged": true,
              "duplex": true,
              "speed": 1000,
              "snr": [
                30,
                30,
                30,
                30
              ],
              "cable_len": 14
            }
          ],
          "ipaddr": [
            "10.210.48.248",
            "169.254.47.157"
          ],
          "gps": {
            "lat": "45.545359",
            "lon": "10.878980",
            "fix": 1,
            "sats": 8,
            "dim": 3,
            "dop": "1.30",
            "alt": "341.6"
          },
          "oob": "false"
        },
        "airmax": {
          "actual_priority": 2,
          "beam": 0,
          "desired_priority": 2,
          "downlink_capacity": 57720,
          "uplink_capacity": 95680,
          "atpc_status": 0,
          "rx": {
            "usage": 1,
            "cinr": 26,
            "evm": [
              [
                25,
                25,
                25,
                26,
                26,
                26,
                26,
                26,
                26,
                26,
                27,
                28,
                28,
                28,
                28,
                28,
                26,
                26,
                26,
                26,
                26,
                26,
                26,
                26,
                26,
                26,
                26,
                26,
                26,
                25,
                25,
                25,
                25,
                25,
                28,
                28,
                28,
                25,
                25,
                25,
                25,
                24,
                24,
                24,
                24,
                24,
                27,
                27,
                27,
                27,
                24,
                24,
                22,
                22,
                26,
                26,
                26,
                26,
                25,
                25,
                25,
                25,
                25,
                25
              ],
              [
                30,
                30,
                30,
                31,
                31,
                31,
                31,
                31,
                31,
                30,
                31,
                30,
                30,
                30,
                30,
                30,
                28,
                28,
                28,
                28,
                28,
                31,
                31,
                31,
                31,
                31,
                31,
                31,
                31,
                31,
                31,
                31,
                31,
                31,
                31,
                31,
                31,
                30,
                30,
                30,
                30,
                30,
                30,
                30,
                30,
                30,
                30,
                30,
                30,
                30,
                30,
                30,
                29,
                29,
                31,
                31,
                31,
                31,
                29,
                29,
                29,
                29,
                29,
                29
              ]
            ]
          },
          "tx": {
            "usage": 1,
            "cinr": 26,
            "evm": [
              [
                24,
                24,
                24,
                24,
                24,
                24,
                24,
                24,
                24,
                24,
                26,
                26,
                26,
                27,
                27,
                27,
                27,
                25,
                27,
                25,
                26,
                26,
                26,
                26,
                25,
                24,
                24,
                24,
                24,
                24,
                24,
                24,
                24,
                28,
                28,
                28,
                28,
                28,
                28,
                28,
                28,
                25,
                25,
                25,
                25,
                25,
                25,
                25,
                25,
                27,
                27,
                27,
                27,
                27,
                27,
                27,
                27,
                27,
                27,
                26,
                26,
                25,
                27,
                27
              ],
              [
                30,
                30,
                30,
                30,
                30,
                30,
                30,
                30,
                30,
                30,
                32,
                32,
                32,
                33,
                33,
                33,
                33,
                31,
                32,
                32,
                32,
                32,
                32,
                32,
                32,
                32,
                32,
                32,
                32,
                32,
                32,
                32,
                32,
                32,
                32,
                32,
                32,
                32,
                32,
                32,
                32,
                33,
                33,
                33,
                33,
                33,
                33,
                33,
                32,
                32,
                32,
                32,
                32,
                32,
                32,
                32,
                32,
                32,
                32,
                32,
                32,
                32,
                32,
                32
              ]
            ]
          }
        }
      }
    ]
  },
  "interfaces": [
    {
      "ifname": "eth0",
      "hwaddr": "78:8A:20:AD:E4:4C",
      "enabled": true,
      "mtu": 1500,
      "status": {
        "plugged": true,
        "tx_bytes": 126448927,
        "rx_bytes": 32773228,
        "tx_errors": 0,
        "rx_errors": 0,
        "ipaddr": "0.0.0.0",
        "speed": 1000,
        "duplex": true,
        "snr": [
          29,
          28,
          29,
          29
        ],
        "cable_len": 38
      }
    },
    {
      "ifname": "ath0",
      "hwaddr": "78:8A:20:AC:E4:4C",
      "enabled": true,
      "mtu": 1500,
      "status": {
        "plugged": false,
        "tx_bytes": 394212716,
        "rx_bytes": 361312482,
        "tx_errors": 0,
        "rx_errors": 0,
        "ipaddr": "0.0.0.0",
        "speed": 0,
        "duplex": false
      }
    },
    {
      "ifname": "br0",
      "hwaddr": "78:8A:20:AC:E4:4C",
      "enabled": true,
      "mtu": 1500,
      "status": {
        "plugged": true,
        "tx_bytes": 312537683,
        "rx_bytes": 249947706,
        "tx_errors": 0,
        "rx_errors": 0,
        "ipaddr": "10.210.48.2",
        "speed": 0,
        "duplex": false
      }
    }
  ],
  "provmode": {},
  "ntpclient": {},
  "unms": {
    "status": 1,
    "timestamp": "2018-01-26T08:29:57+0100"
  }
}
  • tips/airos.1552561433.txt.gz
  • Last modified: 2019/03/14 12:03
  • by scipio