StartTLS/ssl in Config, Manipulation-Befehl, Anpassungen an Huawei-Stick

This commit is contained in:
Joerg Lehmann 2017-11-27 11:28:37 +01:00
parent 2649fb579b
commit 625e3b9777
4 changed files with 68 additions and 13 deletions

Binary file not shown.

View File

@ -26,6 +26,8 @@ Installation auf SD:
- Timezone: Europe/Zurich
- Change Wifi Country: CH
- Keyboard: Generic 105-key (Intl), German (Switzerland)
- Enable SSH Server
- Fuer Variante A: WLAN einrichten (siehe "per WLAN")
# apt-get update
# apt-get upgrade
@ -56,8 +58,7 @@ ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
network={
ssid="haerdoepfu27"
psk="XXXXXXXXXXXX"
ssid="haerdoepfu27" psk="XXXXXXXXXXXX"
}
```
#### per LAN
@ -107,6 +108,18 @@ connection = at
Quick Tutorial Gammu:
https://wammu.eu/docs/manual/quick/index.html
Folgender Init-String muss gesendet werden (sonst werden die empfangenen SMS nicht abfragbar sein):
AT+CPMS="SM";+CNMI=2,0,0,2,1
Wir fuegen den String in /etc/chatscripts/gprs ein:
# +CPIN provides the SIM card PIN
#OK "AT+CPIN=1234"
# Einstellungen wegen SMS-Empfang
OK AT+CPMS="SM";+CNMI=2,0,0,2,1
```
### Variante B
@ -149,13 +162,14 @@ $ cd beielipi
$ tar cvf /var/tmp/beielipi-git-files.tar .
# cd /home/beieli && tar xvf /var/tmp/beielipi-git-files.tar
# rm -rf /home/beieli/.git
# chown -R beieli:beieli /home/beieli
# chown -R root:root /home/beieli/root-bin
# chown -R root:root /home/beieli/web-root
# su - beieli
beieli@beielipi:~ $ mkdir config_backups data send_sms_queue tmp web-csv
beieli@beielipi:~ $ exit
# cd /home/beieli/install_files
# cd /home/beieli/install-files
# for i in $(find . -type f); do echo cp $i /$i ; done
# for i in $(find . -type f); do cp $i /$i ; done
@ -164,6 +178,7 @@ Fuer Variante A wieder loeschen:
# systemctl enable beielimon
# systemctl enable smsmon
Fuer Variante B:
# systemctl disable dhcpcd

View File

@ -1,9 +1,8 @@
beielipi_mobile_number: "077 461 19 91"
beielipi_mobile_number: "076 540 61 23"
scales:
- alias: "Waage Volk 1"
scale_uuid: "46335715-8454-483b-a17b-571619c5015d"
interface_type: usb_pce
interface_name: ttyUSB0
interface_type: dummy
sms_alert_phonenumbers:
- "+41765006123"
- alias: "Waage Volk 2"
@ -15,6 +14,7 @@ read_scale_interval_sec: 300
number_of_samples: 5
swarm_alarm_threshold_gram: 500
mailserver: mail.nbit.ch
mailserver_tls: starttls
mailserver_port: 587
mailfrom: info@nbit.ch
mailto: joerg.lehmann@nbit.ch
@ -24,3 +24,4 @@ balance_number: "444"
balance_command: "STATUS"
forward_sms_from_this_number: "444"
master_sms_number: "+41765006123"
manipulation_duration_minutes: 60

View File

@ -36,6 +36,9 @@ sys.setdefaultencoding('UTF8')
# State Machine fuer Gammu
sm = gammu.StateMachine()
# Alarmunterdrueckung mit "manipulation"
mute_alarm_until = None
# Read Configuration from YAML-File
with open("%s/bin/beielimon-config.yaml" % APP_ROOT, 'r') as stream:
try:
@ -52,8 +55,8 @@ def send_sms(phonenumbers , text):
}
#GELD SPAREN sm.SendSMS(message)
sm.SendSMS(message)
print("Send SMS to %s, Text: %s" % (phonenumber, text))
sm.SendSMS(message)
def send_mail(send_from, send_to, subject, text, files=None):
sm.Terminate()
@ -76,10 +79,15 @@ def send_mail(send_from, send_to, subject, text, files=None):
part['Content-Disposition'] = 'attachment; filename="%s"' % basename(f)
msg.attach(part)
if config_data['mailserver_tls'] == 'ssl':
smtp = smtplib.SMTP_SSL(config_data['mailserver'],config_data['mailserver_port'],timeout=120)
else:
smtp = smtplib.SMTP(config_data['mailserver'],config_data['mailserver_port'],timeout=120)
smtp.set_debuglevel(1)
smtp.ehlo()
if config_data['mailserver_tls'] == 'starttls':
smtp.starttls()
if config_data['mailuser'] != '':
smtp.login(config_data['mailuser'], config_data['mailpwd'])
smtp.sendmail(send_from, send_to, msg.as_string())
smtp.close()
@ -105,6 +113,9 @@ info 20171102 - Messwerte 2. Nov. 2017"""
elif command == 'help':
sms_message = "Zeigt die moeglichen Befehle an"
elif command == 'manipulation':
sms_message = "Manipulation - Schwarmalarm wird fuer %d Minuten abgeschaltet" % (config_data['manipulation_duration_minutes'])
elif command == 'balance':
sms_message = "Anforderung Info zum Prepaid-Guthaben"
@ -153,6 +164,9 @@ def ProcessSend_SMS_Queue():
except yaml.YAMLError as exc:
print(exc)
os.remove(f)
if is_muted():
print("Alarmierung ist abgeschaltet bis %s" % (time.strftime("%d.%m.%Y %H:%M", mute_alarm_until)))
else:
send_sms(sms_data['phonenumbers'],sms_data['text'])
def CreateAttachements(infotime):
@ -222,6 +236,9 @@ def send_info_sms(phonenumber):
for s in config_data['scales']:
my_text += "%s: %s\n" % (s['alias'],GetLastValues(s['scale_uuid']))
if mute_alarm_until:
my_text += "\nAlarmierung ist abgeschaltet bis %s" % (time.strftime("%d.%m.%Y %H:%M", mute_alarm_until))
send_sms([phonenumber],my_text)
def send_info(phonenumber, message_uc):
@ -239,6 +256,23 @@ def send_info(phonenumber, message_uc):
else:
send_info_sms(phonenumber)
def start_manipulation():
global mute_alarm_until
mute_alarm_until = time.localtime(time.time() + (config_data['manipulation_duration_minutes'] * 60))
print("Alarmierung ist abgeschaltet bis %s" % (time.strftime("%d.%m.%Y %H:%M", mute_alarm_until)))
def is_muted():
global mute_alarm_until
res = False
if mute_alarm_until:
if time.localtime() < mute_alarm_until:
res = True
else:
res = False
mute_alarm_until = None
return res
def balance():
send_sms([config_data['balance_number']],config_data['balance_command'])
@ -255,7 +289,7 @@ def hotspot_off():
os.system('/usr/bin/sudo %s/root-bin/hotspot_off' % (APP_ROOT))
def command_not_understood(phonenumber, message):
send_sms([phonenumber],'Befehl nicht verstanden: %s\n\nMoegliche Befehle: help, info, balance, reboot, shutdown, hotspot' % (message[:50]))
send_sms([phonenumber],'Befehl nicht verstanden: %s\n\nMoegliche Befehle: help, info, manipulation, balance, reboot, shutdown, hotspot' % (message[:50]))
def process_received_sms(phonenumber,message):
@ -280,6 +314,8 @@ def process_received_sms(phonenumber,message):
if 'HELP INFO' in message_uc:
send_help(phonenumber,'info')
elif 'HELP MANIPULATION' in message_uc:
send_help(phonenumber,'manipulation')
elif 'HELP HELP' in message_uc:
send_help(phonenumber,'help')
elif 'HELP BALANCE' in message_uc:
@ -294,6 +330,8 @@ def process_received_sms(phonenumber,message):
send_help(phonenumber,'')
elif 'INFO' in message_uc:
send_info(phonenumber, message_uc)
elif 'MANIPULATION' in message_uc:
start_manipulation()
elif 'BALANCE' in message_uc:
balance()
elif 'REBOOT' in message_uc:
@ -330,7 +368,8 @@ def main():
firstsms = sm.GetNextSMS(Start = True, Folder = 0)
#print("FIRSTSMS: %s" % (firstsms))
for x in range(len(firstsms)):
sm.DeleteSMS(firstsms[x]['Folder'], firstsms[x]['Location'])
#sm.DeleteSMS(firstsms[x]['Folder'], firstsms[x]['Location'])
sm.DeleteSMS(0, firstsms[x]['Location'])
#print("sm.DeleteSMS: %s %s" % (firstsms[x]['Folder'], firstsms[x]['Location']))
number = firstsms[x]['Number']
message = firstsms[x]['Text']