aboutsummaryrefslogtreecommitdiffstats
path: root/deluge/common.py
diff options
context:
space:
mode:
Diffstat (limited to 'deluge/common.py')
-rw-r--r--deluge/common.py23
1 files changed, 14 insertions, 9 deletions
diff --git a/deluge/common.py b/deluge/common.py
index 7b76d24..7f94b54 100644
--- a/deluge/common.py
+++ b/deluge/common.py
@@ -1232,12 +1232,9 @@ AUTH_LEVEL_ADMIN = 10
AUTH_LEVEL_DEFAULT = AUTH_LEVEL_NORMAL
-def create_auth_file():
+def create_auth_file(auth_file):
import stat
- import deluge.configmanager
-
- auth_file = deluge.configmanager.get_config_dir('auth')
# Check for auth file and create if necessary
if not os.path.exists(auth_file):
with open(auth_file, 'w', encoding='utf8') as _file:
@@ -1247,22 +1244,26 @@ def create_auth_file():
os.chmod(auth_file, stat.S_IREAD | stat.S_IWRITE)
-def create_localclient_account(append=False):
+def create_localclient_account(append=False, auth_file=None):
import random
from hashlib import sha1 as sha
import deluge.configmanager
- auth_file = deluge.configmanager.get_config_dir('auth')
+ if not auth_file:
+ auth_file = deluge.configmanager.get_config_dir('auth')
+
if not os.path.exists(auth_file):
- create_auth_file()
+ create_auth_file(auth_file)
+ username = 'localclient'
+ password = sha(str(random.random()).encode('utf8')).hexdigest()
with open(auth_file, 'a' if append else 'w', encoding='utf8') as _file:
_file.write(
':'.join(
[
- 'localclient',
- sha(str(random.random()).encode('utf8')).hexdigest(),
+ username,
+ password,
str(AUTH_LEVEL_ADMIN),
]
)
@@ -1270,6 +1271,7 @@ def create_localclient_account(append=False):
)
_file.flush()
os.fsync(_file.fileno())
+ return username, password
def get_localhost_auth():
@@ -1306,6 +1308,9 @@ def get_localhost_auth():
if username == 'localclient':
return (username, password)
+ log.warning('Could not find localclient account in auth file.')
+ return None, None
+
def set_env_variable(name, value):
"""