Show
Ignore:
Timestamp:
05/17/08 18:12:42 (8 months ago)
Author:
coolengineer
Message:
  • #960
  • 로그보기 및 설정 시험 기능 추가
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/plugins/CL_Moblog/index.php

    r5953 r5964  
    77        $userid = 1, $minsize = 10240 ) 
    88    { 
     9        global $pop3logs; 
     10        if( !isset($debugLogs) ) { 
     11            $pop3logs = array(); 
     12        } 
    913        $this->username = $username; 
    1014        $this->password = $password; 
     
    1822        $this->pop3 = new Pop3(); 
    1923        $this->pop3->setLogger( array(&$this,'log') ); 
     24        $this->pop3->setStatCallback( array(&$this,'statCallback') ); 
    2025        $this->pop3->setUidFilter( array(&$this,'checkUid') ); 
    2126        $this->pop3->setSizeFilter( array(&$this,'checkSize') ); 
     
    3944    function log($msg) 
    4045    { 
    41         static $blocked = false; 
    42         if( Acl::check( 'group.administrators' ) ) { 
    43             print $msg."<br/>\n"; 
    44         } else { 
    45             if( !$blocked ) { 
    46                 $blocked = true; 
    47                 print "Log message prohibited. Please login with administrator's account"; 
    48             } 
     46        $f = fopen( ROOT.DS."cache".DS."moblog.txt", "a" ); 
     47        fwrite( $f, date('Y-m-d H:i:s')." $msg\r\n" ); 
     48        fclose($f); 
     49        if( $msg[0] == '*' ) { 
     50            global $pop3logs; 
     51            array_push( $pop3logs, substr($msg,2) ); 
    4952        } 
    5053    } 
     
    6164    { 
    6265        if( !$this->pop3->connect( $this->host, $this->port, $this->ssl ) ) { 
    63             return false; 
    64         } 
     66            $this->log( "* Connection failure : ".$this->host.":".$this->port.($this->ssl?"(SSL)":"(no SSL)") ); 
     67            return false; 
     68        } 
     69        $this->log( "* Connection success : ".$this->host.":".$this->port.($this->ssl?"(SSL)":"(no SSL)") ); 
    6570        if( !$this->pop3->authorize( $this->username, $this->password ) ) { 
    66             return false; 
    67         } 
     71            $this->log( "* Authentication failure" ); 
     72            return false; 
     73        } 
     74        $this->log( "* Authentication success" ); 
    6875 
    6976        $this->pop3->run(); 
     
    8289    } 
    8390 
    84     function checkUid( $uid ) 
     91    function checkUid( $uid, $number ) 
    8592    { 
    8693        $ret = !!strstr( $this->stored_uidl, "[$uid]" ); 
    87 //      echo "Check $uid: ".($ret?"Y":"N")."<br/>\n"; 
     94        if( $ret ) { 
     95            $this->log( "Msg $number: Filterred by uid: $uid" ); 
     96        } 
    8897        return $ret; 
    8998    } 
     
    91100    function checkSize( $size, $number, $total ) 
    92101    { 
    93         if( $number > $total - $this->recentCount ) { 
    94             return false; 
    95         } 
     102        if( $number < $total - $this->recentCount ) { 
     103            return true; 
     104        } 
     105        $this->log( "Msg $number: Filterred by size: $size" ); 
    96106        return $size < $this->minsize; 
    97107    } 
     
    116126    } 
    117127 
     128    function statCallback( $total, $totalsize ) 
     129    { 
     130        $this->log( "* Total $total messages" ); 
     131        $lastStat = getBlogSetting( 'MmsPop3stat', '' ); 
     132        $stat = "$total $totalsize"; 
     133        if( $stat == $lastStat ) { 
     134            $this->log( "* No new message arrived" ); 
     135            return false; 
     136        } 
     137        setBlogSetting( 'MmsPop3stat', $stat ); 
     138        return true; 
     139    } 
     140 
    118141    function retrieveCallback( $lines, $uid ) 
    119142    { 
     143        $slogan = date( "Y-m-d" ); 
    120144        $this->appendUid( $uid ); 
    121145        $mail = $this->pop3->parse( $lines ); 
    122146        if( in_array( $mail['subject'], array( '제목없음' ) ) ) { 
    123             $mail['subject'] = ''; 
    124         } 
    125         $this->log( "Subject: " . $mail['subject'] ); 
     147            $mail['subject'] = date( "Y-m-d H:i:s" ); 
     148        } 
    126149        if( !$this->isMms($mail) ) { 
    127             $this->log( "Dismissed: this is not an MMS message" ); 
     150            $this->log( "* Subject: " . $mail['subject'] . " [SKIP]" ); 
    128151            return false; 
    129152        } 
    130153        if( empty($mail['attachments']) ) { 
    131             $this->log( "Dismissed: there is no attachment" ); 
    132             return false; 
    133         } 
    134         $this->log( "Accepted!" ); 
     154            $this->log( "* Subject: " . $mail['subject'] . " [SKIP]" ); 
     155            return false; 
     156        } 
    135157        requireComponent( "Textcube.Data.Post" ); 
    136158 
    137159        $post = new Post(); 
    138         $slogan = date( "Y-m-d" ); 
    139160 
    140161        if( $post->open( "slogan = '$slogan'" ) ) { 
     
    155176            $post->slogan = $slogan; 
    156177            if( !$post->add() ) { 
    157                 $this->log( "Failed: there is a problem in adding post" ); 
     178                $this->log( "* Subject: " . $mail['subject'] . " [ERROR]" ); 
     179                $this->log( "Failed: there is a problem in adding post : " . $post->error ); 
    158180                return false; 
    159181            } 
     
    170192            ); 
    171193        if( !$att ) { 
     194            $this->log( "* Subject: " . $mail['subject'] . " [ERROR]" ); 
    172195            $this->log( "Failed: there is a problem in attaching file" ); 
    173196            return false; 
     
    177200        $post->content = str_replace( '$HEIGHT', $att['height'], $post->content ); 
    178201        if( !$post->update() ) { 
     202            $this->log( "* Subject: " . $mail['subject'] . " [ERROR]" ); 
    179203            $this->log( "Failed: there is a problem in adding post." ); 
    180204            return false; 
    181205        } 
     206        $this->log( "* Subject: " . $mail['subject'] . " [OK]" ); 
    182207        return true; 
    183208    } 
     
    186211function moblog_check() 
    187212{ 
     213    if( isset($_GET['check']) && $_GET['check'] == 1 ) { 
     214        echo "<style>.emplog{color:red}</style>"; 
     215        echo "<ul>"; 
     216        echo join( "",  
     217            array_map( 
     218                create_function( '$li', 'return preg_match( "/^\S+\s+\S+\s+\*/", $li ) ? "<li class=\"emplog\">$li</li>" : "<li>$li</li>";'),  
     219                split( "\n",file_get_contents(ROOT.DS."cache".DS."moblog.txt")) 
     220            ) 
     221        ); 
     222        echo "</ul>"; 
     223        exit; 
     224    } 
     225 
    188226    $pop3host = getBlogSetting( 'MmsPop3Host', 'localhost' ); 
    189227    $pop3port = getBlogSetting( 'MmsPop3Port', 110 ); 
     
    195233    $pop3fallbackuserid = getBlogSetting( 'MmsPop3Fallbackuserid', 1 ); 
    196234 
     235    header( "Content-type: text/html" ); 
     236    echo "<ul><li>"; 
    197237    $moblog = new Moblog( $pop3username, $pop3password, $pop3host, $pop3port, $pop3ssl, $pop3fallbackuserid, $pop3minsize ); 
     238    $moblog->log( "--BEGIN--" ); 
    198239    $moblog->check(); 
     240    $moblog->log( "-- END --" ); 
     241    if( Acl::check( 'group.administrators' ) ) { 
     242        global $pop3logs; 
     243        print join("</li><li>",$pop3logs); 
     244    } 
     245    echo "</li></ul>"; 
    199246    return true; 
    200247} 
     
    204251    global $blogURL; 
    205252    requireModel("common.setting"); 
    206     if( $_SERVER['REQUEST_METHOD'] == 'POST' ) { 
     253    if( Acl::check('group.administrators') && $_SERVER['REQUEST_METHOD'] == 'POST' ) { 
    207254        setBlogSetting( 'MmsPop3Email', $_POST['pop3email'] ); 
    208255        setBlogSetting( 'MmsPop3Host', $_POST['pop3host'] ); 
     
    240287                                            <dd> 
    241288                                            <?php if( empty($pop3email) ): ?> 
    242                                                 <?php echo _('MMS 메시지를 보내어 연동할 이메일이 공개되지 않았습니다'); ?> 
     289                                                <?php echo _t('MMS 메시지를 보내어 연동할 이메일이 공개되지 않았습니다'); ?> 
    243290                                            <?php else: ?> 
    244                                                 <?php echo _('이동전화를 이용하여 위 메일로 MMS 메시지를 보내면 블로그에 게시됩니다'); ?> 
     291                                                <?php echo _t('이동전화를 이용하여 위 메일로 MMS 메시지를 보내면 블로그에 게시됩니다'); ?> 
    245292                                            <?php endif ?> 
    246293                                            </dd> 
     
    290337                                </div> 
    291338                            </form> 
     339                            <h2 class="caption"><span class="main-text"><?php echo _t('MMS 메시지 테스트');?></span></h2> 
     340                                <div id="editor-section" class="section"> 
     341                                    <dl id="formatter-line" class="line"> 
     342                                        <dt><span class="label"><?php echo _t('명령');?></span></dt> 
     343                                        <dd> 
     344                                            <input type="button" class="save-button input-button wide-button" value="<?php echo _t('로그보기');?>"   
     345                                                onclick="document.getElementById('pop3_debug').src='<?php echo $blogURL."/plugin/moblog/check?check=1"?>'" /> 
     346                                            <input type="button" class="save-button input-button wide-button" value="<?php echo _t('시험하기');?>"  
     347                                                onclick="document.getElementById('pop3_debug').src='<?php echo $blogURL."/plugin/moblog/check"?>'" /> 
     348                                        </dd> 
     349                                    </dl> 
     350                                </div> 
     351                                <iframe src="about:blank" class="debug_message" id="pop3_debug" style="width:100%; height:400px"> 
     352                                </iframe> 
    292353<?php endif ?> 
    293354                        </div>