initial commit v0.1-1
initial commit

--- /dev/null
+++ b/wifischedule-luci/Makefile
@@ -1,1 +1,39 @@
+#
+# Copyright (C) 2010-2011 OpenWrt.org
+#
+# This is free software, licensed under the GNU General Public License v2.
+# See /LICENSE for more information.
+#
 
+include $(TOPDIR)/rules.mk
+
+PKG_NAME:=luci-app-wifischedule
+PKG_VERSION:=0.1
+PKG_RELEASE:=1
+
+include $(INCLUDE_DIR)/package.mk
+
+define Package/luci-app-wifischedule
+  SECTION:=luci
+  CATEGORY:=LuCI
+  DEPENDS:=+wifischedule
+  TITLE:=LuCI - Lua Configuration Interface
+  URL:=http://openwrt.razvi.ro/wifischedule/luci-app-wifischedule_$(PKG_VERSION)-$(PKG_RELEASE).ipk
+  MAINTAINER:=Razvan Stanga <wifischedule@razvi.ro>
+  SUBMENU:=3. Applications
+  TITLE:=LuCI Support for wifischedule
+endef
+
+define Package/luci-app-wifischedule/description
+A wifi scheduler
+endef
+
+define Build/Compile
+endef
+
+define Package/luci-app-wifischedule/install
+	$(CP) ./files/* $(1)
+endef
+
+$(eval $(call BuildPackage,luci-app-wifischedule))
+

--- /dev/null
+++ b/wifischedule-luci/files/usr/lib/lua/luci/controller/wifi_schedule.lua
@@ -1,1 +1,18 @@
+--[[
+LuCI - Lua Configuration Interface
 
+]]--
+
+module("luci.controller.wifi_schedule", package.seeall)
+
+function index()
+	if not nixio.fs.access("/etc/config/wifi_schedule") then
+		return
+	end
+	
+	local page
+
+	page = entry({"admin", "network", "wifi_schedule"}, cbi("wifi_schedule/schedule"), _("Wifi Schedule"), 500)
+	page.dependent = true
+end
+

--- /dev/null
+++ b/wifischedule-luci/files/usr/lib/lua/luci/model/cbi/wifi_schedule/schedule.lua
@@ -1,1 +1,30 @@
 
+require("luci.tools.webadmin")
+
+m = Map("wifi_schedule", translate("Wifi Schedule"),
+	translate(""))
+
+s = m:section(TypedSection, "wifischedule", "")
+s.addremove = false
+s.anonymous = false
+
+s:tab("wd1", translate("Monday"))
+s:tab("wd2", translate("Tuesday"))
+s:tab("wd3", translate("Wednesday"))
+s:tab("wd4", translate("Thursday"))
+s:tab("wd5", translate("Friday"))
+s:tab("wd6", translate("Saturday"))
+s:tab("wd7", translate("Sunday"))
+
+for day=1,7 do
+	for i=0,23 do
+		f=i
+		t=i+1
+		s:taboption("wd"..day, Flag, day.."_"..f,
+        		translate(f..":00 - "..t..":00"),
+	        	translate(""))
+	end
+end
+
+return m
+

--- /dev/null
+++ b/wifischedule/Makefile
@@ -1,1 +1,50 @@
+#
+# Copyright (C) 2010-2011 OpenWrt.org
+#
+# This is free software, licensed under the GNU General Public License v2.
+# See /LICENSE for more information.
+#
 
+include $(TOPDIR)/rules.mk
+
+PKG_NAME:=wifischedule
+PKG_VERSION:=0.1
+PKG_RELEASE:=1
+
+include $(INCLUDE_DIR)/package.mk
+
+define Package/wifischedule
+  SECTION:=net
+  CATEGORY:=Network
+  DEPENDS:=
+  TITLE:=A wifi scheduler
+  URL:=http://openwrt.razvi.ro/wifischedule/wifischedule_$(PKG_VERSION)-$(PKG_RELEASE).ipk
+  MAINTAINER:=Razvan Stanga <wifischedule@razvi.ro>
+endef
+
+define Package/wifischedule/description
+A wifi scheduler
+endef
+
+define Package/wifischedule/conffiles
+/etc/config/wifi_schedule
+endef
+
+define Build/Compile
+endef
+
+define Package/wifischedule/install
+	$(CP) ./files/* $(1)
+endef
+
+define Package/wifischedule/postinst
+if [ -z "$${IPKG_INSTROOT}" ]
+then
+/etc/init.d/wifi_schedule enable
+/etc/init.d/wifi_schedule start
+fi
+exit 0
+endef
+
+$(eval $(call BuildPackage,wifischedule))
+

--- /dev/null
+++ b/wifischedule/files/etc/config/wifi_schedule
@@ -1,1 +1,3 @@
 
+config wifischedule 'Days'
+

--- /dev/null
+++ b/wifischedule/files/etc/init.d/wifi_schedule
@@ -1,1 +1,12 @@
+#!/bin/sh /etc/rc.common
 
+START=99
+
+start() {
+	[ -x /usr/sbin/wifi_schedule ] && [ ! -f /var/run/wifi_schedule.pid ] && /usr/sbin/wifi_schedule &
+}
+
+stop () {
+	[ -f /var/run/wifi_schedule.pid ] && kill $(cat /var/run/wifi_schedule.pid) && rm /var/run/wifi_schedule.pid
+}
+

--- /dev/null
+++ b/wifischedule/files/usr/sbin/wifi_schedule
@@ -1,1 +1,26 @@
+#!/bin/sh
 
+echo "$$" > /var/run/wifi_schedule.pid
+
+while [ 1 ] ; do
+	day_hour=$(date +"%u_%k" | tr -d ' ')
+	enabledoncurrenthour="x$(uci -q get wifi_schedule.Days.`echo $day_hour`)"
+
+	if [ $enabledoncurrenthour == "x1" ]
+	then
+		if [ "x$(uci -q -P /var/state/ get wireless.@wifi-iface[0].up)" != "x1" ]
+		then
+        	        logger "wifi is enabled $day_hour and wifi is off, turn on"
+                	wifi up
+		fi
+	else
+		if [ "x$(uci -q -P /var/state/ get wireless.@wifi-iface[0].up)" == "x1" ]
+	        then
+        	        logger "wifi is disabled $day_hour and wifi is on, turn off"
+	                wifi down
+        	fi
+	fi
+
+	sleep 30
+done
+

comments