%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /data/www_bck/varak.net_bck/epgp.varak.net/
Upload File :
Create Path :
Current File : //data/www_bck/varak.net_bck/epgp.varak.net/lib.php

<?php
$queries = 0;
// downloads a binary file using curl/fopen/fsockopen
function download_file($file_source, $file_target)
{       
	if (function_exists('curl_init')) 
	{
		// curl available
		
		if (($ch = curl_init($file_source)) === FALSE) { return false; }
		if (($fp = fopen($file_target, 'wb')) === FALSE) { return false; }
		
		curl_setopt($ch, CURLOPT_FILE, $fp);
		curl_setopt($ch, CURLOPT_HEADER, 0);
		
		// Begin transfer
		if (!curl_exec($ch)) { 
			curl_close($ch);
			fclose($fp);
			return false; 
		};
		curl_close($ch);
		fclose($fp);
		return true;

	} else if (ini_get('allow_url_fopen') == 1) {
		// curl unavailable, fopen is

		$file_source = str_replace(' ', '%20', html_entity_decode($file_source)); // fix url format
		if (file_exists($file_target)) { chmod($file_target, 0777); } // add write permission
		
		// Begin transfer
		if (($rh = fopen($file_source, 'rb')) === FALSE) { return false; } // fopen() handles
		if (($wh = fopen($file_target, 'wb')) === FALSE) { return false; } // error messages.
		while (!feof($rh))
		{
			// unable to write to file, possibly because the harddrive has filled up
			if (fwrite($wh, fread($rh, 1024)) === FALSE) { 
				fclose($rh); 
				fclose($wh); 
				return false; 
			}
		}
		
		// Finished without errors
		fclose($rh);
		fclose($wh);
		return true;
	} else {
		// curl and fopen unavailable, try fsockopen

		$url_array = parse_url($file_source);
		$fp = fsockopen($url_array['host'], 80, $errno, $errstr, 5); 

		if (!fp) {
			die("cURL isn't installed, 'allow_url_fopen' isn't set and socket opening failed. Socket failed because: <br /><br /> $errstr ($errno)");
		} else {
			if (file_exists($file_target)) { chmod($file_target, 0777); } // add write permission
			if (($wh = fopen($file_target, 'wb')) === FALSE) { return false; }

			// send the request for the file
			$out = "GET " . $url_array[path] . "?" . $url_array[query] ." HTTP/1.0\r\n";
			$out .= "Host: " . $url_array[host] . " \r\n";
			$out .= "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; cs; rv:1.8.1.11) Gecko/20071127 Firefox/2.0.0.11\r\n";
			$out .= "Accept-Encoding: gzip\r\n";
			$out .= "Connection: Close\r\n\r\n";
			fwrite($fp, $out);

			// Begin transfer
			$gzip = false;
			$head_end = false;
			while (!feof($fp)) 
      {
        // unable to write to file, possibly because the harddrive has filled up
        $tmp_w = fgets($fp, 2048);
        if(trim($tmp_w) == "Content-Encoding: gzip")
        {
          $gzip = true;
        }
        if(!$head_end && trim($tmp_w) == "")
        {
          $head_end = true;
          continue;
        }
        if($head_end)
        {
				  if (fwrite($wh, $tmp_w) === FALSE) 
          { 
					 fclose($fp); 
					 fclose($wh); 
					 return false; 
				  }
				}
    	}
			
			// Finished without errors
			fclose($fp);
			fclose($wh);
			return true;
		}
	}
	return false;
}

$queries = 0;
  /**
* Wrapper function so that you can parse a file instead of an array.
* @author six
*/
function ParseLuaFile( $file_name , $file_type=null )
{
	if( file_exists($file_name) && is_readable($file_name) )
	{
		if( $file_type == 'gz' )
		{
			$file_as_array = gzfile($file_name);
		}
		else
		{
			$file_as_array = file($file_name);
		}

		return(ParseLuaArray($file_as_array));
	}
	return(false);
}

/**
* Main LUA parsing function
* @author six, originally mordon
*/
function ParseLuaArray( &$file_as_array )
{
	if( !is_array($file_as_array) )
	{
		// return false if not presented with an array
		return(false);
	}
	else
	{
		// Parse the contents of the array
		$stack = array( array( '',  array() ) );
		$stack_pos = 0;
		$last_line = '';
		foreach( $file_as_array as $line )
		{
			// join lines ending in \\ together
			if( substr( $line, -2, 1 ) == '\\' )
			{
				$last_line .= substr($line, 0, -2) . "\n";
				continue;
			}
			if($last_line!='')
			{
				$line = trim($last_line . $line);
				$last_line = '';
			}
			else
			{
				$line = trim($line);
			}

			// Look for end of an array
			if( $line[0] == '}' )
			{
				$hash = $stack[$stack_pos];
				unset($stack[$stack_pos]);
				$stack_pos--;
				$stack[$stack_pos][1][$hash[0]] = $hash[1];
				unset($hash);
			}
			// Handle other cases
			else
			{
				// Check if the key is given
				if( strpos($line,'=') )
				{
					list($name, $value) = explode( '=', $line, 2 );
					$name = trim($name);
					$value = trim($value,', ');
					if($name[0]=='[')
					{
						$name = trim($name, '[]"');
					}
				}
				// Otherwise we'll have to make one up for ourselves
				else
				{
					$value = $line;
					if( empty($stack[$stack_pos][1]) )
					{
						$name = 1;
					}
					else
					{
						$name = max(array_keys($stack[$stack_pos][1]))+1;
					}
					if( strpos($line,'-- [') )
					{
						$value = explode('-- [',$value);
						array_pop($value);
						$value = implode('-- [',$value);
					}
					$value = trim($value,', ');
				}
				if( $value == '{' )
				{
					$stack_pos++;
					$stack[$stack_pos] = array($name, array());
				}
				else
				{
					if($value[0]=='"')
					{
						$value = substr($value,1,-1);
					}
					else if($value == 'true')
					{
						$value = true;
					}
					else if($value == 'false')
					{
						$value = false;
					}
					else if($value == 'nil')
					{
						$value = NULL;
					}
					$stack[$stack_pos][1][$name] = $value;
				}
			}
		}
		return($stack[0][1]);
	}
}

function q($query,$assoc=0) 
{
	global $queries;
     //echo $query."\n";
   $r = @pg_query($query);
   if( pg_result_error($r) ) {
       $error = 'PGSQL ERROR : <small>' . pg_result_error($r). "</small><br><VAR>$query</VAR>";
       echo($error); return FALSE;
   }
   $queries++;
   if( strtolower(substr($query,0,6)) != 'select' ) return pg_affected_rows($r);
   $count = @pg_num_rows($r);
   if( !$count ) return 0;
   if( $count == 1 ) {
       if( $assoc ) $f = pg_fetch_assoc($r);
       else $f = pg_fetch_row($r);
       pg_free_result($r);
       if( count($f) == 1 ) {
           list($key) = array_keys($f);   
           return $f[$key];
       } else {
           $all = array();
           $all[] = $f;
           return $all;
       }
   } else {
       $all = array();
       for( $i = 0; $i < $count; $i++ ) {
           if( $assoc ) $f = pg_fetch_assoc($r);
           else $f = pg_fetch_row($r);
           $all[] = $f;
       }
       pg_free_result($r);
       return $all;
   }
}


function getmicrotime() 
{
  list($usec,$sec)=explode(" ",microtime()); 
  return ((float)$usec+(float)$sec);
}

?>

Zerion Mini Shell 1.0