add java client

This commit is contained in:
cricket 2010-03-26 16:43:46 +01:00
parent 9c33765dd5
commit 5e846de49e
3 changed files with 53 additions and 1 deletions

View File

@ -6,7 +6,7 @@
<img width="500" height="120" src="./moleflap.png" alt="MoleFlap" border="0"/><br/>
<form action="open" method="get"><textarea name="t" cols="41" rows="4" wrap="soft"></textarea><br/>
<input type="submit" value="Open Door Please!"></form><br/>
Or use the <a href="opendoor">script</a>!<br/><br/>
Or use the <a href="opendoor">script</a>! (optional use <a href="opendoor.class">java</a> [<a href="opendoor.java">source</a>])<br/><br/>
<small>Powered by<br/><img width="80" height="121" src="./mole_people.jpg" alt="Mole People" border="0"/>
</body>
</html>

BIN
www/opendoor.class Normal file

Binary file not shown.

52
www/opendoor.java Normal file
View File

@ -0,0 +1,52 @@
import java.net.*;
import java.io.*;
public class opendoor {
static boolean debug = true;
public static void main(String args[]) throws Exception {
System.out.println("* try to open tronlab's moleflap");
File keyfile = new File(".moleflap.c3d2");
if(!keyfile.exists()) {
keyfile.createNewFile();
System.out.println("please fill "+keyfile.getAbsolutePath()+" with your token.");
System.exit(1);
}
FileInputStream fistream = new FileInputStream(keyfile.getAbsolutePath());
DataInputStream in = new DataInputStream(fistream);
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
String line = reader.readLine();
if(line == null) line = "";
if(line.length() != 164) {
System.out.println("token should be valid (164 chars). not like this: '"+line+"'");
in.close();
System.exit(1);
}
if(debug) System.out.println("old: "+line);
in.close();
fistream.close();
URL url = new URL("http://moleflap.hq.c3d2.de/open?"+line);
InputStream uistream = url.openStream();
BufferedInputStream bufIn = new BufferedInputStream(uistream);
line = ""; int data;
for (;;) {
data = bufIn.read();
if (data == 10 || data == -1) break;
else line += (char) data;
}
if(debug) System.out.println("new: "+line);
bufIn.close();
uistream.close();
System.out.println("* check door ...");
FileWriter fostream = new FileWriter(keyfile.getAbsolutePath());
BufferedWriter out = new BufferedWriter(fostream);
out.write(line);
out.close();
fostream.close();
if(debug) System.out.println("done.");
}
}