forked from annmuor/jnode
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
kreon
committed
Jun 20, 2015
1 parent
031def4
commit 8f9a4e1
Showing
4 changed files
with
246 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
jnode-httpd-module/src/org/jnode/httpd/dto/EchoareaCSV.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package org.jnode.httpd.dto; | ||
|
||
import com.j256.ormlite.field.DatabaseField; | ||
import com.j256.ormlite.table.DatabaseTable; | ||
|
||
@DatabaseTable(tableName = "httpd_echoarea_csv") | ||
public class EchoareaCSV { | ||
@DatabaseField(columnName = "name", id = true) | ||
private String name; | ||
@DatabaseField(columnName = "description") | ||
private String description; | ||
@DatabaseField(columnName = "num") | ||
private Long num; | ||
@DatabaseField(columnName = "latest") | ||
private Long latest; | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public String getDescription() { | ||
return description; | ||
} | ||
|
||
public void setDescription(String description) { | ||
this.description = description; | ||
} | ||
|
||
public Long getNum() { | ||
return num; | ||
} | ||
|
||
public void setNum(Long num) { | ||
this.num = num; | ||
} | ||
|
||
public Long getLatest() { | ||
return latest; | ||
} | ||
|
||
public void setLatest(Long latest) { | ||
this.latest = latest; | ||
} | ||
|
||
} |
67 changes: 67 additions & 0 deletions
67
jnode-httpd-module/src/org/jnode/httpd/routes/get/EchoareaCSVRoute.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package org.jnode.httpd.routes.get; | ||
|
||
import java.sql.SQLException; | ||
import java.util.Date; | ||
import java.util.List; | ||
|
||
import org.jnode.httpd.dto.EchoareaCSV; | ||
|
||
import com.j256.ormlite.dao.GenericRawResults; | ||
|
||
import jnode.dto.Echoarea; | ||
import jnode.logger.Logger; | ||
import jnode.orm.ORMManager; | ||
import spark.Request; | ||
import spark.Response; | ||
import spark.Route; | ||
|
||
public class EchoareaCSVRoute extends Route { | ||
private static final long MAX_CACHE_TIME = 3600000; | ||
private long latest = 0; | ||
|
||
public EchoareaCSVRoute() { | ||
super("/echoarea.csv"); | ||
} | ||
|
||
@Override | ||
public Object handle(Request req, Response resp) { | ||
resp.type("text/plain; charset=utf-8"); | ||
long now = new Date().getTime(); | ||
StringBuilder sb = new StringBuilder(); | ||
if (now - latest > MAX_CACHE_TIME) { | ||
try { | ||
ORMManager.get(EchoareaCSV.class).executeRaw( | ||
"DELETE FROM httpd_echoarea_csv;"); | ||
GenericRawResults<String[]> results = ORMManager | ||
.get(Echoarea.class) | ||
.getRaw("SELECT e.name,e.description,(SELECT count(id) FROM echomail " | ||
+ "WHERE echoarea_id=e.id) AS num,(SELECT max(date) FROM echomail " | ||
+ "WHERE echoarea_id=e.id) AS latest FROM echoarea e ORDER BY e.name;"); | ||
latest = now; | ||
for (String[] row : results.getResults()) { | ||
EchoareaCSV csv = new EchoareaCSV(); | ||
csv.setName(row[0]); | ||
csv.setDescription(row[1]); | ||
csv.setNum(new Long(row[2])); | ||
csv.setLatest(new Long(row[3])); | ||
ORMManager.get(EchoareaCSV.class).save(csv); | ||
sb.append(csv.getName() + "," + csv.getLatest()/1000L + "," | ||
+ csv.getNum() + "," + csv.getDescription() | ||
+ "\r\n"); | ||
} | ||
} catch (SQLException e) { | ||
Logger.getLogger(EchoareaCSVRoute.class) | ||
.l1("Echoarea Error", e); | ||
return "error,0,0,SQLError\r\n"; | ||
} | ||
} else { | ||
List<EchoareaCSV> list = ORMManager.get(EchoareaCSV.class) | ||
.getOrderAnd("name", true); | ||
for (EchoareaCSV csv : list) { | ||
sb.append(csv.getName() + "," + csv.getLatest() + "," | ||
+ csv.getNum() + "," + csv.getDescription() + "\r\n"); | ||
} | ||
} | ||
return sb.toString(); | ||
} | ||
} |
121 changes: 121 additions & 0 deletions
121
jnode-httpd-module/src/org/jnode/httpd/routes/post/HDGPointRequestRoute.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
package org.jnode.httpd.routes.post; | ||
|
||
import org.jnode.httpd.HttpdModule; | ||
import org.jnode.httpd.dto.PointRequest; | ||
|
||
import jnode.dto.Echoarea; | ||
import jnode.dto.Link; | ||
import jnode.ftn.FtnTools; | ||
import jnode.ftn.types.FtnAddress; | ||
import jnode.main.MainHandler; | ||
import jnode.orm.ORMManager; | ||
import spark.Request; | ||
import spark.Response; | ||
import spark.Route; | ||
|
||
public class HDGPointRequestRoute extends Route { | ||
|
||
private boolean enabled = false; | ||
|
||
public HDGPointRequestRoute(boolean enabled) { | ||
super("/hdgpntrequest"); | ||
this.enabled = enabled; | ||
} | ||
|
||
@Override | ||
public Object handle(Request req, Response resp) { | ||
if (!enabled) { | ||
return "ERROR\r\nAUTOPOINT DISABLED\r\n"; | ||
} | ||
String name = req.queryParams("_name"); | ||
String email = req.queryParams("_email"); | ||
String password = req.queryParams("_password"); | ||
String about = req.queryParams("_about"); | ||
String error = ""; | ||
// check this shit | ||
{ | ||
if (!name.matches("^[A-Z][a-z]+ [A-Z][a-z]+$")) { | ||
error += "NAME_CHECK_FAILED "; | ||
} | ||
if (!email | ||
.matches("^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$")) { | ||
error += "MAIL_CHECK_FAILED "; | ||
} | ||
if (password.length() < 8) { | ||
error += "MIN_PASSWD_LEN=8 "; | ||
} | ||
if (!(password.matches(".*[0-9].*") | ||
&& password.matches(".*[A-Z].*") && password | ||
.matches(".*[a-z].*"))) { | ||
error += "WEAK_PASSWD "; | ||
} | ||
if (error.length() > 0) { | ||
error(error); | ||
return "ERROR\r\n" + error; | ||
} | ||
} | ||
// seems ok | ||
String guessedAddress = guessNewPointAddress(); | ||
if (guessedAddress == null) { | ||
error("NO_PNT_ADDRESS_SPACE"); | ||
return "ERROR\r\nNO_PNT_ADDRESS_SPACE"; | ||
} | ||
// do point request | ||
PointRequest pReq = new PointRequest(); | ||
pReq.setAddr(guessedAddress); | ||
pReq.setEmail(email); | ||
pReq.setName(name); | ||
pReq.setPassword(password); | ||
// save | ||
ORMManager.get(PointRequest.class).save(pReq); | ||
// create link | ||
Link link = new Link(); | ||
link.setLinkAddress(guessedAddress); | ||
link.setLinkName(name); | ||
link.setProtocolAddress("-"); | ||
link.setProtocolPassword(password); | ||
link.setPaketPassword(password); | ||
ORMManager.get(Link.class).save(link); | ||
// write echomail | ||
{ | ||
String techArea = MainHandler.getCurrentInstance().getProperty( | ||
"stat.area", null); | ||
String text = guessedAddress + "," + name + "," + about; | ||
if (techArea != null) { | ||
Echoarea area = FtnTools.getAreaByName(techArea, null); | ||
FtnTools.writeEchomail(area, "New HTDGPoint", text); | ||
} | ||
FtnTools.writeNetmail(FtnTools.getPrimaryFtnAddress(), | ||
FtnTools.getPrimaryFtnAddress(), MainHandler | ||
.getCurrentInstance().getInfo().getStationName(), | ||
MainHandler.getCurrentInstance().getInfo().getSysop(), | ||
"New HTDG point", text); | ||
ok(text); | ||
} | ||
return "OK\r\n" + guessedAddress; | ||
} | ||
|
||
private void error(String error) { | ||
HttpdModule.logger.l2("HDGPRError: " + error); | ||
} | ||
|
||
private void ok(String ok) { | ||
HttpdModule.logger.l3("HDGPR: " + ok); | ||
} | ||
|
||
private String guessNewPointAddress() { | ||
FtnAddress baseNodeAddr = FtnTools.getPrimaryFtnAddress().clone(); | ||
if (baseNodeAddr.getPoint() != 0) { | ||
return null; | ||
} | ||
// from 100 to 10000 | ||
for (int i = 100; i < 10000; i++) { | ||
baseNodeAddr.setPoint(i); | ||
Link l = FtnTools.getLinkByFtnAddress(baseNodeAddr); | ||
if (l == null) { | ||
return baseNodeAddr.toString(); | ||
} | ||
} | ||
return null; | ||
} | ||
} |