|
#!/usr/bin/env python3
|
|
import xmlrpc.client
|
|
import sys
|
|
from xml.parsers.expat import ParserCreate, ExpatError, errors
|
|
|
|
# Target pfSense software instance
|
|
target = "198.51.100.34"
|
|
|
|
# User Manager users and authentication servers are required for proper test
|
|
|
|
# LDAP server should be defined and set as source of system authentication in
|
|
# User Manager settings
|
|
|
|
def try_ace(auth, target, expected):
|
|
server = f'https://{auth}@{target}/xmlrpc.php'
|
|
pfs = xmlrpc.client.ServerProxy(server)
|
|
executed = "Unknown"
|
|
try:
|
|
result = pfs.pfsense.exec_php('$toreturn = exec("id"); return $toreturn;')
|
|
print(" Success: ", result )
|
|
executed = "Yes"
|
|
except xmlrpc.client.Fault as err:
|
|
print(" Failed to execute command:")
|
|
print(" Error: %s" % err.faultString)
|
|
executed = "No"
|
|
except ExpatError as err:
|
|
print(" Response is not well-formed")
|
|
print(" Error: %s" % errors.messages[err.code])
|
|
executed = "Possible"
|
|
|
|
if executed == expected:
|
|
print("GOOD!")
|
|
else:
|
|
print("BAD!")
|
|
print("----------------------------------")
|
|
|
|
def main():
|
|
try:
|
|
# The accounts used here are specific to my local setup, replace with your own.
|
|
print('local "admin" user (should succeed):')
|
|
try_ace("admin:pfsense2", target, "Yes")
|
|
print('remote "admin" user (should succeed):')
|
|
try_ace("admin:admin", target, "Yes")
|
|
print('local user with sync privilege (should succeed):')
|
|
try_ace("localsync:ls123", target, "Yes")
|
|
print('local user without sync privilege (should fail):')
|
|
try_ace("shelly:shelly2", target, "No")
|
|
print('remote user with local entry and sync privilege (should succeed):')
|
|
try_ace("vpnguy:vpnguy", target, "Yes")
|
|
print('remote user with local entry but no sync privilege (should fail):')
|
|
try_ace("jimp:jimp", target, "No")
|
|
print('remote user with no local entry (should fail):')
|
|
try_ace("loggy:loggy", target, "No")
|
|
print('nonexistent user (should fail):')
|
|
try_ace("auth:pass", target, "No")
|
|
|
|
except ValueError as err:
|
|
return str(err)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|