Example #1
0
function do_serve_file($fd, $rem)
{
    $file = $rem->filename;
    $file = basename($file);
    $file = "__path_serverfile/{$file}";
    if (!lxfile_exists($file)) {
        log_log("servfile", "datafile {$file} dosn't exist, exiting");
        print_or_write($fd, "fFile Doesn't {$file} Exist...\n\n\n\n");
        return false;
    }
    $array = lfile_get_unserialize($file);
    lunlink($file);
    $realfile = $array['filename'];
    $pass = $array['password'];
    if ($fd) {
        dprint("Got request for {$file}, realfile: {$realfile}\n");
    }
    log_log("servfile", "Got request for {$file} realfile {$realfile}");
    if (!($pass && $pass === $rem->password)) {
        print_or_write($fd, "fPassword doesn't match\n\n");
        return false;
    }
    if (is_dir($realfile)) {
        // This should neverhappen. The directories are zipped at cp-fileserv and tar_to_filserved then itself.
        $b = basename($realfile);
        lxfile_mkdir("__path_serverfile/tmp/");
        $tfile = tempnam("__path_serverfile/tmp/", "{$b}.tar");
        $list = lscandir_without_dot($realfile);
        lxshell_tar($realfile, $tfile, $list);
        $realfile = $tfile;
    }
    $fpr = lfopen($realfile, "rb");
    if (!$fpr) {
        print_or_write($fd, "fCouldn't open {$realfile}\n\n");
        return false;
    }
    print_or_write($fd, "s");
    while (!feof($fpr)) {
        $written = print_or_write($fd, fread($fpr, 8092));
        if ($written <= 0) {
            break;
        }
    }
    // Just send a newline so that the fgets will break after reading. This has to be removed after the file is read.
    print_or_write($fd, "\n");
    fclose($fpr);
    fileserv_unlink_if_tmp($realfile);
    return true;
}
Example #2
0
 function top_level_simple_backup()
 {
     global $gbl, $sgbl, $login, $ghtml;
     $progname = $sgbl->__var_program_name;
     $dir = dirname($this->main->__var_bc_filename);
     $name = basename($this->main->__var_bc_filename);
     $firstname = strtil($name, "-");
     lxfile_mkdir($dir);
     $list = lscandir_without_dot($dir);
     $bc = $this->do_backup();
     $tmpdir = createTempDir("{$sgbl->__path_tmp}", "backupfile");
     lfile_put_contents("{$tmpdir}/{$progname}.file", $this->main->__var_bc_metafile);
     lfile_put_contents("{$tmpdir}/{$progname}.metadata", $this->main->__var_bc_metadata);
     $newarray = lx_array_merge(array($bc[1], array("{$tmpdir}/{$progname}.file", "{$tmpdir}/{$progname}.metadata")));
     if ($this->main->getZiptype() === 'zip') {
         lxshell_zip($bc[0], $this->main->__var_bc_filename, $newarray);
     } else {
         if ($this->main->getZiptype() === 'tar') {
             lxshell_tar($bc[0], $this->main->__var_bc_filename, $newarray);
         } else {
             lxshell_tgz($bc[0], $this->main->__var_bc_filename, $newarray);
         }
     }
     print_time("cpzip", "Copy and Zip");
     lxfile_tmp_rm_rec("{$tmpdir}");
     $this->do_backup_cleanup($bc);
 }