CI 묻고 답하기

제목 RSS 라이브러리 사용중 에러가 나네요 ㅠㅠ
글쓴이 세콩 작성시각 2012/01/02 11:02:02
댓글 : 8 추천 : 0 스크랩 : 0 조회수 : 21803   RSS
CI포럼에서 가져온 라이브러리를 사용해서 RSS를 가져오려고합니다..
(출처 :  http://codeigniter.com/forums/viewthread/160394/#952203 )


라이브러리 작성자는 친절하게도 디버그 모드까지 시전해주었는데..

왜 디렉토리가 아니라고 인식하는건지.. 
삽질하다가 결국 질문을 올리게 되었숩니다..흐규흐규 ㅠㅠ..


컨트롤러부분..
function showList() {
  
  $this->rss->set_debug();
  $this->rss->set_items_limit(2);
  $this->rss->set_cache_life(10);
  $this->rss->set_cache_path(DOC_ROOT.'/rss_cache/');
  
  $this->rss->set_url('http://www.onsuccess.me/?feed=rss2');
  $data['news'] = $this->rss->parse();


 }
 
에러내용..

Debug mode is ON
Cache life time - 600s
Cache path - http://localhost/spdev/rss_cache/
WARNING! Cache path is not a directory
Feed url - http://www.onsuccess.me/?feed=rss2

Not in cache, try to retrieve from http://www.onsuccess.me/?feed=rss2 



 다음글 질문 있습니다! URL의 타이틀 값 따오기. (4)
 이전글 이클립스 원격 디버깅 질문이요~

댓글

세콩 / 2012/01/02 11:16:17 / 추천 0
 라이브러리 내용은 여기 첨부할게요.. 하앜;;

<?php
class Rss {
    
    private $_url;
    private $_feed_urls = array();
    private $_cache_life = 600; // 10 minutes
    private $_cache_path = '';
    private $_cache_prefix = 'rss_';
    private $_use_cache = true;
    private $_debug = false;
    private $_items_limit = 5;
    private $_raw_data;
    private $CI;
    
    public function __construct(){
        $this->CI =& get_instance();
        $this->_cache_path = $this->CI->config->item('cache_path') == '' ? BASEPATH . 'cache/' : $this->CI->config->item('cache_path');
        if(!is_dir($this->_cache_path)){
            $this->_use_cache = false;
        }
    }
    
    public function set_url($url){
        if(is_array($url)){
            $this->_feed_urls = $url;
        } else {
            $this->_feed_urls[] = $url;
        }
        
        if($this->_debug === true) echo 'Feed url - ' . implode(', ', $this->_feed_urls) . '<br/>';
        
        return $this;
    }
    
    public function set_cache_life($time = 0){
        $this->_cache_life = (int)$time * 60;
        if($this->_debug === true) echo 'Cache life time - ' . $this->_cache_life . 's<br/>';
        
        return $this;
    }
    
    public function set_cache_path($path){
        $this->_cache_path = $path;
        if($this->_debug === true) echo 'Cache path - ' . $this->_cache_path . '</br>';
        if(!is_dir($this->_cache_path)){
            $this->_use_cache = false;
            if($this->_debug === true) echo 'WARNING! Cache path is not a directory';   
        }
        
        return $this;
    }
    
    public function set_debug($debug = true){
        $this->_debug = $debug;
        if($this->_debug === true) echo '<em>Debug mode is ON</em><br/>';
        
        return $this;
    }
    
    public function set_items_limit($limit){
        $limit = (int)$limit;
        if($limit > 0) $this->_items_limit = $limit;
        
        return $this;
    }
    
    public function get_raw_data(){
        return $this->_raw_data;
    }
    
    private function _cache_expired(){
        $filename = $this->_cache_path . $this->_cache_prefix . md5($this->_url) . '.cache';
        
        return !(file_exists($filename) AND filemtime($filename) > time() - $this->_cache_life);
    }
    
    private function _cache_read(){
        $filename = $this->_cache_path . $this->_cache_prefix . md5($this->_url) . '.cache';
        $fh = fopen($filename, 'r');
        flock($fh, LOCK_SH);
        $cache = fread($fh, filesize($filename));
        flock($fh, LOCK_UN);
        fclose($fh);
        
        return unserialize(base64_decode($cache));
    }
    
    private function _cache_write($data){
        if($this->_use_cache){
            $filename = $this->_cache_path . $this->_cache_prefix . md5($this->_url) . '.cache';
            // check if cache not expired
            if($this->_cache_expired()){
                $data = serialize($data);
                $fh = fopen($filename, 'w+');
                flock($fh, LOCK_EX);
                ftruncate($fh, 0);
                $bytes = fwrite($fh, base64_encode($data));
                flock($fh, LOCK_UN);
                fclose($fh);
                if($this->_debug === true){
                    if($bytes === false)
                        echo 'WARNING! Cannot frite to the cache!<br/>';
                    else
                        echo 'Cache file ' . $filename . ' was written successfully. File size: ' . $bytes . ' bytes<br/>';
                }
            } else {
                echo 'SUCCESS! Cache hit with file: ' . $filename . '</br>';
            }
        }
    }
    
    public function parse(){
        $return = array();
        foreach($this->_feed_urls as $url){
            $this->_url = $url;
            if($this->_cache_expired()){
                if($this->_debug) echo 'Not in cache, try to retrieve from ' . $this->_url . '</br>';
                $xml = file_get_contents($this->_url);
                $this->_cache_write($xml);
            } else {
                if($this->_debug) echo 'This feed already cached<br/>';
                $xml = $this->_cache_read();
            }
                $xmldoc = new SimpleXMLElement($xml, LIBXML_NOCDATA);
                $this->_raw_data = $xmldoc;
                if($this->_debug) echo 'Raw RSS data: <pre>' . print_r($this->_raw_data, true) . '</pre><br/>';
                
                $items = $xmldoc->channel->item;
            
            $c = 0;
            foreach($items as $item){
                $return[] = $item;
                $c++;
                if($c == $this->_items_limit) break;
            }
        }
        
        return $return;       
    }
}

세콩 / 2012/01/02 11:18:11 / 추천 0
Line : 47, 116 부분에서... 에러가... 도와주시옵소서~~
한대승(불의회상) / 2012/01/02 12:41:43 / 추천 0
DOC_ROOT 경로를 출력해 보세요.

세콩 / 2012/01/02 13:21:13 / 추천 0
DOC_ROOT 경로입니닷

define('DOC_ROOT',  "http://".$_SERVER['HTTP_HOST'].'/spdev');

결과출력 ↓

DOC_ROOT = http://localhost/spdev Debug mode is ON
Cache life time - 600s
Cache path - http://localhost/spdev/rss_cache/
WARNING! Cache path is not a directoryFeed url - http://www.onsuccess.me/?feed=rss2
Not in cache, try to retrieve from http://www.onsuccess.me/?feed=rss2 
변종원(웅파) / 2012/01/02 13:54:18 / 추천 0
DOC_ROOT는 /home/spdev 이렇게 해야 접근될겁니다.


웹에서  http://localhost/spdev/rss_cache/  여기에 접근해서 캐시를 쓸 수 있다면
서버 바로 뚫립니다. 

업로드, 캐시 등은 웹경로로 하면 안됩니다. 기본입니다.
세콩 / 2012/01/02 14:12:57 / 추천 0
크헉..!! 그런것도 모르고 막 만들고있었네요 ㅠㅠ

아직 학생이라 취약한게 너무 많네요 ㅠㅠ
(네 핑계 맞습니다 맞구요~ ㅎㅎ;;)

하루빨리 더 배워야겠어요 ㅎㅎ

뚫린다는건 어떤의미인거죠??
보안쪽지식은 전무하다보니..ㅋㅋ

예를들어 개발소스를 다 가져갈수있다 뭐 이런내용일까요??




세콩 / 2012/01/02 14:26:55 / 추천 0
아직 잘은 모르겠지만 구글링해보니.. 무서운게 많네요 우어...

...... 생략.......................................
http://hackme.com/download.php?filename=test.zip 를,
http://hackme.com/download.php?filename=../download.php 로 바꿈으로써, 우리는 download.php의 소스를 알아 낼 수있고, 그와 동시에 파일이 어디 업로드 되어있는지를 알아 낼 수 있다는 말입니다.
(만약 다운로드 역할을 하는 php가 업로드 폴더보다 한단계 상위가 아닌, 두단계 상위에 있다고 하면 아래처럼 ../를 하나 더 붙혀주면 되겠지요.
http://hackme.com/download.php?filename=../../download.php)

이로써 다운로드 취약점 강좌를 끝내겠습니다.
참고로 이 취약점은, download.php에서 파일 경로의 .. 문자열을 빈 문자로 치환해버림으로써 아주 간단히 막을 수 있습니다만, 국내 대부분의 사이트들은,  ..를 따로 체크해서 치환하지 않습니다..
[Reference] : 퓨틱, 「PHP 개발 - [보안]PHP 해킹하기 #3 다운로드 취약점」 http://www.coolsoft2.com/?mid=php_dev&document_srl=750490.


........... 생략. ..........
PHP의 함수 중, system()이라는 함수가 존재합니다.
이 함수는 자신이 올라가 있는 서버에서 원하는 명령을 실행할 수 있는 함수입니다.

아래는 cmd.php의 소스 입니다.
<?
system($cmd);
?>

위의 소스는,
cmd인자의 값을 system함수로 서버에서 실행시켜주는 함수입니다.
위와 같이 system()함수를 사용해서 서버에서 자신이 원하는 명렁을 실행할 수 있도록 하는 php 파일을,
웹 쉘(Web Shell)이라고 하며, 홈페이지를 대상으로 하는 웹해킹의 최종목적은 보통 웹 쉘의 획득입니다.
업로드 취약점의 경우 웹쉘 획득의 가장 기본적인 방법입니다.

한대승(불의회상) / 2012/01/02 15:49:27 / 추천 0
ㅎㅎ ^^