From b034563347d34f7e9062dd50bc0a10b810837696 Mon Sep 17 00:00:00 2001 From: Jesse Gilles Date: Wed, 18 Dec 2013 16:14:37 -0600 Subject: ocg-scripts: add ocg-cell-router, ocg-set-apn, remove .sh from others --- multitech/recipes/ocg-scripts/ocg-scripts-1.0.inc | 12 +++- .../ocg-scripts/ocg-scripts-1.0/ocg-cell-router | 83 ++++++++++++++++++++++ .../recipes/ocg-scripts/ocg-scripts-1.0/ocg-dhcpd | 38 ++++++++++ .../ocg-scripts/ocg-scripts-1.0/ocg-set-apn | 19 +++++ .../ocg-scripts/ocg-scripts-1.0/ocg-wifi-ap | 65 +++++++++++++++++ .../ocg-scripts/ocg-scripts-1.0/ocg-wifi-ap.sh | 58 --------------- .../ocg-scripts/ocg-scripts-1.0/ocg-wifi-dhcpd.sh | 38 ---------- multitech/recipes/ocg-scripts/ocg-scripts_1.0.bb | 5 +- 8 files changed, 216 insertions(+), 102 deletions(-) create mode 100755 multitech/recipes/ocg-scripts/ocg-scripts-1.0/ocg-cell-router create mode 100755 multitech/recipes/ocg-scripts/ocg-scripts-1.0/ocg-dhcpd create mode 100755 multitech/recipes/ocg-scripts/ocg-scripts-1.0/ocg-set-apn create mode 100755 multitech/recipes/ocg-scripts/ocg-scripts-1.0/ocg-wifi-ap delete mode 100644 multitech/recipes/ocg-scripts/ocg-scripts-1.0/ocg-wifi-ap.sh delete mode 100644 multitech/recipes/ocg-scripts/ocg-scripts-1.0/ocg-wifi-dhcpd.sh diff --git a/multitech/recipes/ocg-scripts/ocg-scripts-1.0.inc b/multitech/recipes/ocg-scripts/ocg-scripts-1.0.inc index b075ede..b686762 100644 --- a/multitech/recipes/ocg-scripts/ocg-scripts-1.0.inc +++ b/multitech/recipes/ocg-scripts/ocg-scripts-1.0.inc @@ -3,8 +3,16 @@ SECTION = "kernel/userland" PRIORITY = "optional" LICENSE = "GPL" +SRC_URI = "file://ocg-wifi-ap \ + file://ocg-dhcpd \ + file://ocg-set-apn \ + file://ocg-cell-router" + + do_install() { install -d ${D}${sbindir} ${D}${sbindir} - install -m 755 ${WORKDIR}/ocg-wifi-ap.sh ${D}${sbindir} - install -m 755 ${WORKDIR}/ocg-wifi-dhcpd.sh ${D}${sbindir} + install -m 755 ${WORKDIR}/ocg-wifi-ap ${D}${sbindir} + install -m 755 ${WORKDIR}/ocg-dhcpd ${D}${sbindir} + install -m 755 ${WORKDIR}/ocg-set-apn ${D}${sbindir} + install -m 755 ${WORKDIR}/ocg-cell-router ${D}${sbindir} } diff --git a/multitech/recipes/ocg-scripts/ocg-scripts-1.0/ocg-cell-router b/multitech/recipes/ocg-scripts/ocg-scripts-1.0/ocg-cell-router new file mode 100755 index 0000000..0d48a9e --- /dev/null +++ b/multitech/recipes/ocg-scripts/ocg-scripts-1.0/ocg-cell-router @@ -0,0 +1,83 @@ +#!/usr/bin/env bash + +set -e + +do_start() { + echo "Configuring firewall rules..." + # Flush all the tables first + iptables -t filter -F + iptables -t nat -F + iptables -t mangle -F + + # Drop all incoming packets by default + iptables -t filter -P INPUT DROP + # Accept all on local loopback + iptables -t filter -A INPUT -i lo -j ACCEPT + # Allow packets in for existing socket connections + iptables -t filter -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT + + # Accept all from LAN (Wired) + iptables -t filter -A INPUT -i eth0 -j ACCEPT + + # Accept ssh from the LAN (Wired) + #iptables -t filter -A INPUT -i eth0 -p tcp --dport 22 -j ACCEPT + # Accept http from the LAN (Wired) + #iptables -t filter -A INPUT -i eth0 -p tcp --dport 80 -j ACCEPT + # Accept tftp from the LAN (Wired) + #iptables -t filter -A INPUT -i eth0 -p udp --dport 69 -j ACCEPT + + # Accept ssh from the WAN (Wireless) + #iptables -t filter -A INPUT -i ppp0 -p tcp --dport 22 -j ACCEPT + # Accept http from the WAN (Wireless) + #iptables -t filter -A INPUT -i ppp0 -p tcp --dport 80 -j ACCEPT + + # Allow packet fowarding from eth0 to ppp0 (cell router) + iptables -t filter -P FORWARD DROP + iptables -t filter -A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT + iptables -t filter -A FORWARD -i eth0 -o ppp0 -j ACCEPT + + # Allow all output packets + iptables -t filter -P OUTPUT ACCEPT + + # enable NAT for cell router + iptables -t nat -A POSTROUTING -o ppp0 -j MASQUERADE + + echo "Enabling packet forwarding..." + # turn on packet forwarding last + echo 1 > /proc/sys/net/ipv4/ip_forward + echo "Done" +} + +do_stop() { + echo "Clearing firewall rules..." + # clear all tables + iptables -t filter -F + iptables -t nat -F + iptables -t mangle -F + # reset policies to ACCEPT + iptables -t filter -P INPUT ACCEPT + iptables -t filter -P OUTPUT ACCEPT + iptables -t filter -P FORWARD ACCEPT + + # turn off packet forwarding + echo "Disabling packet forwarding..." + echo 0 > /proc/sys/net/ipv4/ip_forward + echo "Done" +} + +if [[ $# -ne 1 ]]; then + echo "Usage: $(basename $0) start|stop" + exit 1 +fi + +case $1 in + start) + do_start + ;; + stop) + do_stop + ;; +esac + +exit 0 + diff --git a/multitech/recipes/ocg-scripts/ocg-scripts-1.0/ocg-dhcpd b/multitech/recipes/ocg-scripts/ocg-scripts-1.0/ocg-dhcpd new file mode 100755 index 0000000..575b803 --- /dev/null +++ b/multitech/recipes/ocg-scripts/ocg-scripts-1.0/ocg-dhcpd @@ -0,0 +1,38 @@ +#!/bin/bash + +do_start() { + echo "starting dhcp daemon" + udhcpd -S /etc/udhcpd.conf +} + +do_stop() { + echo "stopping dhcp daemon" + killall udhcpd +} + +# main +if [[ $# -ne 1 ]] +then + echo "usage: $0 start|stop|restart" + exit 1 +fi + +case $1 in + start) + if [[ ! -f "/etc/udhcpd.conf" ]] + then + echo "/etc/udhcpd.conf does not exist" + exit 1 + fi + do_start + ;; + stop) + do_stop + ;; + restart) + do_stop + do_start + ;; +esac + +exit 0 diff --git a/multitech/recipes/ocg-scripts/ocg-scripts-1.0/ocg-set-apn b/multitech/recipes/ocg-scripts/ocg-scripts-1.0/ocg-set-apn new file mode 100755 index 0000000..867c24e --- /dev/null +++ b/multitech/recipes/ocg-scripts/ocg-scripts-1.0/ocg-set-apn @@ -0,0 +1,19 @@ +#!/bin/bash + +if [[ $# != "1" ]]; then + echo "Usage: $(basename $0) APN" + exit 1 +fi + +apn=$1 + +sed -r -i "s/^OK\s+'AT\+CGDCONT=1,\"IP\",\"[^\"]*\"'$/OK 'AT\+CGDCONT=1,\"IP\",\"${apn}\"'/" /etc/ppp/peers/gsm_chat + +if [[ $? != "0" ]]; then + echo "Failed to change APN" + exit 1 +else + echo "Set APN to \"${apn}\"" +fi + +exit 0 diff --git a/multitech/recipes/ocg-scripts/ocg-scripts-1.0/ocg-wifi-ap b/multitech/recipes/ocg-scripts/ocg-scripts-1.0/ocg-wifi-ap new file mode 100755 index 0000000..19f6cc1 --- /dev/null +++ b/multitech/recipes/ocg-scripts/ocg-scripts-1.0/ocg-wifi-ap @@ -0,0 +1,65 @@ +#!/bin/bash + +dhcpd_file=/etc/udhcpd.conf +interface=wlan0 + +do_start() { + echo "starting hostap daemon" + /etc/init.d/hostapd start + echo "setting IP address of access point" + ifconfig $interface $1 + if ! grep -E -q "^interface\s+$interface" $dhcpd_file; then + echo "Changing dhcpd interface to $interface" + sed -r -i "s/^interface\s+.*$/interface $interface/" $dhcpd_file + fi + ocg-dhcpd start +} + +do_stop() { + echo "stopping hostap daemon" + /etc/init.d/hostapd stop + ocg-dhcpd stop +} + +# main +if [[ $# -lt 1 ]] +then + echo "usage: $0 start|stop|restart [access point IP address]" + exit 1 +elif [[ $# -eq 2 ]] +then + ret=1 + if [[ $2 =~ ^([0-9]{1,3}\.){3,3}[0-9]{1,3}$ ]] + then + OIFS=$IFS + IFS='.' + ip=($2) + IFS=$OFIS + [[ ${ip[0]} -le 255 && ${ip[1]} -le 255 && ${ip[2]} -le 255 && ${ip[3]} -le 255 ]] + ret=$? + fi + if [[ ret -ne 0 ]] + then + echo "invalid IP address" + exit 1 + fi + ip=$2 +else + ip="192.168.2.1" +fi + +case $1 in + start) + do_start $ip + ;; + stop) + do_stop + ;; + restart) + do_stop + sleep 1 + do_start $ip + ;; +esac + +exit 0 diff --git a/multitech/recipes/ocg-scripts/ocg-scripts-1.0/ocg-wifi-ap.sh b/multitech/recipes/ocg-scripts/ocg-scripts-1.0/ocg-wifi-ap.sh deleted file mode 100644 index 5c684cb..0000000 --- a/multitech/recipes/ocg-scripts/ocg-scripts-1.0/ocg-wifi-ap.sh +++ /dev/null @@ -1,58 +0,0 @@ -#!/bin/bash - -do_start() { - echo "starting hostap daemon" - /etc/init.d/hostapd start - echo "setting IP address of access point" - ifconfig wlan0 $1 - ocg-wifi-dhcpd.sh start -} - -do_stop() { - echo "stopping hostap daemon" - /etc/init.d/hostapd stop - ocg-wifi-dhcpd.sh stop -} - -# main -if [[ $# -lt 1 ]] -then - echo "usage: $0 start|stop|restart [access point IP address]" - exit 1 -elif [[ $# -eq 2 ]] -then - ret=1 - if [[ $2 =~ ^([0-9]{1,3}\.){3,3}[0-9]{1,3}$ ]] - then - OIFS=$IFS - IFS='.' - ip=($2) - IFS=$OFIS - [[ ${ip[0]} -le 255 && ${ip[1]} -le 255 && ${ip[2]} -le 255 && ${ip[3]} -le 255 ]] - ret=$? - fi - if [[ ret -ne 0 ]] - then - echo "invalid IP address" - exit 1 - fi - ip=$2 -else - ip="192.168.2.1" -fi - -case $1 in - start) - do_start $ip - ;; - stop) - do_stop - ;; - restart) - do_stop - sleep 1 - do_start $ip - ;; -esac - -exit 0 diff --git a/multitech/recipes/ocg-scripts/ocg-scripts-1.0/ocg-wifi-dhcpd.sh b/multitech/recipes/ocg-scripts/ocg-scripts-1.0/ocg-wifi-dhcpd.sh deleted file mode 100644 index 575b803..0000000 --- a/multitech/recipes/ocg-scripts/ocg-scripts-1.0/ocg-wifi-dhcpd.sh +++ /dev/null @@ -1,38 +0,0 @@ -#!/bin/bash - -do_start() { - echo "starting dhcp daemon" - udhcpd -S /etc/udhcpd.conf -} - -do_stop() { - echo "stopping dhcp daemon" - killall udhcpd -} - -# main -if [[ $# -ne 1 ]] -then - echo "usage: $0 start|stop|restart" - exit 1 -fi - -case $1 in - start) - if [[ ! -f "/etc/udhcpd.conf" ]] - then - echo "/etc/udhcpd.conf does not exist" - exit 1 - fi - do_start - ;; - stop) - do_stop - ;; - restart) - do_stop - do_start - ;; -esac - -exit 0 diff --git a/multitech/recipes/ocg-scripts/ocg-scripts_1.0.bb b/multitech/recipes/ocg-scripts/ocg-scripts_1.0.bb index 04a643e..f87cfeb 100644 --- a/multitech/recipes/ocg-scripts/ocg-scripts_1.0.bb +++ b/multitech/recipes/ocg-scripts/ocg-scripts_1.0.bb @@ -2,9 +2,6 @@ DESCRIPTION = "Scripts to easily get started with common OCG use cases" require ocg-scripts-1.0.inc -PR = "r1" - -SRC_URI = "file://ocg-wifi-ap.sh \ - file://ocg-wifi-dhcpd.sh" +PR = "r2" S = "${WORKDIR}/ocg-scripts-${PV}" -- cgit v1.2.3