MKP 2.4.1, removed token parameter, switch to app password parameter only

This commit is contained in:
mellis 2024-01-12 14:12:05 +01:00
parent 714990bffb
commit 05415a8d1d
4 changed files with 25 additions and 30 deletions

View File

@ -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)

View File

@ -2,8 +2,7 @@ def agent_nextcloud_arguments(params, hostname, ipaddress):
return [
"--hostname", params["hostname"],
"--username", params["username"],
"--password", params["password"],
"--token", passwordstore_get_cmdline("%s", params["token"]),
"--password", passwordstore_get_cmdline("%s", params["password"]),
"--port", params["port"],
"--folder", params["folder"],
"--no-https", params["no_https"],

View File

@ -26,19 +26,19 @@ def _valuespec_special_agent_nextcloud():
elements=[
("hostname", TextAscii(title=_("Hostname"),
allow_empty=False,
help=_("Hostname of Nextcloud server (bare FQDN or IP, IP not tested), mandatory"))),
size = 40,
help=_("Hostname of Nextcloud server (bare FQDN or IP), mandatory, eg. nextcloud.yourdomain.tld"))),
("username", TextAscii(title=_("Username"),
size = 40,
allow_empty=False,
help=_("Username with administrative rights, mandatory"))),
("password", Password(title=_("Password"),
allow_empty=True,
help=_("Specify password OR token, not both, token recommended"))),
("token", IndividualOrStoredPassword(title=_("App Password"),
allow_empty=True,
help=_("Specify password OR token, not both, token recommended"))),
("password", IndividualOrStoredPassword(title=_("App Password"),
size = 40,
allow_empty=False,
help=_("Specify app password, mandatory, use Personal Settings|Security|Devices and Sessions within the NC UI to create one for the given user"))),
("port", TextAscii(title=_("Port"),
allow_empty=True,
help=_("Specify port if not listening to HTTPS, optional"))),
help=_("Specify port if not listening to HTTP(S), optional"))),
("folder", TextAscii(title=_("Folder"),
allow_empty=True,
help=_("Specify subfolder if your Nextcloud instance is not installed in the web root, no trailing/leading slashes, optional"))),

BIN
mkp/Nextcloud-2.4.1.mkp Normal file

Binary file not shown.