From 2d8ab09e42c2d67647ffcc35c8fe242233b73406 Mon Sep 17 00:00:00 2001 From: vlp Date: Wed, 26 Apr 2023 15:42:05 +0200 Subject: [PATCH 1/4] test --- misc/userscripts/add-nextcloud-bookmarks | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/misc/userscripts/add-nextcloud-bookmarks b/misc/userscripts/add-nextcloud-bookmarks index 86f4f5bc7..cd084f902 100755 --- a/misc/userscripts/add-nextcloud-bookmarks +++ b/misc/userscripts/add-nextcloud-bookmarks @@ -101,16 +101,22 @@ else: settings_info = [ ("host", "host information.", "required"), ("user", "username.", "required"), - ("password", "password.", "required"), + ("pass", "pass.", "choice"), + ("password", "password.", "choice"), ("description", "description or leave blank", "optional"), ("tags", "tags (comma separated) or leave blank", "optional"), ] # check for settings that need user interaction and clear optional setting if need be for setting in settings_info: - if setting[0] not in settings: - userInput = get_text(setting[0], setting[1]) - settings[setting[0]] = userInput + if setting[1] == "pass" and setting[0] != "": + passwordstore=exec(setting[0]) + if setting[0] not in settings and setting[1] =! "pass": + if setting[1] =! "password" and passwordstore != "": + settings[setting[0]] = passwordstore + else + userInput = get_text(setting[0], setting[1]) + settings[setting[0]] = userInput if setting[2] == "optional": if settings[setting[0]] == "None": settings[setting[0]] = "" From 20ee25e66988614690353537e269af89e2c5bab7 Mon Sep 17 00:00:00 2001 From: vlp Date: Wed, 26 Apr 2023 21:09:05 +0200 Subject: [PATCH 2/4] add pass command --- misc/userscripts/add-nextcloud-bookmarks | 33 +++++++++--------------- 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/misc/userscripts/add-nextcloud-bookmarks b/misc/userscripts/add-nextcloud-bookmarks index cd084f902..37b2747ad 100755 --- a/misc/userscripts/add-nextcloud-bookmarks +++ b/misc/userscripts/add-nextcloud-bookmarks @@ -37,6 +37,8 @@ troubleshooting: """ import configparser +import subprocess + from json import dumps from os import environ, path from sys import argv, exit @@ -98,28 +100,17 @@ if path.isfile(config_file): else: settings = {} -settings_info = [ - ("host", "host information.", "required"), - ("user", "username.", "required"), - ("pass", "pass.", "choice"), - ("password", "password.", "choice"), - ("description", "description or leave blank", "optional"), - ("tags", "tags (comma separated) or leave blank", "optional"), -] +if settings["pass"] == "" and settings["password"] == "": + message("error","at least password ou pass command should be completed") + exit(0) -# check for settings that need user interaction and clear optional setting if need be -for setting in settings_info: - if setting[1] == "pass" and setting[0] != "": - passwordstore=exec(setting[0]) - if setting[0] not in settings and setting[1] =! "pass": - if setting[1] =! "password" and passwordstore != "": - settings[setting[0]] = passwordstore - else - userInput = get_text(setting[0], setting[1]) - settings[setting[0]] = userInput - if setting[2] == "optional": - if settings[setting[0]] == "None": - settings[setting[0]] = "" +if settings["pass"] != "": + passcommand= settings["pass"] + process = subprocess.Popen(passcommand.split(), stdout=subprocess.PIPE) + output, error = process.communicate() + passresult = output.decode("utf-8") + password=passresult.partition('\n')[0] + settings["password"]=password tags = settings["tags"].split(",") From dac8bb87894f285518e6e3aa2effcfdbfd2c8170 Mon Sep 17 00:00:00 2001 From: vlp Date: Wed, 26 Apr 2023 21:14:28 +0200 Subject: [PATCH 3/4] doc --- misc/userscripts/add-nextcloud-bookmarks | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/misc/userscripts/add-nextcloud-bookmarks b/misc/userscripts/add-nextcloud-bookmarks index 37b2747ad..07d033ff5 100755 --- a/misc/userscripts/add-nextcloud-bookmarks +++ b/misc/userscripts/add-nextcloud-bookmarks @@ -13,16 +13,18 @@ userscript setup: [nextcloud] HOST=https://nextcloud.example.com USER=username -;PASSWORD=lamepassword +PASSWORD=lamepassword +or +PASS=get_password_command #PASS=pass bookmarks/user DESCRIPTION=None ;TAGS=just-one TAGS=read-me-later,added-by-qutebrowser, Another-One - If settings aren't in the configuration file, the user will be prompted during - bookmark creation. If DESCRIPTION and TAGS are set to None, they will be left - blank. If the user does not want to be prompted for a password, it is recommended + Settings should be into configuration file. If DESCRIPTION and TAGS are set to None, they will be left + blank. If the user does not want to use his password, it is recommended to set up an 'app password'. See the following for instructions: https://docs.nextcloud.com/server/latest/user_manual/en/session_management.html#managing-devices # noqa: E501 + pass option has been added to avoid clear password in a conf file. qutebrowser setup: add bookmark via hints From 449b3ea3bf5feb968eea30e6919e7a03f0dd427e Mon Sep 17 00:00:00 2001 From: vlp Date: Fri, 28 Apr 2023 12:41:18 +0200 Subject: [PATCH 4/4] input and run --- misc/userscripts/add-nextcloud-bookmarks | 41 ++++++++++++++++-------- 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/misc/userscripts/add-nextcloud-bookmarks b/misc/userscripts/add-nextcloud-bookmarks index 07d033ff5..5a5c905f2 100755 --- a/misc/userscripts/add-nextcloud-bookmarks +++ b/misc/userscripts/add-nextcloud-bookmarks @@ -14,13 +14,15 @@ userscript setup: HOST=https://nextcloud.example.com USER=username PASSWORD=lamepassword -or -PASS=get_password_command #PASS=pass bookmarks/user +PASS=password_command +;PASS=pass bookmarks/user +;PASS=NONE DESCRIPTION=None ;TAGS=just-one TAGS=read-me-later,added-by-qutebrowser, Another-One - Settings should be into configuration file. If DESCRIPTION and TAGS are set to None, they will be left + If settings aren't in the configuration file, the user will be prompted during + bookmark creation. If DESCRIPTION and TAGS are set to None, they will be left blank. If the user does not want to use his password, it is recommended to set up an 'app password'. See the following for instructions: https://docs.nextcloud.com/server/latest/user_manual/en/session_management.html#managing-devices # noqa: E501 @@ -99,20 +101,33 @@ if path.isfile(config_file): config = configparser.ConfigParser() config.read(config_file) settings = dict(config.items("nextcloud")) + if settings["pass"] != "": + passcommand= settings["pass"] + process = subprocess.run(passcommand.split(), capture_output=True, text=True) + output = process.stdout + password=output.partition('\n')[0] + settings["password"]=password else: settings = {} -if settings["pass"] == "" and settings["password"] == "": - message("error","at least password ou pass command should be completed") - exit(0) -if settings["pass"] != "": - passcommand= settings["pass"] - process = subprocess.Popen(passcommand.split(), stdout=subprocess.PIPE) - output, error = process.communicate() - passresult = output.decode("utf-8") - password=passresult.partition('\n')[0] - settings["password"]=password +settings_info = [ + ("host", "host information.", "required"), + ("user", "username.", "required"), + ("password", "password.", "required"), + ("pass", "pass command.", "noinput"), + ("description", "description or leave blank", "optional"), + ("tags", "tags (comma separated) or leave blank", "optional"), +] + +# check for settings that need user interaction and clear optional setting if need be +for setting in settings_info: + if setting[0] not in settings and setting[2] != "noinput": + userInput = get_text(setting[0], setting[1]) + settings[setting[0]] = userInput + if setting[2] == "optional": + if settings[setting[0]] == "None": + settings[setting[0]] = "" tags = settings["tags"].split(",")