Initial Commit

This commit is contained in:
2018-04-06 17:22:19 +02:00
commit cd65d33e3e
57 changed files with 22103 additions and 0 deletions
+18
View File
@@ -0,0 +1,18 @@
#!/bin/bash
echo "$(date): Connect to Internet..."
ifup --force gprs
sleep 1
x=0
# Wait until connection is established
while ! ping -c 1 -W 1 8.8.8.8 &>/dev/null ; do
echo "$(date): wait for internet connection to come up"
sleep 1
if [ $x -gt 60 ]; then
# Time out here
echo "$(date): Could not connect to internet (timeout)..."
exit 1
fi
x=$((x+1))
done
echo "$(date): Connected to Internet...- IP: $(/home/pi/root-bin/get_internet_ip)"
+5
View File
@@ -0,0 +1,5 @@
#!/bin/bash
echo "$(date): Disconnect from Internet..."
ifdown gprs
sleep 5
pkill pppd
+1
View File
@@ -0,0 +1 @@
/home/pi/root-bin/ussd.py *130# | grep -v '^python-gammu' |sed 's/@//'
+2
View File
@@ -0,0 +1,2 @@
#!/bin/bash
ip -4 addr show ppp0 2>/dev/null | grep -oP '(?<=inet\s)\d+(\.\d+){3}'
+7
View File
@@ -0,0 +1,7 @@
#!/bin/bash
ADDR="$(/home/pi/root-bin/get_internet_ip)"
if [ -z "${ADDR}" ]; then
echo "Keine Verbindung mit dem Internet"
else
echo "Internet ist verbunden, IP: $(/home/pi/root-bin/get_internet_ip)"
fi
+61
View File
@@ -0,0 +1,61 @@
#!/usr/bin/python
from bottle import Bottle, run, template, static_file, error, redirect, post, request, response
import glob
import re
import time
import random
import string
import os
import shutil
import subprocess
app = Bottle()
APP_ROOT = "/home/pi"
def run_command(cmd):
proc = subprocess.Popen([cmd], stdout=subprocess.PIPE, shell=True)
(out, err) = proc.communicate()
return out
@app.route('/')
def index():
data = {
'xyz': 1
}
return template('%s/web-root/index.tpl' % (APP_ROOT), data)
@app.route('/internet_on')
def internet_on():
os.system('/home/pi/root-bin/connect_to_internet')
@app.route('/internet_off')
def internet_off():
os.system('/home/pi/root-bin/disconnect_from_internet')
@app.route('/get_balance')
def get_balance():
response.status = 200
myout = run_command('/home/pi/root-bin/get_balance.sh')
return myout
@app.route('/get_status')
def get_status():
response.status = 200
myout = run_command('/home/pi/root-bin/get_status.sh')
return myout
@app.route('/shutdown')
def shutdown_proxypi():
os.system('/sbin/init 0')
@app.route('/static/<filepath:path>')
def server_static(filepath):
return static_file(filepath, root='%s/web-root/static' % (APP_ROOT))
@app.error(404)
def error404(error):
return index()
run(app, host='192.168.255.1', port=80)
+4
View File
@@ -0,0 +1,4 @@
#!/bin/bash
/home/pi/root-bin/connect_to_internet
/usr/sbin/ntpdate 3.de.pool.ntp.org
/home/pi/root-bin/disconnect_from_internet
+125
View File
@@ -0,0 +1,125 @@
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
# vim: expandtab sw=4 ts=4 sts=4:
#
# Copyright © 2003 - 2017 Michal Čihař <michal@cihar.com>
#
# This file is part of python-gammu <https://wammu.eu/python-gammu/>
#
# 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 2 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, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
'''
Service numbers dialogue example.
'''
from __future__ import print_function
import gammu
import sys
import time
REPLY = False
gsm = (u"@£$¥èéùìòÇ\nØø\rÅåΔ_ΦΓΛΩΠΨΣΘΞ\x1bÆæßÉ !\"#¤%&'()*+,-./0123456789:;<=>"
u"?¡ABCDEFGHIJKLMNOPQRSTUVWXYZÄÖÑܧ¿abcdefghijklmnopqrstuvwxyzäöñüà")
def gsm7bitdecode(f):
f = ''.join(["{0:08b}".format(int(f[i:i+2], 16)) for i in range(0, len(f), 2)][::-1])
return ''.join([gsm[int(f[::-1][i:i+7][::-1], 2)] for i in range(0, len(f), 7)])
def gsm7bitencode(src):
result, count, last = [], 0, 0
for c in src:
this = ord(c) << (8 - count)
if count:
result.append('%02X' % ((last >> 8) | (this & 0xFF)))
count = (count + 1) % 8
last = this
result.append('%02x' % (last >> 8))
return ''.join(result)
def callback(state_machine, callback_type, data):
'''
Callback on USSD data.
'''
global REPLY
if callback_type != 'USSD':
print('Unexpected event type: {0}'.format(callback_type))
sys.exit(1)
REPLY = True
#print('Network reply:')
#print('Status: {0}'.format(data['Status']))
#print(data['Text'])
print(gsm7bitdecode(data['Text']))
if data['Status'] == 'ActionNeeded':
do_service(state_machine)
def init():
'''
Intializes gammu and callbacks.
'''
state_machine = gammu.StateMachine()
state_machine.ReadConfig()
state_machine.Init()
state_machine.SetIncomingCallback(callback)
try:
state_machine.SetIncomingUSSD()
except gammu.ERR_NOTSUPPORTED:
print('Incoming USSD notification is not supported.')
sys.exit(1)
return state_machine
def do_service(state_machine):
'''
Main code to talk with worker.
'''
global REPLY
if len(sys.argv) >= 2:
code = sys.argv[1]
del sys.argv[1]
else:
prompt = 'Enter code (empty string to end): '
try:
code = raw_input(prompt)
except NameError:
code = input(prompt)
code=gsm7bitencode(code)
#print(code)
if code != '':
#print('Talking to network...')
REPLY = False
state_machine.DialService(code)
loops = 0
while not REPLY and loops < 10:
#print("Loop")
state_machine.ReadDevice()
time.sleep(1)
loops += 1
def main():
state_machine = init()
do_service(state_machine)
state_machine.Terminate()
if __name__ == '__main__':
main()