์ฝ๋์ด๊ทธ๋์ดํฐ (์ดํ, CI) ๋ก REST API ๊ฐ๋ฐ ์, ๋ง์ด ์ฐ์ด๋ ์คํ ๋ผ์ด๋ธ๋ฌ๋ฆฌ์์
ํน์ IP๋ฅผ ํ์ฉ/์ฐจ๋จ ํ๋ ๊ธฐ๋ฅ์ด ์๋๋ฐ,
ํน์ IP๋ฅผ (์- 1.1.1.1, 1.1.1.2) ์ง์ ํด์ ์จ์ผ๋๋ ๋ถํธํจ์ด ์์ด
ํด๋น ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ปค์คํฐ ๋ง์ด์ง ํ๋ค
REST API LIBRARY
https://github.com/chriskacerguis/codeigniter-restserver
/application/config/rest.php
$config['rest_ip_whitelist_enabled'] = TRUE;
$config['rest_ip_whitelist'] = '192.168.0.1, 192.168.0.2, 192.168.0/24';
์ ํ์ดํธ๋ฆฌ์คํธ์ ์ค์ ๊ฐ์ ๋ณด๋ฉด, 192.168.0.1, 192.168.0.2๋ ๋น์ฐํ ํ์ฉ์ด ์๋์ง๋ง,
์ด ์ธ ๋ค๋ฅธ ์์ดํผ๋ก ์ ๊ทผ ์, ์ ๊ทผ ๋ถ๊ฐ๋ผ๋ ๋ฌธ๊ตฌ๊ฐ ๋ฌ๋ค
ํน์ IP๋ง ๊ฑธ๋ฌ์ฃผ์ง, ๋์ญ๋๋ก๋ ์ ์ฉ์ด ๋ถ๊ฐํ๊ฒ..
๋ง์ฝ ๋ด๋ถ๋ง์์ ์ ๋ IP๋ฅผ ์ฐ๊ณ ์๊ณ , ํน์ ๋์ญ๋๋ก ์ฐจ๋จ/ํ์ฉํ๊ฒ ๋๋ค๋ฉด...
์์ญ~ ์๋ง๊ฐ์ IP๋ฅผ ๋ค ์ ์ด๋๋ ๋ถ์์ฌ๋ฅผ ์์ ๊ธฐ ์ํด
์ฒ๋ฆฌํ๋ ํจ์๋ฅผ ์์ ํด์คฌ๋ค
/application/libraries/REST_Controller.php
protected function _check_whitelist_auth(){$whitelist = explode(',', $this->config->item('rest_ip_whitelist'));array_push($whitelist, '127.0.0.1', '0.0.0.0');$is_ip_chk = FALSE;foreach ($whitelist as &$ip){$ip = trim($ip);if(strpos($ip, "/") !== FALSE) {if( $this->IP_Match($ip, $this->input->ip_address()) == TRUE) {$is_ip_chk = TRUE;break;}}}if (in_array($this->input->ip_address(), $whitelist) === FALSE && $is_ip_chk == FALSE){$this->response([$this->config->item('rest_status_field_name') => FALSE,$this->config->item('rest_message_field_name') => $this->lang->line('text_rest_ip_unauthorized')], self::HTTP_UNAUTHORIZED);}}
>>ํจ์ ์ถ๊ฐ
protected function IP_Match($network, $ip){$ip_arr = explode("/",$network);$network_long=ip2long($ip_arr[0]);$mask_long= pow(2,32)-pow(2,(32-$ip_arr[1]));$ip_long=ip2long($ip);if (($ip_long & $mask_long) == $network_long) {return TRUE;} else {return FALSE;}}
์ด๋ ๊ฒ ์ ์ฉํ๋ฉด, IP๋ฅผ ์ญ~~~ ์์ฑํ ํ์ ์์ด ์ฒ๋ฆฌ ๊ฐ๋ฅํ๋ค
PHP ip2long
http://php.net/manual/kr/function.ip2long.php
PHP pow
http://php.net/manual/kr/function.pow.php
'๊ฐ๋ฐ์ด์ผ๊ธฐ' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
์๋ฐ์คํฌ๋ฆฝํธ(JS) ๋ธ๋ผ์ฐ์ ๋ฅผ ํตํ PC/Mobile ๊ตฌ๋ถ (0) | 2019.12.03 |
---|---|
1. ๋ฆฌ๊ทธ์ค๋ธ๋ ์ ๋(LOL) API KEY ๋ฐ๊ธ (0) | 2019.06.25 |
node js app.js , express generator, sequelize, pug (0) | 2019.01.09 |
์ค๋ผํด ๊ณ์ธตํ์ฟผ๋ฆฌ mysql(maria db)๋ก ๋ณ๊ฒฝ (0) | 2019.01.09 |
Oracle 12c ์ธ์คํด์ค ํด๋ผ์ด์ธํธ ์ค์น ์ ์ค๋ฅ (0) | 2018.12.10 |