<? $GATEWAY_IP = 'CHANGEME'; $USERNAME = 'admin'; $PASSWORD = 'admin'; $ch = curl_init(); $fields = array( 'admin_uid' => $USERNAME, 'admin_password' => $PASSWORD ); curl_setopt($ch, CURLOPT_URL, "https://$GATEWAY_IP/admin/main.html"); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $fields); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_COOKIEFILE, ''); $result = curl_exec($ch); if ($result === false) { $error = curl_error($ch); curl_close($ch); die("Login failed: $error"); } if (preg_match("/Welcome,\\s+$USERNAME/i", $result) == 0 || preg_match("/Log Out/i", $result) == 0) { curl_close($ch); die("Login Failed!"); } $request = array( 'request' => array( 'method' => 'gateway_list', 'parameters' => array() ) ); $string = json_encode($request, JSON_FORCE_OBJECT); $fields = array( 'request' => $string ); curl_setopt($ch, CURLOPT_URL, "https://$GATEWAY_IP/json"); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $fields); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $result = curl_exec($ch); if ($result === false) { $error = curl_error($ch); curl_close($ch); die("Request failed: $error"); } curl_close($ch); $response = json_decode($result); $response_object = json_decode($response->response->result); print $response_object->gateway->model_name; print "\n"; print "Uptime "; print $response_object->gateway->uptime; print "\n"; ?>
#!/usr/bin/perl use strict; use HTTP::Cookies; use LWP::UserAgent; use Data::Dumper; use JSON; $ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = 0; my $ua = new LWP::UserAgent; # Sometimes both of these are required my $cookies = new HTTP::Cookies(); $ua->cookie_jar($cookies); $ua->ssl_opts({'verify_hostname' => 0}); my $GATEWAY_IP = 'CHANGEME'; my $USERNAME = 'admin'; my $PASSWORD = 'admin'; # log in my $response = $ua->post("https://$GATEWAY_IP/admin/main.html", { admin_uid => $USERNAME, admin_password => $PASSWORD, act => 'login', }); my $content = $response->content; print $content; # Response from login is HTML page, check that the main page init() # function is called to be sure we have logged in and are looking at # the main page. if ($content !~ m/Welcome,\s+$USERNAME/i || $content !~ m/Log Out/i) { print "Login Failed!\n"; exit 1; } # get software version my $params = { 'request' => { 'method' => 'gateway_list', 'parameters' => { } }}; $response = $ua->post("https://$GATEWAY_IP/json", { 'request' => JSON->new->utf8->encode($params) }); # Response from non-login requests are JSON and must be decoded twice # as follows: $content = JSON->new->utf8->decode($response->content); my $res = JSON->new->utf8->decode($content->{'response'}{'result'}); # Uncomment this to see all available information #print Data::Dumper::Dumper($res); print sprintf("Model Number: %s\n", $res->{'gateway'}{'model_no'}); print sprintf("Software Version: %s\n", $res->{'gateway'}{'software_version'}); print sprintf("MAC Address: %s\n", $res->{'gateway'}{'mac_address'}); print sprintf("Uptime: %s\n", $res->{'gateway'}{'uptime'}); # shutdown my $params = { 'request' => { 'method' => 'system_reboot_save', 'parameters' => { 'action' => 'shutdown', 'confirm' => 'yes' } }}; # Change to actually reboot. if (0) { print "Shutting down.\n"; $response = $ua->post("https://$GATEWAY_IP/json", { 'request' => JSON->new->utf8->encode($params) }); } else { print "NOT ACTUALLY REBOOTING.\n"; } # Response from reboot/shutdown is unique in that the webserver cannot # send us a response verifying the shutdown went as expected # $content = JSON->new->utf8->decode($response->content); # print Data::Dumper::Dumper($content);
import sys import re import mechanize import cookielib import urllib import json from pprint import pprint def main(): gateway_ip = 'CHANGEME' gateway_user = 'admin' gateway_pass = 'admin' data = { 'admin_uid': gateway_user, 'admin_password': gateway_pass, 'act': 'login' } data_str = '&'.join(['%s=%s' % (k,v) for k,v in data.iteritems()]) # Log in req = mechanize.Request("https://%s/admin/main.html" % gateway_ip, data_str) cj = cookielib.LWPCookieJar() cj.add_cookie_header(req) res = mechanize.urlopen(req) lines = res.read() # Response from login is an HTML page. Check that the main page's init() # function is called to be sure we have logged in and are looking at # the main page. if re.search("Welcome,\s+%s" % gateway_user, lines) is None: print "Login Failed!" return 1 # Request connection status data = { "request" : { "method": "connection_status.list", } } # Something (mechanize?) doesn't like JSON with spaces in it. data_str = json.dumps(data, separators=(',',':')) req = mechanize.Request("https://%s/json" % gateway_ip, data_str) res = mechanize.urlopen(req) lines = res.read() response = json.loads(lines) result = json.loads(response['response']['result']) # check result for interface in result['connection_status']['t1_e1_interfaces']: if True or interface['status_desc'] != 'Up, Active': print "%s is down (status '%s') on %s!" % ( interface['name'], interface['status_desc'], gateway_ip ) # Send an email, postcard, or pidgeon to the sysadmin sys.exit(main() or 0)
Vendor / Model | Digium Gateway Series | Audiocodes Mediant 600 | Audiocodes Mediant 1000/2000 | Mediatrix 3500 Series | NET (formerly Quintum) Tenor | Sangoma Vega Series | Patton SmartNode |
One E1 | G100 | Mediant 1000 | Model: 3531 | ResponsePoint | Vega 100 | SN4950 | |
* Street Price | 1195 | 2950 | 3300 | 1499 | 1530 | 1158 | 2309 |
* List Price | 1195 | 3278 | 3857 | 1950 | 1800 | 1395 | |
Two E1 | G200 | Mediant 1000 | Model: 3532 | Tenor DX 2030 | Vega 200 | SN4950 | |
* Street Price | 1995 | 4,000 | 4500 | 2299 | 3077 | 1821 | 3999 |
* List Price | 1995 | 4485 | 5277 | 2950 | 3620 | 2195 | |
Four E1 | G400 | Mediant 1000 | Tenor DX 4060 | Vega 400 | |||
* Street Price | 2995 | N / A | 8,000 | N / A | 4790 | 7092 | 2050 |
* List Price | 2995 | N / A | 9180 | N / A | 5865 | 8545 | 2700 |
Eight E1 | G800 | Mediant 2000 | Tenor DX 8120 | N / A | |||
* Street Price | 3995 | N / A | 15500 | N / A | 9999 | N / A | |
* List Price | 3995 | N / A | 17820 | N / A | 11750 | N / A |
Source: https://habr.com/ru/post/185468/
All Articles