Join script should rule out retired usernames
[bpt/portal.git] / cert.mlt
index 36e908f..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 %> (<% Util.diffFromNow (#stamp req) %> ago)</td> </tr>
-<tr> <td>Request:</td> <td><% #data req %></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
@@ -66,14 +67,14 @@ elseif $"cmd" = "list" then
 <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 %> (<% Util.diffFromNow (#stamp req) %> ago)</td> </tr>
-<tr> <td>Request:</td> <td><% #data req %></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
@@ -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,24 +121,22 @@ 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>
-
-<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>.</p>
+<h3>Request installation of an SSL certificate</h3>
 
-<p>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.</p>
+<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>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.   In the comments field, be sure to specify the number of days that you would like the certificate to be valid.  If you do not specify a value, we will use 3650 days.  Make sure that the key file is in the same directory as the certificate request, and that it has a "<tt>.key</tt>" extension.</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>
 
@@ -148,8 +145,8 @@ elseif $"mod" <> "" then
 <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>