Skip to content

Instantly share code, notes, and snippets.

@sei-dupdyke
Created August 16, 2020 12:25
Show Gist options
  • Save sei-dupdyke/51671bd0e66efae214bfec0eb2adf072 to your computer and use it in GitHub Desktop.
Save sei-dupdyke/51671bd0e66efae214bfec0eb2adf072 to your computer and use it in GitHub Desktop.
Simple python script to update every machine in an enclave with a new timeline
#!/usr/bin/env python3
import requests
import json
import os
host = "http://localhost:52388/"
# ---
def jsonify(x):
try:
return json.loads(json.dumps(x))
except:
print(x)
print(json.dumps(x))
exit(1)
def get_machines():
headers = {
'accept': '*/*'
}
response = requests.request(
"GET", host + "api/Machines", headers=headers)
return json.loads(response.text.encode('utf8'))
def post_timeline(machine_id):
print("Posting timeline to: " + machine_id)
payload = ""
with open("timeline_update.json", "r") as payload_file:
payload = json.load(payload_file)
payload["machineId"] = machine_id
payload = json.dumps(payload)
print(payload)
headers = {
'accept': 'text/plain',
'Content-Type': 'application/json'
}
response = requests.request(
"POST", host + "Timeline", headers=headers, data=payload)
print(response.text.encode('utf8'))
# ---
for machine in get_machines():
post_timeline(machine["id"])
{
"machineId": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
"type": 0,
"activeUtc": "2020-08-16T11:32:01.474Z",
"status": 0,
"update": {
"status": 0,
"timeLineHandlers": [
{
"handlerType": 1,
"initial": "about:blank",
"loop": true,
"timeLineEvents": [
{
"command": "random",
"commandArgs": ["http://www.ceoexpress.com", "http://wikipedia.org", "http://ebay.com", "http://craigslist.org"],
"delayAfter": 300000,
"delayBefore": 0
}
]
}
]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment