-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathemail.tmp
99 lines (99 loc) · 3.23 KB
/
email.tmp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/bin/bash
# Script Variables
cwd=$(pwd)
EMAILS=$MODULEDIR/emails
MAILER=OFF
ADDRESS=EMAIL_HERE@EMAIL_HOST
# - Prints Hostname Report as Senders Name
NAME=$(echo -e "$HOSTNAME Report")
SENDER='DESIRED_EMAIL@EMAIL_HOST'
TIME=$(TZ='America/Los_Angeles' date)
SIMPLE_TIME=$(TZ='America/Los_Angeles' date '+%Y-%m-%d')
mod_status "Checking for needed software.."
check_depends(){
if ! command_exists ipcalc ; then
mod_noti "Attempting to install ipcalc..";
check_root;
sudo -k apt-get install -y ipcalc &>/dev/null
check_success;
fi
if ! command_exists postfix ; then
mod_noti "Attempting to install postfix..";
check_root;
sudo -k apt-get install -y postfix
check_success;
fi
if ! command_exists mutt ; then
mod_noti "Attempting to install mutt..";
check_root;
sudo -k apt-get install -y mutt
check_success;
fi
if ! command_exists mailutils ; then
mod_noti "Attempting to install mailutils..";
check_root;
sudo -k apt-get install -y mailutils &>/dev/null
check_success;
fi
if ! command_exists nmap ; then
mod_noti "Attempting to install nmap..";
check_root;
sudo -k apt-get install -y nmap &>/dev/null
check_success;
fi
}
check_depends;
do_break
mod_status "Pinging Google to check Internet...";
wget -q --spider http://google.com
if [ $? -eq 0 ]; then
mod_noti "Internet Connection active..";
mod_status "Continuing Script...";
IP=$(curl -s http://whatismyip.akamai.com/)
OUTBOX=$EMAILS/OUTBOX
SENT=$EMAILS/SENT
do_break
if [ ! -d "$EMAILS" ]; then
mkdir $EMAILS
fi
if [ $MAILER = "ON" ]; then
SERVICE=postfix
if (( $(ps -ef | grep -v grep | grep $SERVICE | wc -l) > 0 )); then
do_break
mod_noti "$SERVICE is running, continuing script."
else
/etc/init.d/$SERVICE start
fi
# Need to put email inbox/sent/outgoing stuff here.
if [ ! -d "$OUTBOX" ]; then
mkdir -p "$OUTBOX";
fi
if [ ! -d "$SENT" ]; then
mkdir -p "$SENT";
fi
if [ -f "$MODULEDIR/APT/apt_$SIMPLE_TIME.txt" ]; then
if [ -f "$SENT/apt_$SIMPLE_TIME.txt" ]; then
echo -e "Already sent report for APT today."
else
cp "$MODULEDIR/APT/apt_$SIMPLE_TIME.txt" "$OUTBOX/apt_$SIMPLE_TIME.txt"
CONTENT_ATTACHMENT=$(cat $OUTBOX/apt_$SIMPLE_TIME.txt)
echo -e "$CONTENT_ATTACHMENT" | mutt -s "APT Log for $TIME" $ADDRESS -e "my_hdr"
mv "$OUTBOX/apt_$SIMPLE_TIME.txt" "$SENT/apt_$SIMPLE_TIME.txt"
fi
fi
if [ -f "$MODULEDIR/IP_DATA/IP_DATA_$SIMPLE_TIME.txt" ]; then
if [ -f "$SENT/IP_DATA_$SIMPLE_TIME.txt" ]; then
echo -e "Already sent report for IP_DATA today."
else
cp "$MODULEDIR/IP_DATA/IP_DATA_$SIMPLE_TIME.txt" "$OUTBOX/IP_DATA_$SIMPLE_TIME.txt"
CONTENT_ATTACHMENT=$(cat $OUTBOX/IP_DATA_$SIMPLE_TIME.txt)
echo -e "$CONTENT_ATTACHMENT" | mutt -s "IP Data Log for $TIME" $ADDRESS -e "my_hdr"
mv "$OUTBOX/IP_DATA_$SIMPLE_TIME.txt" "$SENT/IP_DATA_$SIMPLE_TIME.txt"
fi
fi
fi
do_break
do_break
else
mod_error "Offline. Please Check Internet Connection."
fi