Skip to content

Instantly share code, notes, and snippets.

View Gerrrr's full-sized avatar

Alex Sorokoumov Gerrrr

  • Bay Area, California
View GitHub Profile
In [227]: def send(token, pushmagic):
byteToken = a2b_base64(token)
payload = {'mdm': pushmagic}
data = json.dumps(payload)
format = '!BH32sH%ds' % len(data)
notification = struct.pack(format, 0, 32, byteToken, len(data), data)
host = ( 'gateway.sandbox.push.apple.com', 2195 )
certfile = '/Users/gerrrr/Work/curupira/apns-dis/apnsdis/APNS-certs/mobspro-apns.cer.pem'
keyfile = '/Users/gerrrr/Work/curupira/apns-dis/apnsdis/APNS-certs/mobspro-apns.key'
ssl_sock = ssl.wrap_socket(socket.socket(socket.AF_INET, socket.SOCK_STREAM), certfile=certfile, keyfile=keyfile)
@Gerrrr
Gerrrr / gist:3210629
Created July 30, 2012 21:51
pyst2 test
import asterisk.manager
manager = asterisk.manager.Manager()
manager.connect('localhost', port=5038)
manager.login('AMI', 'AMIPASSWORD')
print "connected: ", manager.connected()
print "status: ", manager.status()
print "sip show peers:"
print manager.command("sip show peers").data
{'headers': {'WaitEvent': 'Wait for an event to occur. (Priv: <none>)', 'Redirect': 'Redirect (transfer) a call. (Priv: call,all)', 'Events': 'Control Event Flow. (Priv: <none>)', 'PlayDTMF': 'Play DTMF signal on a specific channel. (Priv: call,all)', 'QueuePenalty': 'Set the penalty for a queue member. (Priv: agent,all)', 'MixMonitorMute': 'Mute / unMute a Mixmonitor recording. (Priv: <none>)', 'MuteAudio': 'Mute an audio stream (Priv: system,all)', 'LocalOptimizeAway': 'Optimize away a local channel when possible. (Priv: system,call,all)', 'DBDelTree': 'Delete DB Tree. (Priv: system,all)', 'QueueLog': 'Adds custom entry in queue_log. (Priv: agent,all)', 'DataGet': 'Retrieve the data api tree. (Priv: <none>)', 'QueuePause': 'Makes a queue member temporarily unavailable. (Priv: agent,all)', 'CoreStatus': 'Show PBX core status variables. (Priv: system,reporting,all)', 'Command': 'Execute Asterisk CLI Command. (Priv: command,all)', 'ParkedCalls': 'List parked calls. (Priv: <none>)', 'GetConfig': '
-------------------------
* Originally designed to return the initial data,
* but for now just return user authentication info.
-------------------------
Request: /init
Parameter: none
Response: return the user authentication info.
Json: {
user: {
isloggedin: true, // if logged in, return true, if not, return false,
(ve)Name:curupira gerrrr$ http 127.0.0.1:5000/user/login login=admin password=123456HTTP/1.0 200 OKContent-Type: text/html; charset=utf-8Content-Length: 34
Set-Cookie: session="ks49WKOyk2zCfr0DGTqql4HEYh0=?_fresh=STAxCi4=&_id=UydceGUzU3dceGYxL1x4MDFqW1x4ZDdceGYzPStUXHhiN2ZpJwpwMQou&user_id=Y2NvcHlfcmVnCl9yZWNvbnN0cnVjdG9yCnAxCihjYnNvbi5vYmplY3RpZApPYmplY3RJZApwMgpjX19idWlsdGluX18Kb2JqZWN0CnAzCk50UnA0ClMiT1x4ZjRLdFx4ZjcnXHhkMlx4MDhtXHgwMFx4MDBceDAwIgpwNQpiLg=="; Path=/; HttpOnly
Server: Werkzeug/0.8.3 Python/2.7.1
Date: Fri, 10 Aug 2012 12:11:23 GMT
{"id": "4ff44b74f727d2086d000000"}
(ve)Name:curupira gerrrr$ http 127.0.0.1:5000/user/status Cookie:session="ks49WKOyk2zCfr0DGTqql4HEYh0=?_fresh=STAxCi4=&_id=UydceGUzU3dceGYxL1x4MDFqW1x4ZDdceGYzPStUXHhiN2ZpJwpwMQou&user_id=Y2NvcHlfcmVnCl9yZWNvbnN0cnVjdG9yCnAxCihjYnNvbi5vYmplY3RpZApPYmplY3RJZApwMgpjX19idWlsdGluX18Kb2JqZWN0CnAzCk50UnA0ClMiT1x4ZjRLdFx4ZjcnXHhkMlx4MDhtXHgwMFx4MDBceDAwIgpwNQpiLg=="
HTTP/1.0 200 OK
Content-Type: text/html; charset=utf-8
Content-Length:
# successful user login
Request:
http 127.0.0.1:5000/user/login login=admin password=123456
Response:
HTTP/1.0 200 OK
Content-Type: text/html; charset=utf-8
Content-Length: 74
Set-Cookie: session="y+s2moFAmfy1aIaEkeeQN9Ps5Q0=?_fresh=STAxCi4=&_id=UydceGMxXHgxOVllXHhkZVx4ZWZpKlRceGU3XHhmYlx4MDNceGNiXHhlZFx4Y2FcbicKcDEKLg==&user_id=Y2NvcHlfcmVnCl9yZWNvbnN0cnVjdG9yCnAxCihjYnNvbi5vYmplY3RpZApPYmplY3RJZApwMgpjX19idWlsdGluX18Kb2JqZWN0CnAzCk50UnA0ClMnUCUwSVx4ZWVceGYzXHhkNXhnZFx4YTgpJwpwNQpiLg=="; Path=/; HttpOnly
Server: Werkzeug/0.8.3 Python/2.7.2+
Date: Tue, 14 Aug 2012 20:51:20 GMT
@Gerrrr
Gerrrr / gist:3350847
Created August 14, 2012 16:56
Json renderer for objectid and datetime
class APIEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, datetime.datetime):
return date_to_str(obj)
elif isinstance(obj, ObjectId):
return str(obj)
return jsonJSONEncoder.default(obj)
def json_renderer(**data):
$ http http://mdm.sandbox.mobsafety.com:5000/device/list
HTTP/1.0 200 OK
Content-Type: text/html; charset=utf-8
Content-Length: 33832
Set-Cookie: session="VMIAYr20KBuDdb8HKgRRUdL8O0o=?_id=UydhJFxcTFx4ZjJ2XHg4OVx4ZTRceGUyXHgwZlx4YWJceGFhXHg5ZVxcXHhmZlx4ZWInCnAxCi4="; Path=/; HttpOnly
Server: Werkzeug/0.8.3 Python/2.7.2+
Date: Mon, 27 Aug 2012 12:37:28 GMT
[{"registration_id": "APA91bEcvB69mfEeLkjfiJTh26ReMGjbkKHe-CGjVMzxB_kMu1ZsJHtMdC-7wbQTNyEn3LY2JijXyKMCf24D7rkEjxS9aFMSlRA6J3OmoCE8N0zJZrQT_aChInVcBzNBSKD1v1o6-nBaES7EVBg0gTdHIadQgJD9LA", "os": "Android (Ice Cream Sandwich)", "phone": "+1-860-9823725", "enrolled": "Thu Aug 23 16:46", "included": "Thu Aug 23 16:46", "notification_type": "email", "message": "Your device [phone] was selected to enter our mobile management service. Link : [link]", "_id": "50365ce2eef3d5539c000001", "holder": "Ding-Ice", "email": "goodfriend1985517@gmail.com", "identity": "published"}, {"registration_id": "APA91bE-S15tdDh0Gevq-n7X-YIdb7KPNSPU1M7BmtTdik9s62mA9QsEfvacQ7FY9KjCqsbz1EC
[
/* file */
{ "keys": ["ctrl+x+s"], "command": "save" },
/* edit */
{ "keys": ["ctrl+/"], "command": "undo" },
{ "keys": ["ctrl+shift+/"], "command": "redo"},
{ "keys": ["alt+d"], "command": "delete_word", "args": { "forward": true, "sub_words": true } },
{ "keys": ["ctrl+w"], "command": "cut" },
{ "keys": ["alt+w"], "command": "copy" },
{u'_id': ObjectId('503d26c5eef3d53674000003'),
u'apps': [{u'app_name': u'Android+Live+Wallpapers',
u'app_status': u'running',
u'package_name': u'com.android.wallpaper',
u'version_name': u'2.3.6'},
{u'app_name': u'Google+Services+Framework',
u'app_status': u'running',
u'package_name': u'com.google.android.gsf',
u'version_name': u'2.3.6'},
{u'app_name': u'%ED%95%9C%EA%B8%80+%EC%A0%91%EC%B4%89%EC%8B%9D+%ED%82%A4%EB%B3%B4%EB%93%9C',