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

This commit is contained in:
jrandom
2005-09-05 00:00:11 +00:00
committed by zzz
parent 09cb5fad59
commit 59a8037599
2 changed files with 44 additions and 1 deletions

View File

@ -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);

View File

@ -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>