Skip to content

Instantly share code, notes, and snippets.

@sammachin
Last active January 21, 2017 21:31
Show Gist options
  • Save sammachin/10261431 to your computer and use it in GitHub Desktop.
Save sammachin/10261431 to your computer and use it in GitHub Desktop.
Simple MO SMS HTTP Server for A&A SIP2SIM
#!/usr/bin/python
import SimpleHTTPServer
import SocketServer
import logging
import cgi
PORT = 8001
I = '0.0.0.0'
def procmsg(data):
#Do something with your SMS here
print "Message recieved from: " + data['iccid'] + " sent to: " + data['destination'] + " containing the text: " + data['message']
class ServerHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
def do_GET(self):
self.send_response(200, 'OK')
self.send_header('Content-type', 'text/html')
self.send_header('Content-length', '0')
self.end_headers()
def do_POST(self):
form = cgi.FieldStorage(
fp=self.rfile,
headers=self.headers,
environ={'REQUEST_METHOD':'POST',
'CONTENT_TYPE':self.headers['Content-Type'],
})
data = {}
for f in form.list:
data[f.name] = f.value
procmsg(data)
SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self)
Handler = ServerHandler
httpd = SocketServer.TCPServer((I, PORT), Handler)
print "Serving at: http://%(interface)s:%(port)s" % dict(interface=I or "localhost", port=PORT)
httpd.serve_forever()
@User2uk
Copy link

User2uk commented May 15, 2015

Hi,
How do i use this script to post sms from sip2sim to external gateway (anveo).
Anveo https gateway script below. wondering where this fit into their script.

!/usr/bin/php -q

,,) * */ function SendSMS($to_number,$from_number,$message){ $apikey="- YOUR API KEY -"; //CHANGE ME echo "Sending sms ...\n"; // need curl with https if using https:// $ch = curl_init ("https://www.anveo.com/api/v1.asp?apikey=".$apikey."&action=sms&destination=".$to_number."&from=".$from_number."&message=".urlencode($message)); curl_setopt($ch, CURLOPT_TIMEOUT, 10); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); $result=curl_exec ($ch); curl_close ($ch); /_parse the result_/ $records_array=explode('^',$result); foreach($records_array as $record){ $field_array=explode('=',$record); if (is_array($field_array)){ $map[$field_array[0]]=$field_array[1]; } } echo "result:".$map["result"]."\n\n"; echo "error text:".$map["error"]."\n"; echo "parts:".$map["parts"]."\n"; echo "fee:".$map["fee"]."\n"; } ?>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment