-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
06d81cc
commit c3c47d4
Showing
15 changed files
with
176 additions
and
264 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,20 @@ | ||
<?php | ||
require_once 'save.php'; | ||
require_once 'remove.php'; | ||
require_once 'zip.php'; | ||
save::saveFile(); | ||
remove::start(); | ||
zip::extract(__DIR__ . '/file.zip'); | ||
header('Content-type: text/html; charset=utf-8'); | ||
require_once 'lib/loader.php'; | ||
//respectively | ||
$behaviors = [ | ||
Receiver::class, | ||
Clean::class, | ||
Archive::class | ||
]; | ||
foreach ($behaviors as $item) { | ||
echo "<p class='panding'>" . $item::terminalStartText() . "</p>"; | ||
flush(); | ||
ob_flush(); | ||
echo "<p class='success'>" . $item::terminalEndText($item::install()) . "</p>"; | ||
echo "\n"; | ||
|
||
flush(); | ||
ob_flush(); | ||
|
||
die('success'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
class Archive implements BehaviorInterface | ||
{ | ||
|
||
static function install() | ||
{ | ||
self::zipExtract(config('fullPathZipFile'),config('projectPath')); | ||
} | ||
|
||
private static function zipExtract($fullPathZipFile,$projectPath){ | ||
$zip = new ZipArchive; | ||
$res = $zip->open($fullPathZipFile); | ||
if ($res === TRUE) { | ||
$zip->extractTo($projectPath); | ||
$zip->close(); | ||
} else { | ||
echo 'error in extract'; | ||
} | ||
} | ||
|
||
static function terminalStartText(): string | ||
{ | ||
return 'extract...'; | ||
} | ||
|
||
static function terminalEndText($resultInstall): string | ||
{ | ||
return 'extract success'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
|
||
interface BehaviorInterface | ||
{ | ||
static function install(); | ||
|
||
static function terminalStartText(): string; | ||
|
||
static function terminalEndText($resultInstall): string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
class Clean implements BehaviorInterface | ||
{ | ||
|
||
static function install() | ||
{ | ||
self::remove(config('projectPath'),config('folderPreventRemove'),config('filesPreventRemove')); | ||
} | ||
|
||
private static function remove($projectDire,$folderPreventRemove,$filesPreventRemove){ | ||
$di = new RecursiveDirectoryIterator($projectDire, FilesystemIterator::SKIP_DOTS); | ||
$ri = new RecursiveIteratorIterator($di, RecursiveIteratorIterator::CHILD_FIRST); | ||
foreach ($ri as $file) { | ||
if ($file->isDir()) { | ||
if (in_array($file->getFilename(), $folderPreventRemove)) | ||
continue; | ||
rmdir($file); | ||
} else { | ||
if (in_array($file->getFilename(), $filesPreventRemove)) | ||
continue; | ||
unlink($file); | ||
} | ||
|
||
} | ||
} | ||
|
||
static function terminalStartText(): string | ||
{ | ||
return 'clean folder and file ...'; | ||
} | ||
|
||
static function terminalEndText($resultInstall): string | ||
{ | ||
return 'clean success'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
class Receiver implements BehaviorInterface | ||
{ | ||
|
||
static function install() | ||
{ | ||
self::validate(); | ||
self::store(config('fullPathZipFile')); | ||
} | ||
|
||
static private function validate(){ | ||
if (!isset($_FILES['file_contents'])) | ||
die('file notfound'); | ||
} | ||
|
||
static private function store($fullPathFile){ | ||
move_uploaded_file($_FILES['file_contents']['tmp_name'], $fullPathFile); | ||
} | ||
|
||
static function terminalStartText(): string | ||
{ | ||
return 'receiver get...'; | ||
} | ||
|
||
static function terminalEndText($resultInstall): string | ||
{ | ||
return 'received zip file'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
return [ | ||
'token' => 'test123', | ||
'tokenKey' => "token", | ||
'zipFileName' => 'file', | ||
'saveReceivedPathFile' => __DIR__ . DIRECTORY_SEPARATOR . 'temp', | ||
'projectPath' => __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'hostFolder', | ||
|
||
//in projectPath | ||
'folderPreventRemove'=>[ | ||
'robot' | ||
], | ||
'filesPreventRemove'=>[ | ||
'protected.txt' | ||
] | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
$config = require_once 'config.php'; | ||
|
||
//validate project key | ||
if (!isset($_POST[config('tokenKey')])) | ||
die('token not found'); | ||
|
||
if ($_POST[config('tokenKey')] != config('token')) | ||
die('token not valid'); | ||
|
||
createSpecialKeys(); | ||
|
||
//get key config | ||
function config($key) | ||
{ | ||
global $config; | ||
return isset($config[$key]) | ||
? $config[$key] | ||
: null; | ||
} | ||
|
||
//run time config key | ||
function createSpecialKeys(){ | ||
global $config; | ||
$config['fullPathZipFile'] = config('saveReceivedPathFile') . DIRECTORY_SEPARATOR . config('zipFileName') . '.zip'; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
require_once 'configHandle.php'; | ||
require_once 'behaviors/BehaviorInterface.php'; | ||
require_once 'behaviors/Receiver.php'; | ||
require_once 'behaviors/Clean.php'; | ||
require_once 'behaviors/Archive.php'; | ||
|
Oops, something went wrong.