aboutsummaryrefslogtreecommitdiffstats
path: root/index.php
blob: 5bdbbfad088e72bab634fe415f2161227bc9c114 (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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
<?php
//
//    Minimalist Admin is a very simple webinterface for Minimalist
//    Copyright (c) 2005-2014 High5! (Mischa Peters <mischa at high5 dot nl>)
//
//    This program is free software; you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation; either version 2 of the License, or
//    (at your option) any later version.
//
//    This program 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 this program; if not, write to the Free Software
//    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
//
//    Minimalist Admin verion 0.6, Copyright (c) 2005-2014 High5! (Mischa Peters)
//    Minimalist Admin comes with ABSOLUTELY NO WARRANTY.
//    This is free software, and you are welcome to redistribute it
//    under certain conditions.
//
//    High5!, hereby disclaims all copyright interest in the program
//    `Minimalist Admin' (which makes passes at Minimalist) written
//    by Vladimir Litovka.
//
//error_reporting(E_NOTICE | E_ERROR | E_WARNING | E_PARSE);

// Read global config file
include "config.inc";

// Minimalist Admin version
$version = "0.6";

// Set some variables.
$get_list = "";
$email = "";
$emailconfirm = "";
$writeonly = "";
$unsubscribe = "";

// _GET list to process
if (!empty($_GET['l']))
{
  $get_list = $_GET['l'];
  if (!preg_match('/^([a-z0-9-])+$/i', trim($get_list)))
  {
    header("Location: index.php");
    exit;
  }
  // Check if list config exists and include it
  if (file_exists("lists/$get_list-config.inc")) include "lists/$get_list-config.inc";
}

// Set variables from config.inc and lists/$get_list-config.inc
$minimalist_lists = $CONF['minimalist_lists'];
$minimalist_email = $CONF['minimalist_email'];
$minimalist_title = $CONF['minimalist_title'];
$minimalist_list_title = $CONF['minimalist_list_title'];
$list_name = $CONF['list_name'];
$list_writers = $CONF['list_writers'];
$list_subscribe = $CONF['list_subscribe'];
$list_unsubscribe = $CONF['list_unsubscribe'];
$error_email_nomatch = $CONF['error_email_nomatch'];
$error_email_notvalid = $CONF['error_email_notvalid'];

// Print the html header
print_header();

// Test if REQUEST_METHOD is a GET request
if ($_SERVER['REQUEST_METHOD'] == "GET")
{
  // If $get_list is not empty print list form
  if (!empty($get_list))
  {
    print_form();
    print_footer();
  }
  // If $get_list is empty process the $minimalist_lists file.
  else
  {
    if (file_exists("$minimalist_lists"))
    {
      $fh = file("$minimalist_lists");
      print "<table border=\"0\" class=\"list\">\n";
      for ($i = 0; $i < sizeof($fh); $i++)
      {
        list($list, $desc) = preg_split("/\t/", $fh[$i], 2);
        if (!empty($list)) print "<tr><td><a href=\"index.php?l=$list\">$list</a></td><td>$desc</td></tr>\n";
      }
      print "</table>\n";
    }
    else
    {
      print "Unable to find minimalists file at: $minimalist_lists\n";
    }
    print_footer();
  }
}

// Test if REQUEST_METHOD is a GET request
if ($_SERVER['REQUEST_METHOD'] == "POST")
{
  if (!empty($_POST['email'])) $email = $_POST['email'];
  if (!empty($_POST['emailconfirm'])) $emailconfirm = $_POST['emailconfirm'];
  if (!empty($_POST['writeonly'])) $writeonly = $_POST['writeonly'];
  if (!empty($_POST['unsubscribe'])) $unsubscribe = $_POST['unsubscribe'];

  if ($email != $emailconfirm)
  {
    print "$error_email_nomatch\n";
    print_form();
    print_footer();
    exit;
  }

  if (!preg_match('/^[-!#$%&\'*+\\.\/0-9=?A-Z^_{|}~]+' . '@' . '([-0-9A-Z]+\.)+' . '([0-9A-Z]){2,4}$/i', trim($email)))
  {
    print "$error_email_notvalid\n";
    print_form();
    print_footer();
    exit;
  }

  if (!empty($writeonly))
  {
    $get_list = $get_list . "-writers";
  }

  if ($unsubscribe)
  {
    mail($minimalist_email, "unsubscribe $get_list $email", "", "From: $email");
    print "$list_unsubscribe\n";
    print_footer();
    exit;
  }
  else
  {
    mail($minimalist_email, "subscribe $get_list $email", "", "From: $email");
    print "$list_subscribe\n";
    print_footer();
    exit;
  }
}

function print_header()
{
  global $get_list;
  global $minimalist_title;
  global $minimalist_list_title;
  global $list_name;
  global $list_writers;

  // Set the title_list_name to $list_name if $get_list is empty.
  $title_list_name = (empty($list_name)) ? $get_list : $list_name;
  // Set the title to $minimalist_title if $get_list is empty.
  $title = (empty($get_list)) ? $minimalist_title : "$minimalist_list_title $title_list_name";

  print "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n";
  print "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n";
  print "<head>\n";
  print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">\n";
  if (file_exists(realpath("lists/$get_list-stylesheet.css")))
  {
    print "<link rel=\"stylesheet\" href=\"lists/$get_list-stylesheet.css\">\n";
  }
  else
  {
    print "<link rel=\"stylesheet\" href=\"stylesheet.css\">\n";
  }
  print "<title>$title</title>\n";
  print "</head>\n";
  print "<body>\n";
  print "<h2>$title</h2>\n";
}

function print_form()
{
  global $list_writers;
  print "<form method=\"post\">\n";
  print "<table border=\"0\">\n";
  print "<tr><td>Email:</td><td><input type=\"textbox\" name=\"email\"></td></tr>\n";
  print "<tr><td>Email (verification):</td><td><input type=\"textbox\" name=\"emailconfirm\"></td></tr>\n";
  if (preg_match("/enable/", $list_writers)) {
    print "<tr><td>Post Only (don't receive):</td><td><input type=\"checkbox\" name=\"writeonly\"></td></tr>\n";
  }
  print "<tr><td>Unsubscribe:</td><td><input type=\"checkbox\" name=\"unsubscribe\"></td></tr>\n";
  print "<tr><td align=\"center\" colspan=\"2\"><input type=\"submit\" name=\"submit\" value=\"Submit\"></tr>\n";
  print "</table>\n";
  print "</form>\n";
  print "<br />\n";
  print "<a href=\"index.php\">Back</a>\n";
}

function print_footer()
{
  global $version;
  print "<div id=\"footer\">\n";
  print "Copyright (c) 2005-2011 by <a target=\"blank\" href=\"http://high5.net/\">High5!</a> -- Minimalist Admin v$version</a>\n";
  print "</div>\n";
  print "</body>\n";
  print "</html>\n";
}
?>