Join script should rule out retired usernames
[bpt/portal.git] / cert.mlt
index c7b25a4..0206458 100644 (file)
--- a/cert.mlt
+++ b/cert.mlt
@@ -3,57 +3,58 @@
 val admin = Group.inGroupName "server";
 
 if $"new" <> "" then
-        if $"kind" = "cert" then
-          if $"req" <> "" then
-             %><h3>You filled data in next to a textbox but didn't check the radio button next to it.</h3><%
-          elseif $"cert" = "" then
-             %><h3>Please fill in a path to a certificate.</h3><%
-          else
-              val cert = $"cert";
-             val msg = $"msg";
-
-             %>Are you sure you want to ask for permissions on an SSL certificate at <% cert %>?<br><br>
-             <a href="cert?cmd=request&req=Certificate+<% cert %>&msg=<% Web.urlEncode msg %>">Yes, I want to request that.</a><%
-          end
-        else
-          if $"cert" <> "" then
-             %><h3>You filled data in next to a textbox but didn't check the radio button next to it.</h3><%
-          elseif $"req" = "" then
-             %><h3>Please fill in a path to an OpenSSL request.</h3><%
-          else
-              val req = $"req";
-             val msg = $"msg";
-
-             %>Are you sure you want to ask for permissions on an SSL certificate to be created from an OpenSSL request at <% req %>?<br><br>
-             <a href="cert?cmd=request&req=OpenSSL+request+<% req %>&msg=<% Web.urlEncode msg %>">Yes, I want to request that.</a><%
-          end
-        end
-
+   val cert = $"cert";
+   val domain = $"domain";
+   val msg = $"msg";
+
+   if cert = "" then
+      %><h3>Please fill in a path to a certificate.</h3><%
+   elseif not (ChooseDomain.yourDomain {user = Init.getUserName (), domain = domain}) then
+      %><h3>You don't have permissions on domain <tt><% Web.html domain %></tt>.</h3><%
+   else
+      %>Are you sure you want to ask for permissions on an SSL certificate
+      <li> at <tt><% Web.html cert %></tt>,</li>
+      <li> for domain <tt><% domain %></tt>?</li>
+      <a href="?cmd=request&cert=<% Web.html cert %>&domain=<% Web.html domain %>&msg=<% Web.urlEncode msg %>">Yes, I want to request that.</a><%
+   end
 elseif $"cmd" = "request" then
-       val id = Cert.add (Init.getUserId (), $"req", $"msg");
-       if not (Cert.notifyNew id) then
-               %><h3>Error sending e-mail notification</h3><%
-       end
-       %><h3>Request added</h3><%
-
+   val cert = $"cert";
+   val domain = $"domain";
+   val msg = $"msg";
+
+   if cert = "" then
+      %><h3>Please fill in a path to a certificate.</h3><%
+   elseif not (ChooseDomain.yourDomain {user = Init.getUserName (), domain = domain}) then
+      %><h3>You don't have permissions on domain <tt><% Web.html domain %></tt>.</h3><%
+   else
+     val text = "/afs/hcoop.net/common/etc/scripts/ca-install "
+       ^ Init.getUserName () ^ " "
+       ^ domain ^ " "
+       ^ cert
+
+     val id = Cert.add (Init.getUserId (), text, msg);
+     if not (Cert.notifyNew id) then
+       %><h3>Error sending e-mail notification</h3><%
+     end
+     %><h3>Request added</h3><%
+  end
 elseif $"cmd" = "open" then
        %><h3>Open requests</h3>
-       <a href="cert?cmd=list">List all requests</a><%
+       <a href="?cmd=list">List all requests</a><%
 
        foreach (name, req) in Cert.listOpen () do %>
 <br><hr><br>
 <table class="blanks">
 <tr> <td>By:</td> <td><a href="user?id=<% #usr req %>"><% name %></a></td> </tr>
-<tr> <td>Time:</td> <td><% #stamp req %></td> </tr>
-<tr> <td>Request:</td> <td><% #data req %></td> </tr>
+<tr> <td>Time:</td> <td><% #stamp req %> (<% Util.diffFromNow (#stamp req) %> ago)</td> </tr>
+<tr> <td>Request:</td> <td><tt><% #data req %></tt></td> </tr>
 <tr> <td>Reason:</td> <td><% Web.html (#msg req) %></td> </tr>
 </table>
 
 <% if admin then %>
        <br>
-       <a href="cert?mod=<% #id req %>">[Modify]</a>
-       <a href="cert?del=<% #id req %>">[Delete]</a><br>
-       To install, run: <i>tell adamc what text to put here</i>.
+       <a href="?mod=<% #id req %>">[Modify]</a>
+       <a href="?del=<% #id req %>">[Delete]</a><br>
 <% end %>
 
 <%     end
@@ -65,15 +66,15 @@ elseif $"cmd" = "list" then
 <br><hr><br>
 <table class="blanks">
 <tr> <td>By:</td> <td><a href="user?id=<% #usr req %>"><% name %></a></td> </tr>
-<tr> <td>Time:</td> <td><% #stamp req %></td> </tr>
-<tr> <td>Request:</td> <td><% #data req %></td> </tr>
+<tr> <td>Time:</td> <td><% #stamp req %> (<% Util.diffFromNow (#stamp req) %> ago)</td> </tr>
+<tr> <td>Request:</td> <td><tt><% #data req %></tt></td> </tr>
 <tr> <td>Reason:</td> <td><% Web.html (#msg req) %></td> </tr>
 </table>
 
 <% if admin then %>
        <br>
-       <a href="cert?mod=<% #id req %>">[Modify]</a>
-       <a href="cert?del=<% #id req %>">[Delete]</a>
+       <a href="?mod=<% #id req %>">[Modify]</a>
+       <a href="?del=<% #id req %>">[Delete]</a>
 <% end %>
 
 <%     end
@@ -89,7 +90,7 @@ elseif $"mod" <> "" then
 <input type="hidden" name="save" value="<% id %>">
 <table class="blanks">
 <tr> <td>Requestor:</td> <td><a href="user?id=<% #usr req %>"><% #name user %></a></td> </tr>
-<tr> <td>Time:</td> <td><% #stamp req %></td> </tr>
+<tr> <td>Time:</td> <td><% #stamp req %> (<% Util.diffFromNow (#stamp req) %> ago)</td> </tr>
 <tr> <td>Status:</td> <td><select name="status">
        <option value="0"<% if #status req = Cert.NEW then %> selected<% end %>>New</option>
        <option value="1"<% if #status req = Cert.INSTALLED then %> selected<% end %>>Installed</option>
@@ -108,13 +109,11 @@ elseif $"mod" <> "" then
        val oldStatus = #status req;
        val newStatus = Cert.statusFromInt (Web.stoi ($"status"));
        Cert.modify {req with data = $"req", msg = $"msg", status = newStatus};
-       if oldStatus <> newStatus then
-               if not (Cert.notifyMod (oldStatus, newStatus, Init.getUserName(), id)) then
-                       %><h3>Error sending e-mail notification</h3><%
-               end
+       if not (Cert.notifyMod (oldStatus, newStatus, Init.getUserName(), id)) then
+               %><h3>Error sending e-mail notification</h3><%
        end
        %><h3>Request modified</h3>
-       Back to: <a href="cert?cmd=open">open requests</a>, <a href="cert?cmd=list">all requests</a>
+       Back to: <a href="?cmd=open">open requests</a>, <a href="?cmd=list">all requests</a>
 
 <% elseif $"del" <> "" then
        Group.requireGroupName "server";
@@ -122,28 +121,32 @@ elseif $"mod" <> "" then
        val req = Cert.lookup id;
        val user = Init.lookupUser (#usr req)
        %><h3>Are you sure you want to delete request by <% #name user %> for <tt><% #data req %></tt>?</h3>
-       <a href="cert?del2=<% id %>">Yes, I'm sure!</a>
+       <a href="?del2=<% id %>">Yes, I'm sure!</a>
 
 <% elseif $"del2" <> "" then
        Group.requireGroupName "server";
        val id = Web.stoi ($"del2");
        Cert.delete id
        %><h3>Request deleted</b><h3>
-       Back to: <a href="cert?cmd=open">open requests</a>, <a href="cert?cmd=list">all requests</a>
+       Back to: <a href="?cmd=open">open requests</a>, <a href="?cmd=list">all requests</a>
 
 <% else %>
 
-<h3>Request permissions on an SSL certificate</h3>
+<h3>Request installation of an SSL certificate</h3>
+
+<p>Use this form to request Domtool permissions to use an SSL certificate.  Give the location of your certificate/key (<tt>.pem</tt>) file within <tt>/afs/hcoop.net</tt>.</p>
 
-<p>Use this form to request use Domtool permissions to use an SSL certificate.  Give the location of your certificate request or certificate within <tt>/afs/hcoop.net</tt>.  If you have your own certificate signed by an outside provider like Verisign, then choose the second option and give the path to that certificate.  If you want your certificate authenticated by chaining through HCoop's root certificate, then choose the first option and give the path to an OpenSSL certificate request.</p>
+<p>If you want your certificate authenticated by chaining through HCoop's root certificate, then <a href="sign">get it signed</a> before submitting this form.</p>
 
 <p>Note that you can't use SSL certificates very well over HTTPS without an IP address assigned to your web virtual host.  You can request one separately on <a href="ip">the IP address request page</a>.</p>
 
+<p>The <a href="http://wiki.hcoop.net/MemberManual/ServingWebsites/SslCert">instructions on our wiki for creating SSL certificates</a> may be helpful.</p>
+
 <form method="post">
 <input type="hidden" name="new" value="1">
 <table class="blanks">
-<tr> <td>OpenSSL request: <input type="radio" name="kind" value="req" checked></td> <td><input name="req" size="60"></td> </tr>
-<tr> <td>OpenSSL certificate: <input type="radio" name="kind" value="cert"></td> <td><input name="cert" size="60"></td> </tr>
+<tr> <td>Domain:</td> <td><% @chooseDomain[] %></td> </tr>
+<tr> <td>OpenSSL certificate:</td> <td><input name="cert" size="60"></td> </tr>
 <tr> <td>Additional comments:</td> <td><textarea name="msg" rows="5" cols="80" wrap="soft"></textarea></td> </tr>
 <tr> <td><input type="submit" value="Request"></td> </tr>
 </table>