Skip to content

Commit

Permalink
refactor : src server
Browse files Browse the repository at this point in the history
  • Loading branch information
iransoftnet1 committed Sep 16, 2021
1 parent 06d81cc commit c3c47d4
Show file tree
Hide file tree
Showing 15 changed files with 176 additions and 264 deletions.
2 changes: 1 addition & 1 deletion src/local/lib/behaviors/Upload.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ static function terminalStartText(): string

static function terminalEndText($resultInstall): string
{
return 'success upload host' . "\n" . $resultInstall;
return 'success upload host';
}
}
2 changes: 1 addition & 1 deletion src/local/lib/view/home.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>Table V01</title>
<title>Mg Build</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!--===============================================================================================-->
Expand Down
176 changes: 0 additions & 176 deletions src/local/lib/view/index.html

This file was deleted.

Empty file.
24 changes: 17 additions & 7 deletions src/server/index.php
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');
}
30 changes: 30 additions & 0 deletions src/server/lib/behaviors/Archive.php
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';
}
}
11 changes: 11 additions & 0 deletions src/server/lib/behaviors/BehaviorInterface.php
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;
}
36 changes: 36 additions & 0 deletions src/server/lib/behaviors/Clean.php
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';
}
}
29 changes: 29 additions & 0 deletions src/server/lib/behaviors/Receiver.php
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';
}
}
16 changes: 16 additions & 0 deletions src/server/lib/config.php
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'
]
];
28 changes: 28 additions & 0 deletions src/server/lib/configHandle.php
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';
}


7 changes: 7 additions & 0 deletions src/server/lib/loader.php
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';

Loading

0 comments on commit c3c47d4

Please sign in to comment.