File: notifynewuser.sh

package info (click to toggle)
didiwiki 3.0.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,912 kB
  • sloc: ansic: 5,985; sh: 1,532; makefile: 27
file content (128 lines) | stat: -rwxr-xr-x 3,153 bytes parent folder | download
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/bin/bash
# This simple bash script will send the validation code to the new users
# Require ssmtp (relay email to your smtp)
# if newwikiusers.txt exists, then it's renamed.
# Email, name,pwd and code are extracted and sent with ssmtp
# then the result file newusersnotified.txt is updated
# if newusermesage.txt exists, it will be read to prepare the email text.
# JP Redonnet May 2010 - inphilly@gmail.com
# Rev 1.5 - Febuary 22, 2015
# newwikiusers.txt should be in  /usr/local/libexec
file1=~/newwikiusers.txt
# temporary file
file2=~/newwikiusers.temp
# list of users notified
file3=~/newusersnotified.txt
# Email message can be customized
file4=~/newusermessage.txt

# ciwiki port - default port=80
port=80

# default subject and body
subject='Your CiWiki Access Code'
body='Hello\r\n\r\nTo validate your new account;
      Please click on the direct link below,
      or in the Wiki, click on login, choose new account,
      Reenter your username, password, and email,
      Enter your access code.'
thanks='Thank you!'
# default internet address
internetAddr=""
# default body and default thanks flag=0
flag1=0
flag2=0

#wiki address, we need the ip address and the port 
#we will create a direct link to validate a new registration
#get the port addr in the arguments
while getopts p:i arg
do
  case $arg in
    p) port=$OPTARG;;
    i) internet=1;;
  esac
done

#get the internet address, subject, body, thanks
if [ -f "$file4" ]
then
  while read line
    do
      if [[ "$line" =~ "I:" ]]
    then
      internetAddr=${line#*I:}
      internetAddr=${internetAddr%% *}
    fi
    
      if [[ "$line" =~ "S:" ]]
    then
      subject=${line#*S:}
    fi
    
      if [[ "$line" =~ "B:" ]]
    then
        if (($flag1 == 0))
      then
        body=${line#*B:}
        flag1=1
      else
        body=$body'\r\n'${line#*B:}
      fi
    fi
      if [[ "$line" =~ "T:" ]]
    then
        if (($flag2 == 0))
      then
        thanks=${line#*T:}
        flag2=1
      else
        thanks=$thanks'\r\n'${line#*T:}
      fi
    fi
  done < $file4
fi

#internet address available?
if [[ -n $internetAddr ]]
then
  #Create the  Internet wiki address
  wikiAddr=$internetAddr':'$port
else
  #extract the ip address of the server
  #some ifconfig version (old?) return adr: rather addr:
  str=`ip a | grep -Eo 'inet ([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1' | paste -sd' '`
  #Create the  Intranet wiki addresse
  wikiAddr='http://'${str%% *}':'$port
fi

#extract the email, login name, password, access code 
# then send email
if [ -f "$file1" ]
then
  mv -f $file1 $file2
  while read line
  do
    email=${line#*M:}
    email=${email%% *}
    usr=${line#*U:}
    usr=${usr%% *}
    pwd=${line#*P:}
    pwd=${pwd%% *}
    code=${line#*C:}
    directLink=$wikiAddr'/Login?rac='$email,$code,$usr,$pwd

    date >> $file3
    echo "$line" >> $file3

    echo -e "Subject:$subject\r\n\r\n \
    $body\r\n\r\n \
    Your username:$usr\r\n \
    Your password:$pwd\r\n \
    Your access code:$code\r\n \
    Direct link : $directLink\r\n\r\n \
    $thanks\r\n"|sendmail $email >> $file3

  done < $file2
fi
exit 0