Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

87 lines (66 sloc) 2.148 kb
<%
db.firewall.ensureIndex( { host :- 1 } );
if ( request.action == "rules" ){
response.setHeader( "Content-Type" , "text/plain" );
print( "sudo /sbin/iptables -F\n" );
db.firewall.find().sort( { host : 1 } ).forEach(
function(z){
print( "sudo /sbin/iptables -m comment --comment \"allow " + z.host + " to db | " + ( z.comment || "" ) + "\" -I INPUT -s " + javaStatic( "java.net.InetAddress" , "getByName" , z.host ).getHostAddress() + " -p tcp --dport 27017 -j ACCEPT\n" );
}
);
print( "sudo /sbin/iptables -m comment --comment \"none shall pass to db\" -A INPUT -s 0.0.0.0/0 -p tcp --dport 27017 -j REJECT" );
return;
}
if ( request.action == "router-rules" ){
response.setHeader( "Content-Type" , "text/plain" );
db.firewall.find().sort( { host : 1 } ).forEach(
function(z){
print( "permit tcp " + javaStatic( "java.net.InetAddress" , "getByName" , z.host ).getHostAddress() + " any eq 27017 \n" );
}
);
return;
}
if ( request.action == "where" ){
response.setHeader( "Content-Type" , "text/plain" );
db.dbs.find().forEach(
function(z){
print( z.machine + "\n" );
}
);
return;
}
%>
<% local.pieces.header(); %>
<%
if ( request.action == "add" && request.host ){
db.firewall.save( { host : request.host , comment : request.comment } );
}
if ( request.action == "delete" && request.id ){
db.firewall.remove( { _id : request.id } );
}
%>
<div class="container">
<table border="1">
<tr>
<th>Host</th>
<th>Comment</th>
</tr>
<forarray h db.firewall.find().sort( { host : -1 } ).toArray() >
<tr>
<td><%= h.host %></td>
<td><%= h.comment || "&nbsp;" %></td>
<td><A href="/firewall?action=delete&id=<%= h._id %>">delete</a></td>
<tr>
</forarray>
<tr>
<form action="/firewall" method="POST">
<td><input name="host"></td>
<td><input name="comment"></td>
<td><input type="submit" name="action" value="add"></td>
</tr>
</tr>
</table>
<a href="/firewall?action=rules">rules</a> |
<a href="/firewall?action=router-rules">router rules</a>
</div>
<% local.pieces.footer(); %>
Jump to Line
Something went wrong with that request. Please try again.