This repository was archived by the owner on Oct 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathMain.py
More file actions
259 lines (237 loc) · 12.3 KB
/
Main.py
File metadata and controls
259 lines (237 loc) · 12.3 KB
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
# AltServer-Linux GUI wrote in PyQT5
# This is the Main part for functions
# Author of the GUI : powen
# import
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PySide2 import QtCore
import glob
import subprocess
import requests
import os
import sys
# set path
def resource_path(relative_path):
base_path = os.path.abspath("./resources")
return os.path.join(base_path, relative_path)
cwd = os.getcwd()
AltServer = resource_path("AltServer")
AutoStart = resource_path("AutoStart.sh")
NetMuxd = resource_path("netmuxd")
Exec = cwd+"/altserver"
UserName = os.getlogin()
def internet_stat():
timeout = 5
try:
requests.get("https://github.com", timeout=timeout)
return True
except (requests.ConnectionError, requests.Timeout):
return False
# Version
with open(resource_path("version"), 'r', encoding='utf-8') as f:
LocalVersion = f.readline().strip()
LatestVersion=""
# Function part
@QtCore.Slot()
def about_message():
msg_box = QMessageBox()
msg_box.setIconPixmap(QPixmap(resource_path("Icon@128.png")))
msg_box.setWindowTitle('AltServer-Linux')
msg_box.setInformativeText(
'GUI by powenn on Github\n\n'
'AltServer-Linux by NyaMisty on Github\n\n'
'Not offical AltServer from Riley Testut\n'
f'Version : {LocalVersion}')
msg_box.setDetailedText(
'Source code :\n'
'https://github.com/powenn/AltServer-LinuxGUI\n'
'For questions about this GUI, you can contact @powen00hsiao on Twitter')
msg_box.exec()
@QtCore.Slot()
def Installation():
DeviceCheck=subprocess.run('idevicepair pair',shell=True)
if DeviceCheck.returncode == 1 :
errmsg_box = QMessageBox()
errmsg_box.setText(
'Please make sure connected to your device\n\n'
'And accept the trust dialog on the screen of the device, then attempt to pair again.')
errmsg_box.exec()
if DeviceCheck.returncode == 0 :
PATH = resource_path("AltStore.ipa")
_udid = subprocess.check_output("lsusb -v 2> /dev/null | grep -e 'Apple Inc' -A 2 | grep iSerial | awk '{print $3}'",shell=True).decode().strip()
_udid_length = len(_udid)
if _udid_length == 24 :
UDID = _udid[:8] + '-' + _udid[8:]
if _udid_length == 40 :
UDID = _udid
AccountArea=QDialog()
Layout = QVBoxLayout()
Privacy_msg = QLabel(
"Your Apple ID and password are not saved\n"
"and are only sent to Apple for authentication.")
Privacy_msg.setFont(QFont('Arial', 10))
label = QLabel("Please Enter your Apple ID and password")
IDInputArea = QLineEdit(placeholderText="Apple ID")
PasswordInputArea = QLineEdit(placeholderText="Password")
PasswordInputArea.setEchoMode(QLineEdit.EchoMode.Password)
btn = QPushButton()
Success_msg = QSystemTrayIcon()
def ButtonClicked():
AccountArea.close()
AppleID=IDInputArea.text()
Password=PasswordInputArea.text()
InsAltStoreCMD=f'{resource_path("AltServer")} -u {UDID} -a {AppleID} -p {Password} {PATH} > {resource_path("log.txt")}'
Installing = True
WarnTime=0
InsAltStore=subprocess.Popen(InsAltStoreCMD, stdin=subprocess.PIPE, stdout=subprocess.PIPE, shell=True)
while Installing :
CheckIns=subprocess.run(f'grep "Installation Failed" {resource_path("log.txt")}',shell=True)
CheckWarn=subprocess.run(f'grep "Are you sure you want to continue?" {resource_path("log.txt")}',shell=True)
CheckSuccess=subprocess.run(f'grep "Installation Succeeded" {resource_path("log.txt")}',shell=True)
Check2fa=subprocess.run(f'grep "Requires two factor..." {resource_path("log.txt")}',shell=True)
if CheckIns.returncode == 0 :
Installing = False
InsAltStore.terminate()
Failmsg=subprocess.check_output(f"tail -6 {resource_path('log.txt')}",shell=True).decode()
Failmsg_box = QMessageBox()
Failmsg_box.setText(Failmsg)
Failmsg_box.exec()
if CheckWarn.returncode == 0 and WarnTime == 0 :
Warnmsg=subprocess.check_output(f"tail -8 {resource_path('log.txt')}",shell=True).decode()
Warnmsg_box = QMessageBox()
buttonReply = QMessageBox.warning(Warnmsg_box, 'Alert', Warnmsg, QMessageBox.Yes | QMessageBox.No,QMessageBox.Yes)
if buttonReply == QMessageBox.Yes:
InsAltStore.communicate(input=b'\n')
if buttonReply == QMessageBox.No:
Installing = False
os.system(f'pkill -TERM -P {InsAltStore.pid}')
Cancelmsg_box = QMessageBox()
Cancelmsg_box.setText("Installation Canceled")
Cancelmsg_box.exec()
WarnTime = 1
if Check2fa.returncode == 0 and WarnTime == 0 :
msg_2fa_Area=QDialog()
msg_2fa_Area.setWindowTitle("Requires two factor")
code_2fa_Layout = QVBoxLayout()
code_2fa_label = QLabel("Please Enter two factor code")
Input_2fa_Area = QLineEdit(placeholderText="two factor code")
send_2fa_btn = QPushButton()
def Button_2fa_Clicked():
msg_2fa_Area.close()
code_2fa=Input_2fa_Area.text()
code_2fa=code_2fa+"\n"
code_2fa_bytes = bytes(code_2fa.encode())
InsAltStore.communicate(input=code_2fa_bytes)
send_2fa_btn.setText("Send")
send_2fa_btn.clicked.connect(Button_2fa_Clicked)
code_2fa_Layout.addWidget(code_2fa_label)
code_2fa_Layout.addWidget(Input_2fa_Area)
code_2fa_Layout.addWidget(send_2fa_btn)
msg_2fa_Area.setLayout(code_2fa_Layout)
msg_2fa_Area.exec()
WarnTime = 1
if CheckSuccess.returncode == 0 :
Installing = False
Success_msg.setVisible(True)
Success_msg.showMessage("Installation Succeded","AltStore was successfully installed",QSystemTrayIcon.Information,200)
btn.setText("Install")
btn.clicked.connect(ButtonClicked)
Layout.addWidget(label)
Layout.addWidget(Privacy_msg)
Layout.addWidget(IDInputArea)
Layout.addWidget(PasswordInputArea)
Layout.addWidget(btn)
AccountArea.setLayout(Layout)
AccountArea.exec()
@QtCore.Slot()
def pair():
subprocess.run('idevicepair pair',shell=True)
@QtCore.Slot()
def restart_daemon():
subprocess.run(f'killall {AltServer}',shell=True)
subprocess.run('idevicepair pair',shell=True)
subprocess.run(f'{AltServer} &> /dev/null &',shell=True)
@QtCore.Slot()
def check_update():
Passwd_Check_Time = 0
if (internet_stat()) == True :
LatestVersion=subprocess.check_output("curl -Lsk https://github.com/powenn/AltServer-LinuxGUI/raw/main/version",shell=True).decode()
if LatestVersion == LocalVersion :
Already_latest_msg_box = QMessageBox()
Already_latest_msg_box.setText("you are using the latest release")
Already_latest_msg_box.exec()
if LatestVersion != LocalVersion :
Updatemsg_box = QMessageBox()
UpdateLog=subprocess.check_output("curl -Lsk https://github.com/powenn/AltServer-LinuxGUI/raw/main/updatelog.md",shell=True).decode()
Updatemsg_box.setText(UpdateLog)
buttonReply = QMessageBox.information(Updatemsg_box, 'Update now ?', UpdateLog, QMessageBox.Yes | QMessageBox.No,QMessageBox.Yes)
if buttonReply == QMessageBox.Yes and Passwd_Check_Time == 0:
Passwd_Check_Time = 1
passwd_Area=QDialog()
passwd_Area.setWindowTitle("Requires password")
passwd_Layout = QVBoxLayout()
passwd_label = QLabel(f"Please enter password for {UserName}")
Input_passwd_Area = QLineEdit(placeholderText="password")
Input_passwd_Area.setEchoMode(QLineEdit.EchoMode.Password)
send_passwd_btn = QPushButton()
def Button_passwd_Clicked():
passwd_Area.close()
sudo_passwd=Input_passwd_Area.text()
sudo_passwd=sudo_passwd+"\n"
sudo_passwd_bytes = bytes(sudo_passwd.encode())
sudo_Check = os.system(f'echo "{sudo_passwd}" | sudo -S echo "check password"')
if sudo_Check == 0 :
Updating_msg_box = QSystemTrayIcon()
Updating_msg_box.setVisible(True)
Updating_msg_box.showMessage("Updating","Please wait a moment",QSystemTrayIcon.Information,200)
update_pyfile = cwd+"/update.py"
deb_file = cwd+"/AltServer.deb"
subprocess.run(f"curl -L 'https://github.com/powenn/AltServer-LinuxGUI/raw/main/update.py' > {update_pyfile}",shell=True)
Updating = subprocess.run(f"python3 {update_pyfile}",shell=True)
if Updating.returncode == 0:
NewRelease_Installation = subprocess.Popen(f"sudo -S dpkg -i {deb_file}", stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE,shell=True)
NewRelease_Installation.communicate(input=sudo_passwd_bytes)
subprocess.run(f"rm -rf {deb_file}",shell=True)
subprocess.run(f"rm -rf {update_pyfile}",shell=True)
if NewRelease_Installation.returncode == 0 :
Update_done_msg_box = QMessageBox()
Update_done_msg_box.setText("Update Done\nApp will restart to apply the new version")
Update_done_msg_box.exec()
os.execl(sys.executable,sys.executable,*sys.argv)
else :
Update_err_msg_box = QMessageBox()
Update_err_msg_box.setText("Error occurred")
Update_err_msg_box.exec()
if Updating.returncode == 1 :
Update_err_msg_box = QMessageBox()
Update_err_msg_box.setText("Error occurred")
Update_err_msg_box.exec()
if sudo_Check != 0 :
Wrong_sudo_passwd_box = QMessageBox()
Wrong_sudo_passwd_box.setText("Wrong password entered")
Wrong_sudo_passwd_box.exec()
send_passwd_btn.setText("Send")
send_passwd_btn.clicked.connect(Button_passwd_Clicked)
passwd_Layout.addWidget(passwd_label)
passwd_Layout.addWidget(Input_passwd_Area)
passwd_Layout.addWidget(send_passwd_btn)
passwd_Area.setLayout(passwd_Layout)
passwd_Area.exec()
if buttonReply == QMessageBox.No:
pass
if (internet_stat()) == False:
No_network_box = QMessageBox()
No_network_box.setWindowTitle('No network')
No_network_box.setText("Please connect to network")
No_network_box.exec()
# Show update avaliable message
@QtCore.Slot()
def UpdateNotification() :
if (internet_stat()) == True:
LatestVersion=subprocess.check_output("curl -Lsk https://github.com/powenn/AltServer-LinuxGUI/raw/main/version",shell=True).decode()
if LatestVersion != LocalVersion :
UpdateLog=subprocess.check_output("curl -Lsk https://github.com/powenn/AltServer-LinuxGUI/raw/main/updatelog.md",shell=True).decode()
Update_Avaliable_box = QMessageBox()
Update_Avaliable_box.setWindowTitle('UPDATE AVALIABLE')
Update_Avaliable_box.setText(UpdateLog)
Update_Avaliable_box.exec()