Vendor Galaxy Roles and Collections
This commit is contained in:
parent
c1e1897cda
commit
2aed20393f
22 changed files with 387444 additions and 2 deletions
19
ansible_collections/debops/debops/roles/smstools/COPYRIGHT
Normal file
19
ansible_collections/debops/debops/roles/smstools/COPYRIGHT
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
debops.smstools - Manage SMS Gateway using Ansible
|
||||
|
||||
Copyright (C) 2014-2019 Maciej Delmanowski <drybjed@gmail.com>
|
||||
Copyright (C) 2015-2019 DebOps <https://debops.org/>
|
||||
SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
This Ansible role is part of DebOps.
|
||||
|
||||
DebOps is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License version 3, as
|
||||
published by the Free Software Foundation.
|
||||
|
||||
DebOps 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 DebOps. If not, see https://www.gnu.org/licenses/.
|
||||
|
|
@ -0,0 +1,262 @@
|
|||
---
|
||||
# .. vim: foldmarker=[[[,]]]:foldmethod=marker
|
||||
|
||||
# .. Copyright (C) 2014-2019 Maciej Delmanowski <drybjed@gmail.com>
|
||||
# .. Copyright (C) 2015-2019 DebOps <https://debops.org/>
|
||||
# .. SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
# .. _smstools__ref_defaults:
|
||||
|
||||
# debops.smstools default variables
|
||||
# =================================
|
||||
|
||||
# .. contents:: Sections
|
||||
# :local:
|
||||
#
|
||||
# .. include:: ../../../../includes/global.rst
|
||||
|
||||
|
||||
# ---- TCP -> SMS gateway ----
|
||||
|
||||
# .. envvar:: smstools_service_allow [[[
|
||||
#
|
||||
# List of IP addresses or CIDR network ranges which are allowed to access TCP
|
||||
# service
|
||||
smstools_service_allow: []
|
||||
|
||||
# ]]]
|
||||
# ---- mail -> SMS gateway ----
|
||||
|
||||
# Settings for subdomains and domains which are used to send messages to SMS
|
||||
# gateway
|
||||
|
||||
# .. envvar:: smstools_mail_transport_subdomain [[[
|
||||
#
|
||||
# Subdomain for SMS transport
|
||||
smstools_mail_transport_subdomain: 'sms'
|
||||
|
||||
# ]]]
|
||||
# .. envvar:: smstools_mail_alias_subdomain [[[
|
||||
#
|
||||
# Subdomain for mail aliases which are resolved to mobile numbers
|
||||
smstools_mail_alias_subdomain: 'gsm'
|
||||
|
||||
# ]]]
|
||||
# .. envvar:: smstools_mail_domain [[[
|
||||
#
|
||||
# Main domain used by this role
|
||||
smstools_mail_domain: '{{ ansible_domain }}'
|
||||
|
||||
# ]]]
|
||||
# .. envvar:: smstools_mail_transport_domain [[[
|
||||
#
|
||||
# Domains that combine above subdomains with main host domain
|
||||
smstools_mail_transport_domain: '{{ smstools_mail_transport_subdomain }}.{{ smstools_mail_domain }}'
|
||||
|
||||
# ]]]
|
||||
# .. envvar:: smstools_mail_alias_domain [[[
|
||||
#
|
||||
# FIXME(yaml4rst): Describe what this variable is doing.
|
||||
smstools_mail_alias_domain: '{{ smstools_mail_alias_subdomain }}.{{ smstools_mail_domain }}'
|
||||
|
||||
# ]]]
|
||||
# .. envvar:: smstools_default_country_prefix [[[
|
||||
#
|
||||
# Default country prefix (with +) to add if number has only 9 digits
|
||||
smstools_default_country_prefix: ''
|
||||
|
||||
# ]]]
|
||||
# .. envvar:: smstools_default_senders [[[
|
||||
#
|
||||
# List of default mail senders that are allowed to send mail messages to mobile
|
||||
# recipients
|
||||
# Options:
|
||||
# - name: 'mail@example.com' # required
|
||||
# state: 'permit/deny' # optional
|
||||
smstools_default_senders:
|
||||
- name: 'root@{{ smstools_mail_domain }}'
|
||||
|
||||
# ]]]
|
||||
# .. envvar:: smstools_senders [[[
|
||||
#
|
||||
# Additional list of mail senders
|
||||
smstools_senders: []
|
||||
|
||||
# ]]]
|
||||
# .. envvar:: smstools_mail_recipients [[[
|
||||
#
|
||||
# Hash table which specifies mail alias to mobile number mapping. Aliases will
|
||||
# be generated in a domain specified with smstools_mail_alias_* variables
|
||||
smstools_mail_recipients: {}
|
||||
#'recipient1': [ '+00123123123' ]
|
||||
#'recipient2': [ '+00123123123', '+00321321321' ]
|
||||
|
||||
# ]]]
|
||||
# .. envvar:: smstools_mail_aliases [[[
|
||||
#
|
||||
# Hash table which specifies aliases for groups of recipients from
|
||||
# smstools_mail_recipients table. Aliases will be created in a domain specified
|
||||
# with smstools_mail_alias_* variables
|
||||
smstools_mail_aliases: {}
|
||||
#'alias': [ 'recipient1', 'recipient2' ]
|
||||
|
||||
# ]]]
|
||||
# .. envvar:: smstools_mail_msgdel_list [[[
|
||||
#
|
||||
# List of regexps which will be used to find and remove strings in SMS messages
|
||||
# before they are sent
|
||||
smstools_mail_msgdel_list: []
|
||||
#- 'linux'
|
||||
#- '^Ansible'
|
||||
|
||||
# ]]]
|
||||
# .. envvar:: smstools_sms_log [[[
|
||||
#
|
||||
# Log sent SMS messages for accounting purposes, use monthly log rotation, logs
|
||||
# should be kept for 2 years
|
||||
smstools_sms_log: '/var/log/sms.log'
|
||||
|
||||
# ]]]
|
||||
# .. envvar:: smstools_sms_log_rotation [[[
|
||||
#
|
||||
# FIXME(yaml4rst): Describe what this variable is doing.
|
||||
smstools_sms_log_rotation: 'monthly'
|
||||
|
||||
# ]]]
|
||||
# .. envvar:: smstools_sms_log_rotation_interval [[[
|
||||
#
|
||||
# FIXME(yaml4rst): Describe what this variable is doing.
|
||||
smstools_sms_log_rotation_interval: '{{ (12 * 2) }}'
|
||||
|
||||
# ]]]
|
||||
# ---- SMS gateway testing ----
|
||||
|
||||
# .. envvar:: smstools_test_recipients [[[
|
||||
#
|
||||
# List of mobile numbers to send a test message to on host reboot
|
||||
# Example: [ '+00123123123' ]
|
||||
smstools_test_recipients: []
|
||||
|
||||
# ]]]
|
||||
# .. envvar:: smstools_test_message [[[
|
||||
#
|
||||
# Test message to send on host reboot
|
||||
smstools_test_message: 'This is a test of the SMS gateway on {{ ansible_fqdn }} sent at $(date)'
|
||||
|
||||
# ]]]
|
||||
# ---- smstools options ----
|
||||
|
||||
# .. envvar:: smstools_sleep [[[
|
||||
#
|
||||
# Time between queue checks, in seconds
|
||||
smstools_sleep: 1
|
||||
|
||||
# ]]]
|
||||
# .. envvar:: smstools_stats_interval [[[
|
||||
#
|
||||
# Generate modem stats once a day
|
||||
smstools_stats_interval: '{{ (60 * 60 * 24) | round | int }}'
|
||||
|
||||
# ]]]
|
||||
# .. envvar:: smstools_global_options [[[
|
||||
#
|
||||
# Hash with options configured in /etc/smsd.conf
|
||||
smstools_global_options:
|
||||
delaytime: '{{ smstools_sleep }}'
|
||||
delaytime_mainprocess: '{{ smstools_sleep }}'
|
||||
receive_before_send: no
|
||||
autosplit: 3
|
||||
loglevel: 5
|
||||
|
||||
# ]]]
|
||||
# .. envvar:: smstools_devices [[[
|
||||
#
|
||||
# List of modems known to smsd, by default it's configured to use one modem on
|
||||
# serial interface
|
||||
smstools_devices:
|
||||
- name: 'GSM1'
|
||||
device: '/dev/ttyS0'
|
||||
options:
|
||||
baudrate: 115200
|
||||
incoming: yes
|
||||
|
||||
# ]]]
|
||||
# Configuration for other Ansible roles [[[
|
||||
# -----------------------------------------
|
||||
|
||||
# .. envvar:: smstools__etc_services__dependent_list [[[
|
||||
#
|
||||
# Configuration for the debops.etc_services_ Ansible role.
|
||||
smstools__etc_services__dependent_list:
|
||||
|
||||
- name: '{{ smstools_service_name }}'
|
||||
port: '{{ smstools_service_port }}'
|
||||
comment: 'SMS service'
|
||||
|
||||
# ]]]
|
||||
# .. envvar:: smstools__tcpwrappers__dependent_allow [[[
|
||||
#
|
||||
# Configuration for the debops.tcpwrappers_ Ansible role.
|
||||
smstools__tcpwrappers__dependent_allow:
|
||||
|
||||
- daemon: '{{ smstools_service_name }}'
|
||||
client: '{{ smstools_service_allow }}'
|
||||
weight: '50'
|
||||
filename: 'smstools_dependency_allow'
|
||||
comment: 'Allow connections to SMS service'
|
||||
|
||||
# ]]]
|
||||
# .. envvar:: smstools__ferm__dependent_rules [[[
|
||||
#
|
||||
# Configuration for the debops.ferm_ Ansible role.
|
||||
smstools__ferm__dependent_rules:
|
||||
|
||||
- name: 'smstools_accept'
|
||||
type: 'accept'
|
||||
dport: [ '{{ smstools_service_name }}' ]
|
||||
saddr: '{{ smstools_service_allow }}'
|
||||
|
||||
# ]]]
|
||||
# .. envvar:: smstools__postfix__dependent_maincf [[[
|
||||
#
|
||||
# The Postfix 'main.cf' configuration for the debops.postfix_ Ansible role.
|
||||
smstools__postfix__dependent_maincf:
|
||||
|
||||
- name: 'recipient_canonical_maps'
|
||||
value: [ 'texthash:/usr/local/lib/smstools/postfix_recipient_canonical_map' ]
|
||||
|
||||
- name: 'transport_maps'
|
||||
value: [ 'texthash:/usr/local/lib/smstools/postfix_transport' ]
|
||||
|
||||
- name: 'relay_domains'
|
||||
value: [ '{{ smstools_mail_transport_domain }}' ]
|
||||
|
||||
- name: 'relay_recipient_maps'
|
||||
value: [ 'regexp:/usr/local/lib/smstools/postfix_relay_recipient_map' ]
|
||||
|
||||
- name: 'virtual_alias_domains'
|
||||
value: [ '{{ smstools_mail_alias_domain }}' ]
|
||||
|
||||
- name: 'virtual_alias_maps'
|
||||
value: [ 'texthash:/usr/local/lib/smstools/postfix_virtual_alias_map' ]
|
||||
|
||||
- name: 'sms_destination_recipient_limit'
|
||||
value: 1
|
||||
|
||||
# ]]]
|
||||
# .. envvar:: smstools__postfix__dependent_mastercf [[[
|
||||
#
|
||||
# The Postfix 'master.cf' configuration for the debops.postfix_ Ansible role.
|
||||
smstools__postfix__dependent_mastercf:
|
||||
|
||||
- name: 'sms'
|
||||
type: 'unix'
|
||||
unpriv: False
|
||||
chroot: False
|
||||
maxproc: 1
|
||||
args: |
|
||||
flags=hqu user=smsd argv=/usr/local/lib/smstools/sms-transport
|
||||
${sender} ${mailbox}
|
||||
command: 'pipe'
|
||||
# ]]]
|
||||
# ]]]
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
---
|
||||
# Copyright (C) 2014-2019 Maciej Delmanowski <drybjed@gmail.com>
|
||||
# Copyright (C) 2015-2022 DebOps <https://debops.org/>
|
||||
# SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
# Ensure that custom Ansible plugins and modules included in the main DebOps
|
||||
# collection are available to roles in other collections.
|
||||
collections: [ 'debops.debops' ]
|
||||
|
||||
dependencies: []
|
||||
|
||||
galaxy_info:
|
||||
|
||||
author: 'Maciej Delmanowski'
|
||||
description: 'Create an TCP-SMS and mail-SMS gateway using a GSM modem'
|
||||
company: 'DebOps'
|
||||
license: 'GPL-3.0-only'
|
||||
min_ansible_version: '1.7.0'
|
||||
|
||||
platforms:
|
||||
|
||||
- name: 'Ubuntu'
|
||||
versions: [ 'all' ]
|
||||
|
||||
- name: 'Debian'
|
||||
versions: [ 'all' ]
|
||||
|
||||
galaxy_tags:
|
||||
- networking
|
||||
- sms
|
||||
- notification
|
||||
194
ansible_collections/debops/debops/roles/smstools/tasks/main.yml
Normal file
194
ansible_collections/debops/debops/roles/smstools/tasks/main.yml
Normal file
|
|
@ -0,0 +1,194 @@
|
|||
---
|
||||
# Copyright (C) 2014-2019 Maciej Delmanowski <drybjed@gmail.com>
|
||||
# Copyright (C) 2015-2019 DebOps <https://debops.org/>
|
||||
# SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
- name: Import DebOps global handlers
|
||||
ansible.builtin.import_role:
|
||||
name: 'global_handlers'
|
||||
|
||||
- name: Install SMS Tools packages
|
||||
ansible.builtin.package:
|
||||
name: '{{ item }}'
|
||||
state: 'present'
|
||||
with_items: [ 'smstools', 'xinetd', 'libconfig-tiny-perl' ]
|
||||
register: smstools__register_packages
|
||||
until: smstools__register_packages is succeeded
|
||||
|
||||
- name: Check current smsd home directory
|
||||
ansible.builtin.shell: set -o nounset -o pipefail -o errexit && getent passwd smsd | grep "/home/smsd" || true
|
||||
args:
|
||||
executable: 'bash'
|
||||
register: smstools_register_home
|
||||
changed_when: False
|
||||
|
||||
- name: Stop smsd for home directory change
|
||||
ansible.builtin.service:
|
||||
name: 'smstools'
|
||||
state: 'stopped'
|
||||
when: smstools_register_home is defined and smstools_register_home.stdout | d()
|
||||
|
||||
- name: Fix smsd home directory
|
||||
ansible.builtin.user:
|
||||
name: 'smsd'
|
||||
home: '/var/spool/sms'
|
||||
when: smstools_register_home is defined and smstools_register_home.stdout | d()
|
||||
|
||||
- name: Start smsd with new home directory
|
||||
ansible.builtin.service:
|
||||
name: 'smstools'
|
||||
state: 'started'
|
||||
when: smstools_register_home is defined and smstools_register_home.stdout | d()
|
||||
|
||||
- name: Configure smsd
|
||||
ansible.builtin.template:
|
||||
src: 'etc/smsd.conf.j2'
|
||||
dest: '/etc/smsd.conf'
|
||||
owner: 'root'
|
||||
group: 'root'
|
||||
mode: '0644'
|
||||
notify: [ 'Restart smstools' ]
|
||||
|
||||
- name: Make sure /srv/users home directory exists
|
||||
ansible.builtin.file:
|
||||
dest: '/srv/users'
|
||||
state: 'directory'
|
||||
owner: 'root'
|
||||
group: 'root'
|
||||
mode: '0751'
|
||||
|
||||
- name: Create SMS service system group
|
||||
ansible.builtin.group:
|
||||
name: '{{ smstools_service_group }}'
|
||||
system: True
|
||||
state: 'present'
|
||||
|
||||
- name: Create SMS service system user
|
||||
ansible.builtin.user:
|
||||
name: '{{ smstools_service_user }}'
|
||||
group: '{{ smstools_service_group }}'
|
||||
system: True
|
||||
home: '{{ smstools_service_home }}'
|
||||
state: 'present'
|
||||
shell: '/bin/false'
|
||||
|
||||
- name: Create directory for SMS service scripts
|
||||
ansible.builtin.file:
|
||||
dest: '/usr/local/lib/smstools'
|
||||
state: 'directory'
|
||||
owner: 'root'
|
||||
group: 'staff'
|
||||
mode: '0755'
|
||||
|
||||
- name: Install smsd scripts
|
||||
ansible.builtin.template:
|
||||
src: '{{ item }}.j2'
|
||||
dest: '/{{ item }}'
|
||||
owner: 'smsd'
|
||||
group: 'sms'
|
||||
mode: '0750'
|
||||
with_items: [ 'usr/local/bin/sendsms',
|
||||
'usr/local/lib/smstools/sms-service',
|
||||
'usr/local/lib/smstools/sms-transport',
|
||||
'usr/local/lib/smstools/test-sms-on-reboot' ]
|
||||
|
||||
- name: Install root scripts
|
||||
ansible.builtin.template:
|
||||
src: '{{ item }}.j2'
|
||||
dest: '/{{ item }}'
|
||||
owner: 'root'
|
||||
group: 'root'
|
||||
mode: '0750'
|
||||
with_items: [ 'usr/local/lib/smstools/fix-device-permissions' ]
|
||||
|
||||
- name: Install Postfix configuration files
|
||||
ansible.builtin.template:
|
||||
src: 'usr/local/lib/smstools/{{ item }}.j2'
|
||||
dest: '/usr/local/lib/smstools/{{ item }}'
|
||||
owner: 'root'
|
||||
group: 'root'
|
||||
mode: '0644'
|
||||
with_items: [ 'postfix_recipient_canonical_map', 'postfix_transport',
|
||||
'postfix_relay_recipient_map', 'postfix_virtual_alias_map' ]
|
||||
notify: [ 'Reload postfix' ]
|
||||
|
||||
- name: Configure access to sendsms via sudo
|
||||
ansible.builtin.template:
|
||||
src: 'etc/sudoers.d/smstools.j2'
|
||||
dest: '/etc/sudoers.d/smstools'
|
||||
owner: 'root'
|
||||
group: 'root'
|
||||
mode: '0440'
|
||||
when: (ansible_local | d() and ansible_local.sudo | d() and
|
||||
(ansible_local.sudo.installed | d()) | bool)
|
||||
|
||||
- name: Configure xinetd SMS service
|
||||
ansible.builtin.template:
|
||||
src: 'etc/xinetd.d/sms.j2'
|
||||
dest: '/etc/xinetd.d/sms'
|
||||
owner: 'root'
|
||||
group: 'root'
|
||||
mode: '0644'
|
||||
notify: [ 'Reload xinetd' ]
|
||||
|
||||
- name: Configure mail to SMS transport
|
||||
ansible.builtin.template:
|
||||
src: '{{ item }}.j2'
|
||||
dest: '/{{ item }}'
|
||||
owner: 'root'
|
||||
group: 'root'
|
||||
mode: '0644'
|
||||
with_items: [ 'etc/sms-senders', 'etc/sms-msgdel', 'etc/sms-transport.conf' ]
|
||||
|
||||
- name: Fix device permissions on boot in OpenVZ containers
|
||||
ansible.builtin.lineinfile:
|
||||
dest: '/etc/rc.local'
|
||||
state: 'present'
|
||||
insertbefore: '^exit 0'
|
||||
regexp: '^/usr/local/lib/smstools/fix-device-permissions'
|
||||
line: '/usr/local/lib/smstools/fix-device-permissions'
|
||||
mode: '0755'
|
||||
register: smstools_register_fixpermissions
|
||||
when: (ansible_virtualization_type is defined and ansible_virtualization_type == 'openvz') and
|
||||
(ansible_virtualization_role is defined and ansible_virtualization_role == 'guest')
|
||||
|
||||
- name: Fix permissions manually if installed
|
||||
ansible.builtin.command: /usr/local/lib/smstools/fix-device-permissions # noqa no-handler
|
||||
register: smstools__register_fix_perms
|
||||
changed_when: smstools__register_fix_perms.changed | bool
|
||||
when: smstools_register_fixpermissions is defined and smstools_register_fixpermissions is changed
|
||||
|
||||
- name: Configure SMS gateway test on reboot
|
||||
ansible.builtin.cron:
|
||||
name: 'SMS gateway test on reboot'
|
||||
user: '{{ smstools_service_user }}'
|
||||
job: '/usr/local/lib/smstools/test-sms-on-reboot'
|
||||
special_time: 'reboot'
|
||||
state: 'present'
|
||||
when: (smstools_test_recipients is defined and smstools_test_recipients)
|
||||
|
||||
- name: Check if rsyslog is installed
|
||||
ansible.builtin.stat:
|
||||
path: '/etc/rsyslog.d'
|
||||
register: smstools_register_rsyslog
|
||||
|
||||
- name: Configure syslog
|
||||
ansible.builtin.template:
|
||||
src: 'etc/rsyslog.d/smstools.conf.j2'
|
||||
dest: '/etc/rsyslog.d/smstools.conf'
|
||||
owner: 'root'
|
||||
group: 'root'
|
||||
mode: '0644'
|
||||
notify: [ 'Restart rsyslogd' ]
|
||||
when: (smstools_register_rsyslog is defined and smstools_register_rsyslog) and
|
||||
smstools_register_rsyslog.stat.exists
|
||||
|
||||
- name: Configure logrotate
|
||||
ansible.builtin.template:
|
||||
src: 'etc/logrotate.d/sms.j2'
|
||||
dest: '/etc/logrotate.d/sms'
|
||||
owner: 'root'
|
||||
group: 'root'
|
||||
mode: '0644'
|
||||
when: (smstools_register_rsyslog is defined and smstools_register_rsyslog) and
|
||||
smstools_register_rsyslog.stat.exists
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
{# Copyright (C) 2014-2019 Maciej Delmanowski <drybjed@gmail.com>
|
||||
# Copyright (C) 2015-2019 DebOps <https://debops.org/>
|
||||
# SPDX-License-Identifier: GPL-3.0-only
|
||||
#}
|
||||
# This file is managed by Ansible, all changes will be lost
|
||||
|
||||
{{ smstools_sms_log }} {
|
||||
rotate {{ smstools_sms_log_rotation_interval | default('52') }}
|
||||
{{ smstools_sms_log_rotation | default('weekly') }}
|
||||
missingok
|
||||
notifempty
|
||||
compress
|
||||
delaycompress
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
{# Copyright (C) 2014-2019 Maciej Delmanowski <drybjed@gmail.com>
|
||||
# Copyright (C) 2015-2019 DebOps <https://debops.org/>
|
||||
# SPDX-License-Identifier: GPL-3.0-only
|
||||
#}
|
||||
# This file is managed by Ansible, all changes will be lost
|
||||
|
||||
# Send copy of SMS gateway logs to a separate log file for accounting
|
||||
if $programname == 'sms-transport' then {{ smstools_sms_log }}
|
||||
if $programname == 'sms-service' then {{ smstools_sms_log }}
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
{# Copyright (C) 2014-2019 Maciej Delmanowski <drybjed@gmail.com>
|
||||
# Copyright (C) 2015-2019 DebOps <https://debops.org/>
|
||||
# SPDX-License-Identifier: GPL-3.0-only
|
||||
#}
|
||||
# This file is managed by Ansible, all changes will be lost
|
||||
|
||||
# List of regexps of strings to remove from SMS messages
|
||||
{% if smstools_mail_msgdel_list is defined and smstools_mail_msgdel_list %}
|
||||
{% for regexp in smstools_mail_msgdel_list %}
|
||||
{{ regexp }}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
{# Copyright (C) 2014-2019 Maciej Delmanowski <drybjed@gmail.com>
|
||||
# Copyright (C) 2015-2019 DebOps <https://debops.org/>
|
||||
# SPDX-License-Identifier: GPL-3.0-only
|
||||
#}
|
||||
# This file is managed by Ansible, all changes will be lost
|
||||
|
||||
# List of e-mail accounts or domains allowed to send SMS messages
|
||||
{% if smstools_default_senders is defined and smstools_default_senders %}
|
||||
{% for sender in smstools_default_senders %}
|
||||
{% if sender.state is undefined or (sender.state is defined and sender.state == 'permit') %}
|
||||
{{ "%-40s permit" | format(sender.name + ":") }}
|
||||
{% else %}
|
||||
{{ "%-40s deny" | format(sender.name + ":") }}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% if smstools_senders is defined and smstools_senders %}
|
||||
{% for sender in smstools_senders %}
|
||||
{% if sender.state is undefined or (sender.state is defined and sender.state == 'permit') %}
|
||||
{{ "%-40s permit" | format(sender.name + ":") }}
|
||||
{% else %}
|
||||
{{ "%-40s deny" | format(sender.name + ":") }}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
{# Copyright (C) 2014-2019 Maciej Delmanowski <drybjed@gmail.com>
|
||||
# Copyright (C) 2015-2019 DebOps <https://debops.org/>
|
||||
# SPDX-License-Identifier: GPL-3.0-only
|
||||
#}
|
||||
# This file is managed by Ansible, all changes will be lost
|
||||
|
||||
# Configuration for sms-transport mail service
|
||||
|
||||
# Path to sendsms script to be used to send SMS messages
|
||||
sendsms = {{ smstools_mail_transport_sendsms }}
|
||||
|
||||
# Path to file with list of allowed or denied sender addresses/domains
|
||||
senders = {{ smstools_mail_transport_senders }}
|
||||
|
||||
# Max length of an SMS message to send
|
||||
maxchars = {{ smstools_mail_transport_maxchars }}
|
||||
|
||||
# Regexp list of strings to remove from SMS messages
|
||||
msgdel = {{ smstools_mail_transport_msgdel }}
|
||||
|
||||
# Debug option, change to 1 to make scripts more verbose
|
||||
debug = 0
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
{# Copyright (C) 2014-2019 Maciej Delmanowski <drybjed@gmail.com>
|
||||
# Copyright (C) 2015-2019 DebOps <https://debops.org/>
|
||||
# SPDX-License-Identifier: GPL-3.0-only
|
||||
#}
|
||||
# This file is managed by Ansible, all changes will be lost
|
||||
|
||||
# /etc/smsd.conf
|
||||
#
|
||||
# Description: Main configuration file for smsd
|
||||
|
||||
devices = {% for modem in smstools_devices %}{{ modem.name }}{% if not loop.last %}, {% endif %}{% endfor %}
|
||||
|
||||
# Global options
|
||||
{% for key, value in smstools_global_options.items() %}
|
||||
{{ key }} = {{ value }}
|
||||
{% endfor %}
|
||||
|
||||
outgoing = /var/spool/sms/outgoing
|
||||
checked = /var/spool/sms/checked
|
||||
incoming = /var/spool/sms/incoming
|
||||
logfile = /var/log/smstools/smsd.log
|
||||
infofile = /var/run/smstools/smsd.working
|
||||
pidfile = /var/run/smstools/smsd.pid
|
||||
outgoing = /var/spool/sms/outgoing
|
||||
checked = /var/spool/sms/checked
|
||||
failed = /var/spool/sms/failed
|
||||
incoming = /var/spool/sms/incoming
|
||||
sent = /var/spool/sms/sent
|
||||
|
||||
stats = /var/log/smstools/smsd_stats
|
||||
stats_interval = {{ smstools_stats_interval }}
|
||||
stats_no_zeroes = yes
|
||||
|
||||
{% for modem in smstools_devices %}
|
||||
[{{ modem.name }}]
|
||||
device = {{ modem.device }}
|
||||
{% for key, value in modem.options.items() %}
|
||||
{{ key }} = {{ value }}
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
{# Copyright (C) 2014-2019 Maciej Delmanowski <drybjed@gmail.com>
|
||||
# Copyright (C) 2015-2019 DebOps <https://debops.org/>
|
||||
# SPDX-License-Identifier: GPL-3.0-only
|
||||
#}
|
||||
# This file is managed by Ansible, all changes will be lost
|
||||
|
||||
%{{ smstools_service_group }} ALL = (smsd) NOPASSWD: /usr/local/bin/sendsms
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
{# Copyright (C) 2014-2019 Maciej Delmanowski <drybjed@gmail.com>
|
||||
# Copyright (C) 2015-2019 DebOps <https://debops.org/>
|
||||
# SPDX-License-Identifier: GPL-3.0-only
|
||||
#}
|
||||
# This file is managed by Ansible, all changes will be lost
|
||||
|
||||
# SMS service configuration for xinetd
|
||||
# only_from is not required, xinetd in Debian is secured using tcpwrappers
|
||||
# (/etc/hosts.allow, /etc/hosts.deny)
|
||||
|
||||
service {{ smstools_service_name }}
|
||||
{
|
||||
disable = no
|
||||
server = /usr/local/lib/smstools/sms-service
|
||||
port = {{ smstools_service_port }}
|
||||
socket_type = stream
|
||||
protocol = tcp
|
||||
libwrap = {{ smstools_service_name }}
|
||||
user = {{ smstools_service_user }}
|
||||
group = {{ smstools_service_group }}
|
||||
wait = no
|
||||
instances = 10
|
||||
nice = -18
|
||||
}
|
||||
|
|
@ -0,0 +1,125 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# Copyright (C) 2014-2019 Maciej Delmanowski <drybjed@gmail.com>
|
||||
# Copyright (C) 2015-2019 DebOps <https://debops.org/>
|
||||
# SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
# This file is managed by Ansible, all changes will be lost
|
||||
|
||||
# This script sends a text message at the command line by creating
|
||||
# a sms file in the outgoing queue.
|
||||
|
||||
# $1 is the destination phone number.
|
||||
# $2 is the message text.
|
||||
# If you leave $2 or both empty, the script will ask you.
|
||||
# If you give more than 2 arguments, last is taken as a text and
|
||||
# all other are taken as destination numbers.
|
||||
# If a destination is asked, you can type multiple numbers
|
||||
# delimited with spaces.
|
||||
|
||||
# Keys for example: "password" and "keke":
|
||||
#KEYS="5f4dcc3b5aa765d61d8327deb882cf99 4a5ea11b030ec1cfbc8b9947fdf2c872 "
|
||||
|
||||
KEYS=""
|
||||
|
||||
# When creating keys, remember to use -n for echo:
|
||||
# echo -n "key" | md5sum
|
||||
|
||||
smsd_user="smsd"
|
||||
|
||||
# Will need echo which accepts -n argument:
|
||||
ECHO="echo"
|
||||
case $(uname) in
|
||||
SunOS)
|
||||
ECHO="/usr/ucb/echo"
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ -n "$KEYS" ]; then
|
||||
printf "Key: "
|
||||
read -r KEY
|
||||
if [ -z "$KEY" ]; then
|
||||
echo "Key required, stopping."
|
||||
exit 1
|
||||
fi
|
||||
KEY="$($ECHO -n "$KEY" | md5sum | awk '{print $1;}')"
|
||||
if ! echo "$KEYS" | grep "$KEY" >/dev/null; then
|
||||
echo "Incorrect key, stopping."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
DEST=$1
|
||||
TEXT=$2
|
||||
|
||||
if [ -z "$DEST" ]; then
|
||||
printf "Destination(s): "
|
||||
read -r DEST
|
||||
if [ -z "$DEST" ]; then
|
||||
echo "No destination, stopping."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -z "$TEXT" ]; then
|
||||
printf "Text: "
|
||||
read -r TEXT
|
||||
if [ -z "$TEXT" ]; then
|
||||
echo "No text, stopping."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ $# -gt 2 ]; then
|
||||
n=$#
|
||||
while [ "$n" -gt 1 ]; do
|
||||
destinations="$destinations $1"
|
||||
shift
|
||||
n=$(( n - 1 ))
|
||||
done
|
||||
TEXT=$1
|
||||
else
|
||||
destinations=$DEST
|
||||
fi
|
||||
|
||||
echo "-- "
|
||||
echo "Text: $TEXT"
|
||||
|
||||
ALPHABET=""
|
||||
if type iconv > /dev/null 2>&1; then
|
||||
if ! $ECHO -n "$TEXT" | iconv -t ISO-8859-15 >/dev/null 2>&1; then
|
||||
ALPHABET="Alphabet: UCS"
|
||||
fi
|
||||
fi
|
||||
|
||||
owner=""
|
||||
if [ -f /etc/passwd ]; then
|
||||
if grep $smsd_user: /etc/passwd >/dev/null; then
|
||||
owner=$smsd_user
|
||||
fi
|
||||
fi
|
||||
|
||||
for destination in $destinations
|
||||
do
|
||||
echo "To: $destination"
|
||||
|
||||
TMPFILE="$(mktemp /tmp/smsd_XXXXXXXXXXXX)"
|
||||
|
||||
$ECHO "To: $destination" >> "$TMPFILE"
|
||||
[ -n "$ALPHABET" ] && $ECHO "$ALPHABET" >> "$TMPFILE"
|
||||
$ECHO "" >> "$TMPFILE"
|
||||
if [ -z "$ALPHABET" ]; then
|
||||
$ECHO -n "$TEXT" >> "$TMPFILE"
|
||||
else
|
||||
$ECHO -n "$TEXT" | iconv -t UNICODEBIG >> "$TMPFILE"
|
||||
fi
|
||||
|
||||
if [ -n "$owner" ]; then
|
||||
chown $owner "$TMPFILE"
|
||||
fi
|
||||
|
||||
FILE="$(mktemp /var/spool/sms/outgoing/send_XXXXXXXXXXXX)"
|
||||
mv "$TMPFILE" "$FILE"
|
||||
done
|
||||
|
||||
# vim:ft=sh
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# Copyright (C) 2014-2019 Maciej Delmanowski <drybjed@gmail.com>
|
||||
# Copyright (C) 2015-2019 DebOps <https://debops.org/>
|
||||
# SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
# This file is managed by Ansible, all changes will be lost
|
||||
|
||||
# Fix device permissions (needed in OpenVZ containers)
|
||||
|
||||
owner='root'
|
||||
group='dialout'
|
||||
mode='ug=rw'
|
||||
|
||||
read -r -a modem_devices <<< "{{ smstools_devices | selectattr('device', 'defined') | map(attribute='device') | list | join(' ') }}"
|
||||
|
||||
for modem in "${modem_devices[@]}" ; do
|
||||
if [ -e "${modem}" ]; then
|
||||
chown ${owner}:${group} "${modem}"
|
||||
chmod ${mode} "${modem}"
|
||||
fi
|
||||
done
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
{# Copyright (C) 2014-2019 Maciej Delmanowski <drybjed@gmail.com>
|
||||
# Copyright (C) 2015-2019 DebOps <https://debops.org/>
|
||||
# SPDX-License-Identifier: GPL-3.0-only
|
||||
#}
|
||||
# This file is managed by Ansible, all changes will be lost
|
||||
|
||||
# Postfix rewrite map used to rewrite short recipient addresses to long
|
||||
# recipient addresses for SMS messages
|
||||
{{ "%-40s %s" | format('@' + smstools_mail_alias_subdomain, '@' + smstools_mail_alias_domain) }}
|
||||
{{ "%-40s %s" | format('@' + smstools_mail_transport_subdomain, '@' + smstools_mail_transport_domain) }}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
{# Copyright (C) 2014-2019 Maciej Delmanowski <drybjed@gmail.com>
|
||||
# Copyright (C) 2015-2019 DebOps <https://debops.org/>
|
||||
# SPDX-License-Identifier: GPL-3.0-only
|
||||
#}
|
||||
# This file is managed by Ansible, all changes will be lost
|
||||
|
||||
# Postfix relay_recipient_maps table, should accept only correctly formatted
|
||||
# mobile numbers
|
||||
{% for regexp in [ '^[0-9]{9}', '^[0-9]{11}', '^\+[0-9]{11}' ] %}
|
||||
{{ "%-40s OK" | format('/' + regexp + '@' + smstools_mail_transport_domain + '/') }}
|
||||
{% endfor %}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
{# Copyright (C) 2014-2019 Maciej Delmanowski <drybjed@gmail.com>
|
||||
# Copyright (C) 2015-2019 DebOps <https://debops.org/>
|
||||
# SPDX-License-Identifier: GPL-3.0-only
|
||||
#}
|
||||
# This file is managed by Ansible, all changes will be lost
|
||||
|
||||
# Postfix transport_maps configuration to relay mail messages to SMS gateway
|
||||
{{ "%-40s %s" | format(smstools_mail_transport_domain, smstools_service_name + ":") }}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
{# Copyright (C) 2014-2019 Maciej Delmanowski <drybjed@gmail.com>
|
||||
# Copyright (C) 2015-2019 DebOps <https://debops.org/>
|
||||
# SPDX-License-Identifier: GPL-3.0-only
|
||||
#}
|
||||
# This file is managed by Ansible, all changes will be lost
|
||||
|
||||
# Mapping of aliases in {{ smstools_mail_alias_domain }} domain to mobile
|
||||
# numbers in {{ smstools_mail_transport_domain }} domain, for Postfix
|
||||
# virtual_alias_maps.
|
||||
|
||||
{% if smstools_mail_recipients is defined and smstools_mail_recipients %}
|
||||
{% for alias, recipients in smstools_mail_recipients.items() %}
|
||||
{% if recipients is defined and recipients %}
|
||||
{{ "%-40s" | format(alias + '@' + smstools_mail_alias_domain) }} {% for number in recipients %}{{ number + '@' + smstools_mail_transport_domain }}{% if not loop.last %}, {% endif %}{% endfor %}
|
||||
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
|
||||
{% endif %}
|
||||
{% if smstools_mail_aliases is defined and smstools_mail_aliases %}
|
||||
{% for alias, recipients in smstools_mail_aliases.items() %}
|
||||
{% if recipients is defined and recipients %}
|
||||
{{ "%-40s" | format(alias + '@' + smstools_mail_alias_domain) }} {% for alias in recipients %}{{ alias + '@' + smstools_mail_alias_domain }}{% if not loop.last %}, {% endif %}{% endfor %}
|
||||
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
|
||||
{% endif %}
|
||||
|
|
@ -0,0 +1,65 @@
|
|||
#!/usr/bin/env perl
|
||||
|
||||
# Copyright (C) 2014-2019 Maciej Delmanowski <drybjed@gmail.com>
|
||||
# Copyright (C) 2015-2019 DebOps <https://debops.org/>
|
||||
# SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
# This file is managed by Ansible, all changes will be lost
|
||||
|
||||
# Simple service script which listens on a port and passes message to send to
|
||||
# sendsms script. Use with xinetd for best results.
|
||||
|
||||
# This is a very simple wrapper to send SMS messages, uses SMTP status codes
|
||||
# for responses. This should be probably rewritten to post SMS messages
|
||||
# directly to smsd queue, support better sanitization, security features and
|
||||
# error handling.
|
||||
|
||||
# Change current directory to home of 'sms' user.
|
||||
chdir "{{ smstools_service_home }}";
|
||||
|
||||
$myname="sms-service";
|
||||
$facility='mail';
|
||||
my $mypid=$$; # global, even when we fork
|
||||
|
||||
sub syslog {
|
||||
my ($level,$msg)=@_;
|
||||
my $pri=$facility.".".$level;
|
||||
$ENV{'HOME'}="/tmp";
|
||||
$ENV{'PATH'}="";
|
||||
$ENV{'BASH_ENV'}="";
|
||||
# the way we're calling system makes it easy to trust $msg
|
||||
# as long as it's not too big, so we just untaint it
|
||||
if ($msg =~ /(.*)/s) {
|
||||
$msg=$1;
|
||||
} else {
|
||||
die "Problem with untainting log message\n";
|
||||
}
|
||||
$msg =~ s/\n/ /g;
|
||||
$msg = substr($msg,0,255)
|
||||
if length($msg) > 255;
|
||||
system("/usr/bin/logger","-p",$pri,"-t",$myname."[".$mypid."]","--",$msg);
|
||||
}
|
||||
|
||||
# New connection, waiting for input
|
||||
$input = <STDIN>;
|
||||
|
||||
if ($input =~ /(QUIT|BYE)/i) {
|
||||
print "221 Bye\n";
|
||||
} elsif ($input =~ /TEXT\s+([0-9]{9})\s+(.+)/i) {
|
||||
system("/usr/bin/sudo -u smsd /usr/local/bin/sendsms {{ smstools_default_country_prefix }}$1 '$2' > /dev/null");
|
||||
syslog('info',"from=<unknown>, prefix=<{{ smstools_default_country_prefix }}>, to=<$1>, size=".length($2).", msg=[$2]\n");
|
||||
print "OK\n";
|
||||
} elsif ($input =~ /TEXT\s+([0-9]{11})\s+(.+)/i) {
|
||||
system("/usr/bin/sudo -u smsd /usr/local/bin/sendsms +$1 '$2' > /dev/null");
|
||||
syslog('info',"from=<unknown>, prefix=<+>, to=<$1>, size=".length($2).", msg=[$2]\n");
|
||||
print "OK\n";
|
||||
} elsif ($input =~ /TEXT\s+(\+[0-9]{11})\s+(.+)/i) {
|
||||
system("/usr/bin/sudo -u smsd /usr/local/bin/sendsms $1 '$2' > /dev/null");
|
||||
syslog('info',"from=<unknown>, to=<$1>, size=".length($2).", msg=[$2]\n");
|
||||
print "OK\n";
|
||||
} else {
|
||||
print "500 Command not recognized\n";
|
||||
exit;
|
||||
}
|
||||
|
||||
# vim:ft=perl
|
||||
|
|
@ -0,0 +1,313 @@
|
|||
#!/usr/bin/perl -Tw
|
||||
|
||||
# Copyright (C) 2014-2019 Maciej Delmanowski <drybjed@gmail.com>
|
||||
# Copyright (C) 2015-2019 DebOps <https://debops.org/>
|
||||
# SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
# This file is managed by Ansible, all changes will be lost
|
||||
|
||||
# sms transport for postfix
|
||||
# uses smstools for delivery
|
||||
#
|
||||
#-------------------------------------------------------------------
|
||||
# Jeremy Laidman, AnswerZ
|
||||
# Version 1.0 - March 2003
|
||||
# Maciej Delmanowski <drybjed@gmail.com>, DebOps project
|
||||
# Version 2.0 - July 2014
|
||||
#
|
||||
# Installation into postfix:
|
||||
#
|
||||
# 1) Copy this script into /usr/local/lib/smstools/sms-transport
|
||||
#
|
||||
# 2) Create the user "sms" with their own group "sms", eg:
|
||||
# useradd -r sms -c "SMS Delivery User for Postfix"
|
||||
#
|
||||
# 3) Add these lines
|
||||
# /etc/postfix/transport:
|
||||
# sms.example.com sms:
|
||||
#
|
||||
# /etc/postfix/master.cf
|
||||
# sms unix - n n - 1 pipe
|
||||
# flags=hqu user=sms argv=/usr/local/lib/smstools/sms-transport ${sender} ${mailbox}
|
||||
#
|
||||
# 4) Add "sms.example.com" to relay_domains parameter in main.cf
|
||||
#
|
||||
# 5) Run "postfix reload".
|
||||
#
|
||||
# 6) Send mail to number@sms.example.com
|
||||
#
|
||||
# 7) Create alias entries mapping usernames to numbers
|
||||
# /etc/postfix/aliases
|
||||
# freddy: 0412555555@sms.example.com
|
||||
#
|
||||
# 8) Run "newaliases".
|
||||
#
|
||||
# 9) Send mail to freddy.
|
||||
#
|
||||
#-------------------------------------------------------------------
|
||||
# Configuration Options Here (will be in config file one day)
|
||||
|
||||
# if non-empty, will reject messages not from matching addresses
|
||||
# a leading dot means any subdomain
|
||||
# if empty, allows from anyone
|
||||
# if non-mepty there's an implicit '' => 'deny'
|
||||
|
||||
use Config::Tiny;
|
||||
|
||||
$config_file = "/etc/sms-transport.conf";
|
||||
|
||||
my $config = Config::Tiny->read($config_file);
|
||||
|
||||
$senders_file = $config->{_}->{senders};
|
||||
$msgdel_file = $config->{_}->{msgdel};
|
||||
$sendsms_path = $config->{_}->{sendsms};
|
||||
$maxsmschars = $config->{_}->{maxchars};
|
||||
$debug = $config->{_}->{debug};
|
||||
|
||||
my %sender_addresses;
|
||||
my @msgdel;
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
# We receive the sender address as @ARGV[0], the number as @ARGV[1]
|
||||
# and the message body on STDIN. We should only receive one message
|
||||
# per user.
|
||||
#
|
||||
# All headers are stripped and only the body is sent.
|
||||
#
|
||||
# Any recipients in the wrong format are bounced with EX_NOUSER=67.
|
||||
# Errors in calling sendsms are assumed to be temporary and are answered
|
||||
# with EX_TEMPFAIL=75. Messages with senders (from-space) that don't
|
||||
# end in anything in the local domains list are bounced with EX_NOPERM=77.
|
||||
#
|
||||
#-------------------------------------------------------------------
|
||||
#
|
||||
# Constants for returning status back to postfix.
|
||||
# (see sysexits.h for the full list)
|
||||
$EX_NOUSER = 67;
|
||||
$EX_TEMPFAIL = 75;
|
||||
$EX_NOPERM = 77;
|
||||
$EX_NOINPUT = 66;
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
my $sender;
|
||||
my $recipient;
|
||||
my $message;
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
$myname="sms-transport";
|
||||
$facility='mail';
|
||||
my $mypid=$$; # global, even when we fork
|
||||
|
||||
sub syslog {
|
||||
my ($level,$msg)=@_;
|
||||
my $pri=$facility.".".$level;
|
||||
$ENV{'HOME'}="/tmp";
|
||||
$ENV{'PATH'}="";
|
||||
$ENV{'BASH_ENV'}="";
|
||||
# the way we're calling system makes it easy to trust $msg
|
||||
# as long as it's not too big, so we just untaint it
|
||||
if ($msg =~ /(.*)/s) {
|
||||
$msg=$1;
|
||||
} else {
|
||||
die "Problem with untainting log message\n";
|
||||
}
|
||||
$msg =~ s/\n/ /g;
|
||||
$msg = substr($msg,0,255)
|
||||
if length($msg) > 255;
|
||||
system("/usr/bin/logger","-p",$pri,"-t",$myname."[".$mypid."]","--",$msg);
|
||||
}
|
||||
|
||||
sub bailout {
|
||||
my ($rc,$msg)=@_;
|
||||
print STDERR "$msg","\n";
|
||||
syslog('error',$msg);
|
||||
exit $rc;
|
||||
}
|
||||
|
||||
sub check_perms {
|
||||
my $sender=lc(shift);
|
||||
my $test;
|
||||
return 1 unless scalar(%sender_addresses);
|
||||
|
||||
# strip enclosing brackets except for <>
|
||||
if ($sender =~ /<[^>]+>/) {
|
||||
$sender=$1;
|
||||
}
|
||||
|
||||
foreach $test (keys %sender_addresses) {
|
||||
$test=lc($test);
|
||||
if ($test =~ /\@/) {
|
||||
# an email address
|
||||
return 1
|
||||
if $test eq $sender;
|
||||
} else {
|
||||
# a domain
|
||||
$sender =~ s/^.*@//;
|
||||
if ($test =~ /^\./) {
|
||||
# allow subdomains
|
||||
return 1
|
||||
if $test eq $sender;
|
||||
return 1
|
||||
if $test eq substr($sender,-length($test));
|
||||
} else {
|
||||
# exact match only
|
||||
return 1
|
||||
if $test eq $sender;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0; # failed
|
||||
}
|
||||
|
||||
sub process_email {
|
||||
my $in_headers=1;
|
||||
my $msg="";
|
||||
my $subject="";
|
||||
my $sender;
|
||||
my $linenum=0;
|
||||
|
||||
while(<STDIN>) {
|
||||
chomp;
|
||||
if ($in_headers) {
|
||||
# headers
|
||||
if (length($_) == 0) {
|
||||
$in_headers=0;
|
||||
next;
|
||||
}
|
||||
if ($_ =~ /^Subject:\s*/) {
|
||||
$subject=$_;
|
||||
}
|
||||
} else {
|
||||
# body
|
||||
$msg .= "\r\n" if $msg =~ /\S/;
|
||||
$msg .= $_;
|
||||
}
|
||||
last if $linenum++ > 500;
|
||||
}
|
||||
|
||||
# no body? return subject
|
||||
$msg = $subject if (!length($msg));
|
||||
|
||||
return $msg;
|
||||
}
|
||||
|
||||
sub send_message {
|
||||
my $recipient_local=shift;
|
||||
my $message_local=shift;
|
||||
|
||||
if ($recipient_local =~ /^([0-9]{9}|[0-9]{11}|\+[0-9]{11})$/) {
|
||||
$recipient_num=$1; # now is untainted
|
||||
}
|
||||
if ($message_local =~ /^(.+)$/) {
|
||||
$message=$1; # now is untained
|
||||
}
|
||||
|
||||
if (length($message) > $maxsmschars) {
|
||||
syslog('info',"Truncated message from ".length($message)." to ".$maxsmschars."-3 chars\n");
|
||||
$message=substr($message,0,$maxsmschars-3)."...";
|
||||
}
|
||||
|
||||
(-x $sendsms_path)
|
||||
|| bailout($EX_TEMPFAIL,"Unable to exec $sendsms_path: $!");
|
||||
$ENV{'HOME'}="/tmp";
|
||||
$ENV{'PATH'}="/bin:/usr/bin";
|
||||
exec($sendsms_path,"$recipient_num","$message")
|
||||
|| bailout($EX_TEMPFAIL,"Unable to exec $sendsms_path: $!");
|
||||
# will never get here
|
||||
}
|
||||
|
||||
sub clean_message {
|
||||
my $msg=shift;
|
||||
$msg =~ s/(\r\n)+$//; # remove trailing crlf
|
||||
# delete message bits that we don't want
|
||||
my $regex;
|
||||
my $changed=0;
|
||||
foreach $regex (@msgdel) {
|
||||
syslog('debug',"Testing if msg [$msg] matches /$regex/")
|
||||
if $debug;
|
||||
if ($msg =~ s/$regex//) {
|
||||
$changed++;
|
||||
}
|
||||
}
|
||||
if ($changed) {
|
||||
syslog('debug',"Message deletions - new message: [$msg]\n")
|
||||
if $debug;
|
||||
}
|
||||
return $msg;
|
||||
}
|
||||
|
||||
# -------------------------------------------------------------------
|
||||
|
||||
$0 .= "";
|
||||
|
||||
$sender_given=$ARGV[0];
|
||||
$recipient_given=$ARGV[1];
|
||||
if (defined($sender_given) and $sender_given =~ /([-A-Za-z0-9_+]+\@[-A-Za-z0-9.]+)/) {
|
||||
$sender=$1; # now is untainted
|
||||
} else {
|
||||
bailout($EX_NOUSER,"Sender address not given")
|
||||
if !defined($sender_given);
|
||||
bailout($EX_NOUSER,"Invalid sender address: $sender_given");
|
||||
}
|
||||
if (defined($recipient_given) and $recipient_given =~ /^([0-9]{9})$/) {
|
||||
$recipient="{{ smstools_default_country_prefix }}$1"; # now is untainted
|
||||
} elsif (defined($recipient_given) and $recipient_given =~ /^([0-9]{11})$/) {
|
||||
$recipient="+$1"; # now is untainted
|
||||
} elsif (defined($recipient_given) and $recipient_given =~ /^(\+[0-9]{11})$/) {
|
||||
$recipient="$1"; # now is untainted
|
||||
} else {
|
||||
bailout($EX_NOUSER,"Mobile number not given")
|
||||
if !defined($recipient_given);
|
||||
bailout($EX_NOUSER,"Not a mobile number: <$recipient_given>");
|
||||
exit $EX_NOUSER;
|
||||
}
|
||||
|
||||
open(FILE,"<$senders_file") or die "Unable to get list of senders from $senders_file: $!\n";
|
||||
while(<FILE>) {
|
||||
chomp;
|
||||
next if /^\s*#/;
|
||||
next if /^\s*$/;
|
||||
# lines are colon-delimited, like aliases
|
||||
my ($addr,$perm);
|
||||
($addr,$perm)=split(/\s*:\s*/);
|
||||
next unless defined($addr) and length($addr);
|
||||
next unless defined($perm) and length($perm);
|
||||
$perm=lc($perm);
|
||||
if ($perm =~ /(permit|deny)/) {
|
||||
$sender_addresses{$addr}=$1;
|
||||
}
|
||||
}
|
||||
close(FILE);
|
||||
|
||||
if (open(FILE,"<$msgdel_file")) {
|
||||
while(<FILE>) {
|
||||
chomp;
|
||||
next if /^\s*#/;
|
||||
next if /^\s*$/;
|
||||
# each line is a regex
|
||||
push @msgdel,$_;
|
||||
}
|
||||
close(FILE);
|
||||
syslog('debug',"Message deletions read in: ".join(',',@msgdel)."\n")
|
||||
if $debug;
|
||||
}
|
||||
|
||||
$message=process_email;
|
||||
$message=clean_message($message);
|
||||
length($message) ||
|
||||
bailout($EX_NOINPUT,"No message body - nothing to send");
|
||||
|
||||
syslog('info',"from=<$sender>, to=<$recipient>, size=".length($message).", msg=[$message]\n");
|
||||
|
||||
if (!check_perms($sender)) {
|
||||
bailout($EX_NOPERM,"Permission denied for <$sender>");
|
||||
}
|
||||
|
||||
send_message($recipient,$message);
|
||||
syslog('info',"sendsms sent message OK\n");
|
||||
|
||||
# ALl OK if it got this far.
|
||||
|
||||
# vim:ft=perl
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue