Current File : /home/users/kundensystem/www/admin/backups.php
<?php
include './inc/header.php';
include './inc/sidebar.php';

if($adminRole['backup']!='1'&&$adminData['role']!='1'){ 
  ?><script>location.href="index.php";</script><?php
  exit;
}

$msg=''; 
if(isset($_GET['code'])&&$_GET['code']==4){
    $f=$_GET['f'];
    unlink('./backups/'.$f);

    $msg='<div class="alert alert-success alert-dismissible fade show" role="alert">
            <i class="bi bi-exclamation-octagon me-1"></i>
            <b>Hinweis</b>: Die Sicherungsdatei wurde gel&ouml;scht.
            <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
        </div>';
}

if(isset($_GET['code'])&&$_GET['code']==1){
    $f=$_GET['f'];
    $importFile ='./backups/'.$f;
    $command='mysql -h' .$db_host .' -u' .$db_user .' -p' .$db_pass .' ' .$db_name .' < ' .$importFile;
    exec($command,$output,$worked);

    $msg='<div class="alert alert-success alert-dismissible fade show" role="alert">
                <i class="bi bi-exclamation-octagon me-1"></i>
                <b>Hinweis</b>: Die Datei wurde erfolgreich importiert!
                <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
            </div>';
}

if(isset($_POST['rand'])&&$_POST['rand']==$_SESSION['rand']){
    $fn=$_FILES['sqlFile']['name'];
    move_uploaded_file($_FILES['sqlFile']['tmp_name'], $fn);
    $importFile ='./'.$fn;
    $command='mysql -h' .$db_host .' -u' .$db_user .' -p' .$db_pass .' ' .$db_name .' < ' .$importFile;
    exec($command,$output,$worked);
    unlink($fn);
    
    $msg='<div class="alert alert-success alert-dismissible fade show" role="alert">
                <i class="bi bi-exclamation-octagon me-1"></i>
                <b>Hinweis</b>: Die Datei wurde erfolgreich importiert!
                <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
            </div>';
}

?>

<main id="main" class="main">

    <div class="pagetitle">
      <h1>Backups anzeigen</h1>
      <nav>
        <ol class="breadcrumb">
          <li class="breadcrumb-item"><a href="index.php">Home</a></li>
          <li class="breadcrumb-item">Backup</li>
          <li class="breadcrumb-item">Backups anzeigen</li>
        </ol>
      </nav>
    </div><!-- End Page Title -->

    <section class="section dashboard">
        <div class="row">
            <div class="col-lg-2"> </div>
            <div class="col-lg-8"> 
                <div class="card">
                    <div class="card-body">
                        <h5 class="card-title">Backups anzeigen</h5>
                        <?php if($msg!='') echo $msg; ?>

                        <form method="post" action="backups.php" enctype="multipart/form-data" >
                            <div class="row">
                                <label class="control-label col-lg-4 col-form-label text-right">Erstelltes Backup hochladen : </label>
                                <div class="col-lg-4">
                                    <input type="file" class="form-control" name="sqlFile" accept=".sql" required>
                                    <?php  $rand = rand(); $_SESSION['rand'] = $rand; ?>
                                    <input type="hidden" name="rand" value="<?= $rand;?>">
                                </div>
                                <div class="col-lg-4">
                                    <input type="submit" class="btn btn-primary btn-sm" value="Backup hochladen">
                                </div>
                            </div>
                        </form>

                        <hr>

                        <table id="data_table" class="table table-striped" style="width:100%">
                            <thead>
                                <tr>
                                    <th>Datenbankname</th>
                                    <th>Datum</th>
                                    <th>Größe</th>
                                    <th></th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php
                                $fileList = glob('backups/*.sql');
                                foreach($fileList as $filename){
                                    if(is_file($filename)&&filesize($filename)!=0){
                                        $fn_arr=explode('/',$filename);
                                        echo '<tr>
                                                <td>'.$fn_arr[1].'</td>
                                                <td>'.date('d.m.Y H:i:s',filemtime($filename)).'</td>
                                                <td>'.round(filesize($filename) / 1024, 2).' KB</td>
                                                <td class="text-right">
                                                    <a href="download_sql.php?f='.$fn_arr[1].'" class="btn btn-primary btn-sm" target="_blank">Herunterladen</a>
                                                    <a href="backups.php?f='.$fn_arr[1].'&code=1" class="btn btn-success btn-sm">Zur&uuml;cksichern</a>
                                                    <a href="backups.php?f='.$fn_arr[1].'&code=4" class="btn btn-danger btn-sm">L&ouml;schen</a>
                                                </td>
                                            </tr>';
                                    }   
                                }
                                ?>
                            </tbody>
                        </table>

                    </div>
                </div>
            </div>
        </div>
    </section>

</main><!-- End #main -->

<?php
include_once './inc/footer.php';
?>
<link href="https://cdn.datatables.net/1.10.22/css/dataTables.bootstrap4.min.css" rel="stylesheet">
<script src="https://cdn.datatables.net/1.10.22/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/1.10.22/js/dataTables.bootstrap4.min.js"></script>

<script>
    $('.sub10 ul').addClass('show');
    $('.sub10 .nav-link').removeClass('collapsed');

    $(document).ready(function(){
        $('#data_table').DataTable({
            "order": [[ 0, "desc" ]],
            "scrollX": true,
            "language": {
                "lengthMenu": "<?php echo $langstr['Zeige _MENU_ Eintrage'];?>",
                "info":           "<?php echo $langstr['Zeige~Eintragen'];?>",
                "search":         "<?php echo $langstr['Suche'];?>:",
                "infoEmpty":      "<?= $langstr['Zeige 0 bis 0 von 0 Eintragen'];?>",
                "emptyTable": "<?= $langstr['Keine Daten verfugbar'];?>",
                "paginate": {
                    "first":      "First",
                    "last":       "Last",
                    "next":       "<?php echo $langstr['Nachste'];?>",
                    "previous":   "<?php echo $langstr['Vorher'];?>"
                },
            }
        });
    })
</script>