I2P Address: [http://git.idk.i2p]

Skip to content
Snippets Groups Projects
Commit 59a80375 authored by jrandom's avatar jrandom Committed by zzz
Browse files

allow exporting eepsite destinations from the syndie database into...

allow exporting eepsite destinations from the syndie database into userhosts.txt (so the eepproxy can get it)
parent 09cb5fad
No related branches found
No related tags found
No related merge requests found
......@@ -301,6 +301,43 @@ public class BlogManager {
return loginResult;
}
}
public String exportHosts(User user) {
if (!user.getAuthenticated() || !user.getAllowAccessRemote())
return "Not authorized to export the hosts";
Map newNames = new HashMap();
PetNameDB db = user.getPetNameDB();
for (Iterator names = db.getNames().iterator(); names.hasNext(); ) {
PetName pn = db.get((String)names.next());
if (pn == null) continue;
if (pn.getNetwork().equalsIgnoreCase("i2p")) {
try {
Destination d = new Destination(pn.getLocation().trim());
newNames.put(pn.getName(), d);
} catch (DataFormatException dfe) {
// ignore
}
}
}
// horribly inefficient...
for (Iterator iter = newNames.keySet().iterator(); iter.hasNext(); ) {
String name = (String)iter.next();
Destination existing = _context.namingService().lookup(name);
if (existing == null) {
Destination known = (Destination)newNames.get(name);
try {
FileOutputStream fos = new FileOutputStream("userhosts.txt", true);
OutputStreamWriter osw = new OutputStreamWriter(fos, "UTF-8");
osw.write(name + "=" + known.toBase64() + "\n");
osw.close();
} catch (IOException ioe) {
ioe.printStackTrace();
return "Error exporting the hosts: " + ioe.getMessage();
}
}
}
return "Hosts exported";
}
public BlogURI createBlogEntry(User user, String subject, String tags, String entryHeaders, String sml) {
return createBlogEntry(user, subject, tags, entryHeaders, sml, null, null, null);
......
......@@ -52,6 +52,8 @@ if (!user.getAuthenticated()) {
names.store(user.getAddressbookLocation());
%><b>Address removed</b><%
}
} else if ( (action != null) && ("Export".equals(action)) ) {
%><%=BlogManager.instance().exportHosts(user)%><%
}
TreeSet sorted = new TreeSet(names.getNames());
%><table border="0" width="100%">
......@@ -170,7 +172,11 @@ if (!user.getAuthenticated()) {
<td><input type="text" name="groups" size="10" /></td>
<td><input type="submit" name="action" value="Add" /></td>
</form></tr>
</table><%
<tr><form action="addresses.jsp" method="POST">
<td colspan="7">Export the eepsites to your router's userhosts.txt: <input type="submit" name="action" value="Export" /></td>
</form></tr>
</table>
<%
}
%>
</td></tr>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment