gzuncompress NineSec Team Shell
NineSec Team Shell
Server IP : 172.19.0.3  /  Your IP : 216.73.216.178
Web Server : Apache/2.4
System : Linux 880f91b28fd7 5.15.0-117-generic #127~20.04.1-Ubuntu SMP Thu Jul 11 15:36:12 UTC 2024 x86_64
User : tomlinde ( 155017)
PHP Version : 5.6.40
Disable Function : dl, syslog, opcache_get_status
MySQL : ON  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON
Directory (0700) :  /home/webpages/lima-city/tomlinde/html/weiterleitungen/../gallerieChina/internals/

[  Home  ][  C0mmand  ][  Upload File  ][  Lock Shell  ][  Logout  ]

Current File : /home/webpages/lima-city/tomlinde/html/weiterleitungen/../gallerieChina/internals/update.php
<?php
class Updater{
	private $available = false;
	private $nextVersion;
	private $unmodified = false;
	private $info;
	private $URL = "http://jepz.dyndns.org/updates/gallery/";
	private $updateFileExceptions = array("pictures", "videos", "cache", "config.inc.php", "HashList.txt", "update");
	
	public $basePath = "./";
	
	private function downloadUpdate(){
		$file_url = $this->URL.$this->available;
		$file_name = $this->basePath."internals/update/".$this->available;
		
		//prepare curl for download
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL, $file_url);
		curl_setopt($ch, CURLOPT_HEADER, 0);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
		curl_setopt($ch, CURLOPT_BINARYTRANSFER, TRUE);
		//download the zip
		$zipContent = curl_exec($ch);
		
		if($zipContent === FALSE)
			return FALSE; // if something went wrong return false
		
		//save the zip to a file
		file_put_contents($file_name, $zipContent);
		
		//unzip the update
		$zip = new ZipArchive();
		$res = $zip->open($file_name);
		if ($res!==TRUE) {
			return FALSE;
		}
		$zip->extractTo($this->basePath."internals/update/");
		$zip->close();
		
		//delete the zip
		unlink($file_name);
		return TRUE;
	}
	
	public function updateAvailable(){
		$currentVersion = trim(file_get_contents($this->basePath."VERSION"));
		//prepare curl for download
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL, $this->URL."info.xml");
		curl_setopt($ch, CURLOPT_HEADER, 0);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
		$info = curl_exec($ch);
		
		if($info === false){
			$this->available = false;
			return false;
		}
		
		$doc = new DOMDocument();
		$doc->loadXML($info);
		
		$xpath = new DOMXPath($doc);
		$query = "count(//version[previousVersion = '".$currentVersion."'])";
		$nextVersion = $xpath->evaluate($query);
		
		if($nextVersion != 1){
			$this->available = false;
			return false;
		}
		
		$query = "//version[previousVersion = '".$currentVersion."']/filename";
		$this->available = $xpath->evaluate($query)->item(0)->nodeValue;
		$query = "//version[previousVersion = '".$currentVersion."']/@id";
		$this->nextVersion = $xpath->evaluate($query)->item(0)->nodeValue;
		return true;
	}
	
	//this method is used since we dont want to overwrite any customizations...
	public function checkForModifications(){
		$oldDom = $this->createHashList();
		$oldDom->save($this->basePath."internals/HashList.txt");
		$dom = new DOMDocument('1.0', 'utf-8');
		$dom->load($this->basePath."internals/HashList.txt");
		$newDom = $this->createHashList();
		$this->unmodified = (md5($dom->saveXML()) == md5($newDom->saveXML()));
		return $this->unmodified;
	}
	
	public function performUpdate(){
		if( !($this->available && $this->unmodified) ){
			return;
		}
		
		mkdir($this->basePath."internals/update");
		
		//download and unpack the update
		$this->downloadUpdate();
		
		//deleting old stuff
		$this->subDirRemove($this->basePath);
		
		//moving new stuff
		moveDirContent($this->basePath."internals/update/gallery", $this->basePath);
		rmdir($this->basePath."internals/update/gallery");
		
		//cleaning up
		rmdir($this->basePath."internals/update");
	}
	
	public function createHashList(){
		$dom = new DOMDocument('1.0', 'utf-8');
		$fileList = $dom->createElement("fileList");
		$fileList->appendChild($this->subDirHashList($dom, $this->basePath, $this->updateFileExceptions));
		$dom->appendChild($fileList);
		return $dom;
	}
	
	//this function goes through the whole file tree and create a XML-node for each file/directory
	private function subDirHashList($dom, $path, $fileExceptions){
		$dirNode = $dom->createElement("directory");
		$dirPath = $dom->createElement("path");
		$dirNode->appendChild($dirPath);
		
		foreach(scandir($path) as $file){
			//skipping
			if(in_array($file, $fileExceptions) OR $file == '.' OR $file == '..')
				continue;
			
			//recursion
			if(is_dir($path."/".$file)){
				$dirNode->appendChild($this->subDirHashList($dom, $path."/".$file, $fileExceptions));
			} else {
				$nameNode = $dom->createElement("name", $file);
				$md5Node = $dom->createElement("md5", md5_file($path."/".$file));
				
 				$fileNode = $dom->createElement("file");
				$fileNode->appendChild($nameNode);
				$fileNode->appendChild($md5Node);
				$dirNode->appendChild($fileNode);
			}
		}
		
		return $dirNode;
	}
	
	function subDirRemove($path){
		foreach(scandir($path) as $file){
			//skipping
			if(in_array($file, $this->updateFileExceptions) OR $file == '.' OR $file == '..')
				continue;
			
			//recursion
			if(is_dir($path."/".$file)){
				$this->subDirRemove($path."/".$file);
				@rmdir($path."/".$file);
			} else {
				unlink($path."/".$file);
			}
		}
	}
}

function moveDirContent($source_path, $dest_path){
	foreach(scandir($source_path) as $file){
		if($file == '.' OR $file == '..')
			continue;
		
		$srcF = $source_path."/".$file;
		$destF = $dest_path."/".$file;
		
		if(is_dir($srcF)){
			@mkdir($destF);
			moveDirContent($srcF, $destF);
			rmdir($srcF);
		} else {
			rename($srcF, $destF);
		}
	}
}
?>

NineSec Team - 2022