Change granter.sh to give permissions to user specified on command line
[hcoop/zz_old/portal.git] / sec.mlt
diff --git a/sec.mlt b/sec.mlt
index c8bdfba..386da98 100644 (file)
--- a/sec.mlt
+++ b/sec.mlt
@@ -7,6 +7,8 @@ val uname = case $"uname" of
 
 val socks = Sec.socketPerms uname;
 val tpe = Sec.isTpe uname;
+val cron = Sec.cronAllowed uname;
+val ftp = Sec.ftpAllowed uname;
 
 ref showNormal = true;
 
@@ -20,9 +22,9 @@ if $"cmd" = "socks" then
 elseif $"cmd" = "socks2" then
        val id = Sec.Req.add (you, String.concat [uname, ": change socket permissions to ", $"socks"], $"msg");
        if not (Sec.Req.notifyNew id) then
-               %><h3><b>Error sending e-mail notification</b></h3><%
+               %><h3>Error sending e-mail notification</h3><%
        end
-       %><h3><b>Request added</b></h3><%
+       %><h3>Request added</h3><%
 
 elseif $"cmd" = "tpe" then
        showNormal := false;
@@ -32,23 +34,90 @@ elseif $"cmd" = "tpe" then
 elseif $"cmd" = "tpe2" then
        val id = Sec.Req.add (you, String.concat [uname, ": turn tpe ", $"tpe"], $"msg");
        if not (Sec.Req.notifyNew id) then
-               %><h3><b>Error sending e-mail notification</b></h3><%
+               %><h3>Error sending e-mail notification</h3><%
        end
-       %><h3><b>Request added</b></h3><%
+       %><h3>Request added</h3><%
+
+elseif $"cmd" = "cron" then
+       showNormal := false;
+       val cron = iff $"cron" = "yes" then "enabled" else "disabled";
+       %>Are you sure you want to request that <tt>cron</tt> permissions for <b><% Web.html uname %></b> be <b><% cron %></b>?<br>
+       <a href="sec?cmd=cron2&uname=<% Web.urlEncode uname %>&cron=<% cron %>&msg=<% Web.urlEncode ($"msg") %>">Yes, place the request!</a><%
+elseif $"cmd" = "cron2" then
+       val cron = iff $"cron" = "enabled" then "enable" else "disable";
+       val id = Sec.Req.add (you, String.concat [uname, ": ", cron, " cron access"], $"msg");
+       if not (Sec.Req.notifyNew id) then
+               %><h3>Error sending e-mail notification</h3><%
+       end
+       %><h3>Request added</h3><%
+
+elseif $"cmd" = "ftp" then
+       showNormal := false;
+       val ftp = iff $"ftp" = "yes" then "enabled" else "disabled";
+       %>Are you sure you want to request that FTP permissions for <b><% Web.html uname %></b> be <b><% ftp %></b>?<br>
+       <a href="sec?cmd=ftp2&uname=<% Web.urlEncode uname %>&ftp=<% ftp %>&msg=<% Web.urlEncode ($"msg") %>">Yes, place the request!</a><%
+elseif $"cmd" = "ftp2" then
+       val ftp = iff $"ftp" = "enabled" then "enable" else "disable";
+       val id = Sec.Req.add (you, String.concat [uname, ": ", ftp, " FTP access"], $"msg");
+       if not (Sec.Req.notifyNew id) then
+               %><h3>Error sending e-mail notification</h3><%
+       end
+       %><h3>Request added</h3><%
+
+elseif $"cmd" = "rule" then
+       showNormal := false;
+       val rule = $"rule";
+       %>Are you sure you want to request the firewall rule <b><% Web.html uname %>&nbsp;<% Web.html rule %></b>?<br>
+       <a href="sec?cmd=rule2&uname=<% Web.urlEncode uname %>&rule=<% Web.urlEncode rule %>&msg=<% Web.urlEncode ($"msg") %>">Yes, place the request!</a><%
+elseif $"cmd" = "rule2" then
+       val id = Sec.Req.add (you, String.concat ["Add firewall rule \"", uname, " ", $"rule", "\""], $"msg");
+       if not (Sec.Req.notifyNew id) then
+               %><h3>Error sending e-mail notification</h3><%
+       end
+       %><h3>Request added</h3><%
+
+elseif $"modRule" <> "" then
+       showNormal := false;
+       val oldRule = $"modRule";
+       val rule = $"rule"
+       if oldRule = rule then
+               %>You didn't modify the textbox for this rule before clicking the button, so there is no request to be made.<%
+       else
+               %>Are you sure you want to request that firewall rule <b><% Web.html uname %>&nbsp;<% Web.html oldRule %></b> be replaced by <b><% Web.html uname %>&nbsp;<% Web.html rule %></b>?<br>
+               <a href="sec?uname=<% Web.urlEncode uname %>&modRule2=<% Web.urlEncode oldRule %>&rule=<% Web.urlEncode rule %>&msg=<% Web.urlEncode ($"msg") %>">Yes, place the request!</a><%
+       end
+elseif $"modRule2" <> "" then
+       val id = Sec.Req.add (you, String.concat ["Change firewall rule \"", uname, " ", $"modRule2", "\" to \"", uname, " ", $"rule", "\""], $"msg");
+       if not (Sec.Req.notifyNew id) then
+               %><h3>Error sending e-mail notification</h3><%
+       end
+       %><h3>Request added</h3><%
+
+elseif $"delRule" <> "" then
+       showNormal := false;
+       val oldRule = $"delRule";
+       %>Are you sure you want to request that firewall rule <b><% Web.html uname %>&nbsp;<% Web.html oldRule %></b> be <b>deleted</b>?<br>
+       <a href="sec?uname=<% Web.urlEncode uname %>&delRule2=<% Web.urlEncode oldRule %>&msg=<% Web.urlEncode ($"msg") %>">Yes, place the request!</a><%
+elseif $"delRule2" <> "" then
+       val id = Sec.Req.add (you, String.concat ["Delete firewall rule \"", uname, " ", $"delRule2", "\""], $"msg");
+       if not (Sec.Req.notifyNew id) then
+               %><h3>Error sending e-mail notification</h3><%
+       end
+       %><h3>Request added</h3><%
 
 elseif $"cmd" = "open" then
        showNormal := false;
        Group.requireGroupName "server";
-       %><h3><b>Open requests</b></h3>
+       %><h3>Open requests</h3>
        <a href="sec?cmd=list">List all requests</a><%
 
        foreach (name, req) in Sec.Req.listOpen () do %>
 <br><hr><br>
-<table>
-<tr> <td align="right"><b>By</b>:</td> <td><a href="user?id=<% #usr req %>"><% name %></a></td> </tr>
-<tr> <td align="right"><b>Time</b>:</td> <td><% #stamp req %></td> </tr>
-<tr> <td align="right"><b>Request</b>:</td> <td><% #data req %></td> </tr>
-<tr> <td align="right" valign="top"><b>Msg</b>:</td> <td colspan="2"><% Web.html (#msg req) %></td> </tr>
+<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>Msg:</td> <td colspan="2"><% Web.html (#msg req) %></td> </tr>
 </table>
 
 <br>
@@ -60,15 +129,15 @@ elseif $"cmd" = "open" then
 elseif $"cmd" = "list" then
        showNormal := false;
        Group.requireGroupName "server"
-       %><h3><b>All requests</b></h3><%
+       %><h3>All requests</h3><%
 
        foreach (name, req) in Sec.Req.list () do %>
 <br><hr><br>
-<table>
-<tr> <td align="right"><b>By</b>:</td> <td colspan="2"><a href="user?id=<% #usr req %>"><% name %></a></td> </tr>
-<tr> <td align="right"><b>Time</b>:</td> <td colspan="2"><% #stamp req %></td> </tr>
-<tr> <td align="right"><b>Request</b>:</td> <td><% #data req %></td> </tr>
-<tr> <td align="right" valign="top"><b>Reason</b>:</td> <td colspan="2"><% Web.html (#msg req) %></td> </tr>
+<table class="blanks">
+<tr> <td>By:</td> <td colspan="2"><a href="user?id=<% #usr req %>"><% name %></a></td> </tr>
+<tr> <td>Time:</td> <td colspan="2"><% #stamp req %></td> </tr>
+<tr> <td>Request:</td> <td><% #data req %></td> </tr>
+<tr> <td>Reason:</td> <td colspan="2"><% Web.html (#msg req) %></td> </tr>
 </table>
 
 <br>
@@ -83,20 +152,20 @@ elseif $"mod" <> "" then
        val id = Web.stoi ($"mod");
        val req = Sec.Req.lookup id;
        val user = Init.lookupUser (#usr req) %>
-<h3><b>Handle request</b></h3>
+<h3>Handle request</h3>
 
 <form action="sec" method="post">
 <input type="hidden" name="save" value="<% id %>">
-<table>
-<tr> <td align="right"><b>Requestor</b>:</td> <td><a href="user?id=<% #usr req %>"><% #name user %></a></td> </tr>
-<tr> <td align="right"><b>Time</b>:</td> <td><% #stamp req %></td> </tr>
-<tr> <td align="right"><b>Status</b>:</td> <td><select name="status">
+<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>Status:</td> <td><select name="status">
        <option value="0"<% if #status req = Sec.Req.NEW then %> selected<% end %>>New</option>
        <option value="1"<% if #status req = Sec.Req.INSTALLED then %> selected<% end %>>Installed</option>
        <option value="2"<% if #status req = Sec.Req.REJECTED then %> selected<% end %>>Rejected</option>
 </select></td> </tr>
-<tr> <td align="right"><b>Request</b>:</td> <td><input name="req" value="<% #data req %>"></td> </tr>
-<tr> <td align="right" valign="top"><b>Message</b>:</td> <td><textarea name="msg" rows="10" cols="80" wrap="soft"><% Web.html (#msg req) %></textarea></td> </tr>
+<tr> <td>Request:</td> <td><input name="req" value="<% #data req %>"></td> </tr>
+<tr> <td>Message:</td> <td><textarea name="msg" rows="10" cols="80" wrap="soft"><% Web.html (#msg req) %></textarea></td> </tr>
 <tr> <td><input type="submit" value="Save"></td> </tr>
 </table>
 </form>
@@ -111,10 +180,10 @@ elseif $"mod" <> "" then
        Sec.Req.modify {req with data = $"req", msg = $"msg", status = newStatus};
        if oldStatus <> newStatus then
                if not (Sec.Req.notifyMod (oldStatus, newStatus, Init.getUserName(), id)) then
-                       %><h3><b>Error sending e-mail notification</b></h3><%
+                       %><h3>Error sending e-mail notification</h3><%
                end
        end
-       %><h3><b>Request modified</b></h3>
+       %><h3>Request modified</h3>
        Back to: <a href="sec?cmd=open">open requests</a>, <a href="sec?cmd=list">all requests</a>
 
 <% elseif $"del" <> "" then
@@ -123,7 +192,7 @@ elseif $"mod" <> "" then
        val id = Web.stoi ($"del");
        val req = Sec.Req.lookup id;
        val user = Init.lookupUser (#usr req)
-       %><h3><b>Are you sure you want to delete request by <% #name user %> for "<% #data req %>"?</b></h3>
+       %><h3>Are you sure you want to delete request by <% #name user %> for "<% #data req %>"?</h3>
        <a href="sec?del2=<% id %>">Yes, I'm sure!</a>
 
 <% elseif $"del2" <> "" then
@@ -131,7 +200,7 @@ elseif $"mod" <> "" then
        Group.requireGroupName "server";
        val id = Web.stoi ($"del2");
        Sec.Req.delete id
-       %><h3><b>Request deleted</b><h3>
+       %><h3>Request deleted</b><h3>
        Back to: <a href="sec?cmd=open">open requests</a>, <a href="sec?cmd=list">all requests</a>
 
 <% end;
@@ -144,34 +213,94 @@ if showNormal then %>
        <option value="<% name %>"<% if uname = name then %> selected<% end %>><% name %></option>
 <% end %></select> <input type="submit" value="Switch"> </form>
 
-<h3><b>Request socket permissions change</b></h3>
+<h3>Request socket permissions change</h3>
 
 <form action="sec" method="post">
 <input type="hidden" name="uname" value="<% uname %>">
 <input type="hidden" name="cmd" value="socks">
-<table>
-<tr> <td align="right"><b>New permissions:</b></td> <td><select name="socks">
+<table class="blanks">
+<tr> <td>New permissions:</td> <td><select name="socks">
        <option value="none"<% if socks = Sec.NADA then %> selected<% end %>>None</option>
        <option value="any"<% if socks = Sec.ANY then %> selected<% end %>>Any</option>
        <option value="client"<% if socks = Sec.CLIENT_ONLY then %> selected<% end %>>Client only</option>
        <option value="server"<% if socks = Sec.SERVER_ONLY then %> selected<% end %>>Server only</option>
 </select></td> </tr>
-<tr> <td align="right" valign="top"><b>Reason:</b></td> <td><textarea name="msg" wrap="soft" rows="3" cols="80"></textarea></td> </tr>
+<tr> <td>Reason:</td> <td><textarea name="msg" wrap="soft" rows="3" cols="80"></textarea></td> </tr>
 <tr> <td><input type="submit" value="Request"></td> </tr>
 </table>
 </form>
 
-<h3><b>Request change to your execute permissions</b></h3>
+<h3>Request change to your execute permissions</h3>
 
 <form action="sec" method="post">
 <input type="hidden" name="uname" value="<% uname %>">
 <input type="hidden" name="cmd" value="tpe">
-<table>
-<tr> <td align="right"><b>Trusted path executables only?</b></td> <td><select name="tpe">
+<table class="blanks">
+<tr> <td>Trusted path executables only?</td> <td><select name="tpe">
        <option value="no"<% if not tpe then %> selected<% end %>>No</option>
        <option value="yes"<% if tpe then %> selected<% end %>>Yes</option>
 </select></td> </tr>
-<tr> <td align="right" valign="top"><b>Reason:</b></td> <td><textarea name="msg" wrap="soft" rows="3" cols="80"></textarea></td> </tr>
+<tr> <td>Reason:</td> <td><textarea name="msg" wrap="soft" rows="3" cols="80"></textarea></td> </tr>
+<tr> <td><input type="submit" value="Request"></td> </tr>
+</table>
+</form>
+
+<h3>Request change to your <tt>cron</tt> permissions</h3>
+
+<form action="sec" method="post">
+<input type="hidden" name="uname" value="<% uname %>">
+<input type="hidden" name="cmd" value="cron">
+<table class="blanks">
+<tr> <td>Allowed to use cron?</td> <td><select name="cron">
+       option value="no"<% if not cron then %> selected<% end %>>No</option>
+       <option value="yes"<% if cron then %> selected<% end %>>Yes</option>
+</select></td> </tr>
+<tr> <td>Reason:</td> <td><textarea name="msg" wrap="soft" rows="3" cols="80"></textarea></td> </tr>
+<tr> <td><input type="submit" value="Request"></td> </tr>
+</table>
+</form>
+
+<h3>Request change to your FTP permissions</h3>
+
+<form action="sec" method="post">
+<input type="hidden" name="uname" value="<% uname %>">
+<input type="hidden" name="cmd" value="ftp">
+<table class="blanks">
+<tr> <td>Allowed to use FTP?</td> <td><select name="ftp">
+       <option value="no"<% if not ftp then %> selected<% end %>>No</option>
+       <option value="yes"<% if ftp then %> selected<% end %>>Yes</option>
+</select></td> </tr>
+<tr> <td>Reason:</td> <td><textarea name="msg" wrap="soft" rows="3" cols="80"></textarea></td> </tr>
+<tr> <td><input type="submit" value="Request"></td> </tr>
+</table>
+</form>
+
+<% val rules = Sec.findFirewallRules uname;
+switch rules of
+  _::_ => %>
+<h3>Your firewall rules</h3>
+
+<% foreach rule in rules do %>
+<form action="sec" method="post">
+<input type="hidden" name="uname" value="<% uname %>">
+<input type="hidden" name="modRule" value="<% Web.html rule %>">
+<input name="rule" value="<% Web.html rule %>">
+<a href="sec?delRule=<% Web.urlEncode rule %>">[Request deletion]</a>
+<input type="submit" value="Request change">
+</form><br>
+<% end
+end%>
+
+<h3>Request a new firewall rule</h3>
+
+<p>You can find a description of rule formats <a href="http://wiki.hcoop.net/wiki/FirewallRules">on our wiki</a>. Enter here the rule you want, without the initial <tt>user</tt> portion.</p>
+
+<form action="sec" method="post">
+<input type="hidden" name="uname" value="<% uname %>">
+<input type="hidden" name="cmd" value="rule">
+<table class="blanks">
+<tr> <td>Rule</td> <td><input name="rule" size="80"></td> </tr>
+<tr> <td>Reason:</td> <td><textarea name="msg" wrap="soft" rows="3" cols="80"></textarea></td> </tr>
 <tr> <td><input type="submit" value="Request"></td> </tr>
 </table>
 </form>