Jump to content

foxclone

Members
  • Posts

    107
  • Joined

  • Last visited

Posts posted by foxclone

  1. @kicken - I thought the md5sum problem was fixed but it's not. Here's an example of the differences:

    md5sum of original foxclone50_amd64.deb file: a00bd61088cf4f4a0138d51f24e554f0

    md5sum of downloaded foxclone50_amd64.deb file:  6f23af927c0a3348345ed1415fb89e36

    Here's the current code:

    <?php
    
    function mydloader($filename=NULL)  {
        if( isset( $filename ) ) {        
            $ext = pathinfo($filename, PATHINFO_EXTENSION);
                {
                if ($ext == '.iso')
                    header('Content-Type: application/x-cd-image');
                elseif ($ext =='.gz')
                    header('Content-Type: application/zip');
                else
                    header('Content-Type: octet-stream'); 
                }
            header('Content-Length: ' .filesize($filename));
            header("Content-Disposition: attachment; filename={$filename}");
            header('Pragma: no-cache');
            header('Expires: 0');        
            readfile($filename);
                      
          }
            
        else {
            echo "isset failed";
            }  
    }
    mydloader($_GET["f"]);

    Thanks for your help.

  2. Thanks to both of you for your replies.

    I check the downloaded file's md5sums manually. Users have been complaining.

    @kicken - You said the following:

    Your formatting needs work.

    I know. I just started using VS Code instead of a text editor.

    You have a pair of {} that are unnecessary and hard to even see.

    I'm not sure where you're talking about

    Your if/elseif/else blocks should have {} around them for readability.  The way you indented your code makes it look like all your headers are part of the else branch but only one of them actually is. 

    I'll reformat it

    You should add code to disable output buffering or you might hit memory errors on large files.

    The largest file is 870Mb and we've had no problems.

    You should add a Content-length header so the browser's download progress bar works.

    Will do.

    -----------------------------------------------------------------------------------------------------

    Again, thanks to both of you. I'll post revised code soon.

  3. The I had this problem solved, but it isn't. Still having a problem with downloaded files having the wrong md5sum. I've scrubbed the script again to be sure there aren't any tabs or blank spaces following the commands. Also no php errors. Here's the code.

    <?PHP
    error_reporting(E_ALL);
    ini_set('display_errors', '1');
    
    function mydloader($filename=NULL) {
        if (isset($filename)) {
            $filename = preg_replace("/\s+/u", " ", $filename);  // Make sure no hidden characters in filename
            $ext = pathinfo($filename, PATHINFO_EXTENSION);{  // Get file extension
            if ($ext == '.iso')
                header('Content-Type: application/x-cd-image');
            elseif ($ext == '.gz')
                header('Content-Type: application/zip');
            else
                header('Content-Type: octet-stream');}
                header("Content-Disposition: attachment; filename={$filename}");
                header('Pragma: no-cache');
                header('Expires: 0');
                readfile($filename);
    }
           else {
              echo "isset failed";
                }
    }
    mydloader($_GET["f"]);  // Filename passed from calling script

    I'm totally confused as to why this isn't working correctly. I spent the entire weekend trying go get this working so I'd really appreciate some help on this.

  4. I'm trying to convert existing website php code to use config.php on my local server but keep getting the following http 500 error before anything shows on the screen:

    "This page isn’t working

    foxtest is currently unable to handle this request."

    My config directory is within my project directory until I get this working. Here's the contents of config.php:

    <?php
    
    $app_root = DIRNAME(__DIR__);
    
    $php_path = $app_root.'config/';
    
    include_once $php_path.'PDO_Connection_Select.php';
    
    include_once $php_path.'GetUserIpAddr.php';

    Here's my index.php

    <?php 
    
    require_once('config/config.php');
    
    
    $ip = $php_path.'GetUserIpAddr()';
    if (!$pdo = $php_path.'PDOConnect("foxclone_data")')   {	
        exit;
        }
       
    $stmt = $pdo->prepare("INSERT INTO access (address) values (?)");
    $stmt->execute([$ip]) ;      	
    
    require_once("header.php"); 
    ?>
    
    <header class="header">
        <div class="header-content">
          <div class="text-container">
    	    <div class="header__top" style="text-align:center;">FoxClone</div>
    	      <p class="p-small">FoxClone is a image backup, restore, and clone tool for Windows and Linux systems, using a simple point-and-click interface. Being Linux-based, it boots to its own system exclusive of anything on the hard disk drive (HDD) or solid disk drive (SSD), where it takes images of the partitions and stores them for later restoration. The resulting image files can optionally be compressed to save space.
    .</p>
            
          </div>                 
        </div>
     </header> 
    
    <body>  
      <nav class="navbar" style="background:transparent;">
        <div class="navbar-links">
    	    <ul>
    		    <li><a href="index.php">Home</a></li>
    		    <li><a href="features.php">Features</a></li>
    		    <li><a href="legal.php">Legal</a></li>
    		    <li><a href="contact.php">Contact</a></li>
    		    <li><a href="download.php">Downloads</a></li>
    	    </ul>
        </div>
      </nav>
    
     
      <header class="header">
        <div class="header-content">
          <div class="text-container">
    	    <div class="header__top" style="text-align:center;">FoxClone</div>
    	      <p class="p-small">FoxClone is a image backup, restore, and clone tool for Windows and Linux systems, using a simple point-and-click interface. Being Linux-based, it boots to its own system exclusive of anything on the hard disk drive (HDD) or solid disk drive (SSD), where it takes images of the partitions and stores them for later restoration. The resulting image files can optionally be compressed to save space.
    .</p>
            
          </div>                 
        </div>
     </header> 
    
     <?PHP require_once("footer.php"); 

    I know I must be looking past the problem after looking at the code for several hours, but I'm stumped. I'd appreciate some help on this.

  5. When I run the following code on my local apache server, the md5sums of the downloaded files are correct. When I run the code on my web host, I get different md5sums. I've scrubbed the code to eliminate blank spaces before the readfile statement. I'm not getting any errors with error_reporting(E_ALL), display_errors=On, and output_buffering = off in my local php.ini as well as on my web host.

    Here's the code I'm currently using:

    <?php
    function mydloader($l_filename=NULL){    
        if( isset( $l_filename ) ) {
            $filename = preg_replace("/\s+/u", " ", $l_filename);//Eliminate any hidden characters
            $ext = pathinfo($filename, PATHINFO_EXTENSION);{
            if  ($ext = '.deb')
                header('Content-Type: application/x-debian-package');
            elseif ($ext = '.iso')
                header('Content-Type: application/x-cd-image');
            elseif ($ext = '.gz')
                header('Content-Type: application/zip');
            else
                header('Content-Type: octet-stream');}
                header("Content-Disposition: attachment; filename={$filename}");
                header('Pragma: no-cache');
                header('Expires: 0');        
                readfile($filename);
          }
            
        else {
            echo "isset failed";
            }  
    }      
    mydloader($_GET["f"]);


    I've removed all other code from this script in order to eliminate any other issues.  Does anyone have an idea what's going on?

    Thanks in advance.
        

  6. @gizmola - I moved all that was in the php directory into a newly created directory called includes. My config.php now looks like this:

    <?php
    
    $app_root = DIRNAME(__DIR__);
    
    $php_path = $app_root.'../includes/';
    
    include_once $php_path.'PDO_Connection_Select.php';

    My index.php starts like this:

    <?php
    
    require('../includes/config.php');
    
    require_once($php_path . 'PDO_Connection_Select.php');
    
    require_once($php_path . 'GetUserIpAddr.php');
    
    $ip = GetUserIpAddr();
    
    if (!$pdo = PDOConnect("foxclone_data")) {
    
    exit;
    
    }
    
    $stmt = $pdo->prepare("INSERT INTO access (address) values (?)");
    
    $stmt->execute([$ip]) ;
    
    ?>
    
    <?PHP require_once($php_path . 'header.php'); ?>

    Problem is, I'm now getting the following error:

    Quote

     

    Internal Server Error

    The server encountered an internal error or misconfiguration and was unable to complete your request.

     

    The error log states:

    Quote

    Invalid command 'RewriteEngine', perhaps misspelled or defined by a module not included in the server configuration, referer: http://foxtest/

    Any idea what's going on?

  7. @gizmola - A question for you. Can I include the file that has your PDO connection script in the config.php? This is what I was thinking:

    <?php
    
    $app_root = DIRNAME(__DIR__);
    
    $php_path = $app_root.'../php/';
    
    include_once $php_path.'PDO_Connection_Select.php';
    
    $get_ip = $php_path.'GetUserIpAddr()';

    Are the variables declared in config.php available in the file that has the include 'config.php' statement?

  8. @gizmola - For example, in config.php,  could I replace the relative path with the absolute path?

    <?php

    $app_root = DIRNAME(__DIR__);

    $connection = '/php/PDO_Connection_Select.php';

    $get_ip = '/php/GetUserIpAddr()';

    Instead of

    <?php

    $app_root = DIRNAME(__DIR__);

    $connection = '../../php/PDO_Connection_Select.php';

    $get_ip = '../../php/GetUserIpAddr()';

     

     

  9. Here's the full code, including the reason for the db connection.

    <?php
    
    error_reporting(E_ALL);
    
    
    
    ini_set('display_errors', '1');
    
    $php_scripts = '../../php/';
    
    require $php_scripts . 'PDO_Connection_Select.php';
    
    require $php_scripts . 'GetUserIpAddr.php';
    
    function mydloader($l_filename=NULL){
    
    
    
    
    $ip = GetUserIpAddr();
    
    if (!$pdo = PDOConnect("foxclone_data"))
    
    { echo "unable to connect";
    
    exit;
    
    }
    
    if( isset( $l_filename ) ) {
    
    
    
    header('Content-Type: octet-stream');
    
    header("Content-Disposition: attachment; filename={$l_filename}");
    
    header('Pragma: no-cache');
    
    header('Expires: 0');
    
    readfile($l_filename);
    
    
    
    $ext = pathinfo($l_filename, PATHINFO_EXTENSION);
    
    $stmt = $pdo->prepare("INSERT INTO download (address, filename,ip_address) VALUES (?, ?, inet_aton('$ip'))");
    
    $stmt->execute([$ip, $ext]) ;
    
    
    
    $test = $pdo->query("SELECT lookup.id FROM lookup WHERE inet_aton('$ip') >= lookup.ipstart AND inet_aton('$ip') <= lookup.ipend");
    
    $ref = $test->fetchColumn();
    
    $ref = intval($ref);
    
    
    
    $stmt = $pdo->prepare("UPDATE download SET lookup_id = '$ref' WHERE address = '$ip'");
    
    $stmt->execute() ;
    
    }
    
    else {
    
    echo "isset failed";
    
    }
    
    }
    
    mydloader($_GET["f"]);
    
    exit;

    Here's the code for the db connection:

    <?php
    
    function PDOConnect($l_dbname=NULL, $l_msg=null, $l_options=null)  {
    
    if ($l_options == null)
    
    { // set my default options
    
    // echo "db name is '$l_dbname'";
    
    $l_options = array(PDO::ATTR_EMULATE_PREPARES => false,
    
    PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
    
    PDO::MYSQL_ATTR_FOUND_ROWS => true,
    
    PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8',
    
    PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC);
    
    }
    
    if ($l_dbname == null)
    
    $host="mysql:host=localhost;charset=utf8";
    
    else
    
    $host="mysql:host=localhost;dbname=$l_dbname;charset=utf8";
    
    $uid = "xxxxxxx";
    
    $pswd = "xxxxxxxxxxx";
    
    try   {
    
    $mysql = new PDO($host, $uid, $pswd, $l_options);
    
    }
    
    catch (PDOException $e)   {
    
    if (strtoupper($l_msg) == "SHOWMSG")
    
        echo "Fatal Error<br>Failed to connect to mysql via PDO.<br>PDO Error msg is:<br>".$e->getMessage();
    
    else
    
         echo "Fatal Error<br>Possible bad dbname?<br>Failed to connect to mysql via PDO. Sensitive error msg may be viewed with additional parm to call to
    
         PDOConnect(dbname,'showmsg')".$e->getMessage();
    
         return false;
    
    }
    
    if (!$mysql)
    
        return false;
    
    else // all worked - return handle to pdo connection.
    
         return $mysql;
    
    }

     

     

  10. I'm having a problem with a download script. It runs fine on my local apache server, but when I put it on the my webhost's apache server, it goes crazy. Here's the script:

    <?php
    
    $php_scripts = '../../php/';
    require $php_scripts . 'PDO_Connection_Select.php';
    require $php_scripts . 'GetUserIpAddr.php';
    function mydloader($l_filename=NULL){
    
    
        $ip = GetUserIpAddr();
           if (!$pdo = PDOConnect("foxclone_data"))
          {    echo "unable to connect";
              exit;
          }
        
        if( isset( $l_filename ) ) {  
    
            header('Content-Type: octet-stream');
            header("Content-Disposition: attachment; filename={$l_filename}");
            header('Pragma: no-cache');
            header('Expires: 0');        
            readfile($l_filename);
    
          }
            
        else {
            echo "isset failed";
            }  
    }
    mydloader($_GET["f"]);
    exit;


    When I say "it goes crazy", I get errors saying that the header values have already been set by apparently by the PDOConnect. Then it actually reads the file. The files being downloaded are .iso, .deb, and .tar.gz. This isn't a php.ini problem; the files are the same on my local machine and the web host. Here's a screenshot:
     

     

    Does anyone have any idea why this is happening?

    Screenshot from 2022-02-27 08-44-28.png

  11. Thanks, Barand. It's working better but now I get both results from the if clause when $chk =1.

    <?php if($chk == 0)  ?>
      <div id='showMe'>
       <div class="container">
          <div class="row" style="color:red; padding-top:6rem; text-align:center;">
             <h1>Database Update Failed</h1>
          </div>
       </div>
     </div>  
    else 
      <div id='showMe'>
        <div class="container">
          <div class="row" style="color:black; padding-top:6rem; text-align:center;" >
            <h1>Database Update Successful</h1>
          </div>
        </div>
      </div>  

     

  12. I need to use a php variable in an if.. else clause outside of the block of php code and can't get it working. The existing code block is below. All help is appreciated.

    $chk is the variable from the php block and is numeric.

    <?php if($chk == 0) { 
      <div id='showMe'>
       <div class="container">
          <div class="row" style="color:red; padding-top:6rem; text-align:center;">
             <h1>Database Update Failed</h1>
          </div>
       </div>
     </div> }
     
    else  { 
    <div id='showMe'>
      <div class="container">
          <div class="row" style="padding-top:6rem; text-align:center;" >
            <h1><center>Database Update Successful</center></h1>
          </div>
      </div>
    endif
    </div>  
    
     </div>  
       </body>
    </html>

    Thanks much.

  13. I'm trying to get the filesize() of a file based on a retrieval of filename from the database. The file is located in the download directory and the code calling the function is in the root of the website. Here's the code I've tried:

    $test = $pdo->query("SELECT filename FROM files WHERE id =1");
       $isoname = $test->fetchColumn();
       $test = "download/".$isoname;
       $isosize = filesize($test)/1000000;

    It always returns zero although is returns the correct filename.

     

    Thanks for any guidance in advance.

×
×
  • 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.