#!/usr/bin/python
#
# This program collects network status information from the router and posts it to a CGI
#  on status.mudlogsys.com.
#

# Most of the information will be JSON data from http://127.0.0.1/cgi-bin/parameters.cgi
#
# {
# "barcode":"ML-997",
# "pingArray":[
#	{"reachable""3},	//Of the 3 test servers, how many are reachable
#	{"rtt":206},		//average round trip time for ping packets that reached a test server
#	{"mdev":10},		//average standard deviation of the ping packets that reached a test server
#	{"loss":0}		//average packet loss
#	],
#	"bucket":0,		//int:percentage of 5GB/mo bandwidth bucket used
#	"buckettx":0,		//int:percentage of 5GB/mo bandwidth bucket used for transmit
#	"bucketrx":0,		//int:percentage of 5GB/mo bandwidth bucket used for receive
# "connectionTime":106,		//int:3G connection time in seconds
# "ip":"10.20.26.4",		//VPN IP
# "vpnStatus":"Active",		//
# "wanManager":"Automatic",	//Automatic, Verizon, or AT&T
# "currentProvider":"Verizon",	//Verizon or AT&T
# "speedCap":"N\/A",		//N/A,10,100 kbps bandwidth capped
# "cards":[
#	{"provider":"AT&T","rssi":"0","roaming":"0"},
#	{"provider":"Verizon","rssi":"-60","roaming":"0"}
#	]
#}

import urllib2
import json
import sys

req = urllib2.Request("http://127.0.0.1/cgi-bin/parameters.cgi")
opener = urllib2.build_opener()
f = opener.open(req)
data = json.load(f)

box = data['barcode']

req2 = urllib2.Request("http://status.mudlogsys.com/cgi-bin/upload.py",json.dumps(data))
req2.add_header('User-Agent', box)
f2 = opener.open(req2)


