← Alle Beiträge
All about Pi 2021-02-16 17:15 Autor: Stefan 11 Min. Lesezeit

SMS Gateway im Eigenbau

Setup SMS Gateway with playSMS and gammu

Allgemein:

Ziel ist es ein SMS Gateway zum versenden von 2FA Kennwörtern zu haben und auch für Meldungen aus dem Monitoring

Hardware:

Software:

  • RaspberryOS 32Bit
  • Rufus
  • gammu-smsd
  • playSMS
  • apache2
  • mariadb-server

Installation:

Betriebssystem herunterladen und mit Rufus auf die SD Karte schreiben

Sobald das fertig ist wird auf das neue Laufwerk x:\boot eine leere Datei ssh erstellt, damit wird dann der SSH Server im System aktiviert.

Sollte WLAN benötigt werden muss auch auf x:\boot eine Datei wpa_supplicant.conf mit Inhalt

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=DE
network={
ssid="Wlanname"
psk="Wlanpasswort"
}

Da die Vorbereitung nun abgeschlossen ist kann die Karte in den Pi und dieser eingeschalten werden. Im Netzwerk nun nach dem Pi suchen mit Netscanner oder im DHCP. Weiter geht es dann mit PuTTY Verbinden mit der gefundenen IP

Benutzername: pi Passwort: raspberry

sudo apt update && apt dist-upgrade -y

Wenn das Update fertig ist, den Pi einmal neu starten: sudo shutdown -r now

Erneut mit PuTTY verbinden Benutzer anlegen mit dem die Anwendung läuft

sudo adduser sms
sudo usermod -a -G sudo sms

Firewall installieren und ssh zulassen, sonst kommt man nicht mehr auf den Pi

sudo apt install ufw
sudo ufw allow ssh
sudo ufw enable
sudo ufw reload

Webserver mit PHP und Datenbankserver installieren

sudo update
sudo rm /etc/source.list.d/vscode.list # Seit dem letzten Update wird vscode von Microsoft automatisch hinzugefüht, da man das auf dem Server nicht braucht, wird es gelöscht
sudo apt install mariadb-server mc unzip apache2 php php-cli php-mysql php-gd php-curl php-mbstring php-xml php-zip

sudo systemctl start mariadb.service
sudo systemctl enable mariadb.service
sudo systemctl start apache2.service
sudo systemctl enable apache2.service
sudo ufw allow http
sudo ufw allow https
sudo ufw reload

Gammu , der SMS Dienst

Da wir die Serielle Schnittstelle brauchen , muss vorher noch die config.txt angepasst werden

sudo nano /boot/config.txt
enable_uart=1

sudo apt install gammu gammu-smsd
mkdir -p /var/log/gammu /var/spool/gammu/{inbox,outbox,sent,error}

chown www-data:www-data -R /var/spool/gammu/*

 

nano /etc/gammu-smsdrc
[gammu]
port = /dev/ttyS0
connection = at
logfile = /var/log/gammu/gammu.log
logformat = textall
[smsd]
Service = files
InboxPath = /var/spool/gammu/inbox/
OutboxPath = /var/spool/gammu/outbox/
SentSMSPath = /var/spool/gammu/sent/
ErrorSMSPath = /var/spool/gammu/error/
InboxFormat = unicode
OutboxFormat = unicode
TransmitFormat = auto
debugLevel = 1
LogFile = /var/log/gammu/smsd.log
DeliveryReport = sms
DeliveryReportDelay = 7200
CheckSecurity = 0

 

Gammu testen

service gammu-smsd start
gammu-smsd-monitor
echo "Testnachricht" | gammu-smsd-inject TEXT +4917XXXXXX

 

Verzeichnis für playSMS vorbereiten und den Webserver

cd /home/sms
mkdir -p public_html log
sudo chmod 775 /home/sms public_html log
sudo chown sms.sms -R /home/sms
sudo chown www-data.sms -R /home/sms/log
ls -l /home/sms
sudo nano /etc/apache2/sites-available/sms.domain.local.conf
ServerName sms.domain.local
DocumentRoot /home/sms/public_html
ErrorLog /home/sms/log/httpd-error.log
CustomLog /home/sms/log/httpd-accesss.log combined
 AllowOverride FileInfo AuthConfig
 Limit Indexes Options MultiViews Indexes
 SymLinksIfOwnerMatch IncludesNoExec Require method GET POST OPTIONS php_admin_value engine On

sudo a2ensite sms.domain.local
sudo a2dissite 000-default.conf
sudo a2dissite default-ssl.conf
sudo systemctl reload apache2.service

Wenn man mit Zertifikat https möchte dann diesen Schritt noch zusätzlich durchführen, da das Gateway intern steht,nicht unbedingt notwendig

sudo apt install python3-certbot-apache
sudo certbot --apache

 

Datenbank erstellen

sudo mysqladmin create playsms
sudo mysql

 

CREATE USER 'playsms'@'localhost' IDENTIFIED BY 'strongpasswordhere';
GRANT ALL PRIVILEGES ON playsms.* TO 'playsms'@'localhost';
FLUSH PRIVILEGES;
exit

 

playSMS installieren

Da die Applikation nicht im root Modus laufen soll wird hier der Benutzer gewechselt und mit diesen Rechten weiter gearbeitet

su sms
cd /home/sms
mkdir -p bin etc lib src
sudo chmod 775 bin etc lib src
sudo touch log/audit.log log/playsms.log
sudo chmod 664 log/audit.log log/playsms.log
sudo chown www-data.sms -R log
ls -l log
cd /home/sms/src
git clone -b 1.4.3 --depth=1 https://github.com/antonraharja/playSMS
cd /home/sms/src/playSMS
nano install.conf

DBUSER="playsms"
DBPASS="strongpasswordhere"
DBNAME="playsms"
DBHOST="localhost"
DBPORT="3306"
WEBSERVERUSER="www-data"
WEBSERVERGROUP="www-data"
PATHSRC="/home/sms/src/playSMS"
PATHWEB="/home/sms/public_html"
PATHLIB="/home/sms/lib"
PATHBIN="/home/sms/bin"
PATHLOG="/home/sms/log"
PATHCONF="/home/sms/etc"
cd /home/sms/src/playSMS
./install-playsms.sh

 

bei der Installation muss man 3 Mal mit y bestätigen

Folgendes muss noch als /etc/systemd/system/playsms.service geseichert werden

[Unit]
Description=PlaySMS
After=mariadb.service
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/home/sms/bin/playsmsd /home/sms/etc/playsmsd.conf start
ExecStop=/home/sms/bin/playsmsd /home/sms/etc/playsmsd.conf stop
[Install]
WantedBy=multi-user.target

Anschließend

systemctl enable playsms.service

Die config.php muss man anpassen für erweiterte Logs und wenn https eingesetzt wird

nano /home/sms/public_html/config.php
logstate 3
ishttps true

http://IP
Username: admin
Password: admin

playSMS https://playsms.org/

Routing Konfiguration: https://edzeame.wordpress.com/2019/06/08/playsms-web-interface-gammu-install-and-configure/

API Referenz: https://github.com/playsms/playsms/blob/master/documents/development/WEBSERVICES.md

Passwort vom Admin vergessen?

Dann per ssh auf den Pi und nach sudo -s folgenden Befehl verwenden

echo "UPDATE playsms_tblUser SET password='21232f297a57a5a743894a0e4a801fc3' WHERE uid='1'" | mysql -uroot -p playsms

Das ganze gibt es auch als fertiges Image

In diesem Artikel sind Amazon-Links enthalten. Durch einen Klick darauf ge­lan­gt ihr direkt zum Anbieter. Solltet ihr euch dort für einen Kauf entscheiden, erhalten wir ei­ne kleine Provision. Für euch ändert sich am Preis nichts.

[:en]

Setup SMS Gateway with playSMS and gammu

Generally:

The aim is to have an SMS gateway for sending 2FA passwords and also for messages from monitoring

Hardware:

  • Gehäuse ( da es nichts passendes gibt muss man das drucken lassen )
  • Gehäuse HiFiBerry ist etwas höher und man kann die Cinch Löcher vermutlich für die Antennen verwenden 

Software:

  • RaspberryOS 32Bit
  • Rufus
  • gammu-smsd
  • playSMS
  • apache2
  • mariadb-server

Installation:

Download the operating system and write to the SD card with Rufus

As soon as this is done, an empty ssh file is created on the new drive x: \ boot, so that the SSH server is activated in the system.

If WLAN is required, a file wpa_supplicant.conf with content must also be found on x: \ boot

ctrlinterface=DIR=/var/run/wpasupplicant GROUP=netdev update_config=1 country=DE network={ ssid="Wlanname" psk="Wlanpasswort" }

 

Now that the preparation is complete, the card can be switched on in the Pi and it can be switched on.

Now search for the Pi in the network with Netscanner or in DHCP.

It then continues with PuTTY

Connect to the found IP

Username: pi

Password: raspberry

sudo apt update && apt dist-upgrade -y

 

When the update is done, restart the Pi once: sudo shutdown -r now

Reconnect to PuTTY

Create user with whom the application runs

sudo adduser sms sudo usermod -a -G sudo sms

 

Install the firewall and allow ssh, otherwise you can no longer get on the Pi

sudo apt install ufw sudo ufw allow ssh sudo ufw enable sudo ufw reload

 

Install web server with PHP and database server

sudo update sudo rm /etc/source.list.d/vscode.list # Seit dem letzten Update wird vscode von Microsoft automatisch hinzugefüht, da man das auf dem Server nicht braucht, wird es gelöscht sudo apt install mariadb-server mc unzip apache2 php php-cli php-mysql php-gd php-curl php-mbstring php-xml php-zip

sudo systemctl start mariadb.service sudo systemctl enable mariadb.service sudo systemctl start apache2.service sudo systemctl enable apache2.service sudo ufw allow http sudo ufw allow https sudo ufw reload

 

Gammu, the SMS service

Since we need the serial interface, the config.txt has to be adjusted beforehand

sudo nano /boot/config.txt enable_uart=1

sudo apt install gammu gammu-smsd mkdir -p /var/log/gammu /var/spool/gammu/{inbox,outbox,sent,error}

chown www-data:www-data -R /var/spool/gammu/*

 

nano /etc/gammu-smsdrc [gammu] port = /dev/ttyS0 connection = at logfile = /var/log/gammu/gammu.log logformat = textall [smsd] Service = files InboxPath = /var/spool/gammu/inbox/ OutboxPath = /var/spool/gammu/outbox/ SentSMSPath = /var/spool/gammu/sent/ ErrorSMSPath = /var/spool/gammu/error/ InboxFormat = unicode OutboxFormat = unicode TransmitFormat = auto debugLevel = 1 LogFile = /var/log/gammu/smsd.log DeliveryReport = sms DeliveryReportDelay = 7200 CheckSecurity = 0

 

Gammu test

service gammu-smsd start gammu-smsd-monitor echo "Testnachricht" | gammu-smsd-inject TEXT +4917XXXXXX

 

Prepare directory for playSMS and the web server

cd /home/sms mkdir -p publichtml log sudo chmod 775 /home/sms publichtml log sudo chown sms.sms -R /home/sms sudo chown www-data.sms -R /home/sms/log ls -l /home/sms

sudo nano /etc/apache2/sites-available/sms.domain.local.conf ServerName sms.domain.local DocumentRoot /home/sms/publichtml ErrorLog /home/sms/log/httpd-error.log CustomLog /home/sms/log/httpd-accesss.log combined  AllowOverride FileInfo AuthConfig  Limit Indexes Options MultiViews Indexes  SymLinksIfOwnerMatch IncludesNoExec Require method GET POST OPTIONS phpadmin_value engine On

sudo a2ensite sms.domain.local sudo a2dissite 000-default.conf sudo a2dissite default-ssl.conf sudo systemctl reload apache2.service

 

If you would like to carry out this step with an https certificate, because the gateway is internal, this is not absolutely necessary

sudo apt install python3-certbot-apache sudo certbot --apache

 

Create database

sudo mysqladmin create playsms sudo mysql

 

CREATE USER 'playsms'@'localhost' IDENTIFIED BY 'strongpasswordhere'; GRANT ALL PRIVILEGES ON playsms.* TO 'playsms'@'localhost'; FLUSH PRIVILEGES; exit

 

Install playSMS

Since the application should not run in root mode, the user is changed here and work continues with these rights

su sms cd /home/sms mkdir -p bin etc lib src sudo chmod 775 bin etc lib src sudo touch log/audit.log log/playsms.log sudo chmod 664 log/audit.log log/playsms.log sudo chown www-data.sms -R log ls -l log

cd /home/sms/src git clone -b 1.4.3 --depth=1 https://github.com/antonraharja/playSMS cd /home/sms/src/playSMS

nano install.conf

DBUSER="playsms" DBPASS="strongpasswordhere" DBNAME="playsms" DBHOST="localhost" DBPORT="3306" WEBSERVERUSER="www-data" WEBSERVERGROUP="www-data" PATHSRC="/home/sms/src/playSMS" PATHWEB="/home/sms/public_html" PATHLIB="/home/sms/lib" PATHBIN="/home/sms/bin" PATHLOG="/home/sms/log" PATHCONF="/home/sms/etc"

cd /home/sms/src/playSMS ./install-playsms.sh

 

During the installation you have to confirm 3 times with y

The following has to be saved as /etc/systemd/system/playsms.service

[Unit] Description=PlaySMS After=mariadb.service [Service] Type=oneshot RemainAfterExit=yes ExecStart=/home/sms/bin/playsmsd /home/sms/etc/playsmsd.conf start ExecStop=/home/sms/bin/playsmsd /home/sms/etc/playsmsd.conf stop [Install] WantedBy=multi-user.target

 

 

Subsequently

systemctl enable playsms.service

 

The config.php has to be adapted for extended logs and if https is used

nano /home/sms/public_html/config.php

logstate 3

ishttps true

 

http://IP

Username: admin

Password: admin

playSMS https://playsms.org/

Routing Konfiguration: https://edzeame.wordpress.com/2019/06/08/playsms-web-interface-gammu-install-and-configure/

API Referenz: https://github.com/playsms/playsms/blob/master/documents/development/WEBSERVICES.md

Forgot admin password?

Then use ssh on the Pi and after sudo -s use the following command

echo "UPDATE playsms_tblUser SET password='21232f297a57a5a743894a0e4a801fc3' WHERE uid='1'" | mysql -uroot -p playsms

Das ganze gibt es auch als fertiges Image

Amazon links are included in this article. Clicking on it will take you directly to the provider. Should you decide to buy there, we will receive a small commission. Nothing changes in the price for you.

Kommentare (0)

Moderiert & spamgeprüft

Noch keine freigegebenen Kommentare vorhanden. Schreibe gerne den ersten Kommentar!

Kommentar schreiben

Hinweis: Dein Kommentar wird vor der Veröffentlichung auf Echtheit geprüft und von einem Moderator freigeschaltet.