Finish API ?
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace RomhackPlazaFS\Endpoints;
|
namespace RomhackPlazaFS\Endpoints;
|
||||||
use RomhackPlazaFS\Library\Data;
|
use RomhackPlazaFS\Library\Data;
|
||||||
|
use RomhackPlazaFS\Library\Log;
|
||||||
use RomhackPlazaFS\RomhackPlazaFS;
|
use RomhackPlazaFS\RomhackPlazaFS;
|
||||||
|
|
||||||
defined( 'ROMHACKPLAZA_FS' ) || exit;
|
defined( 'ROMHACKPLAZA_FS' ) || exit;
|
||||||
@@ -14,7 +15,7 @@ class Checkexistence extends Abstract_Endpoint {
|
|||||||
|
|
||||||
protected function private_endpoint(): bool
|
protected function private_endpoint(): bool
|
||||||
{
|
{
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function require_token(): bool
|
protected function require_token(): bool
|
||||||
@@ -50,6 +51,7 @@ class Checkexistence extends Abstract_Endpoint {
|
|||||||
'file_exists' => $file_exists,
|
'file_exists' => $file_exists,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
new Log( __class__, "WP Id=" . $this->token_info['user_id'] ,$this->file_name, $this->post_id, $this->custom_post_type, "File exists=" . $file_exists );
|
||||||
RomhackPlazaFS::success_response( $resp );
|
RomhackPlazaFS::success_response( $resp );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace RomhackPlazaFS\Endpoints;
|
namespace RomhackPlazaFS\Endpoints;
|
||||||
use RomhackPlazaFS\Library\Data;
|
use RomhackPlazaFS\Library\Data;
|
||||||
|
use RomhackPlazaFS\Library\Log;
|
||||||
use RomhackPlazaFS\RomhackPlazaFS;
|
use RomhackPlazaFS\RomhackPlazaFS;
|
||||||
|
|
||||||
defined( 'ROMHACKPLAZA_FS' ) || exit;
|
defined( 'ROMHACKPLAZA_FS' ) || exit;
|
||||||
@@ -14,12 +15,12 @@ class Deletefile extends Abstract_Endpoint {
|
|||||||
|
|
||||||
protected function private_endpoint(): bool
|
protected function private_endpoint(): bool
|
||||||
{
|
{
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function require_token(): bool
|
protected function require_token(): bool
|
||||||
{
|
{
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function get_post_params(): void {
|
protected function get_post_params(): void {
|
||||||
@@ -56,6 +57,8 @@ class Deletefile extends Abstract_Endpoint {
|
|||||||
Data::F_DELETED_FILE
|
Data::F_DELETED_FILE
|
||||||
);
|
);
|
||||||
|
|
||||||
|
new Log( __class__, "WP Id=" . $this->token_info['user_id'] ,$this->file_name, $this->post_id, $this->custom_post_type );
|
||||||
|
|
||||||
if( $data->change_data_location( $new_data ) )
|
if( $data->change_data_location( $new_data ) )
|
||||||
RomhackPlazaFS::success_response( [ 'status' => Data::STATUS_DELETED ] );
|
RomhackPlazaFS::success_response( [ 'status' => Data::STATUS_DELETED ] );
|
||||||
|
|
||||||
|
|||||||
94
src/Endpoints/Download.php
Normal file
94
src/Endpoints/Download.php
Normal file
@@ -0,0 +1,94 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace RomhackPlazaFS\Endpoints;
|
||||||
|
use RomhackPlazaFS\Library\Data;
|
||||||
|
use RomhackPlazaFS\Library\Log;
|
||||||
|
use RomhackPlazaFS\RomhackPlazaFS;
|
||||||
|
|
||||||
|
defined( 'ROMHACKPLAZA_FS' ) || exit;
|
||||||
|
|
||||||
|
class Download extends Abstract_Endpoint {
|
||||||
|
|
||||||
|
private int $post_id;
|
||||||
|
private string $custom_post_type;
|
||||||
|
private string $file_name;
|
||||||
|
private string $is_private;
|
||||||
|
private string $is_archived;
|
||||||
|
|
||||||
|
protected function private_endpoint(): bool
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function require_token(): bool
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function download_header( string $file_name, string $file_path ): void {
|
||||||
|
|
||||||
|
header('Content-Description: File Transfer');
|
||||||
|
header('Content-Type: application/octet-stream');
|
||||||
|
header('Content-Disposition: attachment; filename="' . basename($file_name) . '"');
|
||||||
|
header('Expires: 0');
|
||||||
|
header('Cache-Control: must-revalidate');
|
||||||
|
header('Pragma: public');
|
||||||
|
header('Content-Length: ' . filesize($file_path) );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function get_post_params(): void {
|
||||||
|
|
||||||
|
$this->post_id = $this->swiffer_get( "entry_id", "int" );
|
||||||
|
if( $this->post_id < 1 )
|
||||||
|
RomhackPlazaFS::invalid_parameter_stop( "entry_id", "GET" );
|
||||||
|
|
||||||
|
$this->custom_post_type = $this->swiffer_get( "post_type", "string" );
|
||||||
|
if( $this->custom_post_type === "" )
|
||||||
|
RomhackPlazaFS::invalid_parameter_stop( "post_type", "GET" );
|
||||||
|
|
||||||
|
$this->file_name = $this->swiffer_get( "filename", "filename" );
|
||||||
|
if( $this->file_name === "" )
|
||||||
|
RomhackPlazaFS::invalid_parameter_stop( "filename", "GET" );
|
||||||
|
|
||||||
|
|
||||||
|
$this->is_private = $this->swiffer_get( "is_private", "string" );
|
||||||
|
if( $this->is_private !== "no" && $this->is_private !== "yes" )
|
||||||
|
$this->is_private = "no";
|
||||||
|
|
||||||
|
$this->is_archived = $this->swiffer_get( "is_archived", "string" );
|
||||||
|
if( $this->is_archived !== "no" && $this->is_archived !== "yes" )
|
||||||
|
$this->is_archived = "no";
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function process(): void {
|
||||||
|
|
||||||
|
$flags = 0;
|
||||||
|
if( $this->is_private === "yes" )
|
||||||
|
$flags |= Data::F_PRIVATE_FILE;
|
||||||
|
else if( $this->is_archived === "yes" )
|
||||||
|
$flags |= Data::F_ARCHIVED_FILE;
|
||||||
|
|
||||||
|
$data = Data::setup(
|
||||||
|
$this->custom_post_type,
|
||||||
|
$this->post_id,
|
||||||
|
$this->file_name,
|
||||||
|
$flags
|
||||||
|
);
|
||||||
|
|
||||||
|
if( $_SERVER['HTTP_REFERER'] && !in_array( $_SERVER['HTTP_REFERER'], RomhackPlazaFS::dotenv_array( 'ROMHACKPLAZAFS_DOWNLOAD_ALLOWED_PARENT_DOMAIN' ) ) )
|
||||||
|
RomhackPlazaFS::fatal_stop( 403, "You can't access to this ressource." );
|
||||||
|
|
||||||
|
if( !$data->file_exists() )
|
||||||
|
RomhackPlazaFS::fatal_stop( 404, "File not found." );
|
||||||
|
|
||||||
|
new Log( __class__, $this->file_name, $this->post_id, $this->custom_post_type );
|
||||||
|
|
||||||
|
$this->download_header( $this->file_name, $data->file_path );
|
||||||
|
$data->download();
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace RomhackPlazaFS\Endpoints;
|
namespace RomhackPlazaFS\Endpoints;
|
||||||
use RomhackPlazaFS\Library\Data;
|
use RomhackPlazaFS\Library\Data;
|
||||||
|
use RomhackPlazaFS\Library\Log;
|
||||||
use RomhackPlazaFS\RomhackPlazaFS;
|
use RomhackPlazaFS\RomhackPlazaFS;
|
||||||
|
|
||||||
defined( 'ROMHACKPLAZA_FS' ) || exit;
|
defined( 'ROMHACKPLAZA_FS' ) || exit;
|
||||||
@@ -48,6 +49,8 @@ class Downloadfilelist extends Abstract_Endpoint {
|
|||||||
$response['files'] = $data->list_files( $this->custom_post_type, $this->post_id );
|
$response['files'] = $data->list_files( $this->custom_post_type, $this->post_id );
|
||||||
$response['archived'] = $archived->list_files( $this->custom_post_type, $this->post_id );
|
$response['archived'] = $archived->list_files( $this->custom_post_type, $this->post_id );
|
||||||
|
|
||||||
|
new Log( __class__, $this->post_id, $this->custom_post_type );
|
||||||
|
|
||||||
RomhackPlazaFS::success_response( $response );
|
RomhackPlazaFS::success_response( $response );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace RomhackPlazaFS\Endpoints;
|
namespace RomhackPlazaFS\Endpoints;
|
||||||
use RomhackPlazaFS\Library\Data;
|
use RomhackPlazaFS\Library\Data;
|
||||||
|
use RomhackPlazaFS\Library\Log;
|
||||||
use RomhackPlazaFS\RomhackPlazaFS;
|
use RomhackPlazaFS\RomhackPlazaFS;
|
||||||
|
|
||||||
defined( 'ROMHACKPLAZA_FS' ) || exit;
|
defined( 'ROMHACKPLAZA_FS' ) || exit;
|
||||||
@@ -12,12 +13,12 @@ class Editorfilelist extends Abstract_Endpoint {
|
|||||||
private string $custom_post_type;
|
private string $custom_post_type;
|
||||||
protected function private_endpoint(): bool
|
protected function private_endpoint(): bool
|
||||||
{
|
{
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function require_token(): bool
|
protected function require_token(): bool
|
||||||
{
|
{
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function get_post_params(): void {
|
protected function get_post_params(): void {
|
||||||
@@ -54,6 +55,8 @@ class Editorfilelist extends Abstract_Endpoint {
|
|||||||
$response['private'] = $private->list_files( $this->custom_post_type, $this->post_id );
|
$response['private'] = $private->list_files( $this->custom_post_type, $this->post_id );
|
||||||
$response['archived'] = $archived->list_files( $this->custom_post_type, $this->post_id );
|
$response['archived'] = $archived->list_files( $this->custom_post_type, $this->post_id );
|
||||||
|
|
||||||
|
new Log( __class__, "WP Id=" . $this->token_info['user_id'], $this->post_id, $this->custom_post_type );
|
||||||
|
|
||||||
RomhackPlazaFS::success_response( $response );
|
RomhackPlazaFS::success_response( $response );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace RomhackPlazaFS\Endpoints;
|
namespace RomhackPlazaFS\Endpoints;
|
||||||
|
use RomhackPlazaFS\Library\ArchiveExplorer;
|
||||||
use RomhackPlazaFS\Library\Data;
|
use RomhackPlazaFS\Library\Data;
|
||||||
|
use RomhackPlazaFS\Library\Log;
|
||||||
use RomhackPlazaFS\RomhackPlazaFS;
|
use RomhackPlazaFS\RomhackPlazaFS;
|
||||||
|
|
||||||
defined( 'ROMHACKPLAZA_FS' ) || exit;
|
defined( 'ROMHACKPLAZA_FS' ) || exit;
|
||||||
@@ -21,7 +23,7 @@ class Fileexplorer extends Abstract_Endpoint {
|
|||||||
|
|
||||||
protected function require_token(): bool
|
protected function require_token(): bool
|
||||||
{
|
{
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function get_post_params(): void {
|
protected function get_post_params(): void {
|
||||||
@@ -66,10 +68,10 @@ class Fileexplorer extends Abstract_Endpoint {
|
|||||||
if( !$data->file_exists() )
|
if( !$data->file_exists() )
|
||||||
RomhackPlazaFS::fatal_stop( 404, "File not found." );
|
RomhackPlazaFS::fatal_stop( 404, "File not found." );
|
||||||
|
|
||||||
|
new Log( __class__, "WP Id=" . $this->token_info['user_id'] ,$this->file_name, $this->post_id, $this->custom_post_type );
|
||||||
|
|
||||||
$response = [];
|
$response = [];
|
||||||
$response['files'] = $data->list_files( $this->custom_post_type, $this->post_id );
|
$response["files"] = new ArchiveExplorer( $data )->open();
|
||||||
$response['private'] = $private->list_files( $this->custom_post_type, $this->post_id );
|
|
||||||
$response['archived'] = $archived->list_files( $this->custom_post_type, $this->post_id );
|
|
||||||
|
|
||||||
RomhackPlazaFS::success_response( $response );
|
RomhackPlazaFS::success_response( $response );
|
||||||
|
|
||||||
|
|||||||
76
src/Endpoints/Getfilesize.php
Normal file
76
src/Endpoints/Getfilesize.php
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace RomhackPlazaFS\Endpoints;
|
||||||
|
use RomhackPlazaFS\Library\Data;
|
||||||
|
use RomhackPlazaFS\Library\Log;
|
||||||
|
use RomhackPlazaFS\RomhackPlazaFS;
|
||||||
|
|
||||||
|
defined( 'ROMHACKPLAZA_FS' ) || exit;
|
||||||
|
|
||||||
|
class Getfilesize extends Abstract_Endpoint {
|
||||||
|
|
||||||
|
private int $post_id;
|
||||||
|
private string $custom_post_type;
|
||||||
|
private string $file_name;
|
||||||
|
private string $is_private;
|
||||||
|
private string $is_archived;
|
||||||
|
|
||||||
|
protected function private_endpoint(): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function require_token(): bool
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function get_post_params(): void {
|
||||||
|
|
||||||
|
$this->post_id = $this->swiffer_get( "entry_id", "int" );
|
||||||
|
if( $this->post_id < 1 )
|
||||||
|
RomhackPlazaFS::invalid_parameter_stop( "entry_id", "GET" );
|
||||||
|
|
||||||
|
$this->custom_post_type = $this->swiffer_get( "post_type", "string" );
|
||||||
|
if( $this->custom_post_type === "" )
|
||||||
|
RomhackPlazaFS::invalid_parameter_stop( "post_type", "GET" );
|
||||||
|
|
||||||
|
$this->file_name = $this->swiffer_get( "filename", "filename" );
|
||||||
|
if( $this->file_name === "" )
|
||||||
|
RomhackPlazaFS::invalid_parameter_stop( "filename", "GET" );
|
||||||
|
|
||||||
|
$this->is_private = $this->swiffer_get( "is_private", "string" );
|
||||||
|
if( $this->is_private !== "no" && $this->is_private !== "yes" )
|
||||||
|
$this->is_private = "no";
|
||||||
|
|
||||||
|
$this->is_archived = $this->swiffer_get( "is_archived", "string" );
|
||||||
|
if( $this->is_archived !== "no" && $this->is_archived !== "yes" )
|
||||||
|
$this->is_archived = "no";
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function process(): void {
|
||||||
|
|
||||||
|
$flags = 0;
|
||||||
|
if( $this->is_private === "yes" )
|
||||||
|
$flags |= Data::F_PRIVATE_FILE;
|
||||||
|
else if( $this->is_archived === "yes" )
|
||||||
|
$flags |= Data::F_ARCHIVED_FILE;
|
||||||
|
|
||||||
|
$data = Data::setup(
|
||||||
|
$this->custom_post_type,
|
||||||
|
$this->post_id,
|
||||||
|
$this->file_name,
|
||||||
|
$flags
|
||||||
|
);
|
||||||
|
|
||||||
|
if( !$data->file_exists() )
|
||||||
|
RomhackPlazaFS::fatal_stop( 404, "File not found." );
|
||||||
|
|
||||||
|
new Log( __class__,$this->file_name, $this->post_id, $this->custom_post_type );
|
||||||
|
|
||||||
|
RomhackPlazaFS::success_response( [ 'size' => $data->size() ] );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace RomhackPlazaFS\Endpoints;
|
namespace RomhackPlazaFS\Endpoints;
|
||||||
use RomhackPlazaFS\Library\Data;
|
use RomhackPlazaFS\Library\Data;
|
||||||
|
use RomhackPlazaFS\Library\Log;
|
||||||
use RomhackPlazaFS\RomhackPlazaFS;
|
use RomhackPlazaFS\RomhackPlazaFS;
|
||||||
|
|
||||||
defined( 'ROMHACKPLAZA_FS' ) || exit;
|
defined( 'ROMHACKPLAZA_FS' ) || exit;
|
||||||
@@ -14,12 +15,12 @@ class Markasarchived extends Abstract_Endpoint {
|
|||||||
|
|
||||||
protected function private_endpoint(): bool
|
protected function private_endpoint(): bool
|
||||||
{
|
{
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function require_token(): bool
|
protected function require_token(): bool
|
||||||
{
|
{
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function get_post_params(): void {
|
protected function get_post_params(): void {
|
||||||
@@ -59,6 +60,8 @@ class Markasarchived extends Abstract_Endpoint {
|
|||||||
if( $new_data->file_exists() )
|
if( $new_data->file_exists() )
|
||||||
RomhackPlazaFS::fatal_stop( 500, "File already exists. You can't archive that have the same name than an other archived file." );
|
RomhackPlazaFS::fatal_stop( 500, "File already exists. You can't archive that have the same name than an other archived file." );
|
||||||
|
|
||||||
|
new Log( __class__, "WP Id=" . $this->token_info['user_id'] ,$this->file_name, $this->post_id, $this->custom_post_type );
|
||||||
|
|
||||||
if( $data->change_data_location( $new_data ) )
|
if( $data->change_data_location( $new_data ) )
|
||||||
RomhackPlazaFS::success_response( [ 'status' => Data::STATUS_ARCHIVED ] );
|
RomhackPlazaFS::success_response( [ 'status' => Data::STATUS_ARCHIVED ] );
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace RomhackPlazaFS\Endpoints;
|
namespace RomhackPlazaFS\Endpoints;
|
||||||
use RomhackPlazaFS\Library\Data;
|
use RomhackPlazaFS\Library\Data;
|
||||||
|
use RomhackPlazaFS\Library\Log;
|
||||||
use RomhackPlazaFS\RomhackPlazaFS;
|
use RomhackPlazaFS\RomhackPlazaFS;
|
||||||
|
|
||||||
defined( 'ROMHACKPLAZA_FS' ) || exit;
|
defined( 'ROMHACKPLAZA_FS' ) || exit;
|
||||||
@@ -14,12 +15,12 @@ class Markasprivate extends Abstract_Endpoint {
|
|||||||
|
|
||||||
protected function private_endpoint(): bool
|
protected function private_endpoint(): bool
|
||||||
{
|
{
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function require_token(): bool
|
protected function require_token(): bool
|
||||||
{
|
{
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function get_post_params(): void {
|
protected function get_post_params(): void {
|
||||||
@@ -59,6 +60,8 @@ class Markasprivate extends Abstract_Endpoint {
|
|||||||
if( $new_data->file_exists() )
|
if( $new_data->file_exists() )
|
||||||
RomhackPlazaFS::fatal_stop( 500, "File already exists. Can't replace. Please delete private file before." );
|
RomhackPlazaFS::fatal_stop( 500, "File already exists. Can't replace. Please delete private file before." );
|
||||||
|
|
||||||
|
new Log( __class__, "WP Id=" . $this->token_info['user_id'] ,$this->file_name, $this->post_id, $this->custom_post_type );
|
||||||
|
|
||||||
if( $data->change_data_location( $new_data ) )
|
if( $data->change_data_location( $new_data ) )
|
||||||
RomhackPlazaFS::success_response( [ 'status' => Data::STATUS_PRIVATE ] );
|
RomhackPlazaFS::success_response( [ 'status' => Data::STATUS_PRIVATE ] );
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace RomhackPlazaFS\Endpoints;
|
namespace RomhackPlazaFS\Endpoints;
|
||||||
use RomhackPlazaFS\Library\Data;
|
use RomhackPlazaFS\Library\Data;
|
||||||
|
use RomhackPlazaFS\Library\Log;
|
||||||
use RomhackPlazaFS\RomhackPlazaFS;
|
use RomhackPlazaFS\RomhackPlazaFS;
|
||||||
|
|
||||||
defined( 'ROMHACKPLAZA_FS' ) || exit;
|
defined( 'ROMHACKPLAZA_FS' ) || exit;
|
||||||
@@ -14,12 +15,12 @@ class Markaspublic extends Abstract_Endpoint {
|
|||||||
|
|
||||||
protected function private_endpoint(): bool
|
protected function private_endpoint(): bool
|
||||||
{
|
{
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function require_token(): bool
|
protected function require_token(): bool
|
||||||
{
|
{
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function get_post_params(): void {
|
protected function get_post_params(): void {
|
||||||
@@ -62,6 +63,8 @@ class Markaspublic extends Abstract_Endpoint {
|
|||||||
if( $data->change_data_location( $new_data ) )
|
if( $data->change_data_location( $new_data ) )
|
||||||
RomhackPlazaFS::success_response( [ 'status' => Data::STATUS_PUBLISH ] );
|
RomhackPlazaFS::success_response( [ 'status' => Data::STATUS_PUBLISH ] );
|
||||||
|
|
||||||
|
new Log( __class__, "WP Id=" . $this->token_info['user_id'] ,$this->file_name, $this->post_id, $this->custom_post_type );
|
||||||
|
|
||||||
RomhackPlazaFS::fatal_stop( 500, "Error during file marking" );
|
RomhackPlazaFS::fatal_stop( 500, "Error during file marking" );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace RomhackPlazaFS\Endpoints;
|
namespace RomhackPlazaFS\Endpoints;
|
||||||
use RomhackPlazaFS\Library\Data;
|
use RomhackPlazaFS\Library\Data;
|
||||||
|
use RomhackPlazaFS\Library\Log;
|
||||||
use RomhackPlazaFS\RomhackPlazaFS;
|
use RomhackPlazaFS\RomhackPlazaFS;
|
||||||
|
|
||||||
defined( 'ROMHACKPLAZA_FS' ) || exit;
|
defined( 'ROMHACKPLAZA_FS' ) || exit;
|
||||||
@@ -16,12 +17,12 @@ class Uploadchunk extends Abstract_Endpoint {
|
|||||||
|
|
||||||
protected function private_endpoint(): bool
|
protected function private_endpoint(): bool
|
||||||
{
|
{
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function require_token(): bool
|
protected function require_token(): bool
|
||||||
{
|
{
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function get_post_params(): void {
|
protected function get_post_params(): void {
|
||||||
@@ -55,6 +56,8 @@ class Uploadchunk extends Abstract_Endpoint {
|
|||||||
|
|
||||||
$data->file_path_to_temp();
|
$data->file_path_to_temp();
|
||||||
|
|
||||||
|
new Log( __class__, "WP Id=" . $this->token_info['user_id'] ,$this->file_name, $this->post_id, $this->custom_post_type, $this->current_chunk + 1 . "/" . $this->total_chunks );
|
||||||
|
|
||||||
if( $data->write( $this->current_chunk, $this->total_chunks ) )
|
if( $data->write( $this->current_chunk, $this->total_chunks ) )
|
||||||
RomhackPlazaFS::success_response( [ 'chunk' => $this->current_chunk, 'total_chunks' => $this->total_chunks, 'uploaded' => true ] );
|
RomhackPlazaFS::success_response( [ 'chunk' => $this->current_chunk, 'total_chunks' => $this->total_chunks, 'uploaded' => true ] );
|
||||||
|
|
||||||
|
|||||||
73
src/Library/ArchiveExplorer.php
Normal file
73
src/Library/ArchiveExplorer.php
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace RomhackPlazaFS\Library;
|
||||||
|
|
||||||
|
use RomhackPlazaFS\RomhackPlazaFS;
|
||||||
|
|
||||||
|
defined( 'ROMHACKPLAZA_FS' ) || exit;
|
||||||
|
|
||||||
|
final class ArchiveExplorer {
|
||||||
|
|
||||||
|
public private(set) Data $data;
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
Data &$data,
|
||||||
|
) {
|
||||||
|
$this->data = &$data;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function check_archive(): string|bool {
|
||||||
|
|
||||||
|
if( !$this->data->file_exists() )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return match (mime_content_type($this->data->file_path)) {
|
||||||
|
'application/zip' => "zip",
|
||||||
|
'application/x-rar' => "rar",
|
||||||
|
'application/vnd.rar' => "rar",
|
||||||
|
'application/x-7z-compressed' => "7z",
|
||||||
|
default => false,
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function open(): array {
|
||||||
|
|
||||||
|
$file_format = $this->check_archive();
|
||||||
|
if( !$file_format )
|
||||||
|
RomhackPlazaFS::fatal_stop( 400, "Not an archive." );
|
||||||
|
|
||||||
|
$files = [];
|
||||||
|
|
||||||
|
if( $file_format === "zip" ){
|
||||||
|
|
||||||
|
$archive = new \ZipArchive();
|
||||||
|
$archive->open( $this->data->file_path );
|
||||||
|
|
||||||
|
for( $i = 0; $i < $archive->numFiles; $i++ )
|
||||||
|
$files[] = $archive->statIndex($i)["name"];
|
||||||
|
$archive->close();
|
||||||
|
|
||||||
|
}
|
||||||
|
else if( $file_format === "rar" ){
|
||||||
|
|
||||||
|
$cmd = 'unrar lb "' . $this->data->file_path . '"';
|
||||||
|
$out = shell_exec( $cmd );
|
||||||
|
$files = explode("\n", $out);
|
||||||
|
|
||||||
|
}
|
||||||
|
else if( $file_format === "7z" ){
|
||||||
|
|
||||||
|
require_once $_ENV['ROMHACKPLAZAFS_FILE_PATH'] . 'vendor/SevenZipArchive/SevenZipArchive.php';
|
||||||
|
$archive = new \SevenZipArchive( $this->data->file_path );
|
||||||
|
|
||||||
|
foreach ( $archive as $entry )
|
||||||
|
$files[] = $entry["Name"];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return $files;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -266,4 +266,13 @@ final class Data {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function download(){
|
||||||
|
|
||||||
|
if( ob_get_level() )
|
||||||
|
ob_end_clean();
|
||||||
|
|
||||||
|
readfile( $this->file_path );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
22
src/Library/Log.php
Normal file
22
src/Library/Log.php
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace RomhackPlazaFS\Library;
|
||||||
|
use RomhackPlazaFS\RomhackPlazaFS;
|
||||||
|
|
||||||
|
defined( 'ROMHACKPLAZA_FS' ) || exit;
|
||||||
|
|
||||||
|
final class Log {
|
||||||
|
|
||||||
|
public function __construct( ...$info ){
|
||||||
|
|
||||||
|
$log = "[" . date( "Y-m-d h:i:sa" ) . "] " . $_SERVER["REMOTE_ADDR"] . " | ";
|
||||||
|
|
||||||
|
foreach( $info as $item )
|
||||||
|
$log .= $item . " | ";
|
||||||
|
|
||||||
|
$log .= PHP_EOL;
|
||||||
|
file_put_contents( $_ENV['ROMHACKPLAZAFS_FILE_LOG_PATH'], $log, FILE_APPEND | LOCK_EX );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace RomhackPlazaFS;
|
namespace RomhackPlazaFS;
|
||||||
use RomhackPlazaFS\Endpoints\Abstract_Endpoint;
|
use RomhackPlazaFS\Endpoints\Abstract_Endpoint;
|
||||||
|
use RomhackPlazaFS\Library\Log;
|
||||||
|
|
||||||
defined( 'ROMHACKPLAZA_FS' ) || exit;
|
defined( 'ROMHACKPLAZA_FS' ) || exit;
|
||||||
|
|
||||||
@@ -51,6 +52,7 @@ final class RomhackPlazaFS {
|
|||||||
|
|
||||||
self::response_type( 'application/json' );
|
self::response_type( 'application/json' );
|
||||||
http_response_code( $html_code );
|
http_response_code( $html_code );
|
||||||
|
new Log( "Error", $html_code, $error_message );
|
||||||
self::response( false, $html_code, error_message: $error_message );
|
self::response( false, $html_code, error_message: $error_message );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user