Changeset 59a80375


Ignore:
Timestamp:
Sep 5, 2005 12:00:11 AM (15 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
3bb445f
Parents:
09cb5fa
git-author:
jrandom <jrandom> (09/05/05 00:00:11)
git-committer:
zzz <zzz@…> (09/05/05 00:00:11)
Message:

allow exporting eepsite destinations from the syndie database into userhosts.txt (so the eepproxy can get it)

Location:
apps/syndie
Files:
2 edited

Legend:

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

    r09cb5fa r59a80375  
    302302        }
    303303    }
     304
     305    public String exportHosts(User user) {
     306        if (!user.getAuthenticated() || !user.getAllowAccessRemote())
     307            return "Not authorized to export the hosts";
     308        Map newNames = new HashMap();
     309        PetNameDB db = user.getPetNameDB();
     310        for (Iterator names = db.getNames().iterator(); names.hasNext(); ) {
     311            PetName pn = db.get((String)names.next());
     312            if (pn == null) continue;
     313            if (pn.getNetwork().equalsIgnoreCase("i2p")) {
     314                try {
     315                    Destination d = new Destination(pn.getLocation().trim());
     316                    newNames.put(pn.getName(), d);
     317                } catch (DataFormatException dfe) {
     318                    // ignore
     319                }
     320            }
     321        }
     322        // horribly inefficient...
     323        for (Iterator iter = newNames.keySet().iterator(); iter.hasNext(); ) {
     324            String name = (String)iter.next();
     325            Destination existing = _context.namingService().lookup(name);
     326            if (existing == null) {
     327                Destination known = (Destination)newNames.get(name);
     328                try {
     329                    FileOutputStream fos = new FileOutputStream("userhosts.txt", true);
     330                    OutputStreamWriter osw = new OutputStreamWriter(fos, "UTF-8");
     331                    osw.write(name + "=" + known.toBase64() + "\n");
     332                    osw.close();
     333                } catch (IOException ioe) {
     334                    ioe.printStackTrace();
     335                    return "Error exporting the hosts: " + ioe.getMessage();
     336                }
     337            }
     338        }
     339        return "Hosts exported";
     340    }
    304341   
    305342    public BlogURI createBlogEntry(User user, String subject, String tags, String entryHeaders, String sml) {
  • apps/syndie/jsp/addresses.jsp

    r09cb5fa r59a80375  
    5353          %><b>Address removed</b><%
    5454        }
     55    } else if ( (action != null) && ("Export".equals(action)) ) {
     56      %><%=BlogManager.instance().exportHosts(user)%><%
    5557    }
    5658    TreeSet sorted = new TreeSet(names.getNames());
     
    171173        <td><input type="submit" name="action" value="Add" /></td>
    172174    </form></tr>
    173     </table><%
     175    <tr><form action="addresses.jsp" method="POST">
     176        <td colspan="7">Export the eepsites to your router's userhosts.txt: <input type="submit" name="action" value="Export" /></td>
     177        </form></tr>
     178    </table>
     179    <%
    174180}
    175181%>
Note: See TracChangeset for help on using the changeset viewer.