showmmlists.php3 6.99 KB
Newer Older
1 2
<?php
#
3
# Copyright (c) 2005, 2006, 2007, 2010 University of Utah and the Flux Group.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
# 
# {{{EMULAB-LICENSE
# 
# This file is part of the Emulab network testbed software.
# 
# This file is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
# 
# This file 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 Affero General Public
# License for more details.
# 
# You should have received a copy of the GNU Affero General Public License
# along with this file.  If not, see <http://www.gnu.org/licenses/>.
# 
# }}}
23 24 25 26 27 28
#
include("defs.php3");

#
# Only known and logged in users allowed.
#
29 30 31 32
$this_user = CheckLoginOrDie();
$uid       = $this_user->uid();
$isadmin   = ISADMIN();
$user_email = $this_user->email();
33

34 35 36 37 38 39 40
#
# Verify page arguments.
#
$optargs = OptionalPageArguments("sortby",      PAGEARG_STRING,
				 "showallmm",   PAGEARG_BOOLEAN,
				 "target_user", PAGEARG_USER);

41 42 43 44 45
#
# Standard Testbed Header
#
PAGEHEADER("Mailman Lists");

46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
if (! isset($sortby)) {
    $sortby = "listname";
}
if ($sortby == "listname") {
    $order = "mm.listname";
}
elseif ($sortby == "uid") {
    $order = "mm.owner_uid";
}
else {
    $order = "mm.listname";
}

#
# Allow admin users to view the lists for a specific uid.
#
62
if (isset($target_user)) {
63 64
    if (!$isadmin &&
	!$target_user->SameUser($this_user)) {
65 66
	USERERROR("You do not have permission to list mailman lists for ".
		  "other users!", 1);
67
    }
68 69
    $target_uid   = $target_user->uid();
    $target_dbuid = $target_user->uid();
70 71
}
else {
72 73 74
    $target_user  = $this_user;
    $target_uid   = $uid;
    $target_dbuid = $uid;
75 76
}

Leigh Stoller's avatar
Leigh Stoller committed
77
SUBPAGESTART();
78
SUBMENUSTART("Mail List Options");
79
WRITESUBMENUBUTTON("Create a Mailman List", "newmmlist.php3");
80 81 82 83

if ($isadmin) {
    WRITESUBMENUBUTTON("Show User Lists", "showmmlists.php3?showallmm=1");
}
84 85 86 87 88
SUBMENUEND();

#
# Ask the mailman server for the users lists. 
#
89
SUEXEC($uid, "nobody", "webmmlistmembership $target_uid", SUEXEC_ACTION_DIE);
90 91 92 93 94 95 96

#
# Parse the suexec output into a table.
#
if (count($suexec_output_array)) {
    echo "<br>
           <center><font size=+1>
97 98
          You are a member of the following Mailman
            lists<sup><font size=+1><b>1</b></font></sup>
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
          </font></center><br>\n";
    
    echo "<table border=2 cellpadding=0 cellspacing=2
           align='center'>\n";

    echo "<tr>
              <th>List Name</th>
              <th>Archives</th>
              <th>Configure</th>
          </tr>\n";
    

    for ($i = 0; $i < count($suexec_output_array); $i++) {
	$listname = $suexec_output_array[$i];

114 115 116 117 118 119 120 121 122 123
	#
	# XXX Since the output array contains stderr as well as stdout,
	# we might get warnings and other chaff.  Do some filtering of
	# lines here.  This is the current DB table_regex regex for a
	# mailman listname.
	#
	if (!preg_match("/^[-\w\.\+]+$/", $listname)) {
	    continue;
	}

124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
	echo "<tr>
                  <td><a href='mailto:$listname@${OURDOMAIN}'>$listname</a>
                       </td>
                  <td align=center>
                       <a href='gotommlist.php3?listname=$listname'>
                         <img src=\"arrow4.ico\"
                         alt='archive' border=0></A></td>
                  <td align=center>
                       <a href='gotommlist.php3?listname=$listname".
	                  "&wantconfig=1'>
                         <img src=\"arrow4.ico\"
                              alt='config' border=0></A></td>
              </tr>\n";
    }
    echo "</table><br>\n";
}

141
#
142
# See if the target is the owner of any lists.
143
#
144
if ($isadmin && isset($showallmm)) {
145 146 147 148 149 150 151 152 153 154
    $query_result =
	DBQueryFatal("select mm.* from mailman_listnames as mm ".
		     "order by $order");
}
else {
    #
    # View lists for a specific user (might be current user)
    # 
    $query_result =
	DBQueryFatal("select mm.* from mailman_listnames as mm ".
155
		     "where mm.owner_uid='$target_dbuid' ".
156 157 158
		     "order by $order");
}

159
if (mysql_num_rows($query_result)) {
160
    echo "<br>
161 162
           <center><font size=+1>";

163
    if (isset($showallmm)) {
164 165 166 167 168 169
	echo "User-Created Mailman lists";
    }
    else {
	echo "You are the administrator for the following Mailman lists";
    }
    echo "</font></center><br>\n";
170 171 172 173
    
    echo "<table border=2 cellpadding=0 cellspacing=2
           align='center'>\n";

174
    $showmmlists_url = CreateUrl("showmmlists", $target_user);
175

176
    echo "<tr>
177 178
              <th><a href='${showmmlists_url}&sortby=listname'>List Name</th>
              <th><a href='${showmmlists_url}&sortby=uid'>Owner</th>
179
              <th>Admin Page</th>
180 181 182 183 184 185 186
              <th>Reset Password</th>
              <th>Delete List</th>
          </tr>\n";

    while ($row = mysql_fetch_array($query_result)) {
	$listname  = $row['listname'];
	$owner_uid = $row['owner_uid'];
187
	$mmurl     = "gotommlist?listname=${listname}";
188 189 190 191 192

	if (! ($owner_user = User::Lookup($owner_uid))) {
	    TBERROR("Could not lookup object for user $owner_uid", 1);
	}
	$showuser_url = CreateURL("showuser", $owner_user);
193 194
	
	echo "<tr>
195 196
                  <td><a href='mailto:$listname@${OURDOMAIN}'>$listname</a>
                       </td>
197
                  <td><A href='$showuser_url'>$owner_uid</A></td>
198 199 200
                  <td align=center><A href='${mmurl}&wantadmin=1'>
                         <img src=\"arrow4.ico\"
                              border=0 alt='admin'></A></td>
201
                  <td align=center>
202 203 204
                       <A href='${mmurl}&wantadmin=1&link=passwords'>
                           <img src='/autostatus-icons/yellowball.gif'
                                border=0 alt=passwd>
205 206 207
                        </A></td>
                  <td align=center>
                       <A href='delmmlist.php3?listname=$listname'>
208 209
                           <img src='/autostatus-icons/redball.gif'
                                border=0 alt=delete>
210 211 212 213 214 215 216
                        </A></td>\n";
        echo "</tr>\n";
    }
    echo "</table>\n";
}
SUBPAGEEND();

217 218 219 220 221 222 223 224 225 226 227 228 229
echo "<br><br>
      <blockquote><blockquote>
      Emulab mailing lists are maintained using the open source
      <a href=http://www.gnu.org/software/mailman/index.html>Mailman</a>
      package. You can find documentation for
      <a href=http://www.gnu.org/software/mailman/users.html>Users</a>
      and documentation for 
      <a href=http://www.gnu.org/software/mailman/admins.html>
      List Managers</a> on the Mailman
      <a href=http://www.gnu.org/software/mailman/docs.html>
      documentation</a> page.
      </blockquote></blockquote>\n";

230 231 232 233 234 235 236
echo "<blockquote><blockquote>
      <b>1</b>: Your subscription list includes only lists where your
         subscription email address is the same as your Emulab registered
         email address ($user_email). Please use this email address when 
         subscribing to Emulab lists. 
      </blockquote></blockquote>\n";

237 238 239 240 241
#
# Standard Testbed Footer
# 
PAGEFOOTER();
?>