-
Notifications
You must be signed in to change notification settings - Fork 7
/
locking.py
127 lines (88 loc) · 2.79 KB
/
locking.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#
# Copyright (C) 2016-
# Sean Poyser (seanpoyser@gmail.com)
#
# This Program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This Program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with XBMC; see the file COPYING. If not, write to
# the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
# http://www.gnu.org/copyleft/gpl.html
#
import xbmcgui
import os
import utils
import favourite
import parameters
import cache
FOLDERCFG = utils.FOLDERCFG
GETTEXT = utils.GETTEXT
def add(path, name):
title = GETTEXT(30079)
password = utils.GetText(title, text='', hidden=True)
if not password:
return False
md5 = utils.generateMD5(password)
cfg = os.path.join(path, FOLDERCFG)
parameters.setParam('LOCK', md5, cfg)
return True
def remove(path,name):
title = GETTEXT(30078)
password = utils.GetText(title, text='', hidden=True)
if not password:
return False
md5 = utils.generateMD5(password)
cfg = os.path.join(path, FOLDERCFG)
lock = parameters.getParam('LOCK', cfg)
if lock != md5:
utils.DialogOK(GETTEXT(30080))
return False
parameters.clearParam('LOCK', cfg)
utils.DialogOK(GETTEXT(30081))
return True
def unlocked(path, lock=None):
if not lock:
folderConfig = os.path.join(path, FOLDERCFG)
lock = parameters.getParam('LOCK', folderConfig)
if not lock:
return True
if cache.exists(path):
return True
return False
def unlock(path):
folderConfig = os.path.join(path, FOLDERCFG)
lock = parameters.getParam('LOCK', folderConfig)
if unlocked(path, lock):
return True
md5 = checkPassword(path, lock)
if len(md5) == 0:
return False
if md5 == 'ERROR':
utils.DialogOK(GETTEXT(30080))
return False
periods = [0, 1, 5, 15]
setting = int(utils.ADDON.getSetting('CACHE'))
period = periods[setting]
cache.add(path, period)
return True
def checkPassword(path, lock=None):
if not lock:
folderConfig = os.path.join(path, FOLDERCFG)
lock = parameters.getParam('LOCK', folderConfig)
title = GETTEXT(30069)
unlock = utils.GetText(title, hidden=True)
if not unlock:
return ''
md5 = utils.generateMD5(unlock)
match = md5 == lock
if not match:
return 'ERROR'
return md5