Page 1 of 1

Reset deluge webui password.

Posted: Fri Aug 27, 2010 8:50 pm
by obses
Hi,

I've searched the forums, but can't find an up-to-date answer to the question.

I have lost my password for the deluge webui, and was wondering how I go about resetting it. I have tried removing the web.conf file, with no luck, and I can't find where it is stored so that I can reset it.

Any help is appreciated.
Thanks

Re: Reset deluge webui password.

Posted: Sat Aug 28, 2010 2:17 am
by johnnyg
You can use the following python script:
See below for newest version: http://forum.deluge-torrent.org/viewtop ... 47#p150899

Code: Select all

#!/usr/bin/env python
# Changes the password for Deluge's Web UI

from deluge.common import json
import hashlib
import os.path

DELUGE_DIR = "/etc/deluge"
                                                                                                                                                                                                                     
try:
    config_file = open(os.path.join(os.path.expanduser(DELUGE_DIR), "web.conf"))
    config = json.load(config_file)
    config_file.close()
except IOError, e:
    print "Can't open web ui config file: ", e
else:
    password = raw_input("Enter new password: ")
    s = hashlib.sha1()
    s.update(config['pwd_salt'])
    s.update(password)
    config['pwd_sha1'] = s.hexdigest()
    try:
        config_file = open(os.path.join(os.path.expanduser(DELUGE_DIR), "web.conf"), "w")
        json.dump(config, config_file)
    except IOError, e:
        print "Couldn't save new password: ", e
    else:
        print "New password successfully set!"
Make sure you change DELUGE_DIR to point to your deluge's setting directory and that deluge-web isn't running when you run this script.

Re: Reset deluge webui password.

Posted: Sat Aug 28, 2010 10:01 am
by obses
When I try to run the script, I get this error:

Code: Select all

Traceback (most recent call last):
  File "./delugeReset.py", line 12, in <module>
    config = json.load(config_file)
  File "/var/lib/python-support/python2.5/simplejson/__init__.py", line 273, in load
    parse_constant=parse_constant, **kw)
  File "/var/lib/python-support/python2.5/simplejson/__init__.py", line 313, in loads
    return _default_decoder.decode(s)
  File "/var/lib/python-support/python2.5/simplejson/decoder.py", line 324, in decode
    raise ValueError(errmsg("Extra data", s, end, len(s)))
ValueError: Extra data: line 4 column 2 - line 20 column 2 (char 31 - 489)
I've double checked my config directory path is correct (~/.config/deluge), but I don't know any python so I'm not sure what it's erroring on to go any further.

Thanks for your help.

Re: Reset deluge webui password.

Posted: Sat Aug 28, 2010 10:11 am
by obses
If it helps, this is what my web.conf file looks like. It seems to error when it tries to read the second part of the file.

Code: Select all

{
  "file": 1,
  "format": 1
}{
  "sidebar_show_zero": false,
  "pkey": "ssl/daemon.pkey",
  "https": false,
  "sessions": {},
  "pwd_salt": "a8fce7b60bc6b1fdd6fdc39d472cee89afa579e5",
  "port": 53009,
  "show_session_speed": false,
  "cert": "ssl/daemon.cert",
  "enabled_plugins": [],
  "pwd_sha1": "88eeeb13cd717c760489d901edde8a1bc65e5bf7",
  "sidebar_show_trackers": false,
  "theme": "slate",
  "session_timeout": 3600,
  "show_sidebar": true,
  "default_daemon": ""
}

Re: Reset deluge webui password.

Posted: Sun Feb 20, 2011 3:15 am
by BugBear
Has anyone gotten the script that johnnyg posted to work? I'm getting the same errors as obses.

Code: Select all

./dwebuipass.py
Traceback (most recent call last):
  File "./dwebuipass.py", line 12, in <module>
    config = json.load(config_file)
  File "/usr/lib/python2.6/json/__init__.py", line 267, in load
    parse_constant=parse_constant, **kw)
  File "/usr/lib/python2.6/json/__init__.py", line 307, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python2.6/json/decoder.py", line 322, in decode
    raise ValueError(errmsg("Extra data", s, end, len(s)))
ValueError: Extra data: line 4 column 2 - line 29 column 1 (char 31 - 672)
This script would be very useful to me.

I would be very grateful if someone shed some light on this.

Thanks

EDIT:

Made it work by removing the following from the top:

Code: Select all

{
  "file": 1,
  "format": 1
}

Re: Reset deluge webui password.

Posted: Sun Feb 20, 2011 11:42 am
by johnnyg
I remember reading that error and then rewriting the script to work with any config file but I obviously forgot to post it :oops:

Anyway, here it is for anyone else who needs it.

Code: Select all

#!/usr/bin/env python                                                                                                                                                                         
# Changes the password for Deluge's Web UI

from deluge.config import Config
import hashlib
import os.path
import sys

if len(sys.argv) == 2:
    deluge_dir = os.path.expanduser(sys.argv[1])

    if os.path.isdir(deluge_dir):
        try:
            config = Config("web.conf", config_dir=deluge_dir)
        except IOError, e:
            print "Can't open web ui config file: ", e
        else:
            password = raw_input("Enter new password: ")
            s = hashlib.sha1()
            s.update(config['pwd_salt'])
            s.update(password)
            config['pwd_sha1'] = s.hexdigest()
            try:
                config.save()
            except IOError, e:
                print "Couldn't save new password: ", e
            else:
                print "New password successfully set!"
    else:
        print "%s is not a directory!" % deluge_dir
else:
    print "Usage: %s <deluge config dir>" % (os.path.basename(sys.argv[0]))

Re: Reset deluge webui password.

Posted: Sun Feb 20, 2011 9:18 pm
by BugBear
Thanks Sooo much :D

Re: Reset deluge webui password.

Posted: Thu Apr 21, 2011 12:14 pm
by forkandspoon
Thanks that python script is useful.

Re: Reset deluge webui password.

Posted: Wed Dec 18, 2024 7:43 pm
by Bob4
Updated script for python3
You still need to remove the leading

Code: Select all

{
  "file": 1,
  "format": 1
}
Copy and save into a file such as pwd_reset.py and mark executable chmod +x pwd_reset.py (if you are a dinosaur still running Windows then everything is automatically executable because what's security.)
Run with pwd_reset.py <Deluge config directory> and without a parameter it will default to /etc/deluge
e.g. For my setup it's pwd_reset.py .config/deluge run from the deluge user directory.

Code: Select all

#!/usr/bin/env python3
# Changes the password for Deluge's Web UI

import getpass
import hashlib
import json
import os
import sys
import traceback
from typing import Any


def get_deluge_cfg_dir() -> str:
    if len(sys.argv) > 1:
        return sys.argv[1]
    else:
        return '/etc/deluge'


def load_web_cfg(path: str) -> Any:
    with open(path, 'r') as fp:
        return json.load(fp)


def get_new_password(salt: str) -> str:
    s = hashlib.sha1()
    s.update(salt.encode())
    password = getpass.getpass('Enter new password: ')
    second = getpass.getpass('Re-enter new password: ')
    if password != second:
        raise ValueError('Passwords do not match')
    s.update(password.encode())
    return s.hexdigest()


def save_web_cfg(path: str, config: Any):
    with open(path, 'w') as fp:
        json.dump(config, fp)
    pass


def main() -> int:
    try:
        deluge_cfg_dir = get_deluge_cfg_dir()
        web_cfg_path = os.path.join(os.path.expanduser(deluge_cfg_dir), 'web.conf')
        config = load_web_cfg(web_cfg_path)
        config['pwd_sha1'] = get_new_password(config['pwd_salt'])
        save_web_cfg(web_cfg_path, config)
        print('New password successfully set!')
        return 0
    except Exception as ex:
        traceback.print_exc()
    pass


if __name__ == '__main__':
    sys.exit(main())