Last active
November 21, 2023 23:00
-
-
Save brysontyrrell/b46422644912fc4e3280ea9bad22d44f to your computer and use it in GitHub Desktop.
Create a JSS admin account
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import getpass | |
import sys | |
import xml.etree.ElementTree as Et | |
import requests | |
try: | |
NEW_USERNAME = sys.argv[1] | |
except IndexError: | |
print('No username provided!') | |
sys.exit(1) | |
JSS_URL = str(raw_input('JSS URL (https://your.jss.com): ')) | |
JSS_USER = str(raw_input('JSS Username: ')) | |
JSS_PASS = getpass.getpass('JSS Password: ') | |
session = requests.Session() | |
resp = session.post(JSS_URL, data={'username':JSS_USER , 'password': JSS_PASS}) | |
try: | |
resp.raise_for_status() | |
except Exception: | |
print('Unable to connect to the JSS!') | |
print(resp.status_code) | |
sys.exit(2) | |
def get_session_token(html_text): | |
for line in html_text.splitlines(): | |
if 'session-token' in line: | |
return line.encode('utf-8').translate(None, '<>"').split('=')[-1] | |
SESSION_TOKEN = get_session_token(session.get('{}/accounts.html?id=1&o=r&nav=null'.format(JSS_URL)).text) | |
FORM_DICT = { | |
'session-token': SESSION_TOKEN, | |
'userUsername': NEW_USERNAME, | |
'FIELD_PRIVILEGE_LEVEL': '4', | |
'FIELD_ACCOUNT_STATUS': '1', | |
'realname': NEW_USERNAME, | |
'emailAddress': '', | |
'userPassword': '', # Populate the password here! | |
'userPasswordVerify': '', # Populate the password here! | |
'FIELD_FORCE_CHANGE_PASSWORD': 'on', | |
'action': 'Save', | |
"objectsCreate": [], # Populate priviliges here! | |
"objectsRead": [], # Populate priviliges here! | |
"objectsUpdate": [], # Populate priviliges here! | |
"objectsDelete": [] # Populate priviliges here! | |
} | |
resp = session.get('{}/accounts.html?id=-1&o=c'.format(JSS_URL)) | |
resp = session.post('{}/accounts.html?id=-1&o=c'.format(JSS_URL), data=FORM_DICT) | |
try: | |
resp.raise_for_status() | |
except Exception: | |
print('There was an error creating the user!') | |
print(resp.status_code) | |
print(resp.text) | |
sys.exit(2) | |
sys.exit(0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment