Commit 90dcbbe2 authored by Leigh B. Stoller's avatar Leigh B. Stoller

Okay, I think I am finally done with WikiWhacking (or WhackingTheWiki?)

for the near future. Two big changes:

* Add WikiOnly accounts. An external user can register for an account on
  the wiki. Rather then use the registration stuff that comes with TWiki,
  redirect to new Emulab web page so we can manage all of the wiki accounts
  from one place. I modified the joinproject page to spit out a subset of
  the required fields so that its simple to get a wiki only account (just a
  few things to fill in).

  In keeping with current security practices, we still generate a
  verification email message to ensure the email address works. However,
  when the user completes the verification, the wiki account is created right
  away, rather then waiting for someone to approve it (since that would
  defeat the entire point of the wiki).

  Aside: I have not thought much about the conversion from a wiki-only
  account to a real account. That is going to happen, and it would be nice
  if that step did not require one of use to go in and hack the DB. Will
  cross that moat later.

  Aside: Rather beat up on the modify user info page too much, I continue
  to spit out the same form, but mark most of the fields as not required,
  and allow wiki-only people to not specify them.

* Both the joinproject and newproject pages sport a new WikiName field so
  that users can select their own WikiName. I added some JavaScript to
  both pages that generate a suitable wikiname from the FullName field, so
  that as soon as the user clicks out of the FullName, a default wikiname is
  inserted in the field.

  Both pages verify the wikinames by checking to make sure it is not
  already in use, and that it meets the WikiRules for WikiTopic names.
  (someone please shoot me if I continue to use WikiNotation).
parent 1b22ebcc
......@@ -58,6 +58,7 @@ ifeq ($(EVENTSYS),1)
endif
@$(MAKE) -C mote post-install
@$(MAKE) -C tools post-install
@$(MAKE) -C wiki post-install
#
# For installation on the 'ops' or 'users' node (okay, plastic)
......
......@@ -167,7 +167,8 @@ if (AuditStart(0)) {
#
$query_result =
DBQueryFatal("select u.usr_pswd,u.unix_uid,u.usr_name, ".
" u.usr_email,u.status,u.webonly,u.usr_shell,admin,u.usr_w_pswd ".
" u.usr_email,u.status,u.webonly,u.usr_shell,admin, ".
" u.usr_w_pswd,u.wikionly ".
"from users as u ".
"where u.uid='$user'");
......@@ -184,6 +185,7 @@ my $webonly = $row[5];
my $usr_shell = $row[6];
my $usr_admin = $row[7];
my $wpswd = $row[8];
my $wikionly = $row[9];
#
# Get the users earliest project membership to use as the default group
......@@ -273,10 +275,20 @@ sub AddUser()
#
# Check status. Only active users get accounts built.
#
if ($webonly || $status ne USERSTATUS_ACTIVE) {
if ($webonly || $wikionly || $status ne USERSTATUS_ACTIVE) {
if ($webonly) {
return 0;
}
if ($wikionly) {
$EUID = $UID;
# And to the wiki if enabled.
system("$ADDWIKIUSER $user")
if ($WIKISUPPORT && !$batch);
$EUID = 0;
return 0;
}
fatal("$user is not active! Cannot build an account!");
}
......
......@@ -5,7 +5,7 @@ area for your project (or group). If you are not familiar with the
information on how to write and create TWiki pages.
* YourFirstWikiTopic (See TWiki.WikiTopic for a brief description)
*
*
__This project wiki can be accessed externally as:__ [[%SCRIPTURL%/view/%WEB%][%SCRIPTURL%/view/%WEB%]]
......
......@@ -200,6 +200,10 @@ function TBvalid_usrname($token) {
return TBcheck_dbslot($token, "users", "usr_name",
TBDB_CHECKDBSLOT_WARN|TBDB_CHECKDBSLOT_ERROR);
}
function TBvalid_wikiname($token) {
return TBcheck_dbslot($token, "users", "wikiname",
TBDB_CHECKDBSLOT_WARN|TBDB_CHECKDBSLOT_ERROR);
}
function TBvalid_email($token) {
return TBcheck_dbslot($token, "users", "usr_email",
TBDB_CHECKDBSLOT_WARN|TBDB_CHECKDBSLOT_ERROR);
......
......@@ -863,6 +863,21 @@ function TBCurrentUser($uid)
return mysql_num_rows($query_result);
}
#
# Confirm a current WikiName or not.
#
# usage TBCurrentWikiName($uid)
# returns 1 if a current wikiname.
# returns 0 if not a current wikiname
#
function TBCurrentWikiName($wikiname)
{
$query_result =
DBQueryFatal("SELECT usr_pswd FROM users WHERE wikiname='$wikiname'");
return mysql_num_rows($query_result);
}
#
# Check to see if an email is being used twice.
#
......@@ -1502,6 +1517,14 @@ function TBCvswebAllowed($uid) {
return mysql_num_rows($query_result);
}
function TBWikiOnlyUser($uid) {
$query_result =
DBQueryFatal("select wikionly from users ".
"WHERE uid='$uid' and wikionly=1");
return mysql_num_rows($query_result);
}
#
# Returns > 0 if a node has a serial console, 0 if it does not
#
......
......@@ -22,7 +22,8 @@ $uid = GETLOGIN();
if ($uid) {
# Allow unapproved users to join multiple groups ...
# Must be verified though.
LOGGEDINORDIE($uid, CHECKLOGIN_UNAPPROVED|CHECKLOGIN_WEBONLY);
LOGGEDINORDIE($uid, CHECKLOGIN_UNAPPROVED|
CHECKLOGIN_WEBONLY|CHECKLOGIN_WIKIONLY);
$joining_uid = $uid;
$returning = 1;
}
......@@ -33,6 +34,10 @@ else {
$returning = 0;
}
if (!isset($forwikionly)) {
$forwikionly = 0;
}
$ACCOUNTWARNING =
"Before continuing, please make sure your username " .
"reflects your normal login name. ".
......@@ -50,15 +55,32 @@ function SPITFORM($formfields, $returning, $errors)
{
global $TBDB_UIDLEN, $TBDB_PIDLEN, $TBDB_GIDLEN;
global $ACCOUNTWARNING, $EMAILWARNING;
PAGEHEADER("Apply for Project Membership");
global $WIKISUPPORT, $forwikionly, $WIKIURL;
if ($forwikionly)
PAGEHEADER("Wiki Registration");
else
PAGEHEADER("Apply for Project Membership");
if (! $returning) {
echo "<center><font size=+1>
echo "<center>\n";
if ($forwikionly) {
echo "<font size=+2>Register for an Emulab Wiki account</font>
<br><br>\n";
}
echo "<font size=+1>
If you already have an Emulab account,
<a href=login.php3?refer=1>
<font color=red>please log on first!</font></a>
</font></center><br>\n";
</font>\n";
if ($forwikionly) {
echo "<br>(You will already have a wiki account)\n";
}
echo "</center><br>\n";
}
elseif ($forwikionly) {
USERERROR("You already have a Wiki account!", 1);
}
if ($errors) {
......@@ -82,6 +104,34 @@ function SPITFORM($formfields, $returning, $errors)
}
echo "</table><br>\n";
}
echo "<SCRIPT LANGUAGE=JavaScript>
function SetWikiName(theform)
{
var validchars = 'abcdefghijklmnopqrstuvwxyz0123456789';
var usrname = theform['formfields[usr_name]'].value;
var wikiname = '';
var docap = 1;
for (var i = 0; i < usrname.length; i++) {
var letter = usrname.charAt(i).toLowerCase();
if (validchars.indexOf(letter) == -1) {
if (letter == ' ') {
docap = 1;
}
continue;
}
else {
if (docap == 1) {
letter = usrname.charAt(i).toUpperCase()
docap = 0;
}
wikiname = wikiname + letter;
}
}
theform['formfields[wikiname]'].value = wikiname;
}
</SCRIPT>\n";
echo "<table align=center border=1>
<tr>
......@@ -90,8 +140,10 @@ function SPITFORM($formfields, $returning, $errors)
</td>
</tr>\n
<form enctype=multipart/form-data
action=joinproject.php3 method=post>\n";
<form name=myform enctype=multipart/form-data
action=" . ($forwikionly ?
"wikiregister.php3" : "joinproject.php3") . " " .
"method=post>\n";
if (! $returning) {
#
......@@ -117,49 +169,68 @@ function SPITFORM($formfields, $returning, $errors)
<td class=left>
<input type=text
name=\"formfields[usr_name]\"
onchange=\"SetWikiName(myform);\"
value=\"" . $formfields[usr_name] . "\"
size=30>
</td>
</tr>\n";
#
# Title/Position:
#
echo "<tr>
<td colspan=2>*Title/Position:</td>
<td class=left>
<input type=text
name=\"formfields[usr_title]\"
value=\"" . $formfields[usr_title] . "\"
size=30>
</td>
</tr>\n";
#
# Affiliation:
#
echo "<tr>
<td colspan=2>*Institutional<br>Affiliation:</td>
<td class=left>
<input type=text
name=\"formfields[usr_affil]\"
value=\"" . $formfields[usr_affil] . "\"
size=40>
</td>
</tr>\n";
#
# User URL
# WikiName
#
echo "<tr>
<td colspan=2>Home Page URL:</td>
<td class=left>
<input type=text
name=\"formfields[usr_URL]\"
value=\"" . $formfields[usr_URL] . "\"
size=45>
</td>
</tr>\n";
if ($WIKISUPPORT) {
echo "<tr>
<td colspan=2>*
<a href=${WIKIURL}/TWiki/WikiName
target=_blank>WikiName</a>:<td class=left>
<input type=text
name=\"formfields[wikiname]\"
value=\"" . $formfields[wikiname] . "\"
size=30>
</td>
</tr>\n";
}
if (! $forwikionly) {
#
# Title/Position:
#
echo "<tr>
<td colspan=2>*Title/Position:</td>
<td class=left>
<input type=text
name=\"formfields[usr_title]\"
value=\"" . $formfields[usr_title] . "\"
size=30>
</td>
</tr>\n";
#
# Affiliation:
#
echo "<tr>
<td colspan=2>*Institutional<br>Affiliation:</td>
<td class=left>
<input type=text
name=\"formfields[usr_affil]\"
value=\"" . $formfields[usr_affil] . "\"
size=40>
</td>
</tr>\n";
#
# User URL
#
echo "<tr>
<td colspan=2>Home Page URL:</td>
<td class=left>
<input type=text
name=\"formfields[usr_URL]\"
value=\"" . $formfields[usr_URL] . "\"
size=45>
</td>
</tr>\n";
}
#
# Email:
......@@ -175,82 +246,88 @@ function SPITFORM($formfields, $returning, $errors)
</td>
</tr>\n";
echo "<tr><td colspan=3>*Postal Address:<br /><center>
<table>
<tr><td>Line 1</td><td colspan=3>
<input type=text
name=\"formfields[usr_addr]\"
value=\"" . $formfields[usr_addr] . "\"
size=45></td></tr>
<tr><td>Line 2</td><td colspan=3>
<input type=text
name=\"formfields[usr_addr2]\"
value=\"" . $formfields[usr_addr2] . "\"
size=45></td></tr>
<tr><td>City</td><td>
<input type=text
name=\"formfields[usr_city]\"
value=\"" . $formfields[usr_city] . "\"
size=25></td>
<td>State/Province</td><td>
<input type=text
name=\"formfields[usr_state]\"
value=\"" . $formfields[usr_state] . "\"
size=2></td></tr>
<tr><td>ZIP/Postal Code</td><td>
<input type=text
name=\"formfields[usr_zip]\"
value=\"" . $formfields[usr_zip] . "\"
size=10></td>
<td>Country</td><td>
<input type=text
name=\"formfields[usr_country]\"
value=\"" . $formfields[usr_country] . "\"
size=15></td></tr>
</table></center></td></tr>";
#
# Phone
#
echo "<tr>
<td colspan=2>*Phone #:</td>
<td class=left>
<input type=text
name=\"formfields[usr_phone]\"
value=\"" . $formfields[usr_phone] . "\"
size=15>
</td>
</tr>\n";
if (! $forwikionly) {
#
# Postal Address
#
echo "<tr><td colspan=3>*Postal Address:<br /><center>
<table>
<tr><td>Line 1</td><td colspan=3>
<input type=text
name=\"formfields[usr_addr]\"
value=\"" . $formfields[usr_addr] . "\"
size=45></td></tr>
<tr><td>Line 2</td><td colspan=3>
<input type=text
name=\"formfields[usr_addr2]\"
value=\"" . $formfields[usr_addr2] . "\"
size=45></td></tr>
<tr><td>City</td><td>
<input type=text
name=\"formfields[usr_city]\"
value=\"" . $formfields[usr_city] . "\"
size=25></td>
<td>State/Province</td><td>
<input type=text
name=\"formfields[usr_state]\"
value=\"" . $formfields[usr_state] . "\"
size=2></td></tr>
<tr><td>ZIP/Postal Code</td><td>
<input type=text
name=\"formfields[usr_zip]\"
value=\"" . $formfields[usr_zip] . "\"
size=10></td>
<td>Country</td><td>
<input type=text
name=\"formfields[usr_country]\"
value=\"" . $formfields[usr_country] . "\"
size=15></td></tr>
</table></center></td></tr>";
#
# Phone
#
echo "<tr>
<td colspan=2>*Phone #:</td>
<td class=left>
<input type=text
name=\"formfields[usr_phone]\"
value=\"" . $formfields[usr_phone] . "\"
size=15>
</td>
</tr>\n";
#
# SSH public key
#
echo "<tr>
<td rowspan><center>
Your SSH Pub Key: &nbsp<br>
[<b>2</b>]
</center></td>
<td rowspan><center>Upload (1K max)[<b>3</b>]<br>
<b>Or</b><br>
Insert Key
</center></td>
<td rowspan>
<input type=hidden name=MAX_FILE_SIZE value=1024>
<input type=file
name=usr_keyfile
value=\"" . $_FILES['usr_keyfile']['name'] . "\"
size=50>
<br>
<br>
<input type=text
name=\"formfields[usr_key]\"
value=\"$formfields[usr_key]\"
size=50
maxlength=1024>
</td>
</tr>\n";
#
# SSH public key
#
echo "<tr>
<td rowspan><center>
Your SSH Pub Key: &nbsp<br>
[<b>2</b>]
</center></td>
<td rowspan><center>Upload (1K max)[<b>3</b>]<br>
<b>Or</b><br>
Insert Key
</center></td>
<td rowspan>
<input type=hidden name=MAX_FILE_SIZE value=1024>
<input type=file
name=usr_keyfile
value=\"" . $_FILES['usr_keyfile']['name'] .
"\"
size=50>
<br>
<br>
<input type=text
name=\"formfields[usr_key]\"
value=\"$formfields[usr_key]\"
size=50
maxlength=1024>
</td>
</tr>\n";
}
#
# Password. Note that we do not resend the password. User
......@@ -273,32 +350,34 @@ function SPITFORM($formfields, $returning, $errors)
</tr>\n";
}
#
# Project Name:
#
echo "<tr>
<td colspan=2>*Project Name:</td>
<td class=left>
<input type=text
name=\"formfields[pid]\"
value=\"" . $formfields[pid] . "\"
size=$TBDB_PIDLEN maxlength=$TBDB_PIDLEN>
</td>
</tr>\n";
if (! $forwikionly) {
#
# Project Name:
#
echo "<tr>
<td colspan=2>*Project Name:</td>
<td class=left>
<input type=text
name=\"formfields[pid]\"
value=\"" . $formfields[pid] . "\"
size=$TBDB_PIDLEN maxlength=$TBDB_PIDLEN>
</td>
</tr>\n";
#
# Group Name:
#
echo "<tr>
<td colspan=2>Group Name:<br>
(Leave blank unless you <em>know</em> the group name)</td>
<td class=left>
<input type=text
name=\"formfields[gid]\"
value=\"" . $formfields[gid] . "\"
size=$TBDB_GIDLEN maxlength=$TBDB_GIDLEN>
</td>
</tr>\n";
#
# Group Name:
#
echo "<tr>
<td colspan=2>Group Name:<br>
(Leave blank unless you <em>know</em> the group name)</td>
<td class=left>
<input type=text
name=\"formfields[gid]\"
value=\"" . $formfields[gid] . "\"
size=$TBDB_GIDLEN maxlength=$TBDB_GIDLEN>
</td>
</tr>\n";
}
echo "<tr>
<td colspan=3 align=center>
......@@ -315,7 +394,7 @@ function SPITFORM($formfields, $returning, $errors)
<a href = 'docwrapper.php3?docname=security.html'>
security policies</a> for information
regarding passwords and email addresses.\n";
if (! $returning) {
if (!$returning && !$forwikionly) {
echo "<li> If you want us to use your existing ssh public key,
then either paste it in or specify the path to your
your identity.pub file. <font color=red>NOTE:</font>
......@@ -342,12 +421,21 @@ function SPITFORM($formfields, $returning, $errors)
# The conclusion of a join request. See below.
#
if (isset($_GET['finished'])) {
PAGEHEADER("Apply for Project Membership");
if ($forwikionly)
PAGEHEADER("Wiki Registration");
else
PAGEHEADER("Apply for Project Membership");
#
# Generate some warm fuzzies.
#
if (! $returning) {
if ($forwikionly) {
echo "An email message has been sent to your account so we may verify
your email address. Please follow the instructions contained in
that message, which will verify your account, and grant you
access to the Wiki.\n";
}
elseif (! $returning) {
echo "<p>
As a pending user of the Testbed you will receive a key via email.
When you receive the message, please follow the instructions
......@@ -356,7 +444,8 @@ if (isset($_GET['finished'])) {
<p>
When you have done that, the project leader will be
notified of your application. ";
} else {
}
else {
echo "<p>
The project leader has been notified of your application. ";
}
......@@ -420,13 +509,6 @@ if (! $returning) {
posix_getpwnam($formfields[joining_uid])) {
$errors["UserName"] = "Already in use. Pick another";
}
if (!isset($formfields[usr_title]) ||
strcmp($formfields[usr_title], "") == 0) {
$errors["Title/Position"] = "Missing Field";
}
elseif (! TBvalid_title($formfields[usr_title])) {
$errors["Title/Position"] = TBFieldErrorString();
}
if (!isset($formfields[usr_name]) ||
strcmp($formfields[usr_name], "") == 0) {
$errors["Full Name"] = "Missing Field";
......@@ -440,14 +522,34 @@ if (! $returning) {
if (count($tokens) < 2) {
$errors["Full Name"] = "Please provide a first and last name";
}
if (!isset($formfields[usr_affil]) ||
strcmp($formfields[usr_affil], "") == 0) {
$errors["Affiliation"] = "Missing Field";
}
elseif (! TBvalid_affiliation($formfields[usr_affil])) {
$errors["Affiliation"] = TBFieldErrorString();
if ($WIKISUPPORT) {
if (!isset($formfields[wikiname]) ||
strcmp($formfields[wikiname], "") == 0) {
$errors["WikiName"] = "Missing Field";
}
elseif (! TBvalid_wikiname($formfields[wikiname])) {
$errors["WikiName"] = TBFieldErrorString();
}
elseif (TBCurrentWikiName($formfields[wikiname])) {
$errors["WikiName"] = "Already in use. Pick another";
}
}
if (!$forwikionly) {
if (!isset($formfields[usr_title]) ||
strcmp($formfields[usr_title], "") == 0) {
$errors["Title/Position"] = "Missing Field";
}
elseif (! TBvalid_title($formfields[usr_title])) {
$errors["Title/Position"] = TBFieldErrorString();
}
if (!isset($formfields[usr_affil]) ||
strcmp($formfields[usr_affil], "") == 0) {
$errors["Affiliation"] = "Missing Field";
}
elseif (! TBvalid_affiliation($formfields[usr_affil])) {
$errors["Affiliation"] = TBFieldErrorString();
}
}
if (!isset($formfields[usr_email]) ||
strcmp($formfields[usr_email], "") == 0) {
$errors["Email Address"] = "Missing Field";
......@@ -465,58 +567,60 @@ if (! $returning) {
"<a href='password.php3?email=$formfields[usr_email]'>".
"forgotten your username.</a>", 1);
}
if (isset($formfields[usr_URL]) &&
strcmp($formfields[usr_URL], "") &&
strcmp($formfields[usr_URL], $HTTPTAG) &&
! CHECKURL($formfields[usr_URL], $urlerror)) {
$errors["Home Page URL"] = $urlerror;
}
if (!isset($formfields[usr_addr]) ||
strcmp($formfields[usr_addr], "") == 0) {
$errors["Address 1"] = "Missing Field";
}
elseif (! TBvalid_addr($formfields[usr_addr])) {
$errors["Address 1"] = TBFieldErrorString();
}
# Optional
if (isset($formfields[usr_addr2]) &&
!TBvalid_addr($formfields[usr_addr2])) {
$errors["Address 2"] = TBFieldErrorString();
}
if (!isset($formfields[usr_city]) ||