File indexing completed on 2024-03-24 17:29:45

0001 <?php
0002 /**
0003  *  ocs-webserver
0004  *
0005  *  Copyright 2016 by pling GmbH.
0006  *
0007  *    This file is part of ocs-webserver.
0008  *
0009  *    This program is free software: you can redistribute it and/or modify
0010  *    it under the terms of the GNU Affero General Public License as
0011  *    published by the Free Software Foundation, either version 3 of the
0012  *    License, or (at your option) any later version.
0013  *
0014  *    This program is distributed in the hope that it will be useful,
0015  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
0016  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0017  *    GNU Affero General Public License for more details.
0018  *
0019  *    You should have received a copy of the GNU Affero General Public License
0020  *    along with this program.  If not, see <http://www.gnu.org/licenses/>.
0021  **/
0022 
0023 //echo "Deactivated for now";
0024 //return;
0025 
0026 
0027 
0028 //Constants
0029 //$CN_APTH = "/mnt/volume-fra1-11/var/www/cdn/pling-cdn";
0030 $CN_APTH = ".";
0031 
0032 if (file_exists('config.php')) {
0033     require_once('config.php');
0034 } else {
0035     header("HTTP/1.0 500 Server Error");
0036     echo "Error" . PHP_EOL;
0037     return;
0038 }
0039 
0040 $configKey = $config['privateKey'];
0041 
0042 
0043 $privKey = urldecode($_GET['key']);
0044 
0045 if (!$privKey || $privKey != $configKey) {
0046     header("HTTP/1.0 500 Server Error");
0047     echo "Error" . PHP_EOL;
0048     return;
0049 }
0050 
0051 $imgurl = urldecode($_GET['path']);
0052 
0053 $delete_post_name = $_GET['post'];
0054 $imagename = basename($imgurl);
0055 
0056 if (!$imgurl || !$imagename) {
0057     header("HTTP/1.0 500 Server Error");
0058     echo "Error, param: path missing" . PHP_EOL;
0059     return;
0060 }
0061 if (!$delete_post_name) {
0062     header("HTTP/1.0 500 Server Error");
0063     echo "Error, param: post missing" . PHP_EOL;
0064     return;
0065 }
0066 
0067 if($imagename == "std_avatar_80.png") {
0068     echo "Nothing to do. We do not delete std_avatar_80.png";
0069     return;
0070 }
0071 
0072 echo "Deleting file: ".$imgurl.PHP_EOL;
0073 
0074 $fileExists = file_exists($CN_APTH.'/img/' . $imgurl);
0075 
0076 if($fileExists) {
0077     echo("File exists" . PHP_EOL);
0078 } else {
0079     echo("File did not exists" . PHP_EOL);
0080 }
0081 
0082 if($fileExists) {
0083     echo("Rename file..." . PHP_EOL);
0084     $last_line = system('mv '.$CN_APTH.'/img/' . $imgurl . ' ' . $CN_APTH.'/img/' . $imgurl . $delete_post_name.' 2>&1');
0085     echo $last_line . PHP_EOL;
0086 
0087     $fileExists = file_exists($CN_APTH.'/img/' . $imgurl . $delete_post_name);
0088 
0089     if($fileExists) {
0090         echo("Rename File done: ".$CN_APTH.'/img/' . $imgurl . $delete_post_name . PHP_EOL);
0091     } else {
0092         header("HTTP/1.0 500 Server Error");
0093         echo("Rename File did not work!" . PHP_EOL);
0094     }
0095 }
0096 
0097 echo("Search for cached files:" . PHP_EOL);
0098 //echo('Command: locate -i "' . $imgurl.'"' . PHP_EOL);
0099 
0100 $last_line = exec('locate -i "' . $imgurl.'" 2>&1', $resultArray, $result);
0101 
0102 $numFiles = count($resultArray);
0103 if($numFiles == 0) {
0104     echo "No cached files found." . PHP_EOL;
0105 } else {
0106     echo "Found $numFiles files." . PHP_EOL;
0107 }
0108 
0109 foreach ($resultArray as $value) {
0110     if(strpos($value, '/cache/') !== false) {
0111         echo "Command: rm $value" . PHP_EOL;
0112         $last_line = system("rm $value 2>&1");
0113         echo $last_line . PHP_EOL;
0114     }
0115 }