-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaccount-switcher.py
207 lines (154 loc) · 6.85 KB
/
account-switcher.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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
# Steam Smurf Switcher with mobile support using steam.guard by ValvePython and PyAutoIt by jacexh #
# PyAutoIt: https://pypi.python.org/pypi/PyAutoIt/0.4 #
# steam.guard: https://github.com/ValvePython/steam #
# Much love, jfx #
# TO-DO:
# Encryption #:
# Coming soon, AES encryption with master password #
import autoit, time, os, json, subprocess, base64
import steam.guard as sa
# Config settings here, feel free to change them!
configpath = os.getenv('APPDATA')+"\\jfx"
config = configpath + "\\users.json"
# Config
if not os.path.exists(configpath):
os.makedirs(configpath)
# Check to see if the config exists, if not make one
# Messy way of doing it but it gets the job done... maybe I'll re-do it one day...
try:
with open(config, 'r') as data_file:
data = json.load(data_file)
except:
f = open(config, 'w+')
f.write('{"accounts":[]}')
f.close()
with open(config) as data_file:
data = json.load(data_file)
# Defining key stuff #
def cls():
os.system('cls' if os.name=='nt' else 'clear')
def enter():
raw_input("Press ENTER to continue . . .")
def validateInput(input):
if input.isdigit() == False or int(input) >= i or int(input) < 1:
return False
else:
return True
def createNewAccount():
newusername = raw_input("Enter the username: ")
newpassword = raw_input("Enter the password: ")
newmobile = raw_input("Enter the mobile code, blank if none: ")
data['accounts'].append({
'username': newusername,
'password': newpassword,
'mobile': newmobile
})
with open(config, 'w') as outfile:
json.dump(data, outfile, sort_keys = False, indent = 4, ensure_ascii=False)
print "Account created."
enter()
main()
def deleteAccount(i):
chosenDelete = raw_input("Type the number for the account you would like to delete: ")
while validateInput(chosenDelete) == False: #validation, check if its a number
print "ERROR: Choose an account on the list."
chosenDelete = raw_input("Type the number for the account you would like to delete: ")
chosenDelete = int(chosenDelete) - 1 #line it up with the json, make it an int
del data['accounts'][chosenDelete]
with open(config, 'w') as outfile:
json.dump(data, outfile, sort_keys = False, indent = 4, ensure_ascii=False)
print "Account deleted."
enter()
main()
def editConfig():
subprocess.call(['notepad.exe', config]) #we use subprocess here because its better and it works
enter()
main()
def browserLogin(i):
chosenAccount = raw_input("Type the number for the account you would like to display login details for: ")
while validateInput(chosenAccount) == False: #validation, check if its a number
print "ERROR: Choose an account on the list"
chosenAccount = raw_input("Type the number for the account you would like to display login details for: ")
chosenAccount = int(chosenAccount) - 1 #line it up with json, make int
print "username: {}".format(data['accounts'][chosenAccount]['username'])
print "password: {}".format(data['accounts'][chosenAccount]['password'])
if data['accounts'][chosenAccount]['mobile']:
print "2FA code: {}".format(sa.generate_twofactor_code(base64.b64decode(data['accounts'][chosenAccount]['mobile'])))
enter()
main()
def mobileCode(i):
chosenAccount = raw_input("Type the number for the account you would like to display login details for: ")
while validateInput(chosenAccount) == False: #validation, check if its a number
print "ERROR: Choose an account on the list"
chosenAccount = raw_input("Type the number for the account you would like to display login details for: ")
chosenAccount = int(chosenAccount) - 1 #line it up with json, make int
if data['accounts'][chosenAccount]['mobile']:
print "2FA code: {}".format(sa.generate_twofactor_code(base64.b64decode(data['accounts'][chosenAccount]['mobile'])))
else:
print "Error finding mobile code for account"
enter()
main()
def main ():
cls()
print "########################"
print "# jfx's Smurf Switcher #"
print "########################"
print ""
global i
i = 1
for account in data['accounts']:
print str(i) + ' - ' + account['username']
i = i + 1
print
print "n - Add new account"
print "d - Delete an account"
print "e - Edit config"
print "b - Print login details (for browser logins)"
print "c - Mobile code only"
print
print "Typing in the account and ENTER will auto login to that account"
chosenAccount = raw_input("Type your choice then press ENTER: ")
while chosenAccount.isdigit() == False: # validation, check if its a number, this check is needed to differentiate the character options from numerical and also to provide some nice feedback to the user
if chosenAccount == "n" or chosenAccount == "e" or chosenAccount == "d" or chosenAccount == "b" or chosenAccount == "c": # we skip if its one of the alpha values
break
print "ERROR: Please enter a valid option"
chosenAccount = raw_input("Type the number for the account then press ENTER: ")
if chosenAccount.isdigit() == False: #if its still false its one of the alpha values
if chosenAccount == "n":
createNewAccount()
if chosenAccount == "d":
deleteAccount(i)
if chosenAccount == "e":
editConfig()
if chosenAccount == "b":
browserLogin(i)
if chosenAccount == "c":
mobileCode(i)
else: #they chose a number of some sorts
while validateInput(chosenAccount) == False: #validation, check if the account exists
print "ERROR: Choose an account on the list."
chosenAccount = raw_input("Type the number for the account then press ENTER: ")
chosenAccount = int(chosenAccount) - 1
print "Killing Steam..."
os.system('taskkill /f /im steam.exe') #kill steam
print "Waiting 3 seconds before starting Steam..."
time.sleep(3)
# For some reason subprocess doesn't work, leaving this commented out until I figure out why...
#dargds = ['C:\Program Files (x86)\Steam\Steam.exe', '-login', data['accounts'][chosenAccount]['username'], data['accounts'][chosenAccount]['password']]#args
#subprocess.call(dargds) #run steam
print "Launching Steam..."
os.system('start "" "C:\Program Files (x86)\Steam\Steam.exe" -login {} {}'.format(data['accounts'][chosenAccount]['username'],data['accounts'][chosenAccount]['password']))
if data['accounts'][chosenAccount]['mobile']: #if theres a mobile code
print "Waiting for Steamguard window..."
autoit.win_wait("Steam Guard") #wait for window... sometimes it takes a while
print "Steamguard window found, generating code..."
code = sa.generate_twofactor_code(base64.b64decode(data['accounts'][chosenAccount]['mobile']))
autoit.win_activate("Steam Guard") #open it up in case it's not activated
autoit.win_wait_active("Steam Guard") #wait for it to be activated, in case of delay
print "Entering auth code: {} into window...".format(code)
autoit.send(code)
time.sleep(0.2) #small delay cant hurt
autoit.send('{ENTER}')
raw_input()
if __name__ == "__main__":
main()