Skip to content

Commit 3373f0e

Browse files
committed
Added app files [v1.6]
1 parent 09b87f0 commit 3373f0e

File tree

7 files changed

+47
-39
lines changed

7 files changed

+47
-39
lines changed

SimpleWebsiteBlocker.exe

212 KB
Binary file not shown.

assets/CHANGELOG.log

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
[10.09.2021 - version 1.2] Small changes in source code now it looks cleaner and some bugs were fixed also checking the operating system before running the app was added!
44
[19.09.2021 - version 1.3] Huuuge update today! we improved the source code to be faster also we added customizing color of the app in settings section check it out!
55
[26.09.2021 - version 1.4] Added inject option to block websites faster!
6-
[05.10.2021 - version 1.5] Added auto update now app download all files from github and extract them to app folder also config extension was changed to ini
6+
[05.10.2021 - version 1.5] Added auto update now app download all files from github and extract them to app folder also config extension was changed to ini
7+
[19.10.2021 - version 1.6] Now source code is much cleaner and faster

assets/lists/.gitkeep

Whitespace-only changes.

assets/lists/example.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

assets/version.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
[settings]
2-
version = 1.5
2+
version = 1.6

main.py

Lines changed: 44 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import requests
88
import logging
99
import os.path
10+
import ctypes
1011
import time
1112
import sys
1213
import os
@@ -22,19 +23,6 @@
2223

2324
COLOR = cfg["settings"]["color"]
2425

25-
user_choice = -1
26-
user_choice_block_website = ""
27-
user_choice_unlock_website = ""
28-
user_confirm_choice = ""
29-
user_choice_settings = -1
30-
user_choice_settings_confirm_color = -1
31-
user_choice_settings_confirm_clear = -1
32-
user_choice_settings_choice_list = ""
33-
34-
current_version = "1.5"
35-
36-
version_url = "https://raw.githubusercontent.com/Rabixx/updater/main/version.txt"
37-
3826
win_path = "C:\\Windows\\System32\\drivers\\etc\\hosts"
3927

4028
def on_start():
@@ -49,25 +37,41 @@ def on_start():
4937

5038
notification.send()
5139

52-
with open(win_path,"w") as m:
53-
m.truncate(0)
40+
with open(win_path,"w") as first_clear:
41+
first_clear.truncate(0)
5442

5543
os.remove("start.tmp")
5644

5745
CONFIG_COLOR = getattr(Fore, COLOR)
5846
print(CONFIG_COLOR)
5947
os.system('cls')
60-
except PermissionError:
61-
logging.warning("Access denied please run SimpleWebsiteBlocker with admin permissions!")
62-
os.system('pause')
63-
sys.exit()
48+
except:
49+
pass
50+
51+
def checkadmin():
52+
try:
53+
isAdmin = (os.getuid() == 0)
54+
except AttributeError:
55+
isAdmin = ctypes.windll.shell32.IsUserAnAdmin() != 0
56+
return isAdmin
6457

6558
def load_config():
6659
CONFIG_COLOR = getattr(Fore, COLOR)
6760
print(CONFIG_COLOR)
6861
os.system('cls')
6962

70-
def main(user_choice,user_choice_block_website,user_choice_unlock_website,win_path,version_url,current_version,user_confirm_choice,user_choice_settings,user_choice_settings_confirm_clear,user_choice_settings_confirm_color,config_path,COLOR,user_choice_settings_choice_list):
63+
def main(win_path):
64+
user_choice = -1
65+
user_choice_block_website = ""
66+
user_choice_unlock_website = ""
67+
user_confirm_choice = ""
68+
user_choice_settings = -1
69+
user_choice_settings_confirm_color = -1
70+
user_choice_settings_confirm_clear = -1
71+
user_choice_settings_choice_list = ""
72+
current_version = "1.6"
73+
version_url = "https://raw.githubusercontent.com/Rabixx/updater/main/version.txt"
74+
7175
while user_choice != 7:
7276
if user_choice == 1:
7377
try:
@@ -78,8 +82,8 @@ def main(user_choice,user_choice_block_website,user_choice_unlock_website,win_pa
7882
print()
7983
user_choice_block_website = str(input(">>: "))
8084

81-
with open(win_path,"a") as c:
82-
c.writelines("0.0.0.0" + " " + user_choice_block_website + "\n")
85+
with open(win_path,"a") as ch_1:
86+
ch_1.writelines("0.0.0.0" + " " + user_choice_block_website + "\n")
8387

8488
print("website was successfully blocked!")
8589
time.sleep(1)
@@ -100,11 +104,11 @@ def main(user_choice,user_choice_block_website,user_choice_unlock_website,win_pa
100104
print("to cancel hold CTRL + C in the same moment")
101105
print()
102106
user_choice_unlock_website = str(input(">>: "))
103-
with open(win_path, 'r') as file:
107+
with open(win_path,"r") as file:
104108
lines = file.readlines()
105109

106110
content = f'0.0.0.0 {user_choice_unlock_website}'
107-
with open(win_path, 'w') as file:
111+
with open(win_path, "w") as file:
108112
for line in lines:
109113
if line.strip("\n") != content:
110114
file.write(line)
@@ -125,8 +129,8 @@ def main(user_choice,user_choice_block_website,user_choice_unlock_website,win_pa
125129
os.system('cls')
126130
print("all the websites that are currently blocked:")
127131
print()
128-
with open(win_path,"r") as a:
129-
lines = a.readlines()
132+
with open(win_path,"r") as ch_3:
133+
lines = ch_3.readlines()
130134

131135
for line in lines:
132136
print(line)
@@ -382,15 +386,20 @@ def main(user_choice,user_choice_block_website,user_choice_unlock_website,win_pa
382386

383387
if __name__ == "__main__":
384388
if sys.platform.startswith("win"):
385-
try:
386-
on_start()
387-
load_config()
388-
main(user_choice,user_choice_block_website,user_choice_unlock_website,win_path,version_url,current_version,user_confirm_choice,user_choice_settings,user_choice_settings_confirm_clear,user_choice_settings_confirm_color,config_path,COLOR,user_choice_settings_choice_list)
389-
except Exception as ex_6:
390-
os.system('cls')
391-
print(f"[ERROR] {ex_6}")
392-
time.sleep(2)
393-
os.system('cls')
389+
if checkadmin():
390+
try:
391+
on_start()
392+
load_config()
393+
main(win_path)
394+
except Exception as ex_6:
395+
os.system('cls')
396+
print(f"[ERROR] {ex_6}")
397+
time.sleep(2)
398+
os.system('cls')
399+
else:
400+
logging.warning("Please run SimpleWebsiteBlocker with admin permissions!")
401+
os.system('pause')
402+
sys.exit()
394403
else:
395404
logging.warning("SimpleWebsiteBlocker works only on Windows operating system!")
396405
os.system('pause')

start.tmp

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)