function add_file($files)
{
    global $STATIC;
    if (empty($files)) {
        return;
    }
    $filelist = get_filelist();
    foreach ($files as $file) {
        $filelist[] = $file;
    }
    file_put_contents($STATIC['TEMPDIR'] . '.filelist', serialize($filelist));
}
    }
    ?>
 >
                                    
      <?php 
}
// **** END of header
$before = microtime(true);
// START benchmark
//var_dump($joomla);
// do the scan
?>
                                    <div id="results">
                                        <h2>Here are the suspicious parts of code found in this scan process :</h2>
                                <?php 
get_filelist($directory);
?>
                                    </div>                                 
                                <?php 
$after = microtime(true);
// STOP benchmark
echo 'We found <b>', $total_results, ' suspicious malware code spots</b> in <u>', $count, ' different files</u>!<br/>
                                    Please analyze the results and interpret them according to README file.<br>';
echo 'Scanning time was ', $after - $before, ' sec! <br>';
?>
                                <hr />

                                It is advisable to delete this script after using it. You can do it by <a href="jamss.php?action=autodestruct">clicking here</a>.<br/>
                                <br/>
                                Thank you for using JAMSS!
Exemple #3
0
// |                          synchronize metadata                         |
// +-----------------------------------------------------------------------+
if (isset($_POST['submit']) and isset($_POST['sync_meta']) and !$general_failure) {
    // sync only never synchronized files ?
    $opts['only_new'] = isset($_POST['meta_all']) ? false : true;
    $opts['category_id'] = '';
    $opts['recursive'] = true;
    if (isset($_POST['cat'])) {
        $opts['category_id'] = $_POST['cat'];
        // recursive ?
        if (!isset($_POST['subcats-included']) or $_POST['subcats-included'] != 1) {
            $opts['recursive'] = false;
        }
    }
    $start = get_moment();
    $files = get_filelist($opts['category_id'], $site_id, $opts['recursive'], $opts['only_new']);
    $template->append('footer_elements', '<!-- get_filelist : ' . get_elapsed_time($start, get_moment()) . ' -->');
    $start = get_moment();
    $datas = array();
    $tags_of = array();
    foreach ($files as $id => $element_infos) {
        $data = $site_reader->get_element_metadata($element_infos);
        if (is_array($data)) {
            $data['date_metadata_update'] = CURRENT_DATE;
            $data['id'] = $id;
            $datas[] = $data;
            foreach (array('keywords', 'tags') as $key) {
                if (isset($data[$key])) {
                    if (!isset($tags_of[$id])) {
                        $tags_of[$id] = array();
                    }
function backup_create()
{
    global $WORKING, $STATIC;
    if ($WORKING['ALLFILESIZE'] == 0) {
        return;
    }
    $filelist = get_filelist();
    //get file list
    $WORKING['STEPTODO'] = count($filelist);
    if (empty($WORKING['STEPDONE'])) {
        $WORKING['STEPDONE'] = 0;
    }
    if (strtolower($STATIC['JOB']['fileformart']) == ".zip") {
        //Zip files
        if ($STATIC['CFG']['phpzip']) {
            //use php zip lib
            trigger_error(sprintf(__('%d. try to create backup zip archive...', 'backwpup'), $WORKING['BACKUP_CREATE']['STEP_TRY']), E_USER_NOTICE);
            $zip = new ZipArchive();
            if ($res = $zip->open($STATIC['JOB']['backupdir'] . $STATIC['backupfile'], ZIPARCHIVE::CREATE) === TRUE) {
                for ($i = $WORKING['STEPDONE']; $i < $WORKING['STEPTODO']; $i++) {
                    if (!$zip->addFile($filelist[$i]['FILE'], $filelist[$i]['OUTFILE'])) {
                        trigger_error(sprintf(__('Can not add "%s" to zip archive!', 'backwpup'), $filelist[$i]['OUTFILE']), E_USER_ERROR);
                    }
                    $WORKING['STEPDONE']++;
                    update_working_file();
                }
                if ($zip->status > 0) {
                    $ziperror = $zip->status;
                    if ($zip->status == 4) {
                        $ziperror = __('(4) ER_SEEK', 'backwpup');
                    }
                    if ($zip->status == 5) {
                        $ziperror = __('(5) ER_READ', 'backwpup');
                    }
                    if ($zip->status == 9) {
                        $ziperror = __('(9) ER_NOENT', 'backwpup');
                    }
                    if ($zip->status == 10) {
                        $ziperror = __('(10) ER_EXISTS', 'backwpup');
                    }
                    if ($zip->status == 11) {
                        $ziperror = __('(11) ER_OPEN', 'backwpup');
                    }
                    if ($zip->status == 14) {
                        $ziperror = __('(14) ER_MEMORY', 'backwpup');
                    }
                    if ($zip->status == 18) {
                        $ziperror = __('(18) ER_INVAL', 'backwpup');
                    }
                    if ($zip->status == 19) {
                        $ziperror = __('(19) ER_NOZIP', 'backwpup');
                    }
                    if ($zip->status == 21) {
                        $ziperror = __('(21) ER_INCONS', 'backwpup');
                    }
                    trigger_error(sprintf(__('Zip returns status: %s', 'backwpup'), $zip->status), E_USER_ERROR);
                }
                $res2 = $zip->close();
                trigger_error(__('Backup zip archive create done!', 'backwpup'), E_USER_NOTICE);
                $WORKING['STEPSDONE'][] = 'BACKUP_CREATE';
                //set done
            } else {
                trigger_error(sprintf(__('Can not create backup zip archive $s!', 'backwpup'), $res), E_USER_ERROR);
            }
        } else {
            //use PclZip
            define('PCLZIP_TEMPORARY_DIR', $STATIC['TEMPDIR']);
            require_once $STATIC['WP']['ABSPATH'] . 'wp-admin/includes/class-pclzip.php';
            if (ini_get('mbstring.func_overload') && function_exists('mb_internal_encoding')) {
                $previous_encoding = mb_internal_encoding();
                mb_internal_encoding('ISO-8859-1');
            }
            //Create Zip File
            if (is_array($filelist[0])) {
                trigger_error(sprintf(__('%d. try to create backup zip (PclZip) archive...', 'backwpup'), $WORKING['BACKUP_CREATE']['STEP_TRY']), E_USER_NOTICE);
                for ($i = 0; $i < $WORKING['STEPTODO']; $i++) {
                    //must begin at 0 for PCLzip
                    $files[$i][79001] = $filelist[$i]['FILE'];
                    $files[$i][79003] = $filelist[$i]['OUTFILE'];
                    $files[$i][79004] = $filelist[$i]['MTIME'];
                }
                need_free_memory('20M');
                //20MB free memory for zip
                $zipbackupfile = new PclZip($STATIC['JOB']['backupdir'] . $STATIC['backupfile']);
                if (0 == $zipbackupfile->create($files, PCLZIP_CB_POST_ADD, '_pclzipPostAddCallBack', PCLZIP_OPT_TEMP_FILE_THRESHOLD, 5)) {
                    trigger_error(sprintf(__('Zip archive create error: %s', 'backwpup'), $zipbackupfile->errorInfo(true)), E_USER_ERROR);
                } else {
                    $WORKING['STEPDONE'] = count($filelist);
                    unset($files);
                    trigger_error(__('Backup zip archive create done', 'backwpup'), E_USER_NOTICE);
                }
            }
            if (isset($previous_encoding)) {
                mb_internal_encoding($previous_encoding);
            }
        }
    } elseif (strtolower($STATIC['JOB']['fileformart']) == ".tar.gz" or strtolower($STATIC['JOB']['fileformart']) == ".tar.bz2" or strtolower($STATIC['JOB']['fileformart']) == ".tar") {
        //tar files
        if (strtolower($STATIC['JOB']['fileformart']) == '.tar.gz') {
            $tarbackup = gzopen($STATIC['JOB']['backupdir'] . $STATIC['backupfile'], 'w9');
        } elseif (strtolower($STATIC['JOB']['fileformart']) == '.tar.bz2') {
            $tarbackup = bzopen($STATIC['JOB']['backupdir'] . $STATIC['backupfile'], 'w');
        } else {
            $tarbackup = fopen($STATIC['JOB']['backupdir'] . $STATIC['backupfile'], 'w');
        }
        if (!$tarbackup) {
            trigger_error(__('Can not create tar arcive file!', 'backwpup'), E_USER_ERROR);
            return;
        } else {
            trigger_error(sprintf(__('%1$d. try to create %2$s archive file...', 'backwpup'), $WORKING['BACKUP_CREATE']['STEP_TRY'], substr($STATIC['JOB']['fileformart'], 1)), E_USER_NOTICE);
        }
        for ($index = $WORKING['STEPDONE']; $index < $WORKING['STEPTODO']; $index++) {
            need_free_memory(2097152);
            //2MB free memory for tar
            $files = $filelist[$index];
            //check file readable
            if (!is_readable($files['FILE']) or empty($files['FILE'])) {
                trigger_error(sprintf(__('File "%s" not readable!', 'backwpup'), $files['FILE']), E_USER_WARNING);
                $WORKING['STEPDONE']++;
                continue;
            }
            //split filename larger than 100 chars
            if (strlen($files['OUTFILE']) <= 100) {
                $filename = $files['OUTFILE'];
                $filenameprefix = "";
            } else {
                $filenameofset = strlen($files['OUTFILE']) - 100;
                $dividor = strpos($files['OUTFILE'], '/', $filenameofset);
                $filename = substr($files['OUTFILE'], $dividor + 1);
                $filenameprefix = substr($files['OUTFILE'], 0, $dividor);
                if (strlen($filename) > 100) {
                    trigger_error(sprintf(__('File name "%1$s" to long to save corectly in %2$s archive!', 'backwpup'), $files['OUTFILE'], substr($STATIC['JOB']['fileformart'], 1)), E_USER_WARNING);
                }
                if (strlen($filenameprefix) > 155) {
                    trigger_error(sprintf(__('File path "%1$s" to long to save corectly in %2$s archive!', 'backwpup'), $files['OUTFILE'], substr($STATIC['JOB']['fileformart'], 1)), E_USER_WARNING);
                }
            }
            //Set file user/group name if linux
            $fileowner = "Unknown";
            $filegroup = "Unknown";
            if (function_exists('posix_getpwuid')) {
                $info = posix_getpwuid($files['UID']);
                $fileowner = $info['name'];
                $info = posix_getgrgid($files['GID']);
                $filegroup = $info['name'];
            }
            // Generate the TAR header for this file
            $header = pack("a100a8a8a8a12a12a8a1a100a6a2a32a32a8a8a155a12", $filename, sprintf("%07o", $files['MODE']), sprintf("%07o", $files['UID']), sprintf("%07o", $files['GID']), sprintf("%011o", $files['SIZE']), sprintf("%011o", $files['MTIME']), "        ", 0, "", "ustar", "00", $fileowner, $filegroup, "", "", $filenameprefix, "");
            //fill block 512K
            // Computes the unsigned Checksum of a file's header
            $checksum = 0;
            for ($i = 0; $i < 512; $i++) {
                $checksum += ord(substr($header, $i, 1));
            }
            $checksum = pack("a8", sprintf("%07o", $checksum));
            $header = substr_replace($header, $checksum, 148, 8);
            if (strtolower($STATIC['JOB']['fileformart']) == '.tar.gz') {
                gzwrite($tarbackup, $header);
            } elseif (strtolower($STATIC['JOB']['fileformart']) == '.tar.bz2') {
                bzwrite($tarbackup, $header);
            } else {
                fwrite($tarbackup, $header);
            }
            // read/write files in 512K Blocks
            $fd = fopen($files['FILE'], 'rb');
            while (!feof($fd)) {
                $filedata = fread($fd, 512);
                if (strlen($filedata) > 0) {
                    if (strtolower($STATIC['JOB']['fileformart']) == '.tar.gz') {
                        gzwrite($tarbackup, pack("a512", $filedata));
                    } elseif (strtolower($STATIC['JOB']['fileformart']) == '.tar.bz2') {
                        bzwrite($tarbackup, pack("a512", $filedata));
                    } else {
                        fwrite($tarbackup, pack("a512", $filedata));
                    }
                }
            }
            fclose($fd);
            $WORKING['STEPDONE']++;
            update_working_file();
        }
        if (strtolower($STATIC['JOB']['fileformart']) == '.tar.gz') {
            gzwrite($tarbackup, pack("a1024", ""));
            // Add 1024 bytes of NULLs to designate EOF
            gzclose($tarbackup);
        } elseif (strtolower($STATIC['JOB']['fileformart']) == '.tar.bz2') {
            bzwrite($tarbackup, pack("a1024", ""));
            // Add 1024 bytes of NULLs to designate EOF
            bzclose($tarbackup);
        } else {
            fwrite($tarbackup, pack("a1024", ""));
            // Add 1024 bytes of NULLs to designate EOF
            fclose($tarbackup);
        }
        trigger_error(sprintf(__('%s archive creation done', 'backwpup'), substr($STATIC['JOB']['fileformart'], 1)), E_USER_NOTICE);
    }
    $WORKING['STEPSDONE'][] = 'BACKUP_CREATE';
    //set done
    if ($filesize = filesize($STATIC['JOB']['backupdir'] . $STATIC['backupfile'])) {
        trigger_error(sprintf(__('Archive size is %s', 'backwpup'), formatBytes($filesize)), E_USER_NOTICE);
    }
}
    if ($cache_stale) {
        unlink($zipfile_path);
    } else {
        header("Location: {$zipfile_url}");
        exit;
    }
}
if (!is_dir($project_path)) {
    echo "download_images.php: no project directory named '{$projectid}'.";
    exit;
}
if (!is_dir(dirname($zipfile_path))) {
    mkdir(dirname($zipfile_path), 0777, TRUE);
}
// Get a list of image filenames to feed into /usr/bin/zip on stdin
$image_files = get_filelist($project_path, array('.png', '.jpg'), True);
if ($image_files === false) {
    echo "download_images.php: Could not list project images.";
    exit;
}
# zip: Process a .zip archive
# -0: Don't compress files
# -q: quiet. Don't emit any output
# -j: 'junk' paths: Store just the filename in the the zip file, not the entire path
# -@: Get file list from stdin
$fh = popen("zip -0 -q -j -@ " . escapeshellcmd($zipfile_path), "w");
if ($fh !== false) {
    fwrite($fh, implode("\n", $image_files));
    if (pclose($fh) != 0) {
        echo "download_images.php: zip command failed";
        exit;
function file_list()
{
    global $WORKING, $STATIC, $tempfilelist;
    //Make filelist
    trigger_error(sprintf(__('%d. try for make list of files to backup....', 'backwpup'), $WORKING['FILE_LIST']['STEP_TRY']), E_USER_NOTICE);
    $WORKING['STEPTODO'] = 2;
    //Check free memory for file list
    need_free_memory('10MB');
    //10MB free memory for filelist
    //empty filelist
    $tempfilelist = array();
    //exlude of job
    $WORKING['FILEEXCLUDES'] = explode(',', trim($STATIC['JOB']['fileexclude']));
    $WORKING['FILEEXCLUDES'][] = '.tmp';
    //do not backup .tmp files
    $WORKING['FILEEXCLUDES'] = array_unique($WORKING['FILEEXCLUDES']);
    //File list for blog folders
    if ($STATIC['JOB']['backuproot']) {
        _file_list($STATIC['WP']['ABSPATH'], 100, array_merge($STATIC['JOB']['backuprootexcludedirs'], _get_exclude_dirs($STATIC['WP']['ABSPATH'])));
    }
    if ($STATIC['JOB']['backupcontent']) {
        _file_list($STATIC['WP']['WP_CONTENT_DIR'], 100, array_merge($STATIC['JOB']['backupcontentexcludedirs'], _get_exclude_dirs($STATIC['WP']['WP_CONTENT_DIR'])));
    }
    if ($STATIC['JOB']['backupplugins']) {
        _file_list($STATIC['WP']['WP_PLUGIN_DIR'], 100, array_merge($STATIC['JOB']['backuppluginsexcludedirs'], _get_exclude_dirs($STATIC['WP']['WP_PLUGIN_DIR'])));
    }
    if ($STATIC['JOB']['backupthemes']) {
        _file_list($STATIC['WP']['WP_THEMES_DIR'], 100, array_merge($STATIC['JOB']['backupthemesexcludedirs'], _get_exclude_dirs($STATIC['WP']['WP_THEMES_DIR'])));
    }
    if ($STATIC['JOB']['backupuploads']) {
        _file_list($STATIC['WP']['WP_UPLOAD_DIR'], 100, array_merge($STATIC['JOB']['backupuploadsexcludedirs'], _get_exclude_dirs($STATIC['WP']['WP_UPLOAD_DIR'])));
    }
    //include dirs
    if (!empty($STATIC['JOB']['dirinclude'])) {
        $dirinclude = explode(',', $STATIC['JOB']['dirinclude']);
        $dirinclude = array_unique($dirinclude);
        //Crate file list for includes
        foreach ($dirinclude as $dirincludevalue) {
            if (is_dir($dirincludevalue)) {
                _file_list($dirincludevalue, 100);
            }
        }
    }
    $tempfilelist = array_unique($tempfilelist);
    //all files only one time in list
    sort($tempfilelist);
    $WORKING['STEPDONE'] = 1;
    //Step done
    update_working_file();
    //Check abs path
    if ($STATIC['WP']['ABSPATH'] == '/' or $STATIC['WP']['ABSPATH'] == '') {
        $removepath = '';
    } else {
        $removepath = $STATIC['WP']['ABSPATH'];
    }
    //make file list
    $filelist = array();
    for ($i = 0; $i < count($tempfilelist); $i++) {
        $filestat = stat($tempfilelist[$i]);
        $WORKING['ALLFILESIZE'] += $filestat['size'];
        $outfile = str_replace($removepath, '', $tempfilelist[$i]);
        if (substr($outfile, 0, 1) == '/') {
            //remove first /
            $outfile = substr($outfile, 1);
        }
        $filelist[] = array('FILE' => $tempfilelist[$i], 'OUTFILE' => $outfile, 'SIZE' => $filestat['size'], 'ATIME' => $filestat['atime'], 'MTIME' => $filestat['mtime'], 'CTIME' => $filestat['ctime'], 'UID' => $filestat['uid'], 'GID' => $filestat['gid'], 'MODE' => $filestat['mode']);
    }
    add_file($filelist);
    //add files to list
    $WORKING['STEPDONE'] = 2;
    $WORKING['STEPSDONE'][] = 'FILE_LIST';
    //set done
    unset($tempfilelist);
    $filelist = get_filelist();
    //get files from list
    if (!is_array($filelist[0])) {
        trigger_error(__('No files to backup', 'backwpup'), E_USER_ERROR);
    } else {
        trigger_error(sprintf(__('%1$d files with %2$s to backup', 'backwpup'), count($filelist), formatBytes($WORKING['ALLFILESIZE'])), E_USER_NOTICE);
    }
}