<?

//=============================//
//                             //
//   myX.net PHP SMS Sender    //
//   myX.net.Class.php         //
//   by Razvan Stanga          //
//   razvan_stanga@yahoo.com   //
//   http://www.phprebel.org   //
//                             //
//       MADE IN ROMANIA       //
//                             //
//=============================//

class myX {
    var 
$user;
    var 
$pass;
    var 
$number;
    var 
$message;
    var 
$alteonp;
    var 
$jsessionid;
    var 
$freemessages;
    
    function 
myX () {
        
$this->user         '';
        
$this->pass         '';
        
$this->number         '';
        
$this->message         '';
        
$this->alteonp         '';
        
$this->jsessionid     '';
        
$this->freemessages '';
    }
    
    function 
myXStart () {

        if ( !
$_POST['do_send'] ) {
            
$this->myXForm ('login');
        } elseif ( 
$_POST['do_send'] == ) {
            
$this->user         $_POST['user'];
            
$this->pass         $_POST['pass'];
            
$this->alteonp         $_POST['alteonp'];
            
$this->jsessionid     $_POST['jsessionid'];
            
$this->myXLogin ();
            
$this->myXGetFreeMessages ();
            
            
$a = array ();
            
$a['msg']           = $this->freemessages;
            
$a['user']             = $this->user;
            
$a['pass']             = $this->pass;
            
$a['alteonp']         = $this->alteonp;
            
$a['jsessionid']     = $this->jsessionid;
            
$this->myXForm ('myx'$a);
        } elseif ( 
$_POST['do_send'] == ) {
            
$this->user         $_POST['user'];
            
$this->pass         $_POST['pass'];
            
$this->number         $_POST['number'];
            
$this->message         $_POST['message'];
            
$this->alteonp         $_POST['alteonp'];
            
$this->jsessionid     $_POST['jsessionid'];
            
$this->myXFormatMessage ();
            
$this->myXLogin ();
            
$this->myXSend ();
        }
    }
    
    function 
myXFormatMessage () {
        
$this->message eregi_replace ("( )+"" "$this->message);
        
$this->message eregi_replace ("\r\n|\r|\n"" "$this->message);
        if ( 
strlen ($this->message) > 160 ) {
            
$this->myXAlert ('Mesajul are peste 160 caractere !');
        }
    }
    
    function 
myXForm ($f$a=array()) {
        
$file 'html/'.$f.'.net';
        if (
file_exists ($file)) {
            
$T fopen($file'r');
            
$filedata fread$Tfilesize($file) );
            
fclose($T);
        } else {
            
$filedata "Template (".$file.") is missing";
        }
        foreach (
$a as $k => $v) {
            
$filedata preg_replace"/\{".$k."\}/i"$v$filedata );
        }
        echo 
$filedata;
    }
    
    function 
myXAlert ($msg) {
        echo 
"
        <script language=\"javascript\">
        alert(\"$msg\");
        history.back(1);
        </script>
        "
;
    exit ();
    }
    
    function 
myXLogin () {
        
        if ( !
$this->alteonp AND !$this->jsessionid ) {
            
$data "userName=".$this->user."&cmd=Login&password=".$this->pass;
            
$html $this->sendTomyX ('www.myx.net''POST''/MyX/mps/Portal?cmd=Login'$data''1);
            
preg_match_all ('/Set-Cookie: AlteonP=(.*); path=/'$html$x);
            
preg_match_all ('/Set-Cookie: JSESSIONID=(.*); path=/'$html$y);

            
$this->alteonp         $x[1][0];
            
$this->jsessionid     $y[1][0];
        }
    }
    
    function 
myXGetFreeMessages () {
        
$headers "Cookie: AlteonP=".$this->alteonp."; JSESSIONID=".$this->jsessionid."";
        
$html $this->sendTomyX ('www.myx.net''POST''/MyX/mps/portal?cmd=FreeSMSHistory'$data$headers1);
        
$x substr_count ($html"Trimis");
        
$this->freemessages     3-$x;
        if ( 
$this->freemessages ) {
            
$this->freemessages 0;
        }
    }
    
    function 
myXSend () {
        
$nSMS 160 strlen $this->message );
        
$headers "Cookie: AlteonP=".$this->alteonp."; JSESSIONID=".$this->jsessionid."";
        
$data "smsAddress=".$this->number."&abbreviations=&contacts=&abbreviationPage=1&abbreviation=Deja+mi-e+dor+de+tine%21+Hai+sa+ne+vedem.+Vrei%3F&smstext=".urlencode($this->message)."&nSMS=".$nSMS."";
        
$html $this->sendTomyX ('www.myx.net''POST''/MyX/mps/portal?cmd=FreeSMS'$data$headers1);
        
        
$a = array ();
        
$a['user']             = $_POST['user'];
        
$a['pass']             = $_POST['pass'];
        
$a['alteonp']         = $this->alteonp;
        
$a['jsessionid']     = $this->jsessionid;
        
$this->myXForm ('resend'$a);
    }

    function 
sendTomyX ($host$method$path$data$header$useragent=0) {

        if ( empty(
$method) ) {
            
$method 'GET';
        }
        
$method strtoupper($method);
        
$fp fsockopen ($host80$errno$errstr15);

        if (
$fp) {
    
            
$headers "".$method." ".$path." HTTP/1.1\r\n";
            
$headers .= "Accept: */*\r\n";
            
$headers .= "Referer: http://www.myx.net/MyX/mps/Portal?cmd=FreeSMS\r\n";
            
$headers .= "Accept-Language: ro\r\n";
            
$headers .= "Host: ".$host."\r\n";
            
$headers .= "Content-type: application/x-www-form-urlencoded\r\n";
            
$headers .= "Content-length: " strlen($data) . "\r\n";
            if (
$useragent) {
                
$headers .= "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)\r\n";
            }
            
$headers .= "Connection: Close\r\n";
            if ( 
$header ) {
                
$headers .= $header."\r\n";
            }
            
$headers .= "\r\n";
    
        if (
$method == 'POST') {
              
$headers .= $data;
        }
    
        
fputs ($fp$headers);
    
        
$buf '';
        while (!
feof($fp))
            
$buf .= fgets($fp,1024);
    
        
fclose($fp);
        } else {
            die (
'shit happens. myx.net is not responding');
        }
    return 
$buf;
    }

// end class

?>