충돌 수정

This commit is contained in:
thisgun
2020-04-13 16:20:12 +09:00
45 changed files with 629 additions and 329 deletions

View File

@ -746,6 +746,10 @@ function get_next_num($table)
function get_group($gr_id, $is_cache=false)
{
global $g5;
if( is_array($gr_id) ){
return array();
}
static $cache = array();
@ -3634,6 +3638,36 @@ function get_head_title($title){
return $title;
}
function is_sms_send($is_type=''){
global $config;
$is_sms_send = false;
// 토큰키를 사용한다면
if(isset($config['cf_icode_token_key']) && $config['cf_icode_token_key']){
$is_sms_send = true;
} else if($config['cf_icode_id'] && $config['cf_icode_pw']) {
// 충전식일 경우 잔액이 있는지 체크
$userinfo = get_icode_userinfo($config['cf_icode_id'], $config['cf_icode_pw']);
if($userinfo['code'] == 0) {
if($userinfo['payment'] == 'C') { // 정액제
$is_sms_send = true;
} else {
$minimum_coin = 100;
if(defined('G5_ICODE_COIN'))
$minimum_coin = intval(G5_ICODE_COIN);
if((int)$userinfo['coin'] >= $minimum_coin)
$is_sms_send = true;
}
}
}
return $is_sms_send;
}
function is_use_email_certify(){
global $config;
@ -3727,12 +3761,12 @@ function is_include_path_check($path='', $is_input='')
try {
// whether $path is unix or not
$unipath = strlen($path)==0 || $path{0}!='/';
$unipath = strlen($path)==0 || substr($path, 0, 1) != '/';
$unc = substr($path,0,2)=='\\\\'?true:false;
// attempts to detect if path is relative in which case, add cwd
if(strpos($path,':') === false && $unipath && !$unc){
$path=getcwd().DIRECTORY_SEPARATOR.$path;
if($path{0}=='/'){
if(substr($path, 0, 1) == '/'){
$unipath = false;
}
}

View File

@ -4,12 +4,19 @@ if (!defined('_GNUBOARD_')) exit;
// 요금제에 따른 port 구분
function get_icode_port_type($id, $pw)
{
global $config;
// 토큰키를 사용한다면 true 로 리턴
if( isset($config['cf_icode_token_key']) && $config['cf_icode_token_key'] ){
return 1;
}
$userinfo = get_icode_userinfo($id, $pw);
if($userinfo['payment'] == 'A') { // 충전제
return 1;
} else if($userinfo['payment'] == 'C') { // 정액제
return 1;
return 2;
} else {
return false;
}
@ -28,10 +35,21 @@ class LMS {
var $socket_portcode;
var $Data = array();
var $Result = array();
var $icode_key;
// SMS 서버 접속
function SMS_con($host, $id, $pw, $portcode) {
$this->socket_host = $host;
global $config;
// 토큰키를 사용한다면
if(isset($config['cf_icode_token_key']) && $config['cf_icode_token_key']){
$this->icode_key = $config['cf_icode_token_key'];
$this->socket_host = ICODE_JSON_SOCKET_HOST;
$this->socket_port = ICODE_JSON_SOCKET_PORT;
} else {
$this->socket_host = $host;
}
$this->socket_portcode = $portcode;
$this->icode_id = FillSpace($id, 10);
$this->icode_pw = FillSpace($pw, 10);
@ -43,32 +61,63 @@ class LMS {
}
function Add($strDest, $strCallBack, $strCaller, $strSubject, $strURL, $strData, $strDate="", $nCount) {
global $config;
// 문자 타입별 Port 설정.
$sendType = strlen($strData) > 90 ? 1 : 0; // 0: SMS / 1: LMS
/* 개발 완료 후 아래 포트를 rand 함수를 이용하는 라인으로 변경 바랍니다.*/
// 토큰키를 사용한다면
if( isset($config['cf_icode_token_key']) && $config['cf_icode_token_key'] === $this->icode_key ){
// 개행치환
$strData = preg_replace("/\r\n/","\n",$strData);
$strData = preg_replace("/\r/","\n",$strData);
// 충전식
if ($this->socket_portcode == 1) {
if($sendType && $sendType == 1) {
//$this->socket_port = 8200; // LMS
$this->socket_port=(int)rand(8200,8201); // LMS
} else {
//$this->socket_port = 6295; // SMS
$this->socket_port=(int)rand(6295,6297); // SMS
}
}
// 정액제
else {
if($sendType && $sendType == 1) {
//$this->socket_port = 8300; // LMS
$this->socket_port=(int)rand(8300,8301); // LMS
} else {
//$this->socket_port = 6291; // SMS
$this->socket_port=(int)rand(6291,6293); // SMS
}
}
$checks = array('msg'=>$strData, 'subject'=>$strSubject);
$tmps = array();
foreach( $checks as $k=>$v ){
// 문자 내용이 euc-kr 인지 체크합니다.
$enc = mb_detect_encoding($v, array('EUC-KR', 'UTF-8'));
// 문자 내용이 euc-kr 이면 json_encode 에서 깨지기 때문에 utf-8 로 변환합니다.
$tmps[$k] = ($enc === 'EUC-KR') ? iconv_utf8($v) : $v;
}
$strData = $tmps['msg'];
$strSubject = $tmps['subject'];
// 문자 타입별 Port 설정.
$sendType = strlen($strData)>90 ? 1 : 0; // 0: SMS / 1: LMS
if($sendType==0) $strSubject = "";
$is_use_json = true;
} else {
/* 개발 완료 후 아래 포트를 rand 함수를 이용하는 라인으로 변경 바랍니다.*/
// 충전식
if ($this->socket_portcode == 1) {
if($sendType && $sendType == 1) {
//$this->socket_port = 8200; // LMS
$this->socket_port=(int)rand(8200,8201); // LMS
} else {
//$this->socket_port = 6295; // SMS
$this->socket_port=(int)rand(6295,6297); // SMS
}
}
// 정액제
else {
if($sendType && $sendType == 1) {
//$this->socket_port = 8300; // LMS
$this->socket_port=(int)rand(8300,8301); // LMS
} else {
//$this->socket_port = 6291; // SMS
$this->socket_port=(int)rand(6291,6293); // SMS
}
}
}
$strCallBack = FillSpace($strCallBack, 11); // 회신번호
$strDate = FillSpace($strDate, 12); // 즉시(12byte 공백), 예약전송(YmdHi)
@ -88,9 +137,9 @@ class LMS {
$strSubject = str_replace(">", "]", $strSubject);
$strSubject = FillSpace($strSubject,30);
$strData = FillSpace(CutChar($strData,1500),1500);
$strData = $is_use_json ? CutCharUtf8($strData, G5_ICODE_JSON_MAX_LENGTH) : FillSpace(CutChar($strData, G5_ICODE_LMS_MAX_LENGTH), G5_ICODE_LMS_MAX_LENGTH);
} else if (!$strURL) {
$strData = FillSpace(CutChar($strData,90),90);
$strData = $is_use_json ? CutCharUtf8($strData, G5_ICODE_JSON_MAX_LENGTH) : FillSpace(CutChar($strData,90),90);
$strCaller = FillSpace($strCaller,10);
} else {
$strURL = FillSpace($strURL,50);
@ -102,39 +151,85 @@ class LMS {
for ($i=0; $i<$nCount; $i++) {
$strDest[$i] = FillSpace($strDest[$i],11);
if ($sendType && $sendType == 1) {
$this->Data[$i] = '01144 '.$this->icode_id.$this->icode_pw.$strDest[$i].$strCallBack.$strSubject.$strDate.$strData;
} else if (!$strURL) {
$this->Data[$i] = '01144 '.$this->icode_id.$this->icode_pw.$strDest[$i].$strCallBack.$strCaller.$strDate.$strData;
} else {
$strData = FillSpace(CheckCallCenter($strURL, $strDest[$i], $strData),80);
$this->Data[$i] = '05173 '.$this->icode_id.$this->icode_pw.$strDest[$i].$strCallBack.$strURL.$strDate.$strData;
}
if($is_use_json) {
$strDest[$i] = $strDest[$i];
$list = array(
"key" => $this->icode_key,
"tel" => $strDest[$i],
"cb" => $strCallBack,
"msg" => $strData,
"title" => $strSubject?$strSubject:"",
"date" => $strDate?$strDate:""
);
$packet = json_encode($list);
if( !$packet ){ // json_encode가 잘못되었으면 보내지 않습니다.
continue;
}
$this->Data[$i] = '06'.str_pad(strlen($packet), 4, "0", STR_PAD_LEFT).$packet;
} else {
$strDest[$i] = FillSpace($strDest[$i],11);
if ($sendType && $sendType == 1) {
$this->Data[$i] = '01144 '.$this->icode_id.$this->icode_pw.$strDest[$i].$strCallBack.$strSubject.$strDate.$strData;
} else if (!$strURL) {
$this->Data[$i] = '01144 '.$this->icode_id.$this->icode_pw.$strDest[$i].$strCallBack.$strCaller.$strDate.$strData;
} else {
$strData = FillSpace(CheckCallCenter($strURL, $strDest[$i], $strData),80);
$this->Data[$i] = '05173 '.$this->icode_id.$this->icode_pw.$strDest[$i].$strCallBack.$strURL.$strDate.$strData;
}
}
}
return true;
}
function Send() {
$fsocket = fsockopen($this->socket_host,$this->socket_port, $errno, $errstr, 2);
if (!$fsocket) return false;
set_time_limit(60);
global $config;
foreach($this->Data as $puts) {
fputs($fsocket, $puts);
while(!$gets) { $gets = fgets($fsocket,30); }
$dest = substr($puts,26,11);
if (substr($gets,0,19) == "0223 00".$dest) {
$this->Result[] = $dest.":".substr($gets,19,10);
} else {
$this->Result[$dest] = $dest.":Error(".substr($gets,6,2).")";
}
$gets = "";
}
// 토큰키를 사용한다면
if( isset($config['cf_icode_token_key']) && $config['cf_icode_token_key'] === $this->icode_key ){
$fsocket = @fsockopen($this->socket_host,$this->socket_port, $errno, $errstr, 2);
if (!$fsocket) return false;
set_time_limit(300);
fclose($fsocket);
$this->Data = "";
foreach($this->Data as $puts) {
fputs($fsocket, $puts);
while(!$gets) { $gets = fgets($fsocket,32); }
$json = json_decode(substr($puts,6), true);
$dest = $json["tel"];
if (substr($gets,0,20) == "0225 00".FillSpace($dest,12)) {
$this->Result[] = $dest.":".substr($gets,20,11);
} else {
$this->Result[$dest] = $dest.":Error(".substr($gets,6,2).")";
if(substr($gets,6,2) >= "80") break;
}
$gets = "";
}
fclose($fsocket);
} else {
$fsocket = @fsockopen($this->socket_host,$this->socket_port, $errno, $errstr, 2);
if (!$fsocket) return false;
set_time_limit(300);
foreach($this->Data as $puts) {
fputs($fsocket, $puts);
while(!$gets) { $gets = fgets($fsocket,30); }
$dest = substr($puts,26,11);
if (substr($gets,0,19) == "0223 00".$dest) {
$this->Result[] = $dest.":".substr($gets,19,10);
} else {
$this->Result[$dest] = $dest.":Error(".substr($gets,6,2).")";
}
$gets = "";
}
fclose($fsocket);
}
$this->Data = array();
return true;
}
}
@ -168,6 +263,24 @@ function CutChar($word, $cut) {
return $word;
}
function CutCharUtf8($word, $cut) {
preg_match_all('/[\xE0-\xFF][\x80-\xFF]{2}|./', $word, $match); // target for BMP
$m = $match[0];
$slen = strlen($word); // length of source string
if ($slen <= $cut) return $word;
$ret = array();
$count = 0;
for ($i=0; $i < $cut; $i++) {
$count += (strlen($m[$i]) > 1)?2:1;
if ($count > $cut) break;
$ret[] = $m[$i];
}
return join('', $ret);
}
/**
* 수신번호의 값이 정확한 값인지 확인합니다.
*
@ -183,7 +296,6 @@ function CheckCommonTypeDest($strDest, $nCount) {
}
}
/**
* 회신번호 유효성 여부조회 *
* @param string callback 회신번호

View File

@ -44,8 +44,20 @@ class SMS {
var $SMS_Port;
var $Data = array();
var $Result = array();
var $icode_key;
var $socket_port;
var $socket_host;
function SMS_con($sms_server,$sms_id,$sms_pw,$port) {
global $config;
// 토큰키를 사용한다면
if(isset($config['cf_icode_token_key']) && $config['cf_icode_token_key']){
$this->icode_key = $config['cf_icode_token_key'];
$this->socket_host = ICODE_JSON_SOCKET_HOST;
$this->socket_port = ICODE_JSON_SOCKET_PORT;
}
$this->ID=$sms_id; // 계약 후 지정
$this->PWD=$sms_pw; // 계약 후 지정
$this->SMS_Server=$sms_server;
@ -60,25 +72,82 @@ class SMS {
}
function Add($dest, $callBack, $Caller, $msg, $rsvTime="") {
global $g5;
global $g5, $config;
// 내용 검사 1
$Error = CheckCommonType($dest, $rsvTime);
if ($Error) return $Error;
// 내용 검사 2
//if ( eregi("[^0-9]",$callBack) ) return "회신 전화번호가 잘못되었습니다";
if ( preg_match("/[^0-9]/i",$callBack) ) return "회신 전화번호가 잘못되었습니다";
// 토큰키를 사용한다면
if( isset($config['cf_icode_token_key']) && $config['cf_icode_token_key'] === $this->icode_key ){
$msg=cut_char($msg,80); // 80자 제한
// 보낼 내용을 배열에 집어넣기
$dest = spacing($dest,11);
$callBack = spacing($callBack,11);
$Caller = spacing($Caller,10);
$rsvTime = spacing($rsvTime,12);
$msg = spacing($msg,80);
// 내용 검사 1
$Error = CheckCommonType($dest, $rsvTime);
if ($Error) return $Error;
if ( preg_match("/[^0-9]/i",$callBack) ) return "회신 전화번호가 잘못되었습니다";
$this->Data[] = '01144 '.$this->ID.$this->PWD.$dest.$callBack.$Caller.$rsvTime.$msg;
return "";
// 개행치환
$msg = preg_replace("/\r\n/", "\n", $msg);
$msg = preg_replace("/\r/", "\n", $msg);
// 90byte 이내는 SMS, 90 ~ 2000 byte 는 LMS 그 이상은 절삭 되어 LMS로 발송
// SMS 이기 때문에 90byte 이내로 합니다.
$msg=cut_char($msg, 90);
$msg = spacing($msg, 90);
// 한글 깨진것이 있는지 체크합니다.
if( preg_match('/^([\x00-\x7e]|.{2})*/', $msg, $z) ){
$msg = $z[0];
}
// 문자 내용이 euc-kr 인지 체크합니다.
$enc = mb_detect_encoding($msg, array('EUC-KR', 'UTF-8'));
// 문자 내용이 euc-kr 이면 json_encode 에서 깨지기 때문에 utf-8 로 변환합니다.
if($enc === 'EUC-KR'){
$msg = iconv_utf8($msg);
}
// 보낼 내용을 배열에 집어넣기
$dest = spacing($dest,11);
$callBack = spacing($callBack,11);
$Caller = spacing($Caller,10);
$rsvTime = $rsvTime ? spacing($rsvTime,12) : '';
$list = array(
"key" => $this->icode_key,
"tel" => $dest,
"cb" => $callBack,
"msg" => $msg,
"title" => "", //SMS 의 경우 타이틀을 지정할수 없습니다.
"date" => $rsvTime
);
$packet = json_encode($list);
if( !$packet ){ // json_encode가 잘못되었으면 보내지 않습니다.
return "json_encode error";
}
$this->Data[] = '06'.str_pad(strlen($packet), 4, "0", STR_PAD_LEFT).$packet;
return '';
} else {
// 기존 OLD SMS
// 내용 검사 1
$Error = CheckCommonType($dest, $rsvTime);
if ($Error) return $Error;
// 내용 검사 2
//if ( eregi("[^0-9]",$callBack) ) return "회신 전화번호가 잘못되었습니다";
if ( preg_match("/[^0-9]/i",$callBack) ) return "회신 전화번호가 잘못되었습니다";
$msg=cut_char($msg,80); // 80자 제한
// 보낼 내용을 배열에 집어넣기
$dest = spacing($dest,11);
$callBack = spacing($callBack,11);
$Caller = spacing($Caller,10);
$rsvTime = spacing($rsvTime,12);
$msg = spacing($msg,80);
$this->Data[] = '01144 '.$this->ID.$this->PWD.$dest.$callBack.$Caller.$rsvTime.$msg;
return "";
}
}
function AddURL($dest, $callBack, $URL, $msg, $rsvTime="") {
@ -121,26 +190,53 @@ class SMS {
return "";
}
function Send () {
$fp=@fsockopen(trim($this->SMS_Server),trim($this->SMS_Port), $errno, $errstr, 2);
if (!$fp) return false;
set_time_limit(60);
function Send() {
global $config;
## php4.3.10일경우
## zend 최신버전으로 업해주세요..
## 또는 122번째 줄을 $this->Data as $tmp => $puts 로 변경해 주세요.
// 토큰키를 사용한다면
if( isset($config['cf_icode_token_key']) && $config['cf_icode_token_key'] === $this->icode_key ){
$fsocket = @fsockopen(trim($this->socket_host),trim($this->socket_port), $errno, $errstr, 2);
if (!$fsocket) return false;
set_time_limit(300);
foreach($this->Data as $puts) {
$dest = substr($puts,26,11);
fputs($fp,$puts);
while(!$gets) { $gets=fgets($fp,30); }
if (substr($gets,0,19)=="0223 00".$dest) $this->Result[]=$dest.":".substr($gets,19,10);
else $this->Result[$dest]=$dest.":Error";
$gets="";
}
fclose($fp);
$this->Data="";
return true;
foreach($this->Data as $puts) {
fputs($fsocket, $puts);
while(!$gets) { $gets = fgets($fsocket,32); }
$json = json_decode(substr($puts,6), true);
$dest = $json["tel"];
if (substr($gets,0,20) == "0225 00".spacing($dest,12)) {
$this->Result[] = $dest.":".substr($gets,20,11);
} else {
$this->Result[$dest] = $dest.":Error(".substr($gets,6,2).")";
if(substr($gets,6,2) >= "80") break;
}
$gets = "";
}
fclose($fsocket);
} else {
$fp=@fsockopen(trim($this->SMS_Server),trim($this->SMS_Port));
if (!$fp) return false;
set_time_limit(300);
## php4.3.10일경우
## zend 최신버전으로 업해주세요..
## 또는 122번째 줄을 $this->Data as $tmp => $puts 로 변경해 주세요.
foreach($this->Data as $puts) {
$dest = substr($puts,26,11);
fputs($fp,$puts);
while(!$gets) { $gets=fgets($fp,30); }
if (substr($gets,0,19)=="0223 00".$dest) $this->Result[]=$dest.":".substr($gets,19,10);
else $this->Result[$dest]=$dest.":Error";
$gets="";
}
fclose($fp);
}
$this->Data=array();
}
}
?>