Changeset ce043943
- Timestamp:
- Mar 23, 2019 4:42:37 PM (2 years ago)
- Branches:
- master
- Children:
- 64039ee
- Parents:
- fea5bd4
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
apps/susidns/src/build.xml
rfea5bd4 rce043943 98 98 <replacefilter token="<!-- precompiled servlets -->" value="${jspc.web.fragment}" /> 99 99 </replace> 100 <!-- Add multipart config to servlets that need them --> 101 <property name="__match1" value="<servlet-class>i2p.susi.dns.jsp." /> 102 <property name="__match2" value="_jsp</servlet-class>" /> 103 <property name="__class1" value="${__match1}addressbook${__match2}" /> 104 <property name="__multipart" value=" 105 <multipart-config> 106 <max-file-size>67108864</max-file-size> 107 <max-request-size>67108864</max-request-size> 108 <file-size-threshold>262144</file-size-threshold> 109 </multipart-config>" /> 110 <replace file="WEB-INF/web-out.xml"> 111 <replacefilter token="${__class1}" value="${__class1}${__multipart}" /> 112 </replace> 100 113 </target> 101 114 -
apps/susidns/src/java/src/i2p/susi/dns/NamingServiceBean.java
rfea5bd4 rce043943 22 22 package i2p.susi.dns; 23 23 24 import java.io.File; 25 import java.io.FileOutputStream; 24 26 import java.io.IOException; 27 import java.io.InputStream; 28 import java.io.OutputStream; 25 29 import java.io.Writer; 26 30 import java.util.Arrays; … … 35 39 36 40 import net.i2p.client.naming.NamingService; 41 import net.i2p.client.naming.SingleFileNamingService; 37 42 import net.i2p.data.DataFormatException; 38 43 import net.i2p.data.DataHelper; 39 44 import net.i2p.data.Destination; 45 import net.i2p.servlet.RequestWrapper; 40 46 41 47 /** … … 357 363 358 364 if( message.length() > 0 ) 359 message = "<p class=\"messages\">" + message + "</p>";365 message = styleMessage(message); 360 366 return message; 361 367 } … … 496 502 497 503 /** 504 * @return messages about this action 505 * @since 0.9.40 506 */ 507 public String importFile(RequestWrapper wrequest) throws IOException { 508 String message = ""; 509 InputStream in = wrequest.getInputStream("file"); 510 OutputStream out = null; 511 File tmp = null; 512 SingleFileNamingService sfns = null; 513 try { 514 // non-null but zero bytes if no file entered, don't know why 515 if (in == null || in.available() <= 0) { 516 return styleMessage(_t("You must enter a file")); 517 } 518 // copy to temp file 519 tmp = new File(_context.getTempDir(), "susidns-import-" + _context.random().nextLong() + ".txt"); 520 out = new FileOutputStream(tmp); 521 DataHelper.copy(in, out); 522 in.close(); 523 in = null; 524 out.close(); 525 out = null; 526 // new SingleFileNamingService 527 sfns = new SingleFileNamingService(_context, tmp.getAbsolutePath()); 528 // getEntries, copy over 529 Map<String, Destination> entries = sfns.getEntries(); 530 int count = entries.size(); 531 if (count <= 0) { 532 return styleMessage(_t("No entries found in file")); 533 } else { 534 NamingService service = getNamingService(); 535 int added = 0, dup = 0; 536 Properties nsOptions = new Properties(); 537 nsOptions.setProperty("list", getFileName()); 538 String now = Long.toString(_context.clock().now()); 539 nsOptions.setProperty("m", now); 540 String filename = wrequest.getFilename("file"); 541 if (filename != null) 542 nsOptions.setProperty("s", _t("Imported from file {0}", filename)); 543 else 544 nsOptions.setProperty("s", _t("Imported from file")); 545 for (Map.Entry<String, Destination> e : entries.entrySet()) { 546 String host = e.getKey(); 547 Destination dest = e.getValue(); 548 boolean ok = service.putIfAbsent(host, dest, nsOptions); 549 if (ok) 550 added++; 551 else 552 dup++; 553 } 554 StringBuilder buf = new StringBuilder(128); 555 if (added > 0) 556 buf.append(styleMessage(ngettext("Loaded {0} entry from file", 557 "Loaded {0} entries from file", 558 added))); 559 if (dup > 0) 560 buf.append(styleMessage(ngettext("Skipped {0} duplicate entry from file", 561 "Skipped {0} duplicate entries from file", 562 dup))); 563 return buf.toString(); 564 } 565 } catch (IOException ioe) { 566 return styleMessage(_t("Import from file failed") + " - " + ioe); 567 } finally { 568 if (in != null) 569 try { in.close(); } catch (IOException ioe) {} 570 if (out != null) 571 try { out.close(); } catch (IOException ioe) {} 572 // shutdown SFNS 573 if (sfns != null) 574 sfns.shutdown(); 575 if (tmp != null) 576 tmp.delete(); 577 } 578 } 579 580 /** 581 * @since 0.9.40 582 */ 583 private static String styleMessage(String message) { 584 return "<p class=\"messages\">" + message + "</p>"; 585 } 586 587 /** 498 588 * @since 0.9.34 499 589 */ -
apps/susidns/src/jsp/addressbook.jsp
rfea5bd4 rce043943 35 35 response.setHeader("Accept-Ranges", "none"); 36 36 37 %> 38 <%@page pageEncoding="UTF-8"%> 39 <%@ page contentType="text/html"%> 40 <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> 37 %><%@page pageEncoding="UTF-8" contentType="text/html" import="net.i2p.servlet.RequestWrapper" 38 %><%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> 41 39 <jsp:useBean id="version" class="i2p.susi.dns.VersionBean" scope="application" /> 42 40 <jsp:useBean id="book" class="i2p.susi.dns.NamingServiceBean" scope="session" /> 43 41 <jsp:useBean id="intl" class="i2p.susi.dns.Messages" scope="application" /> 42 <% 43 String importMessages = null; 44 if (intl._t("Import").equals(request.getParameter("action"))) { 45 RequestWrapper wrequest = new RequestWrapper(request); 46 importMessages = book.importFile(wrequest); 47 } 48 %> 44 49 <jsp:setProperty name="book" property="*" /> 45 50 <jsp:setProperty name="book" property="resetDeletionMarks" value="1"/> … … 76 81 </div> 77 82 78 <div id="messages">${book.messages}</div> 83 <div id="messages">${book.messages}<% 84 if (importMessages != null) { 85 %><%=importMessages%><% 86 } 87 %></div> 79 88 80 89 ${book.loadBookMessages} … … 255 264 </form> 256 265 266 <% if (!book.getBook().equals("published")) { %> 267 <form method="POST" action="addressbook" enctype="multipart/form-data" accept-charset="UTF-8"> 268 <input type="hidden" name="book" value="${book.book}"> 269 <input type="hidden" name="serial" value="<%=susiNonce%>"> 270 <input type="hidden" name="begin" value="0"> 271 <input type="hidden" name="end" value="49"> 272 <div id="import"> 273 <h3><%=intl._t("Import from hosts.txt file")%></h3> 274 <table> 275 <tr> 276 <td><b><%=intl._t("File")%></b></td> 277 <td><input name="file" type="file" accept=".txt" value="" /></td> 278 </tr> 279 </table> 280 <p class="buttons"> 281 <input class="cancel" type="reset" value="<%=intl._t("Cancel")%>" > 282 <input class="download" type="submit" name="action" value="<%=intl._t("Import")%>" > 283 </p> 284 </div> 285 </form> 286 <% } %> 287 257 288 <div id="footer"> 258 289 <hr> -
core/java/src/net/i2p/client/naming/SingleFileNamingService.java
rfea5bd4 rce043943 347 347 348 348 /** 349 * @param options As follows:349 * @param options null OK, or as follows: 350 350 * Key "search": return only those matching substring 351 351 * Key "startsWith": return only those starting with … … 414 414 * Overridden since we store base64 natively. 415 415 * 416 * @param options As follows:416 * @param options null OK, or as follows: 417 417 * Key "search": return only those matching substring 418 418 * Key "startsWith": return only those starting with -
installer/resources/themes/susidns/dark/susidns.css
rfea5bd4 rce043943 752 752 } 753 753 754 div#add {754 div#add, div#import { 755 755 border: 1px solid #2a5f29; 756 756 padding: 0 0 10px; … … 759 759 } 760 760 761 #add h3 {761 #add h3, #import h3 { 762 762 margin-top: -6px; 763 763 margin-left: -1px; … … 767 767 } 768 768 769 #add table {769 #add table, #import table { 770 770 width: 100%; 771 771 width: calc(100% - 1px); … … 773 773 } 774 774 775 #add td:first-child { 775 #add td:first-child, 776 #import table td:first-child { 776 777 text-align: right; 777 778 } 778 779 779 #add td:last-child { 780 #add td:last-child, 781 #import td:last-child { 780 782 width: 94%; 781 783 } 782 784 783 #add p.buttons {785 #add p.buttons, #import p.buttons { 784 786 margin-top: 5px; 785 787 border-top: 1px solid #2a5f29; -
installer/resources/themes/susidns/light/susidns.css
rfea5bd4 rce043943 271 271 } 272 272 273 div#add {273 div#add, div#import { 274 274 border: 1px solid #7778bf; 275 275 margin-top: -1px; … … 278 278 } 279 279 280 .iframed #add {280 .iframed #add, .iframed #import { 281 281 margin-top: 10px; 282 282 } 283 283 284 #add h3 {284 #add h3, #import h3 { 285 285 border-bottom: 1px solid #7778bf; 286 286 margin: 0 -15px; … … 288 288 } 289 289 290 #add table {290 #add table, #import table { 291 291 width: 100%; 292 292 margin: 5px 0; 293 293 } 294 294 295 #add table td:first-child { 295 #add table td:first-child, 296 #import table td:first-child { 296 297 width: 50px; 297 298 white-space: nowrap; … … 299 300 } 300 301 301 #add td {302 #add td, #import td { 302 303 padding: 3px; 303 304 } 304 305 305 div#add p.buttons {306 div#add p.buttons, div#import p.buttons { 306 307 border: 1px solid #7778bf; 307 308 margin: 0 -16px -1px; … … 328 329 } 329 330 330 div.help h3, #add h3 {331 div.help h3, #add h3, #import h3 { 331 332 border: 1px solid #7778bf; 332 333 padding: 5px 10px;
Note: See TracChangeset
for help on using the changeset viewer.