mirror of
				https://github.com/optim-enterprises-bv/control-pane.git
				synced 2025-10-30 17:37:59 +00:00 
			
		
		
		
	* Cleanup
This commit is contained in:
		| @@ -58,13 +58,6 @@ class CBSD { | |||||||
| 	{ | 	{ | ||||||
| 		$cmd='cbsd media mode=register name=%s path=%s type=%s'; | 		$cmd='cbsd media mode=register name=%s path=%s type=%s'; | ||||||
| 		$res=self::run($cmd, array($file, $path.$file, $ext)); | 		$res=self::run($cmd, array($file, $path.$file, $ext)); | ||||||
| 		if($res['error']){ |  | ||||||
| 			$arr['error']=true; |  | ||||||
| 			$arr['error_message']='File image not registered!'; |  | ||||||
| 		} else { |  | ||||||
| 			$arr['error']=false; |  | ||||||
| 		} |  | ||||||
|  |  | ||||||
| 		echo json_encode($arr); | 		echo json_encode($arr); | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|   | |||||||
| @@ -1,6 +1,5 @@ | |||||||
| <?php | <?php | ||||||
| if(isset($_GET['file'])) | if(isset($_GET['file'])){ | ||||||
| { |  | ||||||
| 	$file=$_GET['file']; | 	$file=$_GET['file']; | ||||||
| 	$filename=$file; | 	$filename=$file; | ||||||
| }else{ | }else{ | ||||||
| @@ -9,8 +8,9 @@ if(isset($_GET['file'])) | |||||||
| } | } | ||||||
|  |  | ||||||
| $res=$clonos->userAutologin(); | $res=$clonos->userAutologin(); | ||||||
| if(isset($res['id']) && $res['id']>0) |  | ||||||
| { | if(isset($res['id']) && $res['id']>0){ | ||||||
|  |  | ||||||
| 	$file=$clonos->media_import.$file; | 	$file=$clonos->media_import.$file; | ||||||
|  |  | ||||||
| 	header('Content-disposition: attachment; filename='.$filename); | 	header('Content-disposition: attachment; filename='.$filename); | ||||||
| @@ -20,19 +20,19 @@ if(isset($res['id']) && $res['id']>0) | |||||||
| 	header('Content-Length: '.filesize($file)); | 	header('Content-Length: '.filesize($file)); | ||||||
| 	header("Pragma: no-cache"); | 	header("Pragma: no-cache"); | ||||||
| 	header("Expires: 0"); | 	header("Expires: 0"); | ||||||
| 	 |  | ||||||
| 	$chunkSize = 1024 * 1024; | 	$chunkSize = 1024 * 1024; | ||||||
|     $handle = fopen($file, 'rb'); | 	$handle = fopen($file, 'rb'); | ||||||
|     while (!feof($handle)) | 	while (!feof($handle)) | ||||||
|     { | 	{ | ||||||
| 		$buffer = fread($handle, $chunkSize); | 		$buffer = fread($handle, $chunkSize); | ||||||
| 		echo $buffer; | 		echo $buffer; | ||||||
| 		ob_flush(); | 		ob_flush(); | ||||||
| 		flush(); | 		flush(); | ||||||
|     } | 	} | ||||||
|     fclose($handle); | 	fclose($handle); | ||||||
| 	 |  | ||||||
| 	exit;	 | 	exit; | ||||||
| } | } | ||||||
|  |  | ||||||
| header('HTTP/1.1 401 Unauthorized'); | header('HTTP/1.1 401 Unauthorized'); | ||||||
|   | |||||||
| @@ -4,101 +4,90 @@ header('Content-Type: application/json'); | |||||||
| require_once("../php/cbsd.php"); | require_once("../php/cbsd.php"); | ||||||
|  |  | ||||||
| $cmd=''; | $cmd=''; | ||||||
|  | $status = ''; | ||||||
|  |  | ||||||
| if($_SERVER['REQUEST_METHOD'] === 'POST') | if($_SERVER['REQUEST_METHOD'] === 'POST'){ | ||||||
| { |  | ||||||
| 	//$ppath=realpath('').'/media/'; |  | ||||||
| 	$path=realpath('').'/media/'; | 	$path=realpath('').'/media/'; | ||||||
| 	if(isset($_POST['uplace'])) | 	if(isset($_POST['uplace'])){ | ||||||
| 	{ |  | ||||||
| 		$res=strpos($_POST['uplace'],'jailscontainers'); | 		$res=strpos($_POST['uplace'],'jailscontainers'); | ||||||
| 		if($res!==false) | 		if($res!==false){ | ||||||
| 		{ |  | ||||||
| 			//$ppath='/media_import/'; |  | ||||||
| 			$path=$clonos->media_import; | 			$path=$clonos->media_import; | ||||||
| 			$cmd='import'; | 			$cmd='import'; | ||||||
| 		} | 		} | ||||||
| 		$res=strpos($_POST['uplace'],'imported'); | 		$res=strpos($_POST['uplace'],'imported'); | ||||||
| 		if($res!==false) | 		if($res!==false){ | ||||||
| 		{ |  | ||||||
| 			$path=$clonos->media_import; | 			$path=$clonos->media_import; | ||||||
| 			$cmd='import'; | 			$cmd='import'; | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 	//$path=realpath('').$ppath; |  | ||||||
| 	if(is_uploaded_file($_FILES['file']['tmp_name'])) | 	// https://www.php.net/manual/en/features.file-upload.php | ||||||
| 	{ | 	// Undefined | Multiple Files | $_FILES Corruption Attack | ||||||
| 		$ext = strtolower(pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION)); | 	// If this request falls under any of them, treat it invalid. | ||||||
| 		$file = strtolower(pathinfo($_FILES['file']['name'], PATHINFO_FILENAME)); | 	if ( | ||||||
| 		$uid = uniqid(); | 		!isset($_FILES['file']['error']) || | ||||||
| 		$date = time(); | 		is_array($_FILES['file']['error']) | ||||||
| 		 | 	) { | ||||||
| 		$returnJson[]=array('filepath'=>$path); | 		echo json_encode(array('status' => 'Upload Fail: An error occurred!';)); | ||||||
| 		 | 		exit; | ||||||
| 		//$filename=$path.$filename.'-'.$uid.".".$ext; | 	} | ||||||
| 		$file=$file.'.'.$ext; |  | ||||||
| 		$filename=$path.$file;	//.'.'.$ext; | 	if(is_uploaded_file($_FILES['file']['tmp_name'])){ | ||||||
| 		if (move_uploaded_file($_FILES['file']['tmp_name'], $filename)) | 		$basename = strtolower(pathinfo($_FILES['file']['name'], PATHINFO_BASENAME)); | ||||||
| 		{ |  | ||||||
|  | 		if (move_uploaded_file($_FILES['file']['tmp_name'], $path.$basename)){ | ||||||
| 			$status = 'ok';	//'Successfully uploaded!'; | 			$status = 'ok';	//'Successfully uploaded!'; | ||||||
| 			if($cmd=='import') | 			if($cmd=='import'){ | ||||||
| 			{ | 				$res=CBSD::run('task owner=%s mode=new /usr/local/bin/cbsd jimport jname=%s inter=0', [$clonos->getUserName(), $path.$basename]); | ||||||
| 				$res=CBSD::run('task owner=%s mode=new /usr/local/bin/cbsd jimport jname=%s' inter=0', [$clonos->getUserName(), $filename]); |  | ||||||
| 			} | 			} | ||||||
| 		}else{ | 		} else { | ||||||
| 			$status = 'Upload Fail: Unknown error occurred!'; | 			$status = 'Upload Fail: Unknown error occurred!'; | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 	//echo '<pre>';print_r($_POST); |  | ||||||
| } | } | ||||||
| if($status!='ok') {echo json_encode(array('status' => $status));exit;} |  | ||||||
| return; | if($status!='ok'){ | ||||||
|  | 	echo json_encode(array('status' => $status)); | ||||||
|  | 	exit; | ||||||
|  | } | ||||||
|  | return; # TODO ?! | ||||||
|  |  | ||||||
| $valid_exts = array('image/jpeg', 'image/jpg', 'image/png', 'image/gif'); // valid extensions | $valid_exts = array('image/jpeg', 'image/jpg', 'image/png', 'image/gif'); // valid extensions | ||||||
| $max_size = 30000 * 1024; // max file size in bytes | $max_size = 30000 * 1024; // max file size in bytes | ||||||
|  |  | ||||||
| $json = array(); | if ( $_SERVER['REQUEST_METHOD'] === 'POST' ){ | ||||||
| 	if ( $_SERVER['REQUEST_METHOD'] === 'POST' ) | 	for($i=0;$i<count($_FILES['file']['tmp_name']);$i++){ | ||||||
| 	{ | 		$path="/media/"; | ||||||
| 		for($i=0;$i<count($_FILES['file']['tmp_name']);$i++) |  | ||||||
| 		{ |  | ||||||
| 			$path="/media/"; |  | ||||||
|  |  | ||||||
| 			if(is_uploaded_file($_FILES['file']['tmp_name'][$i]) ) | 		if(is_uploaded_file($_FILES['file']['tmp_name'][$i]) ){ | ||||||
| 			{ | 			// get uploaded file extension | ||||||
| 				// get uploaded file extension | 			$ext = strtolower(pathinfo($_FILES['file']['name'][$i], PATHINFO_EXTENSION)); | ||||||
| 				$ext = strtolower(pathinfo($_FILES['file']['name'][$i], PATHINFO_EXTENSION)); | 			// looking for format and size validity | ||||||
| 				// looking for format and size validity | 			if (in_array($ext, $valid_exts) AND $_FILES['file']['size'][$i] < $max_size){ | ||||||
| 				if (in_array($ext, $valid_exts) AND $_FILES['file']['size'][$i] < $max_size) | 				// unique file path | ||||||
| 				{ | 				$uid = uniqid(); | ||||||
| 					// unique file path | 				$date = date('Y-m-d-H-i-s'); | ||||||
| 					$uid = uniqid(); | 				$path = $path ."image_" .$date. '_' . $uid . "." .$ext; | ||||||
| 					$date = date('Y-m-d-H-i-s'); |  | ||||||
| 					$path = $path ."image_" .$date. '_' . $uid . "." .$ext; |  | ||||||
|  |  | ||||||
| 					$returnJson[]= array("filepath"=>$path); | 				$filename = "image_" . $date . "_" .$uid . "." . $ext; | ||||||
|  | 				//$this->createthumb($i,$filename); | ||||||
|  |  | ||||||
| 					$filename = "image_" . $date . "_" .$uid . "." . $ext; | 				// move uploaded file from temp to uploads directory | ||||||
| 					//$this->createthumb($i,$filename); | 				if (move_uploaded_file($_FILES['file']['tmp_name'][$i], $path)){ | ||||||
|  | 					$status = 'ok';	//'Successfully uploaded!'; | ||||||
| 					// move uploaded file from temp to uploads directory | 					//perform sql updates here | ||||||
| 					if (move_uploaded_file($_FILES['file']['tmp_name'][$i], $path)) | 				} else { | ||||||
| 					{ | 					$status = 'Upload Fail: Unknown error occurred!'; | ||||||
| 						$status = 'ok';	//'Successfully uploaded!'; |  | ||||||
| 						//perform sql updates here |  | ||||||
| 					}else{ |  | ||||||
| 						$status = 'Upload Fail: Unknown error occurred!'; |  | ||||||
| 					} |  | ||||||
| 				}else{ |  | ||||||
| 					$status = 'Upload Fail: Unsupported file format or It is too large to upload!'; |  | ||||||
| 				} | 				} | ||||||
| 			}else{ | 			} else { | ||||||
| 				$status = 'Upload Fail: File not uploaded!'; | 				$status = 'Upload Fail: Unsupported file format or It is too large to upload!'; | ||||||
| 			} | 			} | ||||||
|  | 		} else { | ||||||
|  | 			$status = 'Upload Fail: File not uploaded!'; | ||||||
| 		} | 		} | ||||||
| 	}else{ |  | ||||||
| 		$status = 'Bad request!'; |  | ||||||
| 	} | 	} | ||||||
|  | } else { | ||||||
|  | 	$status = 'Bad request!'; | ||||||
|  | } | ||||||
|  |  | ||||||
| 	echo json_encode(array('status' => $status)); | echo json_encode(array('status' => $status)); | ||||||
| 	//echo json_encode($json); |  | ||||||
		Reference in New Issue
	
	Block a user
	 Momchil Bozhinov
					Momchil Bozhinov