forked from jtmillard/fusionpbx-install.py
/
ask_questions.py
173 lines (139 loc) · 6.3 KB
/
ask_questions.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#!/usr/bin/python3
""" Ask questions module for Fusionpbx install script
Has no arguments.
Output is a single file, "install.json"
containing all of the parameters needed for the install script
"""
"""
FusionPBX
Version: MPL 1.1
The contents of this file are subject to the Mozilla Public License Version
1.1 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
for the specific language governing rights and limitations under the
License.
The Initial Developer of the Original Code is
Jim Millard <jmillard459@gmail.com>
Portions created by the Initial Developer are Copyright (C) 2008-2016
the Initial Developer. All Rights Reserved.
Contributor(s):
Mark J. Crane <markjcrane@fusionpbx.com>
"""
import sys
import os
import random
import FPBXParms
INSTALL_ROOT = os.getcwd()
LOOPNUMBER = 0
#===============================================================================
# Make up a temporary password
#===============================================================================
def mkpass():
""" Make a simi-secure temporary password
"""
words = []
symbols = ["!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "-", "+", "="]
numsymbols = len(symbols) - 1
listofwords = open("%s/resources/words" % (INSTALL_ROOT), 'r')
for word in listofwords.readlines():
word = word.strip()
words.append(word)
numwords = len(words) - 1
listofwords.close()
word1 = words[random.randint(0, numwords)]
word1 = word1.capitalize()
word2 = words[random.randint(0, numwords)]
word2 = word2.capitalize()
number = str(random.randint(0, 9))
symbol = symbols[random.randint(0, numsymbols)]
password = word1 + number + word2 + symbol
return password
#===============================================================================
# Ask a yes or no question
#===============================================================================
def ask_yn(question):
""" Ask a Yes or No question """
ans = input("%s? (y/n) " % (question)).lower()
if 'y' in ans:
return "Yes"
if 'n' in ans:
return "No"
print("Sorry you must answer y or n to this question.")
print("I don't know how to continue!")
sys.exit(1)
#===============================================================================
# Main code starts here
#===============================================================================
def iask_questions():
print("Welcome to FusionPBX installation.")
print("I am checking to see if there are parameters already defined")
#===============================================================================
# Load the previously saved parameters
#===============================================================================
if os.path.isfile("%s/resources/install.json" % (INSTALL_ROOT)):
FPBXParms.PARMS = FPBXParms.load_parms(FPBXParms.PARMS)
print("I found the following parameters")
FPBXParms.show_parms()
USEPARMS = ask_yn("Do you want to use them")
if USEPARMS == "Yes":
pass
# print("In loop %d" % (LOOPNUMBER))
# LOOPNUMBER += 1
else:
#===============================================================================
# Start asking the hard questions
#===============================================================================
print("Very well I will ask you several questions.")
print("Note: if a question has '(a/B)' in it, 'B' is the default")
print("If a question has a value listed that is the default")
print("All default values can be selected by just pressing Enter")
print("If a parameter does not have a default, a value must be entered")
BDR_ANS = "No"
# BDR_ANS = ask_yn(FPBXParms.PARMS["BDR"][1])
FPBXParms.PARMS["BDR"][0] = BDR_ANS
if BDR_ANS == "Yes":
PARM_LIST = FPBXParms.BDR_PARMS
else:
PARM_LIST = FPBXParms.NON_BDR_PARMS
for index in PARM_LIST:
FPBXParms.ask_parm(index)
for index in FPBXParms.COMMON_PARMS:
FPBXParms.ask_parm(index)
#======================================================================
# Make up some passwords that are secure and easy to remember
#======================================================================
# FPBXParms.PARMS["FPBXuserPassword"][0] = mkpass()
# FPBXParms.PARMS["FPBXDBUserPassword"][0] = mkpass()
FPBXParms.save_parms()
else:
print("There is no predefined parameter file.")
print("Please answer the following questions.")
# For now we are only installing a single switch, No BDR
BDR_ANS = "No"
# BDR_ANS = ask_yn(FPBXParms.PARMS["BDR"][1])
FPBXParms.PARMS["BDR"][0] = BDR_ANS
if BDR_ANS == "Yes":
PARM_LIST = FPBXParms.BDR_PARMS
else:
PARM_LIST = FPBXParms.NON_BDR_PARMS
for index in PARM_LIST:
FPBXParms.ask_parm(index)
for index in FPBXParms.COMMON_PARMS:
FPBXParms.ask_parm(index)
#======================================================================
# Make up some passwords that are secure and easy to remember
#======================================================================
# FPBXParms.PARMS["FPBXuserPassword"][0] = mkpass()
# FPBXParms.PARMS["FPBXDBUserPassword"][0] = mkpass()
FPBXParms.save_parms()
# if FPBXParms.PARMS["FS_Install_Type"][0] == "s":
# print("WARNING: There are currently problems with Video and installing from source")
# print("As of Freeswitch 1.6.")
# print("You may need to disable video to compile Freeswitch")
# ans = ask_yn("Do you wish to continue")
# if ans == "No":
# sys.exit()
return