From 0179c5cfe83132ad4ddb1675fda2c9c33f1e61fe Mon Sep 17 00:00:00 2001 From: Philipp Engel Date: Wed, 10 Dec 2014 18:45:35 +0100 Subject: [PATCH 1/6] changed logrotate base filename from logrotate to netconnectd --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 7ea8800..5ad23d6 100644 --- a/setup.py +++ b/setup.py @@ -33,7 +33,7 @@ ('/etc/init.d/', [('extras/netconnectd.init', 'netconnectd', 0755)]), ('/etc/default/', [('extras/netconnectd.default', 'netconnectd', 0644)]), ('/etc/', [('extras/netconnectd.yaml', 'netconnectd.yaml', 0600)]), - ('/etc/logrotate.d/', [('extras/netconnectd.logrotate', 'logrotate', 0644)]), + ('/etc/logrotate.d/', [('extras/netconnectd.logrotate', 'netconnectd', 0644)]), ] From b3d01b2bed3bb751508ee9b3e5126d0e50d3dbf6 Mon Sep 17 00:00:00 2001 From: Philipp Engel Date: Mon, 15 Dec 2014 21:31:20 +0100 Subject: [PATCH 2/6] moved config files to netconnectd folder in etc created callback for link changes --- setup.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/setup.py b/setup.py index 5ad23d6..f20584a 100644 --- a/setup.py +++ b/setup.py @@ -24,15 +24,17 @@ """ EXTRAS_FOLDERS = [ - ('/etc/netconnectd.conf.d', 0755), - ('/etc/netconnectd.conf.d/hostapd', 0755), - ('/etc/netconnectd.conf.d/dnsmasq', 0755) + ('/etc/netconnectd', 0755), + ('/etc/netconnectd/conf.d', 0755), + ('/etc/netconnectd/conf.d/hostapd', 0755), + ('/etc/netconnectd/conf.d/dnsmasq', 0755) ] EXTRAS_FILES = [ ('/etc/init.d/', [('extras/netconnectd.init', 'netconnectd', 0755)]), ('/etc/default/', [('extras/netconnectd.default', 'netconnectd', 0644)]), - ('/etc/', [('extras/netconnectd.yaml', 'netconnectd.yaml', 0600)]), + ('/etc/netconnectd/', [('extras/netconnectd.yaml', 'netconnectd.yaml', 0600)]), + ('/etc/netconnectd/', [('extras/netconnectd.action', 'netconnectd.action', 0755)]), ('/etc/logrotate.d/', [('extras/netconnectd.logrotate', 'netconnectd', 0644)]), ] From 3f6356efbefe82eaae0ab584f2cbdda239004792 Mon Sep 17 00:00:00 2001 From: Philipp Engel Date: Mon, 15 Dec 2014 22:20:30 +0100 Subject: [PATCH 3/6] moved config files to netconnectd folder in etc (last commit not complete) calling action script on link change, ap_mode change and device availability change --- README.md | 2 +- extras/netconnectd.default | 2 +- extras/netconnectd.init | 2 +- extras/netconnectd.yaml | 4 ++-- netconnectd/server.py | 14 +++++++++++--- 5 files changed, 16 insertions(+), 8 deletions(-) mode change 100644 => 100755 extras/netconnectd.init diff --git a/README.md b/README.md index 7833bc5..550cdb5 100644 --- a/README.md +++ b/README.md @@ -128,7 +128,7 @@ It's finally time to install `netconnectd`: sudo python setup.py install sudo python setup.py install_extras -Modify `/etc/netconnectd.yaml` as necessary: +Modify `/etc/netconnectd/netconnectd.yaml` as necessary: * Change the passphrase/psk for your access point * If necessary change the interface names of your wifi and wired network interfaces diff --git a/extras/netconnectd.default b/extras/netconnectd.default index 3308d67..c8f03e3 100644 --- a/extras/netconnectd.default +++ b/extras/netconnectd.default @@ -4,7 +4,7 @@ #DAEMON=/usr/local/bin/netconnectd # Path to netconnectd configuration file -#CONFIGFILE=/etc/netconnectd.yaml +#CONFIGFILE=/etc/netconnectd/netconnectd.yaml # Path to socket file #SOCKET=/var/run/netconnectd.sock diff --git a/extras/netconnectd.init b/extras/netconnectd.init old mode 100644 new mode 100755 index 174d7ee..19cefc2 --- a/extras/netconnectd.init +++ b/extras/netconnectd.init @@ -19,7 +19,7 @@ NAME="netconnectd" DAEMON=/usr/local/bin/netconnectd PIDFILE=/var/run/$NAME.pid SOCKET=/var/run/$NAME.sock -CONFIGFILE=/etc/$NAME.yaml +CONFIGFILE=/etc/$NAME/$NAME.yaml LOGFILE=/var/log/$NAME.log PKGNAME=netconnectd SCRIPTNAME=/etc/init.d/$PKGNAME diff --git a/extras/netconnectd.yaml b/extras/netconnectd.yaml index e30ddd2..2fa39f3 100644 --- a/extras/netconnectd.yaml +++ b/extras/netconnectd.yaml @@ -73,13 +73,13 @@ paths: #hostapd: /usr/sbin/hostapd # folder where to store managed hostapd configuration files - hostapd_conf: /etc/netconnectd.conf.d/hostapd + hostapd_conf: /etc/netconnectd/conf.d/hostapd # path to dnsmasq executable #dnsmasq: /usr/sbin/dnsmasq # folder where to store managed dnsmasq configuration files - dnsmasq_conf: /etc/netconnectd.conf.d/dnsmasq + dnsmasq_conf: /etc/netconnectd/conf.d/dnsmasq # path to interfaces file to use, usually no need to change this #interfaces: /etc/network/interfaces diff --git a/netconnectd/server.py b/netconnectd/server.py index f7665f3..2fe12d8 100644 --- a/netconnectd/server.py +++ b/netconnectd/server.py @@ -85,6 +85,7 @@ def __init__(self, server_address=None, wifi_if=None, wired_if=None, linkmon_ena # for status messages... self.last_link = False self.last_reachable_devs = tuple() + self.last_ap_mode = False # prepare link monitor thread self.link_thread = threading.Thread(target=self._link_monitor, kwargs=dict(callback=self.on_link_change, interval=self.linkmon_interval)) @@ -388,10 +389,17 @@ def on_status_message(self, message): ) def on_link_change(self, former_link, current_link, current_devs): + access_point_running = self.access_point.is_running() + + if (former_link != current_link or self.last_reachable_devs != tuple(current_devs) or self.last_ap_mode != access_point_running): + action_out = subprocess.check_output(["/etc/netconnectd/netconnectd.action", str(former_link), str(current_link), str(self.last_reachable_devs), str(tuple(current_devs)), str(self.last_ap_mode), str(access_point_running)]) + self.logger.debug("invoked action: %s" % action_out) + + self.last_link = current_link self.last_reachable_devs = tuple(current_devs) - - access_point_running = self.access_point.is_running() + self.last_ap_mode = access_point_running + if current_link or access_point_running: if current_link and not former_link and not access_point_running: self.logger.debug("Link restored!") @@ -565,7 +573,7 @@ def dhcp_range(arg): configfile = args.config if not configfile: - configfile = "/etc/netconnectd.yaml" + configfile = "/etc/netconnectd/netconnectd.yaml" import os if os.path.exists(configfile): From 58d4c10dee66e7d9dc7ca3778e988b58a3daf7ec Mon Sep 17 00:00:00 2001 From: Philipp Engel Date: Mon, 15 Dec 2014 23:31:28 +0100 Subject: [PATCH 4/6] added action script template --- extras/netconnectd.action | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100755 extras/netconnectd.action diff --git a/extras/netconnectd.action b/extras/netconnectd.action new file mode 100755 index 0000000..dfcbe7a --- /dev/null +++ b/extras/netconnectd.action @@ -0,0 +1,9 @@ +#!/bin/sh + +# This script accepts arguments on the command line. They are: +# $1 the old link status (True or False) +# $2 the new link status +# $3 the old list of active interfaces +# $4 the new list of active interfaces +# $5 the old ap mode status (True or False) +# $6 the new ap mode status From d66ba39a2469df0dbe7b3a7ac7463148c27b63eb Mon Sep 17 00:00:00 2001 From: Philipp Engel Date: Tue, 16 Dec 2014 16:33:45 +0100 Subject: [PATCH 5/6] Revert "moved config files to netconnectd folder in etc" This reverts commit b3d01b2bed3bb751508ee9b3e5126d0e50d3dbf6. --- README.md | 2 +- extras/netconnectd.action | 9 --------- extras/netconnectd.default | 2 +- extras/netconnectd.init | 2 +- extras/netconnectd.yaml | 4 ++-- netconnectd/server.py | 14 +++----------- setup.py | 10 ++++------ 7 files changed, 12 insertions(+), 31 deletions(-) delete mode 100755 extras/netconnectd.action mode change 100755 => 100644 extras/netconnectd.init diff --git a/README.md b/README.md index 550cdb5..7833bc5 100644 --- a/README.md +++ b/README.md @@ -128,7 +128,7 @@ It's finally time to install `netconnectd`: sudo python setup.py install sudo python setup.py install_extras -Modify `/etc/netconnectd/netconnectd.yaml` as necessary: +Modify `/etc/netconnectd.yaml` as necessary: * Change the passphrase/psk for your access point * If necessary change the interface names of your wifi and wired network interfaces diff --git a/extras/netconnectd.action b/extras/netconnectd.action deleted file mode 100755 index dfcbe7a..0000000 --- a/extras/netconnectd.action +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/sh - -# This script accepts arguments on the command line. They are: -# $1 the old link status (True or False) -# $2 the new link status -# $3 the old list of active interfaces -# $4 the new list of active interfaces -# $5 the old ap mode status (True or False) -# $6 the new ap mode status diff --git a/extras/netconnectd.default b/extras/netconnectd.default index c8f03e3..3308d67 100644 --- a/extras/netconnectd.default +++ b/extras/netconnectd.default @@ -4,7 +4,7 @@ #DAEMON=/usr/local/bin/netconnectd # Path to netconnectd configuration file -#CONFIGFILE=/etc/netconnectd/netconnectd.yaml +#CONFIGFILE=/etc/netconnectd.yaml # Path to socket file #SOCKET=/var/run/netconnectd.sock diff --git a/extras/netconnectd.init b/extras/netconnectd.init old mode 100755 new mode 100644 index 19cefc2..174d7ee --- a/extras/netconnectd.init +++ b/extras/netconnectd.init @@ -19,7 +19,7 @@ NAME="netconnectd" DAEMON=/usr/local/bin/netconnectd PIDFILE=/var/run/$NAME.pid SOCKET=/var/run/$NAME.sock -CONFIGFILE=/etc/$NAME/$NAME.yaml +CONFIGFILE=/etc/$NAME.yaml LOGFILE=/var/log/$NAME.log PKGNAME=netconnectd SCRIPTNAME=/etc/init.d/$PKGNAME diff --git a/extras/netconnectd.yaml b/extras/netconnectd.yaml index 2fa39f3..e30ddd2 100644 --- a/extras/netconnectd.yaml +++ b/extras/netconnectd.yaml @@ -73,13 +73,13 @@ paths: #hostapd: /usr/sbin/hostapd # folder where to store managed hostapd configuration files - hostapd_conf: /etc/netconnectd/conf.d/hostapd + hostapd_conf: /etc/netconnectd.conf.d/hostapd # path to dnsmasq executable #dnsmasq: /usr/sbin/dnsmasq # folder where to store managed dnsmasq configuration files - dnsmasq_conf: /etc/netconnectd/conf.d/dnsmasq + dnsmasq_conf: /etc/netconnectd.conf.d/dnsmasq # path to interfaces file to use, usually no need to change this #interfaces: /etc/network/interfaces diff --git a/netconnectd/server.py b/netconnectd/server.py index 2fe12d8..f7665f3 100644 --- a/netconnectd/server.py +++ b/netconnectd/server.py @@ -85,7 +85,6 @@ def __init__(self, server_address=None, wifi_if=None, wired_if=None, linkmon_ena # for status messages... self.last_link = False self.last_reachable_devs = tuple() - self.last_ap_mode = False # prepare link monitor thread self.link_thread = threading.Thread(target=self._link_monitor, kwargs=dict(callback=self.on_link_change, interval=self.linkmon_interval)) @@ -389,17 +388,10 @@ def on_status_message(self, message): ) def on_link_change(self, former_link, current_link, current_devs): - access_point_running = self.access_point.is_running() - - if (former_link != current_link or self.last_reachable_devs != tuple(current_devs) or self.last_ap_mode != access_point_running): - action_out = subprocess.check_output(["/etc/netconnectd/netconnectd.action", str(former_link), str(current_link), str(self.last_reachable_devs), str(tuple(current_devs)), str(self.last_ap_mode), str(access_point_running)]) - self.logger.debug("invoked action: %s" % action_out) - - self.last_link = current_link self.last_reachable_devs = tuple(current_devs) - self.last_ap_mode = access_point_running - + + access_point_running = self.access_point.is_running() if current_link or access_point_running: if current_link and not former_link and not access_point_running: self.logger.debug("Link restored!") @@ -573,7 +565,7 @@ def dhcp_range(arg): configfile = args.config if not configfile: - configfile = "/etc/netconnectd/netconnectd.yaml" + configfile = "/etc/netconnectd.yaml" import os if os.path.exists(configfile): diff --git a/setup.py b/setup.py index f20584a..5ad23d6 100644 --- a/setup.py +++ b/setup.py @@ -24,17 +24,15 @@ """ EXTRAS_FOLDERS = [ - ('/etc/netconnectd', 0755), - ('/etc/netconnectd/conf.d', 0755), - ('/etc/netconnectd/conf.d/hostapd', 0755), - ('/etc/netconnectd/conf.d/dnsmasq', 0755) + ('/etc/netconnectd.conf.d', 0755), + ('/etc/netconnectd.conf.d/hostapd', 0755), + ('/etc/netconnectd.conf.d/dnsmasq', 0755) ] EXTRAS_FILES = [ ('/etc/init.d/', [('extras/netconnectd.init', 'netconnectd', 0755)]), ('/etc/default/', [('extras/netconnectd.default', 'netconnectd', 0644)]), - ('/etc/netconnectd/', [('extras/netconnectd.yaml', 'netconnectd.yaml', 0600)]), - ('/etc/netconnectd/', [('extras/netconnectd.action', 'netconnectd.action', 0755)]), + ('/etc/', [('extras/netconnectd.yaml', 'netconnectd.yaml', 0600)]), ('/etc/logrotate.d/', [('extras/netconnectd.logrotate', 'netconnectd', 0644)]), ] From a97601af145956a98124445073b63089648b828d Mon Sep 17 00:00:00 2001 From: make-ing Date: Tue, 19 Apr 2016 14:10:08 +0000 Subject: [PATCH 6/6] changed link_down_count to 0 so its doesn't start the ap when a wired network connection is available. This works in jessie and should be checked if it apears in wheezy also and maybe find a better solution (boot order). --- netconnectd/server.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/netconnectd/server.py b/netconnectd/server.py index e049b18..e2a6bb7 100644 --- a/netconnectd/server.py +++ b/netconnectd/server.py @@ -121,7 +121,7 @@ def exception_logger(exc_type, exc_value, exc_tb): self.link_thread.daemon = True # we start out with a fully maxed link down count so that we will directly try to create a connection - self.link_down_count = linkmon_maxdown + self.link_down_count = 0 # we need to make sure that client messages and link events are never handled concurrently, so we synchronize via # this mutex