import java.security.*; import java.math.*; import java.awt.Color; import javax.swing.JApplet; import java.awt.GridLayout; import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; import java.net.URLConnection; import javax.swing.JTextArea; public class SMS extends JApplet { private int pocet=0; private JTextArea t=new JTextArea(); private String text=""; private String vysledek=""; private String tel="",zprava="",heslo=""; /********************************************************************************************************/ private String odesliSMS(String tel,String text) { if(text==null || tel==null)return "Chybne udaje"; if(tel.length()==0 || text.length()==0)return "Chybne udaje"; String cesta="http://www.sms.cz/brana/?jmeno=NAME"; String hash=""; //přeforámujem text text=text.replaceAll(" ","%20"); // HASH /********************************************************************************************************/ pripis("Pripojeni..."); //připojíme se na sms.cz URL u=null,u2=null; HttpURLConnection uc=null; URLConnection uc2=null; InputStreamReader isr=null,isr2=null; BufferedReader br=null,br2=null; String s="",s2="",e="\n"; try { u=new URL(cesta); pripis("Adresa: "+u); uc=(HttpURLConnection) u.openConnection(); uc.setDoOutput(false); uc.setDoInput(true); uc.connect(); isr=new InputStreamReader(uc.getInputStream()); br=new BufferedReader(isr); s=br.readLine(); uc.disconnect(); pripis("Pripojeni se zdarilo."); hash=s; pripis("Hash:"+hash); // Autorizace /********************************************************************************************************/ String autorizace="externibrana"+hash+""+heslo+"overeniMD5"; try { MessageDigest m=MessageDigest.getInstance("MD5"); m.update(autorizace.getBytes(),0,autorizace.length()); autorizace=new BigInteger(1,m.digest()).toString(16); }catch(Exception ex2){pripis("Chyba pri vypoctu MD5");return "Chyba";} // Odeslání /********************************************************************************************************/ pripis("Probiha odesilani zpravy"); String adresa="http://www.sms.cz/brana/?jmeno=NAME&auth="+autorizace+"&mobil="+tel+"&zprava="+text; s=""; try { u2=new URL(adresa); pripis("Adresa: "+adresa); uc2=u2.openConnection(); isr2=new InputStreamReader(uc2.getInputStream()); br2=new BufferedReader(isr2); pripis("Pripojeni se zdarilo."); //načteme obsah while (true) { s2=br2.readLine(); if(s2!=null) { if(s.length()!=0)s=s+e+s2; else s=s2; }else break; } // }catch(Exception ex){pripis("Pripojeni nebylo mozno navzat.");s="Chyba";} }catch(Exception ex){pripis("Pripojeni nebylo mozno navzat.");s="Chyba";}//od hashe return s; } /********************************************************************************************************/ @Override public void init() { this.setLayout(new GridLayout(1,1)); setBackground( Color.cyan ); setForeground( Color.black ); this.addNotify(); this.add("1",t); t.setLocation(0,0); t.setSize(this.getWidth(), this.getHeight()); //načtení parametrů try { tel=getParameter("tel"); zprava=getParameter("zprava"); heslo=getParameter("heslo"); }catch(Exception ex3){tel="";zprava="";heslo="";} // } /********************************************************************************************************/ @Override public void start() { if(pocet==0) { pripis("JAVA APPLET\nOdesilani SMS pres sms.cz\n"); pripis("Telefon: "+tel); pripis("Zprava: "+zprava+"\n"); String s=odesliSMS(tel, zprava); vysledek=s; pripis("\nVysledek:"); pripis(s); destroy(); } pocet++; } /********************************************************************************************************/ public String getVysledek() { return vysledek; } /********************************************************************************************************/ @Override public String getAppletInfo() { return "SMS applet pro DATin.cz"; } /********************************************************************************************************/ private void pripis(String s) { if(text.length()!=0) text+="\n"+s; else text=s; t.setText(text); } }