move the admin page over to the new system

This commit is contained in:
jrandom
2005-11-13 11:04:17 +00:00
committed by zzz
parent 1159c155a4
commit 16fd46db2b
5 changed files with 115 additions and 107 deletions

View File

@ -452,7 +452,7 @@ public class BlogManager {
login = DEFAULT_LOGIN;
return login;
}
private String getDefaultPass() {
public String getDefaultPass() {
String pass = _context.getProperty(PROP_DEFAULT_PASS);
if ( (pass == null) || (pass.trim().length() <= 0) )
pass = DEFAULT_PASS;

View File

@ -0,0 +1,74 @@
package net.i2p.syndie.web;
import java.io.*;
import java.util.*;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletException;
import net.i2p.I2PAppContext;
import net.i2p.client.naming.*;
import net.i2p.data.*;
import net.i2p.syndie.*;
import net.i2p.syndie.data.*;
import net.i2p.syndie.sml.*;
/**
* Admin form
*
*/
public class AdminServlet extends BaseServlet {
protected void renderServletDetails(User user, HttpServletRequest req, PrintWriter out, ThreadIndex index,
int threadOffset, BlogURI visibleEntry, Archive archive) throws IOException {
if (BlogManager.instance().authorizeRemote(user)) {
displayForm(user, req, out);
} else {
out.write("<tr><td colspan=\"3\"><span class=\"b_adminMsgErr\">You are not authorized to configure this Syndie instance</span></td></tr>\n");
}
}
private void displayForm(User user, HttpServletRequest req, PrintWriter out) throws IOException {
out.write("<form action=\"" + req.getRequestURI() + "\" method=\"POST\">\n");
out.write("<tr><td colspan=\"3\">");
out.write("<em class=\"b_adminField\">Single user?</em> <input type=\"checkbox\" class=\"b_adminField\" name=\"singleuser\" ");
if (BlogManager.instance().isSingleUser())
out.write(" checked=\"true\" ");
out.write(" /><br />\n");
out.write("<span class=\"b_adminDescr\">If this is checked, the registration, admin, and remote passwords are unnecessary - anyone");
out.write("can register and administer Syndie, as well as use any remote functionality. This should not be checked if untrusted");
out.write("parties can access this web interface.</span><br />\n");
out.write("<span class=\"b_adminField\">Default user:</span> <input class=\"b_adminField\" type=\"text\" name=\"defaultUser\" size=\"10\" value=\"");
out.write(BlogManager.instance().getDefaultLogin());
out.write("\" />\n");
out.write("<span class=\"b_adminField\">pass:</span> <input class=\"b_adminField\" type=\"text\" name=\"defaultPass\" size=\"10\" value=\"");
out.write(BlogManager.instance().getDefaultPass());
out.write("\"/><br />\n");
out.write("<span class=\"b_adminDescr\">If Syndie is in single user mode, it will create a new 'default' user automatically and use that ");
out.write("whenever you access Syndie unless you explicitly log in to another account. If you want Syndie to use an existing account as ");
out.write("your default account, you can specify them here, in which case it will automatically log you in under that account.</span><br />\n");
out.write("<em class=\"b_adminField\">Registration password:</em> <input class=\"b_adminField\" type=\"text\" name=\"regpass\" size=\"10\" value=\"\" /><br />\n");
out.write("<span class=\"b_adminDescr\">Users must specify this password on the registration form to proceed. If this is ");
out.write("blank, anyone can register.</span><br />\n");
out.write("<em class=\"b_adminField\">Remote password:</em> <input class=\"b_adminField\" type=\"text\" name=\"remotepass\" size=\"10\" value=\"\" /><br />\n");
out.write("<span class=\"b_adminDescr\">To access remote archives, users must first provide this password on their ");
out.write("metadata page. Remote access is 'dangerous', as it allows the user to instruct ");
out.write("this Syndie instance to establish HTTP connections with arbitrary locations. If ");
out.write("this field is not specified, no one can use remote archives.</span><br />\n");
out.write("<em class=\"b_adminField\">Default remote proxy host:</em> <input class=\"b_adminField\" type=\"text\" name=\"proxyhost\" size=\"20\" value=\"");
out.write(BlogManager.instance().getDefaultProxyHost());
out.write("\" /><br />\n");
out.write("<em class=\"b_adminField\">Default remote proxy port:</em> <input class=\"b_adminField\" type=\"text\" name=\"proxyport\" size=\"5\" value=\"");
out.write(BlogManager.instance().getDefaultProxyPort());
out.write("\" /><br />\n");
out.write("<span class=\"b_adminDescr\">This is the default HTTP proxy shown on the remote archive page.</span><br />\n");
out.write("<hr />\n");
out.write("<input class=\"b_adminSave\" type=\"submit\" name=\"action\" value=\"Save config\" />\n");
out.write("</td></tr>\n");
out.write("</form>\n");
}
}

View File

@ -60,6 +60,8 @@ public abstract class BaseServlet extends HttpServlet {
req.getSession().setAttribute("user", user);
handleAdmin(user, req);
forceNewIndex = handleAddressbook(user, req) || forceNewIndex;
forceNewIndex = handleBookmarking(user, req) || forceNewIndex;
handleUpdateProfile(user, req);
@ -346,6 +348,31 @@ public abstract class BaseServlet extends HttpServlet {
}
}
private void handleAdmin(User user, HttpServletRequest req) throws IOException {
if (BlogManager.instance().authorizeRemote(user)) {
String action = req.getParameter("action");
if ( (action != null) && ("Save config".equals(action)) ) {
boolean wantSingle = !empty(req, "singleuser");
String defaultUser = req.getParameter("defaultUser");
String defaultPass = req.getParameter("defaultPass");
String regPass = req.getParameter("regpass");
String remotePass = req.getParameter("remotepass");
String proxyHost = req.getParameter("proxyhost");
String proxyPort = req.getParameter("proxyport");
// default user cannot be empty, but the rest can be blank
if ( (!empty(defaultUser)) && (defaultPass != null) && (regPass != null) && (remotePass != null) &&
(proxyHost != null) && (proxyPort != null) ) {
int port = 4444;
try { port = Integer.parseInt(proxyPort); } catch (NumberFormatException nfe) {}
BlogManager.instance().configure(regPass, remotePass, null, null, proxyHost, port, wantSingle,
null, defaultUser, defaultPass);
}
}
}
}
protected void render(User user, HttpServletRequest req, PrintWriter out, ThreadIndex index) throws ServletException, IOException {
Archive archive = BlogManager.instance().getArchive();
int numThreads = 10;
@ -375,7 +402,7 @@ public abstract class BaseServlet extends HttpServlet {
}
protected void renderBegin(User user, HttpServletRequest req, PrintWriter out, ThreadIndex index) throws IOException {
out.write(BEGIN_HTML);
out.write("<html>\n<head><title>" + getTitle() + "</title>\n" + BEGIN_HTML);
}
protected void renderNavBar(User user, HttpServletRequest req, PrintWriter out, ThreadIndex index) throws IOException {
//out.write("<tr class=\"topNav\"><td class=\"topNav_user\" colspan=\"2\" nowrap=\"true\">\n");
@ -770,10 +797,7 @@ public abstract class BaseServlet extends HttpServlet {
}
}
private static final String BEGIN_HTML = "<html>\n" +
"<head>\n" +
"<title>Syndie</title>\n" +
"<style>\n" +
private static final String BEGIN_HTML = "<style>\n" +
".overallTable {\n" +
" border-spacing: 0px;\n" +
" border-width: 0px;\n" +
@ -855,6 +879,8 @@ public abstract class BaseServlet extends HttpServlet {
private static final String END_HTML = "</table>\n" +
"</body>\n";
protected String getTitle() { return "Syndie"; }
protected static class TreeRenderState {
private int _rowsWritten;
private int _rowsSkipped;

View File

@ -1,101 +0,0 @@
<%@page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" import="net.i2p.data.Base64, net.i2p.syndie.web.*, net.i2p.syndie.sml.*, net.i2p.syndie.data.*, net.i2p.syndie.*, org.mortbay.servlet.MultiPartRequest, java.util.*, java.io.*" %><%
request.setCharacterEncoding("UTF-8");
%><jsp:useBean scope="session" class="net.i2p.syndie.User" id="user"
/><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 TRANSITIONAL//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd"><html>
<head>
<title>SyndieMedia admin</title>
<link href="style.jsp" rel="stylesheet" type="text/css" >
</head>
<body>
<table border="1" cellpadding="0" cellspacing="0" width="100%">
<tr class="b_toplogo"><td colspan="5" valign="top" align="left" class="b_toplogo"><jsp:include page="_toplogo.jsp" /></td></tr>
<tr><td valign="top" align="left" rowspan="2" class="b_leftnav"><jsp:include page="_leftnav.jsp" /></td>
<jsp:include page="_topnav.jsp" />
<td valign="top" align="left" rowspan="2" class="b_rightnav"><jsp:include page="_rightnav.jsp" /></td></tr>
<tr class="b_content"><td valign="top" align="left" colspan="3" class="b_content"><%
if (!user.getAuthenticated()) {
%><span class="b_adminMsgErr">You must be logged in to configure your Syndie instance!</span><%
} else {
String action = request.getParameter("action");
if ( (action != null) && ("Save".equals(action)) ) {
boolean configured = BlogManager.instance().isConfigured();
String adminPass = request.getParameter("adminpass");
String regPass = request.getParameter("regpass");
String remotePass = request.getParameter("remotepass");
String proxyHost = request.getParameter("proxyhost");
String proxyPort = request.getParameter("proxyport");
String selector = request.getParameter("selector");
boolean isSingleUser = BlogManager.instance().isSingleUser();
String singleSet = request.getParameter("singleuser");
if (singleSet != null)
isSingleUser = true;
else
isSingleUser = false;
String defaultUser = request.getParameter("defaultUser");
String defaultPass = request.getParameter("defaultPass");
if (configured) {
if (BlogManager.instance().authorizeAdmin(adminPass)) {
int port = -1;
try { port = Integer.parseInt(proxyPort); } catch (NumberFormatException nfe) { port = 4444; }
BlogManager.instance().configure(regPass, remotePass, adminPass, selector, proxyHost, port, isSingleUser, null, defaultUser, defaultPass);
%><span class="b_adminMsgOk">Configuration updated</span><%
} else {
%><span class="b_adminMsgErr">Invalid admin password. If you lost it, please update your syndie.config.</span><%
}
} else {
int port = -1;
try { port = Integer.parseInt(proxyPort); } catch (NumberFormatException nfe) { port = 4444; }
BlogManager.instance().configure(regPass, remotePass, adminPass, selector, proxyHost, port, isSingleUser, null, defaultUser, defaultPass);
%><span class="b_adminMsgOk">Configuration saved</span><%
}
} else {
%><form action="admin.jsp" method="POST">
<em class="b_adminField">Single user?</em> <input type="checkbox" class="b_adminField" name="singleuser" <%=BlogManager.instance().isSingleUser() ? " checked=\"true\" " : ""%> /><br />
<span class="b_adminDescr">If this is checked, the registration, admin, and remote passwords are unnecessary - anyone
can register and administer Syndie, as well as use any remote functionality. This should not be checked if untrusted
parties can access this web interface.</span><br />
<span class="b_adminField">Default user:</span> <input class="b_adminField" type="text" name="defaultUser" size="10" />
<span class="b_adminField">pass:</span> <input class="b_adminField" type="password" name="defaultPass" size="10" /><br />
<span class="b_adminDescr">If Syndie is in single user mode, it will create a new 'default' user automatically and use that
whenever you access Syndie unless you explicitly log in to another account. If you want Syndie to use an existing account as
your default account, you can specify them here, in which case it will automatically log you in under that account.</span><br />
<em class="b_adminField">Registration password:</em> <input class="b_adminField" type="text" name="regpass" size="10" /><br />
<span class="b_adminDescr">Users must specify this password on the registration form to proceed. If this is
blank, anyone can register.</span><br />
<em class="b_adminField">Remote password:</em> <input class="b_adminField" type="text" name="remotepass" size="10" /><br />
<span class="b_adminDescr">To access remote archives, users must first provide this password on their
metadata page. Remote access is 'dangerous', as it allows the user to instruct
this Syndie instance to establish HTTP connections with arbitrary locations. If
this field is not specified, no one can use remote archives.</span><br />
<em class="b_adminField">Default remote proxy host:</em> <input class="b_adminField" type="text" name="proxyhost" size="20" value="localhost" /><br />
<em class="b_adminField">Default remote proxy port:</em> <input class="b_adminField" type="text" name="proxyport" size="5" value="4444" /><br />
<span class="b_adminDescr">This is the default HTTP proxy shown on the remote archive page.</span><br />
<em class="b_adminField">Default blog selector:</em> <input class="b_adminField" type="text" name="selector" size="40" value="ALL" /><br />
<span class="b_adminDescr">The selector lets you choose what blog (or blogs) are shown on the front page for
new, unregistered users. Valid values include:<ul class="b_adminDescr">
<li class="b_adminDescr"><code class="b_adminDescr">ALL</code>: all blogs</li>
<li class="b_adminDescr"><code class="b_adminDescr">blog://$blogHash</code>: all posts in the blog identified by $blogHash</li>
<li class="b_adminDescr"><code class="b_adminDescr">blogtag://$blogHash/$tagBase64</code>: all posts in the blog identified by $blogHash
tagged by the tag whose modified base64 encoding is $tagBase64</li>
<li class="b_adminDescr"><code class="b_adminDescr">tag://$tagBase64</code>: all posts in any blog tagged by the tag whose
modified base64 encoding is $tagBase64</li>
</ul>
</span>
<hr />
<% if (!BlogManager.instance().isConfigured()) {
long passNum = new Random().nextLong(); %>
<em class="b_adminField">Administrative password:</em> <input class="b_adminField" type="password" name="adminpass" size="10" value="<%=passNum%>" /> <br />
<span class="b_adminDescr b_adminDescrFirstRun">Since this Syndie instance is not already configured, you can specify a new
administrative password which must be presented whenever you update this configuration.
The default value filled in there is <code class="b_adminDescr b_adminDescrFirstRun"><%=passNum%></code></span><br />
<% } else { %>
<em class="b_adminField">Administrative password:</em> <input class="b_adminField" type="password" name="adminpass" size="10" value="" /> <br />
<% } %>
<input class="b_adminSave" type="submit" name="action" value="Save" />
<% }
} %>
</td></tr>
</table>
</body>

View File

@ -39,6 +39,11 @@
<servlet-class>net.i2p.syndie.web.PostServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>net.i2p.syndie.web.AdminServlet</servlet-name>
<servlet-class>net.i2p.syndie.web.AdminServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>net.i2p.syndie.UpdaterServlet</servlet-name>
<servlet-class>net.i2p.syndie.UpdaterServlet</servlet-class>
@ -81,6 +86,10 @@
<servlet-name>net.i2p.syndie.web.PostServlet</servlet-name>
<url-pattern>/post.jsp</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>net.i2p.syndie.web.AdminServlet</servlet-name>
<url-pattern>/admin.jsp</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>