Changeset f958342


Ignore:
Timestamp:
Sep 5, 2005 8:53:25 PM (15 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
e6b1457
Parents:
5a1f738
git-author:
jrandom <jrandom> (09/05/05 20:53:25)
git-committer:
zzz <zzz@…> (09/05/05 20:53:25)
Message:

admin page - no more editing config props manually (w3wt)

Location:
apps/syndie
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • apps/syndie/java/src/net/i2p/syndie/Archive.java

    r5a1f738 rf958342  
    9191   
    9292    public String getDefaultSelector() { return _defaultSelector; }
     93    public void setDefaultSelector(String sel) {
     94        if (sel == null)
     95            _defaultSelector = "";
     96        else
     97            _defaultSelector = sel;
     98    }
    9399       
    94100    public BlogInfo getBlogInfo(BlogURI uri) {
  • apps/syndie/java/src/net/i2p/syndie/BlogManager.java

    r5a1f738 rf958342  
    6464    }
    6565   
     66    private File getConfigFile() { return new File(_rootDir, "syndie.config"); }
    6667    private void readConfig() {
    67         File config = new File(_rootDir, "syndie.config");
     68        File config = getConfigFile();
    6869        if (config.exists()) {
    6970            try {
     
    216217   
    217218    /** hash of the password required to register and create a new blog (null means no password required) */
    218     public String getRegistrationPassword() {
     219    public String getRegistrationPasswordHash() {
    219220        String pass = _context.getProperty("syndie.registrationPassword");
    220221        if ( (pass == null) || (pass.trim().length() <= 0) ) return null;
     
    223224   
    224225    /** Password required to access the remote syndication functinoality (null means no password required) */
    225     public String getRemotePassword() {
     226    public String getRemotePasswordHash() {
    226227        String pass = _context.getProperty("syndie.remotePassword");
    227228       
     
    230231        return pass;
    231232    }
     233    public String getAdminPasswordHash() {
     234        String pass = _context.getProperty("syndie.adminPassword");
     235        if ( (pass == null) || (pass.trim().length() <= 0) ) return "";
     236        return pass;
     237    }
     238   
     239    public boolean isConfigured() {
     240        File cfg = getConfigFile();
     241        return (cfg.exists());
     242    }
     243
     244    public String getDefaultProxyHost() { return _context.getProperty("syndie.defaultProxyHost", "localhost"); }
     245    public String getDefaultProxyPort() { return _context.getProperty("syndie.defaultProxyPort", "4444"); }
     246   
     247    public boolean authorizeAdmin(String pass) {
     248        String admin = getAdminPasswordHash();
     249        if ( (admin == null) || (admin.trim().length() <= 0) )
     250            return false;
     251        String hash = Base64.encode(_context.sha().calculateHash(DataHelper.getUTF8(pass.trim())).getData());
     252        return (hash.equals(admin));
     253    }
     254    public boolean authorizeRemote(String pass) {
     255        String rem = getRemotePasswordHash();
     256        if ( (rem == null) || (rem.trim().length() <= 0) )
     257            return false;
     258        String hash = Base64.encode(_context.sha().calculateHash(DataHelper.getUTF8(pass.trim())).getData());
     259        return (hash.equals(rem));
     260    }
     261   
     262    public void configure(String registrationPassword, String remotePassword, String adminPass, String defaultSelector,
     263                          String defaultProxyHost, int defaultProxyPort, Properties opts) {
     264        File cfg = getConfigFile();
     265        Writer out = null;
     266        try {
     267            out = new OutputStreamWriter(new FileOutputStream(cfg), "UTF-8");
     268            if (registrationPassword != null)
     269                out.write("syndie.registrationPassword="+Base64.encode(_context.sha().calculateHash(DataHelper.getUTF8(registrationPassword.trim())).getData()) + "\n");
     270            if (remotePassword != null)
     271                out.write("syndie.remotePassword="+Base64.encode(_context.sha().calculateHash(DataHelper.getUTF8(remotePassword.trim())).getData()) + "\n");
     272            if (adminPass != null)
     273                out.write("syndie.adminPassword="+Base64.encode(_context.sha().calculateHash(DataHelper.getUTF8(adminPass.trim())).getData()) + "\n");
     274            if (defaultSelector != null)
     275                out.write("syndie.defaultSelector="+defaultSelector.trim() + "\n");
     276            if (defaultProxyHost != null)
     277                out.write("syndie.defaultProxyHost="+defaultProxyHost.trim() + "\n");
     278            if (defaultProxyHost != null)
     279                out.write("syndie.defaultProxyHost="+defaultProxyHost.trim() + "\n");
     280            if (defaultProxyPort > 0)
     281                out.write("syndie.defaultProxyPort="+defaultProxyPort + "\n");
     282            if (opts != null) {
     283                for (Iterator iter = opts.keySet().iterator(); iter.hasNext(); ) {
     284                    String key = (String)iter.next();
     285                    String val = opts.getProperty(key);
     286                    out.write(key.trim() + "=" + val.trim() + "\n");
     287                }
     288            }
     289            _archive.setDefaultSelector(defaultSelector);
     290        } catch (IOException ioe) {
     291            ioe.printStackTrace();
     292        } finally {
     293            if (out != null) try { out.close(); } catch (IOException ioe) {}
     294            readConfig();
     295        }
     296    }
    232297   
    233298    public String authorizeRemoteAccess(User user, String password) {
    234299        if (!user.getAuthenticated()) return "Not logged in";
    235         String remPass = getRemotePassword();
     300        String remPass = getRemotePasswordHash();
    236301        if (remPass == null)
    237             return "Remote access password not configured - please specify 'syndie.remotePassword' in your syndie.config";
    238        
    239         if (remPass.equals(password)) {
     302            return "Remote access password not configured - please specify a remote archive password in your syndie.config or on /admin.jsp";
     303       
     304        if (authorizeRemote(password)) {
    240305            user.setAllowAccessRemote(true);
    241306            saveUser(user);
     
    262327    }
    263328    public String register(User user, String login, String password, String registrationPassword, String blogName, String blogDescription, String contactURL) {
    264         System.err.println("Register [" + login + "] pass [" + password + "] name [" + blogName + "] descr [" + blogDescription + "] contact [" + contactURL + "]");
    265         System.err.println("reference bad string: [" + EncodingTestGenerator.TEST_STRING + "]");
    266         String hashedRegistrationPassword = getRegistrationPassword();
     329        System.err.println("Register [" + login + "] pass [" + password + "] name [" + blogName + "] descr [" + blogDescription + "] contact [" + contactURL + "] regPass [" + registrationPassword + "]");
     330        String hashedRegistrationPassword = getRegistrationPasswordHash();
    267331        if (hashedRegistrationPassword != null) {
    268332            try {
  • apps/syndie/jsp/_topnav.jsp

    r5a1f738 rf958342  
    33<td valign="top" align="left" class="syndieTopNavBlogsCell" height="10"><a href="index.jsp">Home</a></td>
    44<td valign="top" align="left" class="syndieTopNavRemoteCell" height="10">
     5<a href="admin.jsp">Syndie admin</a>
    56<a href="remote.jsp">Remote archives</a>
    67<a href="import.jsp">Import</a>
  • apps/syndie/jsp/remote.jsp

    r5a1f738 rf958342  
    2626 <option value="usenet" <%=("usenet".equals(request.getParameter("schema")) ? "selected=\"true\"" : "")%>>Usenet</option>
    2727</select>
    28 Proxy <input type="text" size="10" name="proxyhost" value="localhost" />:<input type="text" size="4" name="proxyport" value="4444" /><br />
     28Proxy <input type="text" size="10" name="proxyhost" value="<%=BlogManager.instance().getDefaultProxyHost()%>" />:<input type="text" size="4" name="proxyport" value="<%=BlogManager.instance().getDefaultProxyPort()%>" /><br />
    2929Bookmarked archives: <select name="archivepetname"><option value="">Custom location</option><%
    3030for (Iterator iter = user.getPetNameDB().getNames().iterator(); iter.hasNext(); ) {
Note: See TracChangeset for help on using the changeset viewer.