Ignore:
Timestamp:
Dec 10, 2017, 4:32:57 PM (9 years ago)
Author:
Joachim Langenbach <joachim.langenbach@…>
Branches:
debian/bullseye, debian/jessie
Children:
ce5244e
Parents:
c810990 (diff), 8ef59a1 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'debian/jessie' of ​https://svn.engsas.de/gnuboat into debian/jessie

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/webapp/webservice/inc/GnuBoat/ServiceLogFiles.php

    rc810990 r8fd7454  
    3232                $debug = $this->debug();
    3333                $config = new Config();
     34                if($debug > 1)
     35                        print "Log directory: ". $config->logDirectory() ."\n";
    3436
    3537                if(!array_key_exists("logfilesSelected", $_POST)){
    … …  
    3739                        $files = glob($config->logDirectory() ."*.log");
    3840                        array_walk($files, 'GnuBoat\ServiceLogFiles::stripLogDirectory');
     41                        return $this->output($files);
     42                }
    3943
    40                         header('Content-Type: application/json');
    41                         if($debug > 0){
    42                                 echo json_encode($files,  JSON_PRETTY_PRINT) ."\n";
     44                // prepare a download of available log files
     45                $files = $_POST["logfilesSelected"];
     46                if(count($files) < 1)
     47                        return $this->error("No logfile selected");
     48                elseif(count($files) == 1){
     49                        $content = file_get_contents($config->logDirectory() . $files[0]);
     50                        if($content === false){
     51                                echo "<html><head></head><body>Failed to read logfile ". $files[0] ."</body></html>";
    4352                        }
    44                         else{
    45                                 echo json_encode($files) ."\n";
    46                         }
     53               
     54                        header('Content-Type: text/plain');
     55                        header('Content-disposition: attachment; filename="'. $files[0] .'"');
     56                        header('Content-Length: ' . filesize($config->logDirectory() . $files[0]));
     57                        echo $content;
    4758                }
    4859                else{
    49                         // prepare a download of available log files
    50                         $files = $_POST["logfilesSelected"];
    51                         if(count($files) < 1){
     60                        $date = new \DateTime('NOW');
     61                        $archiveName = "gnuboat-logs-". $date->format("Y-m-d");
     62               
     63                        // provide files as zip file
     64                        $tmpArchive = tempnam(sys_get_temp_dir(), $archiveName);
     65                        $zip = new \ZipArchive();
     66                        if($zip->open($tmpArchive, \ZipArchive::CREATE) !== TRUE){
     67                                echo "<html><head></head><body>Failed to create zip file</body></html>";
    5268                                return;
    5369                        }
    54                         elseif(count($files) == 1){
    55                                 $content = file_get_contents($config->logDirectory() . $files[0]);
    56                                 if($content === false){
    57                                         echo "<html><head></head><body>Failed to read logfile ". $files[0] ."</body></html>";
    58                                 }
    59                        
    60                                 header('Content-Type: text/plain');
    61                                 header('Content-disposition: attachment; filename="'. $files[0] .'"');
    62                                 header('Content-Length: ' . filesize($config->logDirectory() . $files[0]));
    63                                 echo $content;
    64                         }
    65                         else{
    66                                 $date = new \DateTime('NOW');
    67                                 $archiveName = "gnuboat-logs-". $date->format("Y-m-d");
    68                        
    69                                 // provide files as zip file
    70                                 $tmpArchive = tempnam(sys_get_temp_dir(), $archiveName);
    71                                 $zip = new \ZipArchive();
    72                                 if($zip->open($tmpArchive, \ZipArchive::CREATE) !== TRUE){
    73                                         echo "<html><head></head><body>Failed to create zip file</body></html>";
     70                        foreach($files as $file){
     71                                if($zip->addFile($config->logDirectory() . $file, $archiveName ."/". $file) !== true){
     72                                        $zip->close();
     73                                        echo "<html><head></head><body>Failed to add logfile ". $file ." to the zip file</body></html>";
    7474                                        return;
    7575                                }
    76                                 foreach($files as $file){
    77                                         if($zip->addFile($config->logDirectory() . $file, $archiveName ."/". $file) !== true){
    78                                                 $zip->close();
    79                                                 echo "<html><head></head><body>Failed to add logfile ". $file ." to the zip file</body></html>";
    80                                                 return;
    81                                         }
    82                                 }
    83                                 if($zip->close() !== true){
    84                                                 echo "<html><head></head><body>Failed to save zip file</body></html>";
    85                                                 return;
    86                                 }
    87                                
    88                                 echo "<html><head></head><body>Failed to add logfile ". $file ." to the zip file</body></html>";
    89                                
    90                                 //Send zip folder
    91                                 while (ob_get_level()) {
    92                                         ob_end_clean();
    93                                 }
    94                                 ob_start();
    95                                 header('Content-Type: application/zip');
    96                                 header('Content-Transfer-Encoding: Binary');
    97                                 header('Content-disposition: attachment; filename=' . $archiveName . '.zip');
    98                                 header('Content-Length: ' . filesize($tmpArchive));
    99                                 ob_flush();
    100                                 ob_clean();
    101                                 readfile($tmpArchive);
    102                                 unlink($tmpArchive);
    103                                 return;
    10476                        }
     77                        if($zip->close() !== true){
     78                                        echo "<html><head></head><body>Failed to save zip file</body></html>";
     79                                        return;
     80                        }
     81                       
     82                        echo "<html><head></head><body>Failed to add logfile ". $file ." to the zip file</body></html>";
     83                       
     84                        //Send zip folder
     85                        while (ob_get_level()) {
     86                                ob_end_clean();
     87                        }
     88                        ob_start();
     89                        header('Content-Type: application/zip');
     90                        header('Content-Transfer-Encoding: Binary');
     91                        header('Content-disposition: attachment; filename=' . $archiveName . '.zip');
     92                        header('Content-Length: ' . filesize($tmpArchive));
     93                        ob_flush();
     94                        ob_clean();
     95                        readfile($tmpArchive);
     96                        unlink($tmpArchive);
     97                        return;
    10598                }
    10699        }
Note: See TracChangeset for help on using the changeset viewer.