Commit aed9dff4 authored by iWallet Dev's avatar iWallet Dev

AWS S3 Bucket Integration

parent c3a5024b
......@@ -45,7 +45,7 @@ include_once('template/base_head.php');
<p class="kycT mb20"><input type="button" id="btnKyc" value="Upload" class="btn bg-grad px120 calign"></p>
<input type="hidden" value="" id="type" name="type" />
<input type="hidden" value="save" id="type" name="type" />
<input type="hidden" value="settting_kyc" id="action" name="action" />
<input type="hidden" value="0" id="img_1_flg" name="img_1_flg" />
<input type="hidden" value="0" id="img_2_flg" name="img_2_flg" />
......
......@@ -77,7 +77,7 @@ include_once('template/base_head.php');
※ご提出頂いた順に書類確認させて頂いておりますので、アップロード書類状態が未認証のお客様は審査完了までファイルを追加しないでお待ちください。</p>
<p class="kycT mb20"><input type="button" id="btnKyc" value="アップロード" class="btn bg-grad px120 calign"></p>
<input type="hidden" value="" id="type" name="type" />
<input type="hidden" value="save" id="type" name="type" />
<input type="hidden" value="settting_kyc" id="action" name="action" />
<input type="hidden" value="0" id="img_1_flg" name="img_1_flg" />
......
......@@ -44,7 +44,6 @@ class LogicSetting extends SettingModelClass {
* @return : なし
-------------------------------------------------------------------------*/
private function biz() {
// ロジックの振り分け
if($this -> getAction() == NO_STRING
&& $this -> getType() == TYPE_COMPLETE) { // プロフィール登録
......@@ -55,17 +54,18 @@ class LogicSetting extends SettingModelClass {
$this -> loadImageKycPerson();
$this -> updateKycValidateStatus();
$this -> listKYC();
header('Location: /' . $this -> getLangage() . '/setting?type=settting_kyc');
header('Location: /' . $this -> getLangage() . '/setting?type=settting_kyc&loaded=1');
} else if($this -> getAction() == CONTROL_SETTING_KYC
&& $this -> getType() == TYPE_COMPLETE) { // KYC登録(法人)
$this -> loadImageKycCorp();
$this -> updateKycValidateStatus();
$this -> listKYC();
header('Location: /' . $this -> getLangage() . '/setting?type=settting_kyc');
header('Location: /' . $this -> getLangage() . '/setting?type=settting_kyc&loaded=1');
} else if($this -> getAction() == CONTROL_SETTING_KYC
&& $this -> getType() == TYPE_EXPORT) { // KYC書類ダウンロード
$this -> download();
} else if($this -> getAction() == CONTROL_SETTING_CHANGE_PASSWORD
&& $this -> getType() == TYPE_COMPLETE) { // パスワード変更
......@@ -110,6 +110,10 @@ class LogicSetting extends SettingModelClass {
$this -> setAccountType();
$this -> load();
$this -> listKYC();
if($this->getDataGet("loaded")){
AWSMangos3Bucket::getInstance()->deleteLocalDirectory($this->getKycDirectory($this->getUserData(PARAM_USER_ACCOUNT)));
}
} else {
$this -> load();
}
......@@ -578,6 +582,9 @@ class LogicSetting extends SettingModelClass {
if($flg) {
$this -> accessModify('UPDATE_KYC_FLG', array($this -> getUserData(PARAM_USER_ACCOUNT), NO_COUNT), false);
}
// syncing to bucket
AWSMangos3Bucket::getInstance()->uploadDirectory($path);
}
/*-------------------------------------------------------------------------
......@@ -1036,6 +1043,9 @@ class LogicSetting extends SettingModelClass {
, $params
, VAR_NOTICE_MAIL_ADDRESS
, VAR_NOTICE_MAIL_ADDRESS);
// syncing to bucket
AWSMangos3Bucket::getInstance()->uploadDirectory($path);
}
}
......
<?php
require_once "../lib/config.php";
class kyczipdl extends System {
/**
*
* @var zipdl
*/
private static $instance = null;
public function __construct(){
parent::__construct();
}
/**
*
* renders the content of a zip file to be downloaded
*
*/
public function render(){
$downloadable = urldecode($this->getDataGet("f"));
if(!@file_exists($downloadable)){
http_response_code(404);
die("404 Not Found");
}
header("Content-Type: application/zip");
header("Content-Disposition: attachment; filename=\"".basename($downloadable)."\"");
header("Content-Length: ".filesize($downloadable));
readfile($downloadable);
unlink($downloadable);
}
public static function getInstance(){
if(is_null(self::$instance)){
self::$instance = new kyczipdl();
}
return self::$instance;
}
}
kyczipdl::getInstance()->render();
\ No newline at end of file
......@@ -6,7 +6,7 @@ use Aws\Exception\CredentialsException;
class AWSMangoMailer {
private $sender_email = 'cs@iwl.world';
private $sender_email = 'cs-test@iwl.world';
private $sesClient;
private $altName = NO_STRING;
......@@ -15,8 +15,8 @@ class AWSMangoMailer {
'version' => '2010-12-01',
'region' => 'ap-southeast-1',
'credentials' => [
'key' => 'AKIARMKWQUBIYI4VSFZO',
'secret' => '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'
'key' => 'AKIARMKWQUBIXLNHNIG6',
'secret' => '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'
]
]);
}
......
<?php
use Aws\Exception\AwsException;
use Aws\S3\S3Client;
/**
*
* @author Anthony
*
*/
class AWSMangos3Bucket {
/**
*
* @var string
*/
private const BUCKET_NAME = "iwl-world-stg";
/**
*
* @var AWSMangos3Bucket
*/
private static $instance = null;
/**
*
* @var S3Client
*/
private $s3;
private function __construct(){
$this->s3 = new S3Client([
"version" => "latest",
'region' => 'ap-southeast-1',
'credentials' => [
'key' => 'AKIARMKWQUBIX45B6GR7',
'secret' => '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',
]
]);
}
/**
*
* syncing a file to bucket
*
* @param string $filekey
* @param string $sourceFilePath
* @return boolean
*/
public function uploadFile(string $filekey, string $sourceFilePath){
try{
// Upload the file to S3
$this->s3->putObject([
'Bucket' => self::BUCKET_NAME,
'Key' => $filekey,
'SourceFile' => $sourceFilePath,
]);
// Print the URL of the uploaded file
return true;
}catch(AwsException $ex){
return false;
}
}
/**
*
* unlinks a file from bucket
*
* @param string $filekey
* @return boolean
*/
public function deleteFile(string $filekey){
try {
// Delete the object
$result = $this->s3->deleteObject([
'Bucket' => self::BUCKET_NAME,
'Key' => $filekey,
]);
// Check if the deletion was successful
return $result ? true : false;
} catch (AwsException $ex) {
return false;
}
}
/**
*
* syncing the directory to bucket
*
* @param string $directoryPath
*/
public function uploadDirectory(string $directoryPath){
$files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directoryPath));
foreach($files as $file){
if($file->isFile()){
$filekey = str_replace("\\", "/",
substr($file->getPathname(), strrpos($directoryPath, basename($directoryPath))));
$this->uploadFile($filekey, $file->getPathname());
}
}
}
/**
*
* used as a tool to remove the designated local directory from local storage
* after syncing to s3 bucket
*
* @param string $directoryPath
* @return boolean
*/
public function deleteLocalDirectory(string $directoryPath){
if(!is_dir($directoryPath)) {
return false; // Not a directory
}
$items = array_diff(scandir($directoryPath), array('.', '..')); // Get all items in the directory
foreach ($items as $item) {
$path = "{$directoryPath}/{$item}";
if(is_dir($path)) {
$this->deleteDirectory($path); // Recursively delete subdirectories
}else{
unlink($path); // Delete files
}
}
rmdir($directoryPath); // Delete the now-empty directory
return true;
}
/**
*
* retrieves the URL of a presigned bucket file
*
* @param string $filekey
* @return string
*/
public function getPresignedBucketFile(string $filekey){
$cmd = $this->s3->getCommand('GetObject', [
'Bucket' => self::BUCKET_NAME,
'Key' => $filekey
]);
$request = $this->s3->createPresignedRequest($cmd, '+60 minutes');
// Get the pre-signed URL
return (string) $request->getUri();
}
/**
*
* @param string $filekey
* @return string
*/
public function viewFile(string $filekey){
// Get the pre-signed URL
$uri = (string) $this->getPresignedBucketFile($filekey);
$mimeType = mime_content_type($filekey);
header("Content-type: {$mimeType}");
header("Content-Disposition: inline;filename=\"{$filekey}\"");
return readfile($uri);
}
/**
*
* @return AWSMangos3Bucket
*/
public static function getInstance(){
if(is_null(self::$instance)){
self::$instance = new AWSMangos3Bucket();
}
return self::$instance;
}
}
......@@ -7,7 +7,8 @@
return [
"vendor/autoload.php",
"duplicate/PotentialDuplicateAccountChecker.php",
"aws-ses-ext/AWSMangoMailer.php",
"aws/AWSMangoMailer.php",
"aws/AWSMangos3Bucket.php",
"ini-ext/ini-ext-load.php",
"util/TransactionTokenUtil.php"
];
\ No newline at end of file
......@@ -25,7 +25,6 @@ class LogicAccountEdit extends AccountEditModelClass {
function logic() {
try {
// 初期データ処理
$this -> init();
......@@ -36,6 +35,10 @@ class LogicAccountEdit extends AccountEditModelClass {
$this -> selectLogin();
if($this -> getType() == NO_STRING){
$this -> insertActivity();
if($this->getDataGet("loaded")){
AWSMangos3Bucket::getInstance()->deleteLocalDirectory($this->getKycDirectory($this->getDetailAccount()));
}
}
//获取2faenable
$this -> set2fa(true);
......@@ -131,7 +134,10 @@ class LogicAccountEdit extends AccountEditModelClass {
$this -> loadImageKycCorp();
$this -> updateKycValidateStatus();
}
$this -> setType(TYPE_COMPLETE);
// $this -> setType(TYPE_COMPLETE);
header("Location: {$_SERVER["REQUEST_URI"]}&loaded=1");
exit();
}
} catch (Exception $e) {
......
......@@ -2982,6 +2982,8 @@ class AccountEditModelClass extends ModelClassEx {
if($flg) {
$this -> accessModify('UPDATE_KYC_FLG', array($this -> detailAccount, NO_COUNT), false);
}
AWSMangos3Bucket::getInstance()->uploadDirectory($path);
}
/*-------------------------------------------------------------------------
......@@ -3397,6 +3399,8 @@ class AccountEditModelClass extends ModelClassEx {
$this -> accessModify('UPDATE_KYC_FLG', array($this -> detailAccount, NO_COUNT), false);
}
AWSMangos3Bucket::getInstance()->uploadDirectory($path);
// アップロードファイルが存在したらメールを送信する
// if($this -> isLoopData($uploads)) {
......
......@@ -577,18 +577,19 @@ class KYCModelClass extends ModelClassEx {
$domain = NO_STRING;
}
$filetype = $this -> getFileType($this -> rs[$rCnt + $i][COLUMN_SAVE_FILENAME]);
$path = $this -> getKycDirectoryWeb($this -> userAccount);
$bucketKyc = AWSMangos3Bucket::getInstance()
->getPresignedBucketFile("{$this->userAccount}/{$this->rs[$rCnt + $i][COLUMN_SAVE_FILENAME]}");
if($filetype == 'pdf'){
$rtn .= '<td>'
.'<div class="kyc_img"><a href="' . $domain . $path . DELIMIT_SLASH . $this -> rs[$rCnt + $i][COLUMN_SAVE_FILENAME] . '" target="_blank">' . $this -> rs[$rCnt + $i][COLUMN_OLD_FILENAME] . '</a></div>'
.'<div class="kyc_img"><a href="' . $bucketKyc . '" target="_blank">' . $this -> rs[$rCnt + $i][COLUMN_OLD_FILENAME] . '</a></div>'
.'<input type="checkbox" class="cb-left" name="download[]" value="'.substr($key, 0,-1).'">Uploaded: ' . $this -> rs[$rCnt + $i][COLUMN_CREATE_TIME] . '<br>'.VAL_KYC_ADMIN_FILENAME.': ' . $this -> getColumnData($row, COLUMN_OLD_FILENAME)
. '</td>';
}else{
$rtn .= '<td>'
.'<div class="kyc_img"> <img data-original="' . $domain . $path . DELIMIT_SLASH . $this -> rs[$rCnt + $i][COLUMN_SAVE_FILENAME] . '" src="' . $domain . $path . DELIMIT_SLASH . $this -> rs[$rCnt + $i][COLUMN_SAVE_FILENAME] . '" width="65%;"></div>'
.'<div class="kyc_img"> <img data-original="' . $bucketKyc . '" src="' . $bucketKyc . '" width="65%;"></div>'
.'<input type="checkbox" class="cb-left" name="download[]" value="'.substr($key, 0,-1).'">Uploaded: ' . $this -> rs[$rCnt + $i][COLUMN_CREATE_TIME] . '<br>'.VAL_KYC_ADMIN_FILENAME.': ' . $this -> getColumnData($row, COLUMN_OLD_FILENAME)
. '</td>';
}
......@@ -654,24 +655,19 @@ class KYCModelClass extends ModelClassEx {
if($arr[NO_COUNT] == NO_STRING){
return;
}else if($arr[VAL_INT_1] == VAL_INT_2){
//当值为2时删除记录与文件
//获取文件路径
$path = $this -> getKycDirectoryWeb($this -> userAccount);
$filename = '';
//查询记录
$this -> setResult($this -> accessSelect('SELECT_KYC_BY_K_ID', array($arr[0])));
if($this -> isLoopData($this -> rs)) {
foreach ($this -> rs as $row) {
$filename = $path.DIRECTORY_SEPARATOR.$this -> getColumnData($row, COLUMN_SAVE_FILENAME);
$saveFilename = $this -> getColumnData($row, COLUMN_SAVE_FILENAME);
}
//删除存在文件
if(file_exists(SYSTEM_PATH.$filename)){
unlink(SYSTEM_PATH.$filename);
}
AWSMangos3Bucket::getInstance()->deleteFile("{$this->userAccount}/{$saveFilename}");
}
$this -> accessModifyCommon('DELETE_KYC_ADMIN_IMAGE_RECORDS', array($arr[0]));
return 1;
}
......@@ -753,6 +749,8 @@ class KYCModelClass extends ModelClassEx {
}
public function downloadImage(){
ob_start();
//整理要下载的图片的信息,名称,路径等信息
$date = date("YmdHis");
......@@ -761,14 +759,25 @@ class KYCModelClass extends ModelClassEx {
echo '<script>alert("'.VAL_KYC_ADMIN_DLIMAGEMES.'");</script>';
return;
}
$path = $this -> getKycDirectoryWeb($this -> userAccount);
$temp = SYSTEM_PATH.$path;
mkdir($temp, 0777, true);
$arrTmp = array();
if($this -> isLoopData($this -> rs)){
foreach($this -> rs as $row){
if(in_array($row['k_id'],$this -> downArr)){
$arrTmp[$row['k_id']] = $path.DIRECTORY_SEPARATOR.$row['save_filename'];
$kycContent = file_get_contents(AWSMangos3Bucket::getInstance()->getPresignedBucketFile("{$this->userAccount}/{$row['save_filename']}"));
if($kycContent){
file_put_contents($temp.DIRECTORY_SEPARATOR.$row['save_filename'], $kycContent);
$arrTmp[$row['k_id']] = $path.DIRECTORY_SEPARATOR.$row['save_filename'];
}
}
}
}
......@@ -778,27 +787,26 @@ class KYCModelClass extends ModelClassEx {
$downloadFilename = $date.'_'.$this -> userAccount.'.zip';
$apiPath = dirname(SYSTEM_PATH).DIRECTORY_SEPARATOR.'api';
$result = $zip->open($apiPath.DIRECTORY_SEPARATOR.$downloadFilename, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE);
if ($result !== true) {
return false;
}
//処理制限時間を外す
set_time_limit(0);
// set_time_limit(0);
foreach($arrTmp as $val){
$filename = basename($val);
//取得ファイルをZipに追加
$zip->addFromString($filename,file_get_contents(SYSTEM_PATH.$val));
$zip->addFile(SYSTEM_PATH.$val, basename($val));
}
$zip->close();
sleep(3);
header('Content-Type: application/zip; name="' . $downloadFilename . '"');
header('Content-Disposition: attachment; filename="' . $downloadFilename . '"');
header('Content-Length: '.filesize($apiPath.DIRECTORY_SEPARATOR.$downloadFilename));
echo file_get_contents($apiPath.DIRECTORY_SEPARATOR.$downloadFilename);
unlink($apiPath.DIRECTORY_SEPARATOR.$downloadFilename);
sleep(2);
AWSMangos3Bucket::getInstance()->deleteLocalDirectory($temp);
header("Location: /api/kyczipdl.php?f=".urlencode($apiPath.DIRECTORY_SEPARATOR.$downloadFilename));
exit();
}
/*-------------------------------------------------------------------------
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment