Skip to content

Commit

Permalink
try to make mac os work
Browse files Browse the repository at this point in the history
  • Loading branch information
ali77gh committed Feb 11, 2022
1 parent dc73947 commit 374e884
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fi

# download
echo "downloading..."
wget -q -O - https://github.com/ali77gh/shecan-cli/releases/download/1.2.1/shecan.py > temp.py
wget -q -O - https://github.com/ali77gh/shecan-cli/releases/download/1.2.2/shecan.py > temp.py
echo "done"

# copy
Expand Down
40 changes: 20 additions & 20 deletions shecan.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,8 @@

# OS X configs
interface = "Wi-Fi"
user = os.popen("whoami").read()
dns_file_bak_mac = f"/User/{user}/.shecan-cli"
dns_file_bak_mac = "/var/root/.shecan-cli"

def check_root():
if os.geteuid() != 0:
print("run as root")
exit(-1)

def bool_to_status(bool_value):
if bool_value:
Expand Down Expand Up @@ -61,7 +56,6 @@ def enable():
print("shecan is already enabled")
exit(0)

check_root()
# backup
os.system(f'cp {dns_file} {dns_file_bak}')

Expand All @@ -73,7 +67,6 @@ def enable():

@staticmethod
def disable():
check_root()
if not os.path.isfile(dns_file_bak):
print("shecan is already disabled")
exit(0)
Expand All @@ -83,27 +76,25 @@ def disable():

class Darwin_dns_util:

def get_current_dns():
return os.popen(f"networksetup -getdnsservers {interface}").read().replace("\n", "")

@staticmethod
def get_dns_list() -> str:
result = ""
for dns_server in shecan_dns:
result+=dns_server + " "
return result
def get_shecan_dns_list() -> str:
return " ".join(shecan_dns)

@staticmethod
def local_status() -> bool:
result = os.popen(f"networksetup -getdnsservers {interface}").read()
return Darwin_dns_util.get_dns_list() == result
return Darwin_dns_util.get_shecan_dns_list() == Darwin_dns_util.get_current_dns()

@staticmethod
def enable():
# backup
result = os.popen(f"networksetup -getdnsservers {interface}").read()
f = open(dns_file_bak_mac,"w")
f.write(result)
f.write(Darwin_dns_util.get_current_dns())

# enable
os.system(f"networksetup -setdnsservers {interface} {Darwin_dns_util.get_dns_list()}")
os.system(f"networksetup -setdnsservers {interface} {Darwin_dns_util.get_shecan_dns_list()}")
pass

@staticmethod
Expand Down Expand Up @@ -167,6 +158,11 @@ def live_status():
except KeyboardInterrupt:
exit(0)

def show_permission_error():
print("┌───────────────────────────────────────────────────────┐")
print("│ Permission denied. you may need to run with 'sudo' │")
print("└───────────────────────────────────────────────────────┘")

def show_help():
print("┌────────────────────────────────────────────────────────┐");
print("│ shecan-cli │");
Expand Down Expand Up @@ -201,7 +197,11 @@ def main():
if len(sys.argv) != 2:
show_help()
else:
main_switch(sys.argv[1])
try:
main_switch(sys.argv[1])
except PermissionError:
show_permission_error()

main()

if __name__ == '__main__':
main()

0 comments on commit 374e884

Please sign in to comment.