summaryrefslogtreecommitdiff
path: root/support/lug/lugs.rb
blob: 06b43700974027d6e02b14ab9fe1a656ea296b3b (plain)
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
#!/usr/bin/env ruby
# encoding: UTF-8
require 'cgi'
require 'erb'
require 'open-uri'
require 'date'
require 'resolv'


# admins to be informed, one per line:
ADMINS = %w{
  wybo@dekkerdocumenten.nl
}

RESPONSE = <<EOF
Content-type: text/html

<%= open(CALLERDIR+"../1blok1e.inc") { |f| f.read } %>
<%= open(CALLERDIR+"../1blok2e.inc") { |f| f.read } %>
<h1>TeX user groups around the world</h1>
<% if errmess.empty? %>
    <h2>Thank you for your support of the LUG database</h2>
    Your corrections will be sent to <%= ADMINS[0] %> for handling.
<% else %>
    <h3>Sorry, you did not correctly enter the required fields:</h3><br>
    <font color="red">
    <%= errmess.join("<br>") %>
    </font><p>
    <form>Please try again by going
        <input type="button" value="Back" onClick="history.go(-1);return true;">
    </form>
<% end %>
<hr noshade>
</td></tr></table></td></tr></table>
<%= open(CALLERDIR+"../1blok4e.inc") { |f| f.read } %> <%= DateTime.now %>
</p></div></body></html>
EOF

MESS = <<EOF
password=<%= q['password'] %>
submitemail=<%= q['submitemail'] %>
addr=<%= q['addr'] %>
bacc=<%= q['bacc'] %>
baddr=<%= q['baddr'] %>
bank=<%= q['bank'] %>
bcode=<%= q['bcode'] %>
brout=<%= q['brout'] %>
code=<%= q['code'] %>
editor=<%= q['editor'] %>
eemail=<%= q['eemail'] %>
email=<%= q['email'] %>
faddr=<%= q['faddr'] %>
femail=<%= q['femail'] %>
ffax=<%= q['ffax'] %>
fname=<%= q['fname'] %>
fphone=<%= q['fphone'] %>
fpos=<%= q['fpos'] %>
full=<%= q['full'] %>
gaddr=<%= q['gaddr'] %>
gemail=<%= q['gemail'] %>
gfax=<%= q['gfax'] %>
gname=<%= q['gname'] %>
gphone=<%= q['gphone'] %>
gpos=<%= q['gpos'] %>
lang=<%= q['lang'] %>
list=<%= q['list'] %>
members=<%= q['members'] %>
paddr=<%= q['paddr'] %>
pemail=<%= q['pemail'] %>
pfax=<%= q['pfax'] %>
pname=<%= q['pname'] %>
pphone=<%= q['pphone'] %>
ppos=<%= q['ppos'] %>
publ=<%= q['publ'] %>
short=<%= q['short'] %>
subscr=<%= q['subscr'] %>
www=<%= q['www'] %>
country=<%= q['country'] %>
EOF

def validate_email_domain(email)
   return false unless email =~ /\@(.*)/
   Resolv::DNS.open do |dns|
      @mx = dns.getresources($1, Resolv::DNS::Resource::IN::MX)
   end
   @mx.size > 0 ? true : false
end

def mail(message,to,code)
   m = open("|/usr/bin/mail -s '===LUG correction for #{code}===' #{to}",'w')
   m.puts message
   m.close
end

q = CGI.new

CALLERDIR=ENV['HTTP_REFERER'].sub(/[^\/]*$/,'')

errmess = []
q['password'] == 'kjwb' ||
   errmess.push("You typed the wrong (or no) password")
validate_email_domain(q['submitemail']) ||
   errmess.push("You must enter a valid email addres")

message = ERB.new(RESPONSE).result
print message

exit unless errmess.empty?
message = ERB.new(MESS).result.gsub(/\r\n/,"\n             ").strip
ADMINS.each { |m| mail(message,m,q['code']) }