-
Notifications
You must be signed in to change notification settings - Fork 0
/
initwebuser.py
64 lines (55 loc) · 2.08 KB
/
initwebuser.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
#!/usr/bin/python
import sys
sys.dont_write_bytecode = True # No '*.pyc' precompiled files
import re, time
from lib_parameters import asterisk_db
from lib_parameters import ampusers_table
from lib_parameters import db_user
from lib_parameters import db_password
from lib_parameters import host
from lib_parameters import web_admin_name
from lib_parameters import web_admin_sha
from lib_mysql import MySqlConnector
class WebAdminInitiation:
'''
Class for automatic creation of an initial web admin user.
'''
def __init__(self, asterisk_db, ampusers_table):
self.asterisk_db = asterisk_db
self.db_user = db_user
self.db_password = db_password
self.host = host
self.ampusers_table = ampusers_table
self.web_admin_name = web_admin_name
self.web_admin_sha = web_admin_sha
self.connector_to_asterisk_db = MySqlConnector(
database=self.asterisk_db,
db_user=self.db_user,
db_password=self.db_password,
host=self.host,
)
def del_webadmin_from_ampusers_table(self, ampusers_table='ampusers'):
self.connector_to_asterisk_db.connect()
self.connector_to_asterisk_db.delete_from_table(table=ampusers_table)
self.connector_to_asterisk_db.disconnect()
def add_webadmin_to_ampusers_table(self):
'''
Record that needs to be added to or removed from
the ampusers table.
'''
# Del the previous user.
self.del_webadmin_from_ampusers_table()
time.sleep(0.5)
self.connector_to_asterisk_db.connect()
web_admin_table_fields = []
web_admin_table_fields.append([
web_admin_name, web_admin_sha, '', '', '', '*'])
self.connector_to_asterisk_db.insert_into_table(
table=ampusers_table, records=web_admin_table_fields)
self.connector_to_asterisk_db.disconnect()
def main():
my_class = WebAdminInitiation(asterisk_db, ampusers_table)
my_class.add_webadmin_to_ampusers_table()
print('The webuser added.')
if __name__ == '__main__':
main()