MKP 2.4.1, removed token parameter, switch to app password parameter only
This commit is contained in:
@@ -16,26 +16,24 @@ def showUsage():
|
||||
|
||||
USAGE: agent_nextcloud_info -u [username] -p [password]
|
||||
OR
|
||||
agent_nextcloud_info -u [username] -t [token]
|
||||
agent_nextcloud_info -h
|
||||
|
||||
OPTIONS:
|
||||
-H, --hostname Hostname (FQDN or IP) of Nextcloud server
|
||||
-u, --username Username
|
||||
-p, --password Password
|
||||
-p, --password App Password
|
||||
-P, --port Port
|
||||
-f, --folder Subfolder if not installed in web root
|
||||
-t, --token Token (recommended)
|
||||
--no-https True|False If "True": Disable HTTPS, use HTTP (not recommended!)
|
||||
--no-cert-check True|False If "True": Disable TLS certificate check (not recommended!)
|
||||
-h, --help Show this help message and exit
|
||||
""")
|
||||
|
||||
# set this to true to produce debug output (this clutters the agent output)
|
||||
# be aware: activating this logs very sensitive information to debug files in ~/tmp
|
||||
# be aware: activating this flag logs very sensitive information to debug files in ~/tmp
|
||||
# !!DO NOT FORGET to delete these files after debugging is done!!
|
||||
|
||||
DEBUG = True
|
||||
DEBUG = False
|
||||
|
||||
nc_api_endpoint = "ocs/v2.php/apps/serverinfo/api/v1/info?format=json"
|
||||
nc_api_endpoint_all_users = "ocs/v1.php/cloud/users?format=json"
|
||||
@@ -46,13 +44,12 @@ opt_username = ""
|
||||
opt_password = ""
|
||||
opt_port = ""
|
||||
opt_folder = ""
|
||||
opt_token = "0"
|
||||
opt_no_https = False
|
||||
opt_no_cert_check = False
|
||||
|
||||
short_options = 'hH:u:p:P:f:t:'
|
||||
short_options = 'hH:u:p:P:f:'
|
||||
long_options = [
|
||||
'hostname=', 'username=', 'password=', 'port=', 'token=', 'folder=', 'no-https=', 'no-cert-check=', 'help'
|
||||
'hostname=', 'username=', 'password=', 'port=', 'folder=', 'no-https=', 'no-cert-check=', 'help'
|
||||
]
|
||||
|
||||
def logDebug(line):
|
||||
@@ -70,7 +67,6 @@ def getOptions():
|
||||
global opt_password
|
||||
global opt_port
|
||||
global opt_folder
|
||||
global opt_token
|
||||
global opt_no_https
|
||||
global opt_no_cert_check
|
||||
|
||||
@@ -86,8 +82,6 @@ def getOptions():
|
||||
opt_port = arg
|
||||
elif opt in ['-f', '--folder']:
|
||||
opt_folder = arg
|
||||
elif opt in ['-t', '--token']:
|
||||
opt_token = arg
|
||||
elif opt in ['--no-https']:
|
||||
if arg == 'True':
|
||||
opt_no_https = True
|
||||
@@ -109,13 +103,12 @@ def showOptions():
|
||||
print(f"Password: {opt_password}")
|
||||
print(f"Port: {opt_port}")
|
||||
print(f"Folder: {opt_folder}")
|
||||
print(f"Token: {opt_token}")
|
||||
print(f"No HTTPS: {opt_no_https}")
|
||||
print(f"No TLS Check: {opt_no_cert_check}")
|
||||
logDebug(f"showOptions - Hostname: {opt_hostname}, Port: {opt_port}, No HTTPS: {opt_no_https}, No Cert Check: {opt_no_cert_check}\n")
|
||||
|
||||
def createUrl(endpoint, hostname, protocol, port, folder):
|
||||
# these parameters are needed, otherwise no information about updates regarding apps and Nextcloud itself are not reported (since version 28)
|
||||
# these parameters are needed, otherwise no information about updates regarding apps and Nextcloud itself are reported (since version 28)
|
||||
params = "skipApps=false&skipUpdate=false"
|
||||
if folder == "":
|
||||
url = f"{protocol}://{hostname}:{port}/{endpoint}"
|
||||
@@ -264,6 +257,14 @@ def main():
|
||||
sys.stderr.write(f"No hostname given.\n")
|
||||
showUsage()
|
||||
sys.exit(1)
|
||||
if (opt_username == ""):
|
||||
sys.stderr.write(f"No username given.\n")
|
||||
showUsage()
|
||||
sys.exit(1)
|
||||
if (opt_password == ""):
|
||||
sys.stderr.write(f"No password given.\n")
|
||||
showUsage()
|
||||
sys.exit(1)
|
||||
if (opt_no_cert_check):
|
||||
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
|
||||
verify = False
|
||||
@@ -290,13 +291,8 @@ def main():
|
||||
if (protocol == "https" and port == "80"):
|
||||
sys.stderr.write(f"Combining HTTPS with port 80 is not supported.\n")
|
||||
sys.exit(1)
|
||||
if (opt_token == '0'):
|
||||
# authenticate with username and password
|
||||
pwd = opt_password
|
||||
else:
|
||||
# authenticate with token
|
||||
pwd = opt_token
|
||||
|
||||
pwd = opt_password
|
||||
|
||||
# create session
|
||||
session = getSession(opt_username, pwd)
|
||||
nc_url = createUrl(nc_api_endpoint, opt_hostname, protocol, port, opt_folder)
|
||||
|
||||
Reference in New Issue
Block a user