1
0
Fork 0
mirror of https://github.com/Ysurac/openmptcprouter-feeds.git synced 2025-03-09 15:40:03 +00:00

Add option to send mail when connection status change

This commit is contained in:
Ycarus 2018-11-05 19:14:23 +01:00
parent 80cb838778
commit 2679958caa
9 changed files with 155 additions and 0 deletions

15
luci-app-mail/Makefile Normal file
View file

@ -0,0 +1,15 @@
#
# Copyright (C) 2018 Ycarus (Yannick Chabanois) <ycarus@zugaina.org>
#
#
include $(TOPDIR)/rules.mk
LUCI_TITLE:=LuCI Mail Configuration
LUCI_DEPENDS:=+msmtp-mta +ca-certificates
PKG_LICENSE:=GPLv3
include ../luci/luci.mk
# call BuildPackage - OpenWrt buildroot signature

View file

@ -0,0 +1,8 @@
local ucic = luci.model.uci.cursor()
local dt = require "luci.cbi.datatypes"
module("luci.controller.mail", package.seeall)
function index()
entry({"admin", "services", "mail"}, alias("admin", "services", "mail", "index"), _("Mail"))
entry({"admin", "services", "mail", "index"}, cbi("mail"))
end

View file

@ -0,0 +1,44 @@
-- Copyright 2018 Ycarus (Yannick Chabanois) <ycarus@zugaina.org>
-- Licensed to the public under the Apache License 2.0.
m = Map("mail", translate("Send mail"), translate("Send mail settings"))
s = m:section(TypedSection, "smtp", translate("SMTP"))
s.anonymous = true
s.addremove = false
server = s:option(Value, "server", translate("Server"))
server.datatype = "host"
server.placeholder = "smtp.gmail.com"
server.optional = false
port = s:option(Value, "port", translate("Port"))
port.datatype = "port"
port.optional = false
port.rmempty = true
port.default = "25"
tls = s:option(Flag, "tls", translate("TLS"))
tls.rmempty = false
tls_starttls = s:option(Flag, "tls_starttls", translate("STARTTLS"))
tls_starttls.rmempty = false
user = s:option(Value, "user", translate("User"))
user.rmempty = true
password = s:option(Value, "password", translate("Password"))
password.password = true
password.rmempty = true
from = s:option(Value, "from", translate("From"))
from.optional = false
from.rmempty = true
from.placeholder = "myself@gmail.com"
to = s:option(Value, "to", translate("To"))
to.optional = false
to.rmempty = true
to.placeholder = "myself@gmail.com"
return m

View file

@ -0,0 +1 @@
config smtp 'default'

View file

@ -0,0 +1,60 @@
#!/bin/sh /etc/rc.common
# Copyright (C) 2018 Ycarus (Yannick Chabanois) <ycarus@zugaina.org>
START=90
STOP=10
USE_PROCD=1
validate_section() {
uci_validate_section mail smtp "${1}" \
'server:host' \
'tls:bool:0' \
'tls_starttls:bool:0' \
'from:string' \
'user:string' \
'password:string' \
'port:port:25'
}
config_account() {
local server tls tls_starttls from user password
validate_section "${1}" || {
_err "validation failed"
return 1
}
cat > /tmp/msmtp.tmp <<-EOF
account default
host $server
port $port
EOF
[ -n "$user" ] && [ -n "$password" ] && {
cat >> /tmp/msmtp.tmp <<-EOF
auth on
user $user
password $password
EOF
}
[ -n "$from" ] && echo "from $from" >> /tmp/msmtp.tmp
[ "$tls" = "1" ] && {
cat >> /tmp/msmtp.tmp <<-EOF
tls_trust_file /etc/ssl/certs/ca-certificates.crt
tls on
EOF
} || {
echo 'tls off' >> /tmp/msmtp.tmp
}
[ "$tls_starttls" = "1" ] && {
echo 'tls_starttls on' >> /tmp/msmtp.tmp
} || {
echo 'tls_starttls off' >> /tmp/msmtp.tmp
}
}
start_service() {
config_load mail
config_foreach config_account smtp
[ -f "/tmp/msmtp.tmp" ] && mv /tmp/msmtp.tmp /etc/msmtprc
}

View file

@ -0,0 +1,8 @@
#!/bin/sh
uci -q batch <<-EOF >/dev/null
delete ucitrack.@mail[-1]
add ucitrack mail
set ucitrack.@mail[-1].init=mail
commit ucitrack
EOF
exit 0