forked from I2P_Developers/i2p.i2p
admin page - no more editing config props manually (w3wt)
This commit is contained in:
@@ -90,6 +90,12 @@ public class Archive {
|
||||
}
|
||||
|
||||
public String getDefaultSelector() { return _defaultSelector; }
|
||||
public void setDefaultSelector(String sel) {
|
||||
if (sel == null)
|
||||
_defaultSelector = "";
|
||||
else
|
||||
_defaultSelector = sel;
|
||||
}
|
||||
|
||||
public BlogInfo getBlogInfo(BlogURI uri) {
|
||||
if (uri == null) return null;
|
||||
|
||||
@@ -63,8 +63,9 @@ public class BlogManager {
|
||||
_archive.regenerateIndex();
|
||||
}
|
||||
|
||||
private File getConfigFile() { return new File(_rootDir, "syndie.config"); }
|
||||
private void readConfig() {
|
||||
File config = new File(_rootDir, "syndie.config");
|
||||
File config = getConfigFile();
|
||||
if (config.exists()) {
|
||||
try {
|
||||
Properties p = new Properties();
|
||||
@@ -215,28 +216,92 @@ public class BlogManager {
|
||||
}
|
||||
|
||||
/** hash of the password required to register and create a new blog (null means no password required) */
|
||||
public String getRegistrationPassword() {
|
||||
public String getRegistrationPasswordHash() {
|
||||
String pass = _context.getProperty("syndie.registrationPassword");
|
||||
if ( (pass == null) || (pass.trim().length() <= 0) ) return null;
|
||||
return pass;
|
||||
}
|
||||
|
||||
/** Password required to access the remote syndication functinoality (null means no password required) */
|
||||
public String getRemotePassword() {
|
||||
public String getRemotePasswordHash() {
|
||||
String pass = _context.getProperty("syndie.remotePassword");
|
||||
|
||||
System.out.println("Remote password? [" + pass + "]");
|
||||
if ( (pass == null) || (pass.trim().length() <= 0) ) return null;
|
||||
return pass;
|
||||
}
|
||||
public String getAdminPasswordHash() {
|
||||
String pass = _context.getProperty("syndie.adminPassword");
|
||||
if ( (pass == null) || (pass.trim().length() <= 0) ) return "";
|
||||
return pass;
|
||||
}
|
||||
|
||||
public boolean isConfigured() {
|
||||
File cfg = getConfigFile();
|
||||
return (cfg.exists());
|
||||
}
|
||||
|
||||
public String getDefaultProxyHost() { return _context.getProperty("syndie.defaultProxyHost", "localhost"); }
|
||||
public String getDefaultProxyPort() { return _context.getProperty("syndie.defaultProxyPort", "4444"); }
|
||||
|
||||
public boolean authorizeAdmin(String pass) {
|
||||
String admin = getAdminPasswordHash();
|
||||
if ( (admin == null) || (admin.trim().length() <= 0) )
|
||||
return false;
|
||||
String hash = Base64.encode(_context.sha().calculateHash(DataHelper.getUTF8(pass.trim())).getData());
|
||||
return (hash.equals(admin));
|
||||
}
|
||||
public boolean authorizeRemote(String pass) {
|
||||
String rem = getRemotePasswordHash();
|
||||
if ( (rem == null) || (rem.trim().length() <= 0) )
|
||||
return false;
|
||||
String hash = Base64.encode(_context.sha().calculateHash(DataHelper.getUTF8(pass.trim())).getData());
|
||||
return (hash.equals(rem));
|
||||
}
|
||||
|
||||
public void configure(String registrationPassword, String remotePassword, String adminPass, String defaultSelector,
|
||||
String defaultProxyHost, int defaultProxyPort, Properties opts) {
|
||||
File cfg = getConfigFile();
|
||||
Writer out = null;
|
||||
try {
|
||||
out = new OutputStreamWriter(new FileOutputStream(cfg), "UTF-8");
|
||||
if (registrationPassword != null)
|
||||
out.write("syndie.registrationPassword="+Base64.encode(_context.sha().calculateHash(DataHelper.getUTF8(registrationPassword.trim())).getData()) + "\n");
|
||||
if (remotePassword != null)
|
||||
out.write("syndie.remotePassword="+Base64.encode(_context.sha().calculateHash(DataHelper.getUTF8(remotePassword.trim())).getData()) + "\n");
|
||||
if (adminPass != null)
|
||||
out.write("syndie.adminPassword="+Base64.encode(_context.sha().calculateHash(DataHelper.getUTF8(adminPass.trim())).getData()) + "\n");
|
||||
if (defaultSelector != null)
|
||||
out.write("syndie.defaultSelector="+defaultSelector.trim() + "\n");
|
||||
if (defaultProxyHost != null)
|
||||
out.write("syndie.defaultProxyHost="+defaultProxyHost.trim() + "\n");
|
||||
if (defaultProxyHost != null)
|
||||
out.write("syndie.defaultProxyHost="+defaultProxyHost.trim() + "\n");
|
||||
if (defaultProxyPort > 0)
|
||||
out.write("syndie.defaultProxyPort="+defaultProxyPort + "\n");
|
||||
if (opts != null) {
|
||||
for (Iterator iter = opts.keySet().iterator(); iter.hasNext(); ) {
|
||||
String key = (String)iter.next();
|
||||
String val = opts.getProperty(key);
|
||||
out.write(key.trim() + "=" + val.trim() + "\n");
|
||||
}
|
||||
}
|
||||
_archive.setDefaultSelector(defaultSelector);
|
||||
} catch (IOException ioe) {
|
||||
ioe.printStackTrace();
|
||||
} finally {
|
||||
if (out != null) try { out.close(); } catch (IOException ioe) {}
|
||||
readConfig();
|
||||
}
|
||||
}
|
||||
|
||||
public String authorizeRemoteAccess(User user, String password) {
|
||||
if (!user.getAuthenticated()) return "Not logged in";
|
||||
String remPass = getRemotePassword();
|
||||
String remPass = getRemotePasswordHash();
|
||||
if (remPass == null)
|
||||
return "Remote access password not configured - please specify 'syndie.remotePassword' in your syndie.config";
|
||||
return "Remote access password not configured - please specify a remote archive password in your syndie.config or on /admin.jsp";
|
||||
|
||||
if (remPass.equals(password)) {
|
||||
if (authorizeRemote(password)) {
|
||||
user.setAllowAccessRemote(true);
|
||||
saveUser(user);
|
||||
return "Remote access authorized";
|
||||
@@ -261,9 +326,8 @@ public class BlogManager {
|
||||
}
|
||||
}
|
||||
public String register(User user, String login, String password, String registrationPassword, String blogName, String blogDescription, String contactURL) {
|
||||
System.err.println("Register [" + login + "] pass [" + password + "] name [" + blogName + "] descr [" + blogDescription + "] contact [" + contactURL + "]");
|
||||
System.err.println("reference bad string: [" + EncodingTestGenerator.TEST_STRING + "]");
|
||||
String hashedRegistrationPassword = getRegistrationPassword();
|
||||
System.err.println("Register [" + login + "] pass [" + password + "] name [" + blogName + "] descr [" + blogDescription + "] contact [" + contactURL + "] regPass [" + registrationPassword + "]");
|
||||
String hashedRegistrationPassword = getRegistrationPasswordHash();
|
||||
if (hashedRegistrationPassword != null) {
|
||||
try {
|
||||
if (!hashedRegistrationPassword.equals(Base64.encode(_context.sha().calculateHash(registrationPassword.getBytes("UTF-8")).getData())))
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
<jsp:useBean scope="session" class="net.i2p.syndie.User" id="user" />
|
||||
<td valign="top" align="left" class="syndieTopNavBlogsCell" height="10"><a href="index.jsp">Home</a></td>
|
||||
<td valign="top" align="left" class="syndieTopNavRemoteCell" height="10">
|
||||
<a href="admin.jsp">Syndie admin</a>
|
||||
<a href="remote.jsp">Remote archives</a>
|
||||
<a href="import.jsp">Import</a>
|
||||
</td>
|
||||
|
||||
@@ -25,7 +25,7 @@ if (!user.getAuthenticated() || !user.getAllowAccessRemote()) {
|
||||
<option value="feedspace" <%=("feedspace".equals(request.getParameter("schema")) ? "selected=\"true\"" : "")%>>Feedspace</option>
|
||||
<option value="usenet" <%=("usenet".equals(request.getParameter("schema")) ? "selected=\"true\"" : "")%>>Usenet</option>
|
||||
</select>
|
||||
Proxy <input type="text" size="10" name="proxyhost" value="localhost" />:<input type="text" size="4" name="proxyport" value="4444" /><br />
|
||||
Proxy <input type="text" size="10" name="proxyhost" value="<%=BlogManager.instance().getDefaultProxyHost()%>" />:<input type="text" size="4" name="proxyport" value="<%=BlogManager.instance().getDefaultProxyPort()%>" /><br />
|
||||
Bookmarked archives: <select name="archivepetname"><option value="">Custom location</option><%
|
||||
for (Iterator iter = user.getPetNameDB().getNames().iterator(); iter.hasNext(); ) {
|
||||
PetName pn = user.getPetNameDB().get((String)iter.next());
|
||||
|
||||
Reference in New Issue
Block a user