Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Copyright (c) 2012 [iPs]TeaM
- * Bruno da Silva (email@brunodasilva.com)
- * Sistema de hospedagem de arquivos http em CELULAR !!
- *
- * www.brunodasilva.com
- * www.ips-team.forumeiros.com
- */
- import java.io.*;
- import javax.microedition.io.*;
- import javax.microedition.midlet.*;
- import javax.microedition.lcdui.*;
- import javax.microedition.pki.*;
- import java.lang.IllegalArgumentException;
- public class VisualMIDlet extends MIDlet implements CommandListener, Runnable {
- private Display displayCelular ;
- private Form formularioDisplay ;
- private ServerSocketConnection servidorSocket ;
- private boolean rodandoServidor = true ;
- private boolean processandoPagina ;
- private String porta = "80" ;
- public void startApp() {
- displayCelular = Display.getDisplay(this);
- if (formularioDisplay == null) {
- formularioDisplay = new Form("VisualMIDlet");
- formularioDisplay.addCommand(new Command("Sair", Command.EXIT, 0));
- formularioDisplay.setCommandListener(this);
- }
- Thread t = new Thread(this);
- t.start();
- displayCelular.setCurrent(formularioDisplay);
- }
- public void pauseApp() {}
- public void destroyApp(boolean unconditional)
- {
- // shutdown();
- }
- public void commandAction(Command c, Displayable s) {
- if (c.getCommandType() == Command.EXIT) {
- rodandoServidor = false;
- try {
- servidorSocket.close();
- }
- catch (IOException ioe) {
- }
- notifyDestroyed();
- }
- }
- public void run() {
- try {
- formularioDisplay.append(new StringItem(null, "[x] Host Móvel ligado !! "));
- servidorSocket = (ServerSocketConnection)Connector.open("socket://:" + porta);
- }
- catch ( Exception e ) {}
- while ( rodandoServidor ) {
- if( processandoPagina == false ) {
- processandoPagina = true;
- SocketConnection sc = null;
- InputStream entrada = null;
- Reader in = null;
- HttpConnection http = null;
- PrintStream out = null;
- try {
- sc = (SocketConnection)servidorSocket.acceptAndOpen();
- in = new InputStreamReader(sc.openInputStream());
- out = new PrintStream(sc.openOutputStream());
- out.print( "HTTP/1.1 200 OK\r\n\r\n" );
- StringBuffer tmpStr = new StringBuffer();
- int ch;
- while (-1 != (ch = in.read()) ) {
- if ( (char) ch == '\n') break;
- else if( ( (char) ch != '\r') ) {
- tmpStr.append( (char) ch);
- }
- }
- if (tmpStr.length() != 0)
- {
- String url = tmpStr.toString();
- url = url.substring(5,url.length()-9) ;
- if(url.indexOf("favicon.ico") != -1) continue ;
- if(url.length() < 2) {
- url = "index.html";
- }
- formularioDisplay.append(new StringItem(null, "[x] Conexão de entrada -" + sc.getAddress()));
- formularioDisplay.append(new StringItem(null, "[x] Dados requisitados -" + url));
- out.print(file (url));
- out.close();
- sc.close();
- }
- }
- catch (Exception bla) {
- out.close();
- }
- }
- processandoPagina = false;
- }
- }
- private String file(String strs){
- InputStream is = getClass().getResourceAsStream("website/"+strs);
- StringBuffer sb = new StringBuffer();
- try{
- int chars, i = 0;
- while ((chars = is.read()) != -1){
- sb.append((char) chars);
- }
- return sb.toString();
- }
- catch (Exception e) {
- }
- return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement