-
Notifications
You must be signed in to change notification settings - Fork 12
Custom dns #56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Custom dns #56
Changes from all commits
cc73ad2
af2fa2b
28a0186
6c13dd8
b889c25
7fb3100
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. looks AI generated, is it the case ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah I made set-dns.sh But I didn't know how to execute it from the .qml file So I shoved the set-dns.sh in AI and converted it to set-dns.py Then used the similar format from /usr/share/sleex/modules/dashboard/quickToggles/IdleInhibitor.qml but idk why it still isn't working There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So it doesn't works ? In that case open the PR as draft and request a review when it's working There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The script itself works |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| #!/usr/bin/env python3 | ||
| import subprocess | ||
| import json | ||
| import os | ||
| import getpass | ||
|
|
||
| # Path to the settings JSON | ||
| CONFIG_FILE = os.path.expanduser("~/.sleex/settings.json") | ||
|
|
||
| def run_cmd(cmd, capture_output=True): | ||
| """Run a shell command and return its output.""" | ||
| result = subprocess.run(cmd, shell=True, text=True, | ||
| capture_output=capture_output) | ||
| if result.returncode != 0: | ||
| return None | ||
| return result.stdout.strip() | ||
|
|
||
| def get_custom_dns(): | ||
| """Read customDNS from settings.json.""" | ||
| if not os.path.exists(CONFIG_FILE): | ||
| print(f"Settings file not found: {CONFIG_FILE}") | ||
| return None | ||
| try: | ||
| with open(CONFIG_FILE, "r") as f: | ||
| config = json.load(f) | ||
| # Navigate to dashboard.customDNS | ||
| dns = config.get("dashboard", {}).get("customDNS", "").strip() | ||
| if dns: | ||
| return dns | ||
| else: | ||
| print("customDNS is empty in settings.json") | ||
| return None | ||
| except Exception as e: | ||
| print(f"Failed to read settings.json: {e}") | ||
| return None | ||
|
|
||
| def main(): | ||
| dns_server = get_custom_dns() | ||
| if not dns_server: | ||
| print("Please set a custom DNS in ~/.sleex/settings.json under dashboard.customDNS") | ||
| return | ||
|
|
||
| # Detect the active connection | ||
| active_conn_cmd = "nmcli -t -f NAME,DEVICE connection show --active | head -n1 | cut -d: -f1" | ||
| active_conn = run_cmd(active_conn_cmd) | ||
| if not active_conn: | ||
| print("No active network connection found.") | ||
| return | ||
|
|
||
| print(f"Setting DNS {dns_server} for connection '{active_conn}'...") | ||
|
|
||
| # Check connection type | ||
| con_type_cmd = f"nmcli -g connection.type connection show '{active_conn}'" | ||
| con_type = run_cmd(con_type_cmd) | ||
|
|
||
| # If Wi-Fi, check for PSK | ||
| if con_type == "wifi": | ||
| psk_cmd = f"nmcli -g 802-11-wireless-security.psk connection show '{active_conn}'" | ||
| psk = run_cmd(psk_cmd) | ||
| if not psk: | ||
| psk = getpass.getpass("Wi-Fi password not found. Please enter it: ") | ||
| subprocess.run(f"nmcli connection modify '{active_conn}' wifi-sec.psk '{psk}'", shell=True) | ||
|
|
||
| # Set the DNS and ignore auto DNS | ||
| set_dns_cmd = f"nmcli connection modify '{active_conn}' ipv4.dns '{dns_server}' ipv4.ignore-auto-dns yes" | ||
| if run_cmd(set_dns_cmd) is None: | ||
| print(f"Failed to set DNS {dns_server} for connection '{active_conn}'.") | ||
| return | ||
|
|
||
| # Reactivate the connection | ||
| subprocess.run(f"nmcli connection down '{active_conn}'", shell=True) | ||
| subprocess.run(f"nmcli connection up '{active_conn}'", shell=True) | ||
|
|
||
| print("DNS updated successfully.") | ||
| subprocess.run("nmcli dev show | grep DNS", shell=True) | ||
|
|
||
| if __name__ == "__main__": | ||
| main() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You shouldn't remove that. This makes the whole switch+label clickable, instead of just the switch.