From 7f6aa327f268afaf102c542f167dad9817396e6b Mon Sep 17 00:00:00 2001 From: jrandom <jrandom> Date: Fri, 11 Nov 2005 12:26:17 +0000 Subject: [PATCH] allow the user to override what login/pass is used for the default user in single user mode --- .../java/src/net/i2p/syndie/BlogManager.java | 33 ++++++++++++++++--- apps/syndie/jsp/admin.jsp | 12 +++++-- 2 files changed, 39 insertions(+), 6 deletions(-) diff --git a/apps/syndie/java/src/net/i2p/syndie/BlogManager.java b/apps/syndie/java/src/net/i2p/syndie/BlogManager.java index 56a90377e8..bdab2cae64 100644 --- a/apps/syndie/java/src/net/i2p/syndie/BlogManager.java +++ b/apps/syndie/java/src/net/i2p/syndie/BlogManager.java @@ -432,6 +432,22 @@ public class BlogManager { private static final String DEFAULT_LOGIN = "default"; private static final String DEFAULT_PASS = ""; + private static final String PROP_DEFAULT_LOGIN = "syndie.defaultSingleUserLogin"; + private static final String PROP_DEFAULT_PASS = "syndie.defaultSingleUserPass"; + + private String getDefaultLogin() { + String login = _context.getProperty(PROP_DEFAULT_LOGIN); + if ( (login == null) || (login.trim().length() <= 0) ) + login = DEFAULT_LOGIN; + return login; + } + private String getDefaultPass() { + String pass = _context.getProperty(PROP_DEFAULT_PASS); + if ( (pass == null) || (pass.trim().length() <= 0) ) + pass = DEFAULT_PASS; + return pass; + } + public User getDefaultUser() { User user = new User(_context); getDefaultUser(user); @@ -439,7 +455,7 @@ public class BlogManager { } public void getDefaultUser(User user) { if (isSingleUser()) { - Hash userHash = _context.sha().calculateHash(DataHelper.getUTF8(DEFAULT_LOGIN)); + Hash userHash = _context.sha().calculateHash(DataHelper.getUTF8(getDefaultLogin())); File userFile = new File(_userDir, Base64.encode(userHash.getData())); if (_log.shouldLog(Log.INFO)) _log.info("Attempting to login to the default user: " + userFile.getAbsolutePath()); @@ -451,7 +467,7 @@ public class BlogManager { _log.error("Error reading the default user file: " + userFile); return; } - String ok = user.login(DEFAULT_LOGIN, DEFAULT_PASS, props); + String ok = user.login(getDefaultLogin(), getDefaultPass(), props); if (User.LOGIN_OK.equals(ok)) { return; } else { @@ -460,7 +476,7 @@ public class BlogManager { return; } } else { - String ok = register(user, DEFAULT_LOGIN, DEFAULT_PASS, "", "default", "Default Syndie blog", ""); + String ok = register(user, getDefaultLogin(), getDefaultPass(), "", "default", "Default Syndie blog", ""); if (User.LOGIN_OK.equals(ok)) { _log.info("Default user created: " + user); return; @@ -497,7 +513,8 @@ public class BlogManager { } public void configure(String registrationPassword, String remotePassword, String adminPass, String defaultSelector, - String defaultProxyHost, int defaultProxyPort, boolean isSingleUser, Properties opts) { + String defaultProxyHost, int defaultProxyPort, boolean isSingleUser, Properties opts, + String defaultUser, String defaultPass) { File cfg = getConfigFile(); Writer out = null; try { @@ -514,6 +531,14 @@ public class BlogManager { out.write("syndie.defaultProxyHost="+defaultProxyHost.trim() + "\n"); if (defaultProxyPort > 0) out.write("syndie.defaultProxyPort="+defaultProxyPort + "\n"); + + if ( (defaultUser == null) || (defaultUser.length() <= 0) ) + defaultUser = getDefaultLogin(); + if (defaultPass == null) + defaultPass = getDefaultPass(); + out.write("syndie.defaultSingleUserLogin="+defaultUser+"\n"); + out.write("syndie.defaultSingleUserPass="+defaultPass+"\n"); + out.write("syndie.singleUser=" + isSingleUser + "\n"); // Used also in isConfigured() if (opts != null) { for (Iterator iter = opts.keySet().iterator(); iter.hasNext(); ) { diff --git a/apps/syndie/jsp/admin.jsp b/apps/syndie/jsp/admin.jsp index 7fd2ae6715..28a208b58e 100644 --- a/apps/syndie/jsp/admin.jsp +++ b/apps/syndie/jsp/admin.jsp @@ -31,12 +31,15 @@ if (!user.getAuthenticated()) { 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); + 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><% @@ -44,7 +47,7 @@ if (!user.getAuthenticated()) { } 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); + BlogManager.instance().configure(regPass, remotePass, adminPass, selector, proxyHost, port, isSingleUser, null, defaultUser, defaultPass); %><span class="b_adminMsgOk">Configuration saved</span><% } } else { @@ -53,6 +56,11 @@ if (!user.getAuthenticated()) { <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 /> -- GitLab