forked from adrienluitot/surfshark-linux-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_window.py
353 lines (264 loc) · 16.1 KB
/
main_window.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
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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk, Gdk, Pango
import os.path
import urllib.request
class MainWindow(Gtk.Window):
def __init__(self, main):
Gtk.Window.__init__(self, title="SurfShark Client - App")
self.set_default_size(510, 720)
self.set_resizable(False)
self.set_icon_from_file(main.folder_path + "surfshark_linux_client.png")
self.main = main
h_parent = Gtk.HBox(spacing=1)
self.add(h_parent)
self.tabs = Gtk.Notebook()
self.tabs.connect("enter-notify-event", self.hover)
self.tabs.connect("leave-notify-event", self.not_hover)
h_parent.pack_start(self.tabs, True, True, 0)
# ================================
# Servers
# ================================
servers_container = Gtk.VBox(spacing=0)
self.tabs.append_page(servers_container)
self.tabs.set_tab_label_text(servers_container, "Servers")
self.tabs.child_set_property(servers_container, 'tab-expand', True)
self.server_list = Gtk.ListBox()
self.server_list.connect("enter-notify-event", self.hover)
self.server_list.connect("leave-notify-event", self.not_hover)
self.server_list.connect("selected-rows-changed", self.select_server)
servers_scroll = Gtk.ScrolledWindow()
servers_scroll.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
servers_scroll.add_with_viewport(self.server_list)
servers_container.pack_start(servers_scroll, True, True, 0)
i = 0
for server in self.main.servers:
if (server['type'] == "double" or server['type'] == "static"): continue
vpn_server = Gtk.HBox()
image = Gtk.Image()
flag_array = server['flagUrl'].split('/')
if (not os.path.isfile(main.folder_path + 'flags/' + flag_array[len(flag_array) - 1])):
opener = urllib.request.build_opener()
opener.addheaders = [
('User-Agent', 'Mozilla/5.0 (X11; Linux x86_64; rv:73.0) Gecko/20100101 Firefox/73.0')]
urllib.request.install_opener(opener)
urllib.request.urlretrieve(server['flagUrl'], main.folder_path + "flags/" + flag_array[len(flag_array) - 1])
image.set_from_file(main.folder_path + 'flags/' + flag_array[len(flag_array) - 1])
vpn_server.pack_start(image, False, False, 10)
city = Gtk.Label(server['country'] + ', ' + server['location'])
vpn_server.pack_start(city, True, True, 20)
load = Gtk.Label(str(server['load']) + "%")
vpn_server.pack_start(load, False, False, 20)
self.server_list.insert(vpn_server, i)
self.main.config_files[server['country'] + ', ' + server['location']] = server['connectionName']
i += 1
bottom = Gtk.HBox(spacing=0)
servers_container.pack_start(bottom, False, False, 5)
connections_info = Gtk.VBox(spacing=0)
connections_info.get_style_context().add_class('connection-info')
bottom.pack_start(connections_info, True, True, 5)
selected = Gtk.HBox(spacing=0)
connections_info.pack_start(selected, False, False, 3)
sel_rom_text = Gtk.Label("Selected server : ")
selected.pack_start(sel_rom_text, False, False, 2)
self.selected_label = Gtk.Label("Nothing")
selected.pack_start(self.selected_label, False, False, 2)
connected_to = Gtk.HBox(spacing=0)
connections_info.pack_start(connected_to, False, False, 3)
rom_text = Gtk.Label("Currently connected to : ")
connected_to.pack_start(rom_text, False, False, 2)
self.connected_to_label = Gtk.Label("Nothing")
connected_to.pack_start(self.connected_to_label, False, False, 2)
ip_container = Gtk.HBox()
connections_info.pack_start(ip_container, False, False, 3)
ip_rom_text = Gtk.Label("Ip: ")
ip_container.pack_start(ip_rom_text, False, False, 2)
self.ip_label = Gtk.Label()
ip_container.pack_start(self.ip_label, False, False, 2)
vpn_buttons = Gtk.VBox()
bottom.pack_start(vpn_buttons, False, False, 5)
self.switch_server_btn = Gtk.Button(label="Switch server")
self.switch_server_btn.connect('clicked', self.main.switch_server)
self.switch_server_btn.connect("enter-notify-event", self.hover)
self.switch_server_btn.connect("leave-notify-event", self.not_hover)
vpn_buttons.pack_start(self.switch_server_btn, False, False, 2)
self.disconnect_btn = Gtk.Button(label="Disconnect")
self.disconnect_btn.set_sensitive(False)
self.disconnect_btn.connect('clicked', self.main.disconnect)
self.disconnect_btn.connect("enter-notify-event", self.hover)
self.disconnect_btn.connect("leave-notify-event", self.not_hover)
vpn_buttons.pack_start(self.disconnect_btn, False, False, 2)
# ================================
# Settings
# ================================
settings_padding = Gtk.HBox()
settings_scroll = Gtk.ScrolledWindow()
settings_scroll.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
settings_scroll.add_with_viewport(settings_padding)
self.tabs.append_page(settings_scroll)
self.tabs.set_tab_label_text(settings_scroll, "Settings")
self.tabs.child_set_property(settings_scroll, 'tab-expand', True)
vpn_settings_container = Gtk.VBox()
settings_padding.pack_start(vpn_settings_container, True, True, 15)
credentials_v_container = Gtk.VBox()
vpn_settings_container.pack_start(credentials_v_container, False, False, 15)
self.username_label = Gtk.Label()
self.username_label.set_markup("OpenVPN Username")
credentials_v_container.pack_start(self.username_label, False, False, 10)
self.credentials_username = Gtk.Entry()
self.credentials_username.set_placeholder_text("OpenVPN Username")
credentials_v_container.pack_start(self.credentials_username, False, False, 0)
credentials_v_container.pack_start(Gtk.Label(), False, False, 0)
self.password_label = Gtk.Label()
self.password_label.set_markup("OpenVPN Password")
credentials_v_container.pack_start(self.password_label, False, False, 10)
self.credentials_password = Gtk.Entry()
self.credentials_password.set_placeholder_text("OpenVPN Password")
credentials_v_container.pack_start(self.credentials_password, False, False, 0)
self.save_credentials_button = Gtk.Button(label="Save")
self.save_credentials_button.connect("clicked", self.main.save_credentials)
self.save_credentials_button.connect("enter-notify-event", self.hover)
self.save_credentials_button.connect("leave-notify-event", self.not_hover)
credentials_v_container.pack_start(self.save_credentials_button, False, False, 7)
self.updated_vpn_credential_label = Gtk.Label()
credentials_v_container.pack_start(self.updated_vpn_credential_label, False, False, 0)
vpn_settings_container.pack_start(Gtk.Separator(), False, False, 10)
self.check_for_updates_btn = Gtk.Button("Check for VPN updates")
self.check_for_updates_btn.connect("clicked", self.main.check_updates)
self.check_for_updates_btn.connect("enter-notify-event", self.hover)
self.check_for_updates_btn.connect("leave-notify-event", self.not_hover)
vpn_settings_container.pack_start(self.check_for_updates_btn, False, False, 15)
vpn_settings_container.pack_start(Gtk.Separator(), False, False, 10)
#Theme
theme_container = Gtk.HBox()
theme_label = Gtk.Label("Theme")
theme_container.pack_start(theme_label, True, False, 3)
current_theme = True if main.config['theme'] == "light" else False
self.light_label = Gtk.Label()
self.light_label.set_markup("<b>Light</b>" if current_theme else "Light")
theme_container.pack_start(self.light_label, False, False, 0)
self.theme_switch = Gtk.Switch()
self.theme_switch.set_active(not current_theme)
self.theme_switch.connect("state-set", self.main.change_theme)
self.theme_switch.connect("enter-notify-event", self.hover)
self.theme_switch.connect("leave-notify-event", self.not_hover)
theme_container.pack_start(self.theme_switch, False, False, 20)
self.dark_label = Gtk.Label()
self.dark_label.set_markup("Dark" if current_theme else "<b>Dark</b>")
theme_container.pack_start(self.dark_label, False, False, 0)
vpn_settings_container.pack_start(theme_container, False, False, 15)
theme_container.pack_start(Gtk.Label(), True, False, 0)
vpn_settings_container.pack_start(Gtk.Separator(), False, False, 10)
protocol_container = Gtk.HBox()
protocol_container.pack_start(Gtk.Label(), True, False, 0)
is_tcp = True if main.config["connection_protocol"] == "tcp" else False
self.udp_label = Gtk.Label()
self.udp_label.set_markup("UDP" if is_tcp else "<b>UDP</b>")
protocol_container.pack_start(self.udp_label, False, False, 0)
self.protocol_switch = Gtk.Switch()
self.protocol_switch.set_active(is_tcp)
self.protocol_switch.connect("state-set", self.main.change_protocol)
self.protocol_switch.connect("enter-notify-event", self.hover)
self.protocol_switch.connect("leave-notify-event", self.not_hover)
protocol_container.pack_start(self.protocol_switch, False, False, 20)
self.tcp_label = Gtk.Label()
self.tcp_label.set_markup("<b>TCP</b>" if is_tcp else "TCP")
protocol_container.pack_start(self.tcp_label, False, False, 0)
vpn_settings_container.pack_start(protocol_container, False, False, 15)
protocol_container.pack_start(Gtk.Label(), True, False, 0)
vpn_settings_container.pack_start(Gtk.Separator(), False, False, 10)
#Killswitch
killswitch_container = Gtk.HBox()
killswitch_label = Gtk.Label("Disable/Enable the VPN Killswitch")
killswitch_container.pack_start(killswitch_label, True, False, 3)
killswitch_status = True if main.config["killswitch"] == "on" else False
self.killswitch_off_label = Gtk.Label()
self.killswitch_off_label.set_markup("OFF" if killswitch_status else "<b>OFF</b>")
killswitch_container.pack_start(self.killswitch_off_label, False, False, 0)
self.killswitch_switch = Gtk.Switch()
self.killswitch_switch.set_active(killswitch_status)
self.killswitch_switch.connect("state-set", self.main.change_killswitch)
self.killswitch_switch.connect("enter-notify-event", self.hover)
self.killswitch_switch.connect("leave-notify-event", self.not_hover)
killswitch_container.pack_start(self.killswitch_switch, False, False, 20)
self.killswitch_on_label = Gtk.Label()
self.killswitch_on_label.set_markup("<b>ON</b>" if killswitch_status else "ON")
killswitch_container.pack_start(self.killswitch_on_label, False, False, 0)
vpn_settings_container.pack_start(killswitch_container, False, False, 15)
killswitch_container.pack_start(Gtk.Label(), True, False, 0)
vpn_settings_container.pack_start(Gtk.Separator(), False, False, 10)
self.updates_info = Gtk.Label()
vpn_settings_container.pack_start(self.updates_info, False, False, 0)
self.enable_password_container = Gtk.VBox()
if(not self.main.config['password_needed']):
self.enable_password_container.set_sensitive(False)
vpn_settings_container.pack_start(self.enable_password_container, False, False, 3)
disable_pass_label = Gtk.Label("Disable/Enable the password")
self.enable_password_container.pack_start(disable_pass_label, False, False, 3)
self.disable_pass_button = Gtk.Button()
self.disable_pass_button.set_label("Disable Pass" if self.main.config['password_needed'] else "Enable Pass")
self.disable_pass_button.connect("clicked", self.main.change_password_need)
self.disable_pass_button.connect("enter-notify-event", self.hover)
self.disable_pass_button.connect("leave-notify-event", self.not_hover)
self.enable_password_container.pack_start(self.disable_pass_button, False, False, 20)
disable_pass_warn_label = Gtk.Label()
disable_pass_warn_label.set_markup("<small>Disabling your password will display it uncrypted in the config.json!</small>")
disable_pass_warn_label.get_style_context().add_class('warn')
self.enable_password_container.pack_start(disable_pass_warn_label, False, False, 3)
vpn_settings_container.pack_start(Gtk.Separator(), False, False, 10)
self.updates_info = Gtk.Label()
vpn_settings_container.pack_start(self.updates_info, False, False, 0)
self.check_for_updates_btn = Gtk.Button("Check for VPN updates")
self.check_for_updates_btn.connect("clicked", self.main.check_updates)
self.check_for_updates_btn.connect("enter-notify-event", self.hover)
self.check_for_updates_btn.connect("leave-notify-event", self.not_hover)
vpn_settings_container.pack_start(self.check_for_updates_btn, False, False, 15)
vpn_settings_container.pack_start(Gtk.Separator(), False, False, 10)
vpn_settings_container.pack_start(Gtk.Label(), False, False, 13)
update_pass_label = Gtk.Label('Change your password')
update_pass_label.get_style_context().add_class('title')
vpn_settings_container.pack_start(update_pass_label, False, False, 5)
vpn_settings_container.pack_start(Gtk.Label(), False, False, 0)
self.new_password_label = Gtk.Label()
self.new_password_label.set_markup("New Password")
self.new_password_label.get_style_context().add_class('label')
vpn_settings_container.pack_start(self.new_password_label, False, False, 0)
self.new_password = Gtk.Entry()
self.new_password.set_placeholder_text("New Password")
self.new_password.set_visibility(False)
vpn_settings_container.pack_start(self.new_password, False, False, 0)
vpn_settings_container.pack_start(Gtk.Label(), False, False, 0)
self.confirm_new_password_label = Gtk.Label()
self.confirm_new_password_label.set_markup("Confirm New Password")
self.confirm_new_password_label.get_style_context().add_class('label')
vpn_settings_container.pack_start(self.confirm_new_password_label, False, False, 0)
self.confirm_new_password = Gtk.Entry()
self.confirm_new_password.set_placeholder_text("Confirm New Password")
self.confirm_new_password.set_visibility(False)
vpn_settings_container.pack_start(self.confirm_new_password, False, False, 0)
self.update_password = Gtk.Button("Update password")
self.update_password.connect("clicked", self.main.update_password)
self.update_password.connect("enter-notify-event", self.hover)
self.update_password.connect("leave-notify-event", self.not_hover)
vpn_settings_container.pack_start(self.update_password, False, False, 10)
self.updated_password_label = Gtk.Label()
vpn_settings_container.pack_start(self.updated_password_label, False, False, 5)
def hover(self, listbox_widget, crossing):
self.get_window().set_cursor(Gdk.Cursor(Gdk.CursorType.HAND2))
def not_hover(self, listbox_widget, crossing):
self.get_window().set_cursor(None)
def select_server(self, listbox):
server_text = listbox.get_selected_row().get_children()[0].get_children()[1].get_text()
self.selected_label.set_label(server_text)
def confirm_connection(self):
text = self.selected_label.get_text()
self.switch_server_btn.set_sensitive(True)
self.connected_to_label.set_label(text)
self.ip_label.set_label(self.main.ip)
self.disconnect_btn.set_sensitive(True)
def vpn_connection_failed(self):
self.switch_server_btn.set_sensitive(True)
self.connected_to_label.set_label("ERROR")
self.disconnect_btn.set_sensitive(False)
def vpn_exited(self):
self.connected_to_label.set_label("DISCONNECTED")