Jump to content

Recommended Posts

hello

 

dont know if i'm in the right forum,but i realy need to know what this code do -

 

function file_act_check( $code )
{
   $lines = file( $GLOBALS['file_act'] );
   if ( is_array( $lines ) )
   {
      $code = " " . $code . "=";
      foreach ( $lines as $line )
      {
         if ( strstr( $line, $code ) )
         {
            $pieces = explode( "   ", $line );
            $days = explode( "=", $pieces[3] );
            $date_st = explode( ": ", $pieces[4] );
            $date_end = explode( ": ", $pieces[5] );
            $days = $days[1];
            list($year, $month, $day) = split( '[/.-]', $date_st[1] );
            $date_st = mktime( 0, 0, 0, $month, $day, $year );
            list($year, $month, $day) = split( '[/.-]', $date_end[1] );
            $date_end = mktime( 0, 0, 0, $month, $day, $year );
            return array( "Days" => "{$days}", "Start" => "{$date_st}", "End" => "{$date_end}" );
         }
      }
   }
   return 0;
}

 

can someone please explain in simple English what it do ? i really need to know

 

if this is not the place for this kind of question i apologize.

 

many thanx

Link to comment
https://forums.phpfreaks.com/topic/243317-need-help-with-code/
Share on other sites

tanks for reply.

 

this is the full PHP if it helps -

 

include "conf.php";
$GLOBALS['file_codes'] = "/var/users/proxy.codes";
$GLOBALS['file_act'] = "/var/users/proxy.act";
$GLOBALS['file_user'] = "/var/users/user.xml";
$GLOBALS['file_cccam'] = "/var/etc/CCcam.cfg";
$GLOBALS['USER_AG'] = "MY_AGENT";

function plugin_src( $user, $pass, $msg, $code, $enddate=0 )
{
   echo "grep -v \"#L\"  /var/tuxbox/plugins/active_code.cfg > /tmp/actv.cfg";
   echo "\necho \"#LastName={$user}\" >> /tmp/actv.cfg";
   echo "\nmv /tmp/actv.cfg /var/tuxbox/plugins/active_code.cfg";
   echo "\ngrep -v \"#C\"  /var/tuxbox/plugins/active_code.cfg > /tmp/actv.cfg";
   echo "\necho \"#Code={$code}\" >> /tmp/actv.cfg";
   echo "\nmv /tmp/actv.cfg /var/tuxbox/plugins/active_code.cfg";
   include "Lines.php";
   echo "\necho \"{$msg}\" > /var/tmp/msgS.tmp";
}

function plugin_src2( $user, $pass, $msg )
{
   echo "echo \"{$msg}\" > /var/tmp/msgS.tmp";
   include "Lines.php";
}

function browser_src( $user=NULL, $pass=NULL, $msg=NULL )
{
}

if ( $_SERVER["HTTP_USER_AGENT"] == $GLOBALS['USER_AG'] )
{
   main();
   exit;
}
else
{
//   echo "hello !\n";
   main();
   exit;
}

function main()
{
   if ( !$_GET['code'] || empty( $_GET['code'] ) )
   {
      echo "1";
      return;
   }
   else
   {
      $code = trim( $_GET['code'] );
   }

   if ( !is_numeric( $_GET['code'] ) )
   {
      echo "2";
      return;
   }
   $my_pass = gen_pass();

   if ( !isset( $_GET['LastName'] ) || empty( $_GET['LastName'] ) )
   {
      $my_user = "abd" . time();
   }
   else
   {
      $my_user = trim( $_GET['LastName'] );
   }
   $days = file_codes_check( $code );
   if ( $days > 0 )
   {
      $text_msg = "{$GLOBALS['WELCOME']} votre compte est active avec succes! Expirera a " . date( "Y-m-d", time() + ($days * 24 * 60 * 60) );
      $enddate = time() + ($days * 24 * 60 * 60);
      $str_date = 0;
      $end_date = 0;
      if ( $_GET['LastName'] && is_array( $act = file_user_check( "name=\"{$_GET['LastName']}\"" ) ) )
      {
         if ( $act['End'] > time() )
         {
            $str_date = $act['Start'];
            $end_date = $act['End'] + ($days * 24 * 60 * 60);
            $text_msg = "Compte est etendue avec {$days} jours! Expirera a " . date( "Y-m-d", $end_date );
            $enddate = $end_date;
         }
      }
      file_act_add( $my_user, $my_pass, $code, $days, $str_date, $end_date );
      file_codes_del( $code );
      if ( $_SERVER["HTTP_USER_AGENT"] == $GLOBALS['USER_AG'] )
         plugin_src( $my_user, $my_pass, $text_msg, $code, $enddate );
      else
         browser_src( $my_user, $my_pass, $text_msg );
   }
   else
   {
      $code_wrong = 1;
      if ( $days == 0 )
      {
         $act = file_user_check( "code=\"{$code}\"" );
         if ( is_array( $act ) )
         {
            $code_wrong = 0;
            $my_user = $act['name'];
            if ( $act['End'] > time() )
            {
               file_act_add( $my_user, $my_pass, $code, $act['days'], $act['Start'], $act['End'] );
               if ( $_SERVER["HTTP_USER_AGENT"] == $GLOBALS['USER_AG'] )
               {
                  plugin_src( $my_user, $my_pass, "Compte est reactif! Expirera a " . date( "Y-m-d", $act['End'] ), $code, $act['End'] );
               }
               else
               {
                  browser_src( $my_user, $my_pass, "Compte est reactif! Expirera a " . date( "Y-m-d", $act['End'] ) );
               }
            }
            else
            {
               if ( $_SERVER["HTTP_USER_AGENT"] == $GLOBALS['USER_AG'] && isset( $_GET['update'] ) && $_GET['update'] == "ok" )
               {
                  $passwd = $act['password'];
                  plugin_src2( $my_user, $passwd, "Votre compte a ete mise a jour avec succes!" );
               }
               else
               {
                  echo "3";
               }
            }
         }
      }
      if ( $code_wrong )
      {
         echo "2";
      }
   }
}

function gen_pass()
{
   $str = md5( uniqid() * time() );

   return $str = strtolower( substr( $str, -13 ) );
}

function xml2array( $xml )
{
   $xmlary = array( );
   $reels = '/<(\w+)\s*([^\/>]*)\s*(?:\/>|>(.*)<\/\s*\\1\s*>)/s';
   $reattrs = '/(\w+)=(?:"|\')([^"\']*)(:?"|\')/';
   preg_match_all( $reels, $xml, $elements );
   foreach ( $elements[1] as $ie => $xx )
   {
      $xmlary[$ie]["name"] = $elements[1][$ie];
      $attributes = trim( $elements[2][$ie] );
      if ( $attributes )
      {
         preg_match_all( $reattrs, $attributes, $att );
         foreach ( $att[1] as $ia => $xx )
            $xmlary[$ie]["attributes"][$att[1][$ia]] = $att[2][$ia];
      }
      $cdend = strpos( $elements[3][$ie], "<" );
      if ( $cdend > 0 )
      {
         $xmlary[$ie]["text"] = substr( $elements[3][$ie], 0, $cdend - 1 );
      }
      if ( preg_match( $reels, $elements[3][$ie] ) )
      {
         $xmlary[$ie]["elements"] = xml2array( $elements[3][$ie] );
      }
      else if ( $elements[3][$ie] )
      {
         $xmlary[$ie]["text"] = $elements[3][$ie];
      }
   }
   return $xmlary;
}

function file_act_add( $user, $pass, $code, $days, $date_st=0, $date_end=0 )
{
   $file_handle = fopen( $GLOBALS['file_act'], "a+" );
   if ( $file_handle )
   {
      if ( $date_st == 0 )
      {
         $date_st = time();
      }
      $txt_date_st = date( "Y/m/d", $date_st );
      if ( $date_end == 0 )
      {
         $date_end = time() + ($days * 24 * 60 * 60);
      }
      $txt_date_end = date( "Y/m/d", $date_end );
      fwrite( $file_handle, date( "[Y/m/d][H:i:s]   " ) );
      fwrite( $file_handle, "Username = {$user}   Password = {$pass}   {$code}={$days}   Start: {$txt_date_st}   End: {$txt_date_end}\n" );
      fclose( $file_handle );
      if ( $GLOBALS['ACTION'] == "N" )
      {
         file_user_update( $user, $pass, $code, $days, date( "d-m-Y", $date_st ), date( "d-m-Y", $date_end ) );
      }
      elseif ( $GLOBALS['ACTION'] == "C" )
      {
         file_CCcam_update( $user, $pass, $code, date( "d-m-Y", $date_end ) );
         file_user_update( $user, $pass, $code, $days, date( "d-m-Y", $date_st ), date( "d-m-Y", $date_end ) );
      }
      elseif ( $GLOBALS['ACTION'] == "NC" )
      {
         file_user_update( $user, $pass, $code, $days, date( "d-m-Y", $date_st ), date( "d-m-Y", $date_end ) );
         file_CCcam_update( $user, $pass, $code, date( "d-m-Y", $date_end ) );
      }
   }
}

function file_act_check( $code )
{
   $lines = file( $GLOBALS['file_act'] );
   if ( is_array( $lines ) )
   {
      $code = " " . $code . "=";
      foreach ( $lines as $line )
      {
         if ( strstr( $line, $code ) )
         {
            $pieces = explode( "   ", $line );
            $days = explode( "=", $pieces[3] );
            $date_st = explode( ": ", $pieces[4] );
            $date_end = explode( ": ", $pieces[5] );
            $days = $days[1];
            list($year, $month, $day) = split( '[/.-]', $date_st[1] );
            $date_st = mktime( 0, 0, 0, $month, $day, $year );
            list($year, $month, $day) = split( '[/.-]', $date_end[1] );
            $date_end = mktime( 0, 0, 0, $month, $day, $year );
            return array( "Days" => "{$days}", "Start" => "{$date_st}", "End" => "{$date_end}" );
         }
      }
   }
   return 0;
}

function file_codes_check( $code )
{
   $lines = file( $GLOBALS['file_codes'] );
   if ( is_array( $lines ) )
   {
      foreach ( $lines as $line )
      {
         list($cc, $day) = split( '=', $line );
         if ( strcmp( $cc, $code ) == 0 )
         {
            return trim( $day );
         }
      }
   }
   return 0;
}

function file_codes_del( $code )
{
   $lines = file( $GLOBALS['file_codes'] );
   if ( is_array( $lines ) )
   {
      $file_handle = fopen( $GLOBALS['file_codes'], "w" );
      if ( $file_handle )
      {
         $code = $code . "=";
         foreach ( $lines as $line )
         {
            if ( strstr( $line, $code ) === FALSE )
            {
               fwrite( $file_handle, $line );
            }
         }
         fclose( $file_handle );
      }
   }
}

function file_user_write( $data )
{
   $fp = fopen( $GLOBALS['file_user'], "w" );
   if ( $fp )
   {
      foreach ( $data as $value )
      {
         $value = trim( $value );
         if ( $value )
         {
            fwrite( $fp, $value . "\n" );
         }
      }
      fclose( $fp );
   }
}

function file_CCcam_write( $data )
{
   $fp = fopen( $GLOBALS['file_cccam'], "w" );
   if ( $fp )
   {
      foreach ( $data as $value )
      {
         $value - trim( $value );
         if ( $value )
         {
            fwrite( $fp, $value . "\n" );
         }
      }
      fclose( $fp );
   }
}

function file_user_check( $find )
{
   $lines = file( $GLOBALS['file_user'] );
   if ( is_array( $lines ) )
   {
      foreach ( $lines as $line )
      {
         if ( strstr( $line, $find ) )
         {
            $act = xml2array( $line );
            if ( $act[0]['name'] == "user" && is_array( $act[0]['attributes'] ) )
            {
               $act = $act[0]['attributes'];
               list($day, $month, $year) = split( '[/.-]', $act['startDate'] );
               $act['Start'] = mktime( 0, 0, 0, $month, $day, $year );
               list($day, $month, $year) = split( '[/.-]', $act['date'] );
               $act['End'] = mktime( 0, 0, 0, $month, $day, $year );
               return $act;
            }
            return 0;
         }
      }
   }
   return 0;
}

function file_user_update( $user, $pass, $code, $days, $date_st, $date_end )
{
   $lines = file( $GLOBALS['file_user'] );
   $newline = "<user name=\"{$user}\" password=\"{$pass}\" max-connections=\"1\" EcmRate=\"-1\" code=\"{$code}\" days=\"{$days}\" startDate=\"{$date_st}\" expire-date=\"{$date_end}\"/>";
   if ( is_array( $lines ) )
   {
      $code_str = "code=\"{$code}\"";
      if ( $_GET['LastName'] )
      {
         $code_str = "name=\"{$_GET['LastName']}\"";
      }
      $i = 0;
      foreach ( $lines as $line )
      {
         if ( strstr( $line, $code_str ) )
         {
            $lines[$i] = $newline;
            file_user_write( $lines );
            return 1;
         }
         $i++;
      }
      $frstel = $lines[0];
      $lines[0] = $newline;
      array_unshift( $lines, $frstel );
      file_user_write( $lines );
   }
   return 0;
}

function file_cccam_update( $user, $pass, $code, $date_end )
{
   $lines = file( $GLOBALS['file_cccam'], FILE_IGNORE_NEW_LINES );
   $newline = "F: {$user} {$pass} 3 0 0 { 0:0:1 } #  {$date_end}";
    if ( is_array( $lines ) )
   {
      if ( $_GET['LastName'] )
      {
         $code_str = "F: {$_GET['LastName']}";
      }
      else
      {
          $code_str="F: $user";
      }
      $i = 0;
      foreach ( $lines as $line )
      {
         if ( strstr( $line, $code_str ))
         {
            $lines[$i] = $newline;
            file_CCcam_write( $lines );
            return 1;
         }
         $i++;
      }
      $frstel = $lines[0];
      $lines[0] = $newline;
      array_unshift( $lines, $frstel );
      file_CCcam_write( $lines );
   }
   return 0;
}

 

 

i have this files -

 

index.php >>> this is the php code above

conf.php

Lines.php

user.xml

 

i know i must create  proxy.codes and proxy.act but don't know what to put in this 2 files.

 

again many thanx

 

Link to comment
https://forums.phpfreaks.com/topic/243317-need-help-with-code/#findComment-1249561
Share on other sites

Well I'm not going to read that huge script, but what exactly are you trying to do here? The purpose is kind of unclear, and you never explained what was wrong with the code (or if there was even a problem at all)

 

A little word of advice: Learn PHP before you try to get over your head with a project. It seems like you don't know anything about PHP at all and are using a fairly advanced script. We aren't going to make it work for you since this is a forum of volunteers. You need to be able to help  yourself before you can get help from us.

Link to comment
https://forums.phpfreaks.com/topic/243317-need-help-with-code/#findComment-1249574
Share on other sites

hello again,

 

i'm less than a beginner with PHP,but i take it as a challenge to understand this code.

 

someone already told me he can help me with this code if i pay him 100USD ,but i like i said its a challenge.

 

i started to read more and more about PHP and now i understand the code more.

 

now i have one simple(i hope) Q -

 

this code -

 

function file_codes_check( $code )
{
   $lines = file( $GLOBALS['file_codes'] );
   if ( is_array( $lines ) )
   {
      foreach ( $lines as $line )
      {
         list($cc, $day) = split( '=', $line );
         if ( strcmp( $cc, $code ) == 0 )
         {
            return trim( $day );
         }
      }
   }
   return 0;
}

 

 

in which format should i put the lines in the file ?

and i fail to understand the "$cc"

 

many thanx

Link to comment
https://forums.phpfreaks.com/topic/243317-need-help-with-code/#findComment-1249799
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.