/
orangehrm.py
executable file
·52 lines (39 loc) · 1.22 KB
/
orangehrm.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
#!/usr/bin/python3
"""Set OrangeHRM admin password
Option:
--pass= unless provided, will ask interactively
"""
import sys
import getopt
import hashlib
from libinithooks.dialog_wrapper import Dialog
from mysqlconf import MySQL
def usage(s=None):
if s:
print("Error:", s, file=sys.stderr)
print("Syntax: %s [options]" % sys.argv[0], file=sys.stderr)
print(__doc__, file=sys.stderr)
sys.exit(1)
def main():
try:
opts, args = getopt.gnu_getopt(sys.argv[1:], "h",
['help', 'pass='])
except getopt.GetoptError as e:
usage(e)
password = ""
for opt, val in opts:
if opt in ('-h', '--help'):
usage()
elif opt == '--pass':
password = val
if not password:
d = Dialog('TurnKey Linux - First boot configuration')
password = d.get_password(
"OrangeHRM Password",
"Enter new password for the OrangeHRM 'admin' account.",
min_complexity=4)
hash = hashlib.md5(password.encode('utf8')).hexdigest()
m = MySQL()
m.execute('UPDATE orangehrm.ohrm_user SET user_password=%s WHERE user_name=\"admin\";', (hash,))
if __name__ == "__main__":
main()