Changeset 5964
- Timestamp:
- 05/17/08 18:12:42 (6 months ago)
- Files:
-
- 1 modified
-
trunk/plugins/CL_Moblog/index.php (modified) (15 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/plugins/CL_Moblog/index.php
r5953 r5964 7 7 $userid = 1, $minsize = 10240 ) 8 8 { 9 global $pop3logs; 10 if( !isset($debugLogs) ) { 11 $pop3logs = array(); 12 } 9 13 $this->username = $username; 10 14 $this->password = $password; … … 18 22 $this->pop3 = new Pop3(); 19 23 $this->pop3->setLogger( array(&$this,'log') ); 24 $this->pop3->setStatCallback( array(&$this,'statCallback') ); 20 25 $this->pop3->setUidFilter( array(&$this,'checkUid') ); 21 26 $this->pop3->setSizeFilter( array(&$this,'checkSize') ); … … 39 44 function log($msg) 40 45 { 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) ); 49 52 } 50 53 } … … 61 64 { 62 65 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)") ); 65 70 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" ); 68 75 69 76 $this->pop3->run(); … … 82 89 } 83 90 84 function checkUid( $uid )91 function checkUid( $uid, $number ) 85 92 { 86 93 $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 } 88 97 return $ret; 89 98 } … … 91 100 function checkSize( $size, $number, $total ) 92 101 { 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" ); 96 106 return $size < $this->minsize; 97 107 } … … 116 126 } 117 127 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 118 141 function retrieveCallback( $lines, $uid ) 119 142 { 143 $slogan = date( "Y-m-d" ); 120 144 $this->appendUid( $uid ); 121 145 $mail = $this->pop3->parse( $lines ); 122 146 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 } 126 149 if( !$this->isMms($mail) ) { 127 $this->log( " Dismissed: this is not an MMS message" );150 $this->log( "* Subject: " . $mail['subject'] . " [SKIP]" ); 128 151 return false; 129 152 } 130 153 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 } 135 157 requireComponent( "Textcube.Data.Post" ); 136 158 137 159 $post = new Post(); 138 $slogan = date( "Y-m-d" );139 160 140 161 if( $post->open( "slogan = '$slogan'" ) ) { … … 155 176 $post->slogan = $slogan; 156 177 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 ); 158 180 return false; 159 181 } … … 170 192 ); 171 193 if( !$att ) { 194 $this->log( "* Subject: " . $mail['subject'] . " [ERROR]" ); 172 195 $this->log( "Failed: there is a problem in attaching file" ); 173 196 return false; … … 177 200 $post->content = str_replace( '$HEIGHT', $att['height'], $post->content ); 178 201 if( !$post->update() ) { 202 $this->log( "* Subject: " . $mail['subject'] . " [ERROR]" ); 179 203 $this->log( "Failed: there is a problem in adding post." ); 180 204 return false; 181 205 } 206 $this->log( "* Subject: " . $mail['subject'] . " [OK]" ); 182 207 return true; 183 208 } … … 186 211 function moblog_check() 187 212 { 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 188 226 $pop3host = getBlogSetting( 'MmsPop3Host', 'localhost' ); 189 227 $pop3port = getBlogSetting( 'MmsPop3Port', 110 ); … … 195 233 $pop3fallbackuserid = getBlogSetting( 'MmsPop3Fallbackuserid', 1 ); 196 234 235 header( "Content-type: text/html" ); 236 echo "<ul><li>"; 197 237 $moblog = new Moblog( $pop3username, $pop3password, $pop3host, $pop3port, $pop3ssl, $pop3fallbackuserid, $pop3minsize ); 238 $moblog->log( "--BEGIN--" ); 198 239 $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>"; 199 246 return true; 200 247 } … … 204 251 global $blogURL; 205 252 requireModel("common.setting"); 206 if( $_SERVER['REQUEST_METHOD'] == 'POST' ) {253 if( Acl::check('group.administrators') && $_SERVER['REQUEST_METHOD'] == 'POST' ) { 207 254 setBlogSetting( 'MmsPop3Email', $_POST['pop3email'] ); 208 255 setBlogSetting( 'MmsPop3Host', $_POST['pop3host'] ); … … 240 287 <dd> 241 288 <?php if( empty($pop3email) ): ?> 242 <?php echo _ ('MMS 메시지를 보내어 연동할 이메일이 공개되지 않았습니다'); ?>289 <?php echo _t('MMS 메시지를 보내어 연동할 이메일이 공개되지 않았습니다'); ?> 243 290 <?php else: ?> 244 <?php echo _ ('이동전화를 이용하여 위 메일로 MMS 메시지를 보내면 블로그에 게시됩니다'); ?>291 <?php echo _t('이동전화를 이용하여 위 메일로 MMS 메시지를 보내면 블로그에 게시됩니다'); ?> 245 292 <?php endif ?> 246 293 </dd> … … 290 337 </div> 291 338 </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> 292 353 <?php endif ?> 293 354 </div>
