showmmlists.php3 6.3 KB
Newer Older
1 2 3
<?php
#
# EMULAB-COPYRIGHT
4
# Copyright (c) 2005, 2006, 2007, 2010 University of Utah and the Flux Group.
5 6 7 8 9 10 11
# All rights reserved.
#
include("defs.php3");

#
# Only known and logged in users allowed.
#
12 13 14 15
$this_user = CheckLoginOrDie();
$uid       = $this_user->uid();
$isadmin   = ISADMIN();
$user_email = $this_user->email();
16

17 18 19 20 21 22 23
#
# Verify page arguments.
#
$optargs = OptionalPageArguments("sortby",      PAGEARG_STRING,
				 "showallmm",   PAGEARG_BOOLEAN,
				 "target_user", PAGEARG_USER);

24 25 26 27 28
#
# Standard Testbed Header
#
PAGEHEADER("Mailman Lists");

29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
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.
#
45
if (isset($target_user)) {
46 47
    if (!$isadmin &&
	!$target_user->SameUser($this_user)) {
48 49
	USERERROR("You do not have permission to list mailman lists for ".
		  "other users!", 1);
50
    }
51 52
    $target_uid   = $target_user->uid();
    $target_dbuid = $target_user->uid();
53 54
}
else {
55 56 57
    $target_user  = $this_user;
    $target_uid   = $uid;
    $target_dbuid = $uid;
58 59
}

Leigh B. Stoller's avatar
Leigh B. Stoller committed
60
SUBPAGESTART();
61
SUBMENUSTART("Mail List Options");
62
WRITESUBMENUBUTTON("Create a Mailman List", "newmmlist.php3");
63 64 65 66

if ($isadmin) {
    WRITESUBMENUBUTTON("Show User Lists", "showmmlists.php3?showallmm=1");
}
67 68 69 70 71
SUBMENUEND();

#
# Ask the mailman server for the users lists. 
#
72
SUEXEC($uid, "nobody", "webmmlistmembership $target_uid", SUEXEC_ACTION_DIE);
73 74 75 76 77 78 79

#
# Parse the suexec output into a table.
#
if (count($suexec_output_array)) {
    echo "<br>
           <center><font size=+1>
80 81
          You are a member of the following Mailman
            lists<sup><font size=+1><b>1</b></font></sup>
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
          </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];

97 98 99 100 101 102 103 104 105 106
	#
	# 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;
	}

107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
	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";
}

124
#
125
# See if the target is the owner of any lists.
126
#
127
if ($isadmin && isset($showallmm)) {
128 129 130 131 132 133 134 135 136 137
    $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 ".
138
		     "where mm.owner_uid='$target_dbuid' ".
139 140 141
		     "order by $order");
}

142
if (mysql_num_rows($query_result)) {
143
    echo "<br>
144 145
           <center><font size=+1>";

146
    if (isset($showallmm)) {
147 148 149 150 151 152
	echo "User-Created Mailman lists";
    }
    else {
	echo "You are the administrator for the following Mailman lists";
    }
    echo "</font></center><br>\n";
153 154 155 156
    
    echo "<table border=2 cellpadding=0 cellspacing=2
           align='center'>\n";

157
    $showmmlists_url = CreateUrl("showmmlists", $target_user);
158

159
    echo "<tr>
160 161
              <th><a href='${showmmlists_url}&sortby=listname'>List Name</th>
              <th><a href='${showmmlists_url}&sortby=uid'>Owner</th>
162
              <th>Admin Page</th>
163 164 165 166 167 168 169
              <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'];
170
	$mmurl     = "gotommlist?listname=${listname}";
171 172 173 174 175

	if (! ($owner_user = User::Lookup($owner_uid))) {
	    TBERROR("Could not lookup object for user $owner_uid", 1);
	}
	$showuser_url = CreateURL("showuser", $owner_user);
176 177
	
	echo "<tr>
178 179
                  <td><a href='mailto:$listname@${OURDOMAIN}'>$listname</a>
                       </td>
180
                  <td><A href='$showuser_url'>$owner_uid</A></td>
181 182 183
                  <td align=center><A href='${mmurl}&wantadmin=1'>
                         <img src=\"arrow4.ico\"
                              border=0 alt='admin'></A></td>
184
                  <td align=center>
185 186 187
                       <A href='${mmurl}&wantadmin=1&link=passwords'>
                           <img src='/autostatus-icons/yellowball.gif'
                                border=0 alt=passwd>
188 189 190
                        </A></td>
                  <td align=center>
                       <A href='delmmlist.php3?listname=$listname'>
191 192
                           <img src='/autostatus-icons/redball.gif'
                                border=0 alt=delete>
193 194 195 196 197 198 199
                        </A></td>\n";
        echo "</tr>\n";
    }
    echo "</table>\n";
}
SUBPAGEEND();

200 201 202 203 204 205 206 207 208 209 210 211 212
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";

213 214 215 216 217 218 219
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";

220 221 222 223 224
#
# Standard Testbed Footer
# 
PAGEFOOTER();
?>