From 9c6081ea87cb8d4688107b1789fbe1412d3d17af Mon Sep 17 00:00:00 2001 From: Pranav Jerry Date: Sun, 25 Jul 2021 14:06:17 +0530 Subject: [PATCH 1/3] added rfkill support Updated HACKING.md and added license disclaimer to all python files. And tidied up scripts.py --- HACKING.md | 6 +--- naxalnet/__init__.py | 16 ++++++++++ naxalnet/__main__.py | 16 ++++++++++ naxalnet/scripts.py | 73 ++++++++++++++++++++++++++++---------------- 4 files changed, 80 insertions(+), 31 deletions(-) diff --git a/HACKING.md b/HACKING.md index 6ddeed4..d52594e 100644 --- a/HACKING.md +++ b/HACKING.md @@ -12,11 +12,7 @@ relevant label. ## Contribute code To push to this repo, you need your username to be in the -contributors list. -To add you as a contributor, email any of the authors with -your username: - -- `echo yvoervangbe cyhf akyarg ng qvfebbg qbg bet | tr 'A-Za-z' 'N-ZA-Mn-za-m' | sed 's/plus/+/' | sed 's/ at /@/' | sed 's/dot/./' | tr -d ' '` +contributors list. See issue #8. ## Packaging diff --git a/naxalnet/__init__.py b/naxalnet/__init__.py index c2fbd44..32cd1a5 100644 --- a/naxalnet/__init__.py +++ b/naxalnet/__init__.py @@ -1,3 +1,19 @@ #!/usr/bin/env python3 +# Copyright (C) 2021 The naxalnet Authors + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + + __version__ = "0.1.0a" diff --git a/naxalnet/__main__.py b/naxalnet/__main__.py index 4d9d341..f2ebcf9 100644 --- a/naxalnet/__main__.py +++ b/naxalnet/__main__.py @@ -1,5 +1,21 @@ #!/usr/bin/env python3 +# Copyright (C) 2021 The naxalnet Authors + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + + from naxalnet.scripts import here_be_dragons if __name__ == "__main__": diff --git a/naxalnet/scripts.py b/naxalnet/scripts.py index fde65f4..a61878c 100644 --- a/naxalnet/scripts.py +++ b/naxalnet/scripts.py @@ -23,8 +23,6 @@ with systemd-networkd and iwd import sys from pathlib import Path from shutil import copy - -# from dasbus.connection import SystemMessageBus from dasbus.error import DBusError from naxalnet.iwd import IWD, Device, Adapter @@ -35,23 +33,33 @@ AP_SSID = "NaxalNet" AP_PASSWD = "naxalnet256" +def copy_files(): + """ + Copy networkd configs to volatile dir. + The D-Bus API does not support creating new interfaces + or linking to bridges. So we use config files. + See man:systemd.network(5) + """ + + print("Copying network config files") + dest = Path(NETWORKD_VOLATILE_DIR) + src = Path(NETWORKD_CONFIGS) + + # Create the volatile directory if it doesn't exist + dest.mkdir(parents=True, exist_ok=True) + + # Copy all files in src to dest + for i in src.iterdir(): + copy(i, dest) + + def here_be_dragons(): - # Copy networkd configs to volatile dir. - # The D-Bus API does not support creating new interfaces - # or linking to bridges. So we use config files. - # See man:systemd.network(5) - + """ + This function is run every time you + execute naxalnet from commandline + """ try: - print("Copying network config files") - dest = Path(NETWORKD_VOLATILE_DIR) - src = Path(NETWORKD_CONFIGS) - - # Create the volatile directory if it doesn't exist - dest.mkdir(parents=True, exist_ok=True) - - # Copy all files in src to dest - for i in src.iterdir(): - copy(i, dest) + copy_files() except PermissionError as error: print(error) sys.exit("Make sure you are root") @@ -64,11 +72,11 @@ def here_be_dragons(): ap_devices = [] for i in devices: - d = Device(i) - a = Adapter(d.adapter) - if a.supports_mode("ad-hoc"): + device = Device(i) + adapter = Adapter(device.adapter) + if adapter.supports_mode("ad-hoc"): adhoc_devices.append(i) - if a.supports_mode("ap"): + if adapter.supports_mode("ap"): ap_devices.append(i) if len(adhoc_devices) != 0: @@ -76,19 +84,32 @@ def here_be_dragons(): adhoc_device = Device(adhoc_devices.pop()) # The same device is likely to have ap support too. # But we can't start ad-hoc and ap on the same interface. - # Remove dev1 from ap_devices if it exists there + # Remove adhoc_device from ap_devices if it exists there if adhoc_device.name in ap_devices: ap_devices.remove(adhoc_device.name) - print("Working on ad-hoc") - adhoc_device.start_adhoc_open(ADHOC_SSID) - # Start Access point if ap_device is not empty, - # ie, we have more devices + print("Working on ad-hoc") + # Turn on adapter if it is off + # See issue #9 + adhoc_adapter = Adapter(adhoc_device.adapter) + if not adhoc_adapter.is_powered_on(): + adhoc_adapter.power_on() + adhoc_device.reload() + adhoc_device.start_adhoc_open(ADHOC_SSID) + # Start Access point if ap_device is not empty, + # ie, we have more devices if len(ap_devices) != 0: print("Working on AP") ap_device = Device(ap_devices.pop()) + # Turn on adapter if it is off + # See issue #9 + ap_adapter = Adapter(ap_device.adapter) + if not ap_adapter.is_powered_on(): + ap_adapter.power_on() + ap_adapter.reload() ap_device.start_ap(AP_SSID, AP_PASSWD) except DBusError as error: print(error) sys.exit("An error occured while communicating with iwd") + # naxalnet will print Bye if no errors occured print("Bye") From 1500f486eff4e825c59f4840e7ed24bcb6c8f544 Mon Sep 17 00:00:00 2001 From: Pranav Jerry Date: Mon, 26 Jul 2021 12:44:24 +0530 Subject: [PATCH 2/3] added clean in Makefile --- Makefile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Makefile b/Makefile index f81213a..54c2b15 100644 --- a/Makefile +++ b/Makefile @@ -6,3 +6,6 @@ build: install: build python setup.py install --root="$(DESTDIR)/" --optimize=1 --skip-build + +clean: + rm -rf build naxalnet.egg-info From 86042b98529946a0b641dfdc27b1f0c16cfa5f4e Mon Sep 17 00:00:00 2001 From: Pranav Jerry Date: Mon, 26 Jul 2021 12:48:45 +0530 Subject: [PATCH 3/3] uncommented IPNS address --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index 1900aec..e14922b 100644 --- a/README.md +++ b/README.md @@ -63,13 +63,11 @@ git clone https://git.disroot.org/pranav/naxalnet.git cd naxalnet ``` - Run `sudo make install` to install naxalnet. This will install naxalnet in `/usr/bin/naxalnet`.