403Webshell
Server IP : 37.9.174.138  /  Your IP : 216.73.216.117
Web Server : Apache
System : Linux vps6.backend.sk 6.12.100+deb13-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.12.100-1 (2026-07-30) x86_64
User : ftpuser ( 1001)
PHP Version : 8.4.24
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /var/www/html/backend-accounting.sk/dev/app/classes/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/html/backend-accounting.sk/dev/app/classes/PDODatabaseBackupper.php
<?php
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

namespace app\classes;

/**
 * Description of PDODatabaseBackupper
 *
 * @author maros
 */
class PDODatabaseBackupper {

    /** @var PDODatabase */
    private $db;

    /** @var \PDO */
    private $con;

    /** @var \App */
    private $app;
    private $path;
    private $url;

    public function __construct() {
        $this->db = PDODatabase::getInstance();
        $this->con = $this->db->getConnection();
        $this->app = \App::getInstance();

        $this->path = DOCUMENT_ROOT . "uploads/backups";
        if (!file_exists($this->path)) {
            mkdir($this->path);
        }
        $this->path = DOCUMENT_ROOT . "uploads/backups/mysql";
        if (!file_exists($this->path)) {
            mkdir($this->path);
        }
        $this->path .= "/";
        $this->url = $this->app->getBaseUrl(true) . "uploads/backups/mysql";

        $this->path = DOCUMENT_ROOT . "uploads/exports/";
        $this->url = $this->app->getBaseUrl(true) . "uploads/exports/";
    }

    /**
     * Perform MySQL Database Backup
     *
     * @param $pdo
     * @param string $tables
     * @param string $filePath
     * @return bool
     */
    public function backupTablesRaw(\PDO $pdo, $tables = '*', $filePath = '/') {
        try {

            // Get all of the tables
            if ($tables == '*') {
                $tables = [];
                $query = $pdo->query('SHOW TABLES');
                while ($row = $query->fetch()) {
                    $tables[] = $row[0];
                }
            } else {
                $tables = is_array($tables) ? $tables : explode(',', $tables);
            }

            if (empty($tables)) {
                return false;
            }

            $out = '';

            // Loop through the tables
            foreach ($tables as $table) {
                $query = $pdo->query('SELECT * FROM ' . $table);
                if ($query !== false) {
                    // Add DROP TABLE statement
                    $out .= 'DROP TABLE ' . $table . ';' . "\n\n";

                    // Add CREATE TABLE statement     
                    $query2 = $pdo->query('SHOW CREATE TABLE ' . $table);
                    if ($query2 !== null) {
                        $row2 = $query2->fetch();

                        $out .= $row2[1] . ';' . "\n\n";

                        // Add INSERT INTO statements
                        while ($row = $query->fetch(\PDO::FETCH_NUM)) {
                            $out .= 'INSERT INTO ' . $table . ' VALUES("';
                            for ($j = 0; $j < count($row); $j++) {
                                $row[$j] = addslashes($row[$j]);
                                $row[$j] = preg_replace("/\n/us", "\\n", $row[$j]);
                            }
                            $out .= implode('", "', $row);
                            $out .= '");' . "\n";
                        }
                        $out .= "\n\n\n";
                    }
                }
            }
            // Save file
            file_put_contents($filePath, $out);
        } catch (\Exception $e) {
            echo "<br><pre>Exception: " . $e->getMessage() . "</pre>\n";
            return false;
        }

        return true;
    }

    public function backupTables($tables, $moduleName, $backupName) {
        $dest = $this->path . $moduleName;
        if (!file_exists($dest)) {
            mkdir($dest);
        }
        $dest .= "/" . $backupName . ".sql";
        $this->backupTablesRaw($this->con, $tables, $dest);
    }

    public function getBackups($moduleName) {
        $backups = array();
        $path = $this->path . $moduleName;
        foreach (scandir($path) as $file) {
            if ($file === "." || $file === "..") {
                continue;
            }

            if (filemtime($this->path . $moduleName . "/" . $file) < time() - 60 * 24 * 60 * 60) {
                unlink($this->path . $moduleName . "/" . $file);
                continue;
            }

            $backups[$file] = filemtime($this->path . $moduleName . "/" . $file);
        }
        asort($backups);
        return array_reverse($backups);
    }

    public function deleteOldBackups($moduleName, $keepCount = 10) {
        $backups = $this->getBackups($moduleName);
        $c = 0;
        foreach ($backups as $file => $mtime) {
            if ($c >= $keepCount) {
                unlink($this->path . $moduleName . "/" . $file);
            }
            $c++;
        }
    }

    public function printBackups($moduleName) {
        $t = Translator::getInstance();
        $backups = $this->getBackups($moduleName);
        if (count($backups) === 0) {
            ?>
            <div class="text-center">
                <?php echo $t->_get("Neboli nájdené žiadne záznamy.") ?>
            </div>
            <?php
            return;
        }
        ?>
        <div class="panel panel-default">
            <table class="table table-bordered table-striped text-center mb45 reportsTable"> 
                <thead>
                    <tr>
                        <th><?php echo $t->_get("Dátum") ?></th>
                        <th><?php echo $t->_get("Súbor") ?></th>
                        <th><?php echo $t->_get("Stiahnuť") ?></th>
                    </tr>
                </thead>
                <tbody>
                    <?php
                    foreach ($backups as $file => $date) {
                        ?>
                        <tr>         
                            <td><?php echo date("d.m.Y H:i:s", $date) ?></td>    
                            <td><a target="_blank" href="<?php echo $this->url . $file ?>"><?php echo $file ?></a></td>
                            <td><a download target="_blank" href="<?php echo $this->url . $file ?>" class="export-btn-xls btn btn-success btn-xs"><i class="fa fa-download"></i> <?php echo $t->_get("Stiahnuť") ?></a></td>
                        </tr>
                        <?php
                    }
                    ?>
                </tbody>
            </table>
        </div>
        <?php
    }

}

Youez - 2016 - github.com/yon3zu
LinuXploit