require __DIR__ . '/../aws/aws-autoloader.php';
use Aws\Kms\KmsClient;
class KmsEncryptDecrypt
{
private $kmsClient;
public function __construct()
{
$this->kmsClient = new KmsClient([
'region' => 'ap-northeast-2',
'version' => 'latest',
'credentials' => [
'key' => G5_AWS_CREDENTIALS_KEY,
'secret' => G5_AWS_CREDENTIALS_SECRET,
],
]);
}
public function encrypt($plaintext)
{
try {
$result = $this->kmsClient->encrypt([
'KeyId' => G5_AWS_KMS_KEY_ARN,
'Plaintext' => $plaintext,
]);
return base64_encode($result->get('CiphertextBlob'));
} catch (Aws\Exception\AwsException $e) {
echo $e->getMessage();
return null;
}
}
public function decrypt($ciphertextBlob)
{
try {
$result = $this->kmsClient->decrypt([
'CiphertextBlob' => base64_decode($ciphertextBlob),
]);
return $result->get('Plaintext');
} catch (Aws\Exception\AwsException $e) {
echo $e->getMessage();
return null;
}
}
}
if (!function_exists('get_hide_class_')) {
function get_hide_class_(bool $color = true): string
{
//숨기고자 할 때
//$classname = 'disp_hide';
//모두 보이고자 할때
$classname = "";
return $classname;
}
}
//dewbian 20240131 //
//$possible_ip = array("222.238.66.76", "203.216.182.245", "121.78.167.249");
$possible_ip = array();
//로그 남기기 dewbian 20240207
function log_detail_insert($job, $dr_location = '', $desc = ''){
global $g5, $mb, $member;
//echo "dr_location===>[".$dr_location."]
";
$member_id = ($member['mb_id'] == '') ? '' : trim($member['mb_id']);
$member_id = ($member_id == '') ? trim($mb['mb_id']) : $member_id;
$lo_ip = $_SERVER['REMOTE_ADDR'];
if ($dr_location){
$lo_location = addslashes($dr_location);
}else {
$lo_location = addslashes($g5['title']);
}
$lo_url = addslashes(clean_xss_tags($_SERVER['REQUEST_URI']));
$lo_job = addslashes(clean_xss_tags($job));
$job = preg_replace("|([^가-힣0-9a-zA-Z\s<>\(\)\[\].,/&%:-])|u", " ", $job);
if($member_id){
$tmp_sql = " insert into blot_login_admin
( lo_ip, mb_id, lo_datetime, lo_location, lo_url, lo_job, lo_desc )
values
( '{$lo_ip}', '{$member_id}', '".G5_TIME_YMDHIS."', '{$lo_location}', '{$lo_url}', '{$job}', '{$desc}') ";
$result = sql_query($tmp_sql);
// echo "tmp_sql===>[".$tmp_sql."]
";
// echo "result===>[".$result."]
";
}
}
add_event('password_is_wrong', 'login_log_insert_function', 1, 2); // 로그인 실패시 내용 기록
function login_log_insert_function($arg, $mb){ // 로그인 실패 기록 추가 함수
//echo "login_log_insert_function============================
";
global $g5;
$sql = "select mb_id from `{$g5['member_table']}` where mb_id = '".$_POST['mb_id']."'";
//echo "sql===>[".$sql."]
";
$mb_id_check = sql_fetch($sql);
if($mb_id_check){ // 그누보드 멤버 테이블에 존재하는 계정인지 체크
// mb_2 : 비밀번호 틀린횟수
$sql = "select mb_2 from `{$g5['member_table']}` where mb_id = \"".$_POST['mb_id']."\" ";
//echo "sql===>[".$sql."]
";
$tmp = sql_fetch($sql);
$mb_2 = $tmp['mb_2'];
if( $mb_2 == ''){
$mb_2 = 0;
}
$mb_id = isset($_POST['mb_id']) ? $_POST['mb_id'] : '';
//echo "mb_2==>[".$mb_2."]
";
if( $mb_2 < 5 ){ // 접근 차단 횟수를 넘으면 login_ban_time 기록
$mb_2 = (int)$mb_2 + 1;
$sql = "update `{$g5['member_table']}` set mb_2 = '".$mb_2."' where mb_id = '".$mb_id."' ";
//echo "sql==>[".$sql."]
";
$result = sql_query($sql, false);
}
}
}
add_event('member_login_check_before', 'ban_login_check', 1, 1);
function ban_login_check($mb_id) { // 차단횟수, 시간 체크 함수
global $g5;
$sql = "select mb_id, mb_2 as cnt from `{$g5['member_table']}` where mb_id = \"".$_POST['mb_id']."\" ";
$tmp = sql_fetch($sql);
if( !isset($tmp['cnt']) || $tmp['cnt'] == ''){
$mb_2 = 0;
}else {
$mb_2 = $tmp['cnt'];
}
if( $mb_2 >= 5 ){ // 접근 차단 횟수 제한 // 차단횟수 따라 사용시 캡챠 로그인 페이지로 이동시킴
// include_once(G5_CAPTCHA_PATH.'/captcha.lib.php'); // 캡챠 체크를 위한 라이브러리 불러옴
$mb_id = isset($_POST['mb_id']) ? trim($_POST['mb_id']) : '';
$mb_password = isset($_POST['mb_password']) ? trim($_POST['mb_password']) : '';
//
if (!$mb_id || !$mb_password)
alert('회원아이디나 비밀번호가 공백이면 안됩니다.');
//
$mb = get_member($mb_id); // 회원 체크를 위해 회원 정보를 불러옴
//
if (! (isset($mb['mb_id']) && $mb['mb_id']) || !login_password_check($mb, $mb_password, $mb['mb_password'])) {
//run_event('password_is_wrong', 'login', $mb);
alert(sprintf('로그인을 %s회 이상 실패하였습니다.\n관리자에게 문의하십시오.', $mb_2));
//alert(sprintf('로그인을 %s회 이상 시도하셨습니다. \n 자동입력 방지문자를 입력해주세요', 5 ), G5_ADMIN_URL . '/login_capt.php');
}else {
$arg['mb_id'] = array();
$arg['login_ip'] = array();
$arg['mb_id'][] = $_POST['mb_id'];
$arg['login_ip'][] = $_SERVER['REMOTE_ADDR'];
login_log_delete_function($arg); // 로그인 성공시 차단해제
}
}
}
function login_log_delete_function($arg){ // 차단된 ip와 id 기준으로 데이터를 제거하여 차단 해제
global $g5;
//echo "login_log_delete_function============================
";
//print_r($arg);
if (isset($arg['mb_id']) && isset($arg['mb_login_ip'])) { // 로그인 성공시 차단기록 삭제를 위한 전달받은 파라미터 형식 수정
$arg['mb_id'] = array();
$arg['login_ip'] = array();
$arg['mb_id'][] = $arg['mb_id'];
$arg['login_ip'][] = $arg['mb_login_ip'];
}
foreach($arg['login_ip'] as $row => $val){
$sql = "update `{$g5['member_table']}` set mb_2 = 0 where mb_id = \"".$arg['mb_id'][$row]."\" ;";
//echo "sql===>[".$sql."]
";
sql_query($sql);
}
}
function setSessionWithExpiration($key, $value, $ttl) {
$_SESSION[$key] = [
'value' => $value,
'expires' => time() + $ttl
];
}
function getSessionValue($key) {
//echo "1
";
if (isset($_SESSION[$key])) {
//echo "2
";
// 만료 시간 체크
if (time() < $_SESSION[$key]['expires']) {
//echo "3
";
return $_SESSION[$key]['value'];
} else {
//echo "4
";
// 만료된 경우 세션에서 제거
unset($_SESSION[$key]);
}
//echo "5
";
}
return null;
}
?>
// 문자열 암복호화
class str_encrypt_AES256
{
var $encrypt_key;
var $iv;
function __construct(){
$this->encrypt_key = defined('G5_AES256_ENCRYPTION_KEY') ? G5_AES256_ENCRYPTION_KEY : '';
$this->iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length('aes-256-cbc'));
}
function encrypt($str){
$encryptedText = openssl_encrypt($str, 'aes-256-cbc', $this->encrypt_key , 0, $this->iv);
//벡터 데이터와 함께 저장
$encryptedData = base64_encode($encryptedText . '::' . $this->iv);
return $encryptedData;
}
function decrypt($encryptedData){
$returnStr = '';
// 암호화된 데이터를 다시 복호화
list($encryptedText, $iv) = explode('::', base64_decode($encryptedData), 2);
if ($iv === false) {
$returnStr = "";
}else {
$decryptedText = openssl_decrypt($encryptedText, 'aes-256-cbc', $this->encrypt_key, 0, $iv);
if ($decryptedText === false) {
$returnStr = "";
}else{
$returnStr = $decryptedText;
}
}
return $returnStr;
}
}
// 문자열 암복호화
class str_encrypt_md5
{
var $salt;
var $length;
function __construct($salt='', $type='')
{
// if(!$type) $type = '16';
// //echo "md5 알고리즘====>타입[".$type."]
";
// if(!$salt){
// if($type == '18'){
// //echo "여기--->18
";
// $this->salt = md5(preg_replace('/[^0-9A-Za-z]/', '8' , $_SERVER['SERVER_SOFTWARE'].$_SERVER['DOCUMENT_ROOT']));
// }elseif($type == '24'){
// //echo "여기--->24
";
// $this->salt = md5(preg_replace('/[^0-9A-Za-z]/', '4' , 'Apache/ttg2024/www' ));
// }elseif($type == '16'){
// //echo "여기--->16
";
// $this->salt = md5(preg_replace('/[^0-9A-Za-z]/', '6', 'Apache/blot16/www' ));
// }
// }else{
// $this->salt = $salt;
// }
$this->salt = md5(preg_replace('/[^0-9A-Za-z]/', '9' , 'samsunggalaxy' ));
$this->length = strlen($this->salt);
}
function encrypt($str)
{
$length = strlen($str);
$result = '';
for($i=0; $i<$length; $i++) {
$char = substr($str, $i, 1);
$keychar = substr($this->salt, ($i % $this->length) - 1, 1);
$char = chr(ord($char) + ord($keychar));
$result .= $char;
}
return strtr(base64_encode($result) , '+/=', '._-');
}
function decrypt($str) {
$result = '';
$str = base64_decode(strtr($str, '._-', '+/='));
$length = strlen($str);
for($i=0; $i<$length; $i++) {
$char = substr($str, $i, 1);
$keychar = substr($this->salt, ($i % $this->length) - 1, 1);
$char = chr(ord($char) - ord($keychar));
$result .= $char;
}
return $result;
}
}
function get_bo_ix_by_bo_hp($user_hp){
global $g5;
//$query_search = "SELECT * FROM {$g5['tg_booking_order_table']} where bo_status in ('10', '20') ";
$query_search = "SELECT * FROM {$g5['tg_booking_order_table']} where bo_rent_frdate = curdate() and bo_status in ('10', '20') ";
$result_search = sql_query($query_search);
while ($result_row = sql_fetch_array($result_search)) {
$decript_bo_hp = get_string_decrypt($result_row['bo_hp']);
//echo "decript_bo_hp==>[".$decript_bo_hp."] user_hp==>[".$user_hp."]
";
if ($decript_bo_hp === $user_hp) {
$db['bo_ix'] = $result_row['bo_ix'];
break;
}
}
return $db['bo_ix'];
}
function get_class_encrypt_md5($type){
static $cache2;
if( $cache2 && is_object($cache2) ){
return $cache2;
}
$cache2 = new str_encrypt_md5('',$type);
return $cache2;
}
function get_string_decrypt_md5($str, $type=''){
//echo "1
";
$new = get_class_encrypt_md5($type);
$decrypt_str = $new->decrypt($str);
return $decrypt_str;
}
function get_string_encrypt_md5($str, $type=''){
//echo "2
";
$new = get_class_encrypt_md5($type);
$encrypt_str = $new->encrypt($str);
return $encrypt_str;
}
function get_class_encrypt_aes256(){
static $cache;
if( $cache && is_object($cache) ){
return $cache;
}
$cache = run_replace('get_class_encrypt', new str_encrypt_AES256());
//dewbian 20240222
//$cache = run_replace('get_class_encrypt', new str_encrypt());
return $cache;
}
function get_string_encrypt_aes256($str){
$new = get_class_encrypt_aes256();
$encrypt_str = $new->encrypt($str);
return $encrypt_str;
}
function get_string_decrypt_aes256($str){
$new = get_class_encrypt_aes256();
$decrypt_str = $new->decrypt($str);
return $decrypt_str;
}