nntp.inc
来自「eGroupWare is a multi-user, web-based gr」· INC 代码 · 共 568 行 · 第 1/2 页
INC
568 行
return; } $data = trim(substr($data, $e, ($e2-$e))); $data = str_replace("\r", "", $data); $this->attachments[$filename] = base64_decode($data); } function parse_attachments() { // uu encoded $s = 0; while (($s = @strpos($this->body, "begin ", $s)) !== false) { if (!$s || ($this->body[$s - 2] == "\r" && $this->body[$s - 1] == "\n")) { if (($e = strpos($this->body, "\r\nend\r\n", $s)) === false) { if (substr($this->body, -3) == 'end') { $e = strlen($this->body) - 5; } else { $s += 6; continue; } } if ($this->nntp_opt & 8) { $this->fud_uudecode(str_replace("\r", "", substr($this->body, $s, ($e + 5 - $s)))); } $this->body = substr($this->body, 0, $s) . substr($this->body, ($e + 7)); $s = 0; } $s += 6; } // base64 encoded $s = 0; while (($s = strpos($this->body, "begin-base64 ", $s)) !== false) { if (!$s || ($this->body[$s - 2] == "\r" && $this->body[$s - 1] == "\n")) { if (($e = strpos($this->body, "====\r\n", $s)) === false) { if (substr($this->body, -4) == '====') { $e = strlen($this->body) - 4; } else { $s += 13; continue; } } if ($this->nntp_opt & 8) { $this->fud_base64decode(str_replace("\r", "", substr($this->body, $s, ($e+4-$s)))); } $this->body = substr($this->body, 0, $s) . substr($this->body, ($e + 5)); $s = 0; } $s += 13; } } function exit_handler() { if (!empty($this->error)) { $u = umask(0111); $fp = fopen($GLOBALS['ERROR_PATH'].".nntp/error_log", "ab"); fwrite($fp, $this->error); fclose($fp); umask($u); } exit($this->close_connection()); } function parse_msgs($frm, $nntp_adm, $start_id=0) { if (!$this->connect()) { $this->exit_handler(); } $this->group_last++; if ($start_id && $start_id > $this->group_first && $start_id <= $this->group_last) { $this->group_first = $start_id; } for ($i = $this->group_first; $i < $this->group_last; $i++) { if (!$this->get_message($i)) { $this->error = null; continue; } $this->format_headers(); $this->parse_attachments(); $msg_post = new fud_msg_edit; // Handler for our own messages, which do not need to be imported. if (isset($this->headers['x-fudforum']) && preg_match('!([A-Za-z0-9]{32}) <([0-9]+)>!', $this->headers['x-fudforum'], $m)) { if ($m[1] == md5($GLOBALS['WWW_ROOT'])) { q("UPDATE ".sql_p."msg SET mlist_msg_id='".addslashes($this->msg_id)."' WHERE id=".intval($m[2])." AND mlist_msg_id IS NULL"); if (db_affected()) { continue; } } } $msg_post->body = apply_custom_replace($this->body); if ($frm->forum_opt & 16) { $msg_post->body = tags_to_html($msg_post->body, 'N'); } else { $msg_post->body = nl2br($msg_post->body); } fud_wordwrap($msg_post->body); if (isset($this->headers['date'])) { $msg_post->post_stamp = strtotime($this->headers['date']); if ($msg_post->post_stamp <= 0 || $msg_post->post_stamp > time()) { $msg_post->post_stamp = time(); } } $msg_post->subject = htmlspecialchars(apply_custom_replace($this->subject)); $msg_post->poster_id = match_user_to_post($this->from_email, $this->from_name, $this->nntp_opt & 32, $this->user_id); $msg_post->ip_addr = $this->ip; $msg_post->mlist_msg_id = addslashes($this->msg_id); $msg_post->attach_cnt = 0; $msg_post->msg_opt = 2; $msg_post->poll_id = 0; /* try to determine whether this message is a reply or a new thread */ list($msg_post->reply_to, $msg_post->thread_id) = get_fud_reply_id(($nntp_adm->nntp_opt & 16), $frm->id, $msg_post->subject, $this->reply_to_msg_id); $msg_post->add($frm->id, $frm->message_threshold, 0, 0, false); // Handle File Attachments if (isset($this->attachments) && is_array($this->attachments)) { foreach($this->attachments as $key => $val) { if (!($nntp_adm->nntp_opt & 8) && (strlen($val) > $frm->max_attach_size || (isset($attach_list) && count($attach_list) > $frm->max_file_attachments) || filter_ext($key))) { continue; } $tmpfname = tempnam($GLOBALS['TMP'], 'FUDf_'); $fp = fopen($tmpfname, 'wb'); fwrite($fp, $val); fclose($fp); $id = attach_add(array('name' => $key, 'size' => strlen($val), 'tmp_name' => $tmpfname), $msg_post->poster_id, 0, 1); $attach_list[$id] = $id; } if (isset($attach_list)) { attach_finalize($attach_list, $msg_post->id); } } if (!($nntp_adm->nntp_opt & 1)) { fud_msg_edit::approve($msg_post->id, true); } unset($msg_post); } $this->set_end($this->group_last); $this->exit_handler(); } function get_lock() { $u = umask(0111); $fp = fopen($GLOBALS['ERROR_PATH'].'.nntp/'.$this->server.'-'.$this->newsgroup.'.lock' , "wb"); flock($fp, LOCK_EX); umask($u); return $fp; } function release_lock($fp) { fclose($fp); } function read_start() { if (!@file_exists($GLOBALS['ERROR_PATH'].'.nntp/'.$this->server.'-'.$this->newsgroup)) { return; } return (int) trim(file_get_contents($GLOBALS['ERROR_PATH'].'.nntp/'.$this->server.'-'.$this->newsgroup)); } function set_end($val) { $u = umask(0111); $fp = fopen($GLOBALS['ERROR_PATH'].'.nntp/'.$this->server.'-'.$this->newsgroup , "wb"); flock($fp, LOCK_EX); fwrite($fp, $val); fclose($fp); umask($u); } function post_message($subject, $body, $from, $forum_msg_id, $reply_to='', $attch='') { if (!$this->connect()) { $this->exit_handler(); } if ($this->cmd("POST") != 340) { $this->error = "Failed to recieve proper response to POST command, NNTP server replied: ".$this->lrc."\n"; $this->exit_handler(); } if ($GLOBALS['FUD_OPT_3'] & 8) { $from = str_replace(array('.', '@'), array('[dot]','[at]'), $from); } fputs($this->fs, "From: $from\r\n"); fputs($this->fs, "Newsgroups: $this->newsgroup\r\n"); fputs($this->fs, "Subject: $subject\r\n"); if ($GLOBALS['FORUM_TITLE']) { fputs($this->fs, "Organization: ".$GLOBALS['FORUM_TITLE']."\r\n"); } fputs($this->fs, "Date: ".date("r")."\r\n"); fputs($this->fs, "Reply-To: $from\r\n"); fputs($this->fs, "Lines: ".substr_count($body,"\n")."\r\n"); // will be used to identify forum's messages fputs($this->fs, "X-FUDforum: ".md5($GLOBALS['WWW_ROOT'])." <$forum_msg_id>\r\n"); if ($reply_to) { fputs($this->fs, "References: <".$reply_to.">\r\n"); } fputs($this->fs, "User-Agent: FUDforum ".$GLOBALS['FORUM_VERSION']."\r\n"); fputs($this->fs, "\r\n$body\r\n"); // handle file attachments, if there are any if (is_array($attch)) { fputs($this->fs, "\r\n"); foreach ($attch as $fname => $file_data) { fputs($this->fs, uuencode($file_data, $fname)); } } fputs($this->fs, ".\r\n"); if (!$this->compare_return_codes(240)) { $this->error = "Posting Failed, NNTP Server Said: ".$this->lrc."\n"; $this->exit_handler(); } $this->close_connection(); return true; }}function uuencode($in, $file_name){ $out = 'begin 644 ' . $file_name . "\r\n"; $n = strlen($in); for ($i = 0; $i < $n; $i += 3) { if (!($i % 45)) { if ($i) { $out .= "\r\n"; } if (($i + 45) < $n) { $out .= 'M'; } else { if (($c = ($n - $i))) { $out .= chr(($c & 077) + 32); } else { $out .= '`'; } } } $n1 = ($i + 1 < $n) ? ord($in[$i + 1]) : 0; $n2 = ($i + 2 < $n) ? ord($in[$i + 2]) : 0; $c = ord($in[$i]) >> 2; $out .= $c ? chr(($c & 077) + 32) : '`'; $c = ((ord($in[$i]) << 4) & 060) | (($n1 >> 4) & 017); $out .= $c ? chr(($c & 077) + 32) : '`'; $c = (($n1 << 2) & 074) | (($n2 >> 6) & 03); $out .= $c ? chr(($c & 077) + 32) : '`'; $c = $n2 & 077; $out .= $c ? chr(($c & 077) + 32) : '`'; } return $out . "\r\n`\r\nend\r\n";}?>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?