Exemplo n.º 1
0
 function delete($pass)
 {
     global $_attach_messages, $notify, $notify_subject;
     if ($this->status['freeze']) {
         return attach_info('msg_isfreeze');
     }
     if (!pkwk_login($pass)) {
         if (PLUGIN_ATTACH_DELETE_ADMIN_ONLY || $this->age) {
             return attach_info('err_adminpass');
         } else {
             if (PLUGIN_ATTACH_PASSWORD_REQUIRE && md5($pass) != $this->status['pass']) {
                 return attach_info('err_password');
             }
         }
     }
     // バックアップ
     if ($this->age || PLUGIN_ATTACH_DELETE_ADMIN_ONLY && PLUGIN_ATTACH_DELETE_ADMIN_NOBACKUP) {
         @unlink($this->filename);
     } else {
         do {
             $age = ++$this->status['age'];
         } while (file_exists($this->basename . '.' . $age));
         if (!rename($this->basename, $this->basename . '.' . $age)) {
             // 削除失敗 why?
             return array('msg' => $_attach_messages['err_delete']);
         }
         $this->status['count'][$age] = $this->status['count'][0];
         $this->status['count'][0] = 0;
         $this->putstatus();
     }
     if (is_page($this->page)) {
         touch(get_filename($this->page));
     }
     if ($notify) {
         $footer['ACTION'] = 'File deleted';
         $footer['FILENAME'] =& $this->file;
         $footer['PAGE'] =& $this->page;
         $footer['URI'] = get_script_uri() . '?' . rawurlencode($this->page);
         $footer['USER_AGENT'] = TRUE;
         $footer['REMOTE_ADDR'] = TRUE;
         pkwk_mail_notify($notify_subject, "\n", $footer) or die('pkwk_mail_notify(): Failed');
     }
     return array('msg' => $_attach_messages['msg_deleted']);
 }
Exemplo n.º 2
0
function file_write($dir, $page, $str, $notimestamp = FALSE)
{
    global $update_exec;
    global $notify, $notify_diff_only, $notify_subject;
    global $notify_exclude;
    global $whatsdeleted, $maxshow_deleted;
    global $_string;
    // if (PKWK_READONLY) return; // Do nothing
    if (auth::check_role('readonly')) {
        return;
    }
    // Do nothing
    if ($dir != DATA_DIR && $dir != DIFF_DIR) {
        die('file_write(): Invalid directory');
    }
    $page = strip_bracket($page);
    $file = $dir . encode($page) . '.txt';
    $file_exists = file_exists($file);
    // ----
    // Delete?
    if ($dir == DATA_DIR && $str === '') {
        // Page deletion
        if (!$file_exists) {
            return;
        }
        // Ignore null posting for DATA_DIR
        // Update RecentDeleted (Add the $page)
        add_recent($page, $whatsdeleted, '', $maxshow_deleted);
        // Remove the page
        unlink($file);
        // Update RecentDeleted, and remove the page from RecentChanges
        lastmodified_add($whatsdeleted, $page);
        // Clear is_page() cache
        is_page($page, TRUE);
        return;
    } else {
        if ($dir == DIFF_DIR && $str === " \n") {
            return;
            // Ignore null posting for DIFF_DIR
        }
    }
    // ----
    // File replacement (Edit)
    if (!is_pagename($page)) {
        die_message(str_replace('$1', htmlspecialchars($page), str_replace('$2', 'WikiName', $_msg_invalidiwn)));
    }
    $str = rtrim(preg_replace('/' . "\r" . '/', '', $str)) . "\n";
    $timestamp = $file_exists && $notimestamp ? filemtime($file) : FALSE;
    $fp = fopen($file, 'a') or die('fopen() failed: ' . htmlspecialchars(basename($dir) . '/' . encode($page) . '.txt') . '<br />' . "\n" . 'Maybe permission is not writable or filename is too long');
    set_file_buffer($fp, 0);
    @flock($fp, LOCK_EX);
    $last = ignore_user_abort(1);
    ftruncate($fp, 0);
    rewind($fp);
    fputs($fp, $str);
    ignore_user_abort($last);
    @flock($fp, LOCK_UN);
    fclose($fp);
    if ($timestamp) {
        pkwk_touch_file($file, $timestamp);
    }
    // Optional actions
    if ($dir == DATA_DIR) {
        if ($timestamp === FALSE) {
            lastmodified_add($page);
        }
        // Command execution per update
        if (defined('PKWK_UPDATE_EXEC') && PKWK_UPDATE_EXEC) {
            system(PKWK_UPDATE_EXEC . ' > /dev/null &');
        } elseif ($update_exec) {
            system($update_exec . ' > /dev/null &');
        }
    } else {
        if ($dir == DIFF_DIR && $notify) {
            $notify_exec = TRUE;
            foreach ($notify_exclude as $exclude) {
                $exclude = preg_quote($exclude);
                if (substr($exclude, -1) == '.') {
                    $exclude = $exclude . '*';
                }
                if (preg_match('/^' . $exclude . '/', $_SERVER["REMOTE_ADDR"])) {
                    $notify_exec = FALSE;
                    break;
                }
            }
            if ($notify_exec !== FALSE) {
                if ($notify_diff_only) {
                    $str = preg_replace('/^[^-+].*\\n/m', '', $str);
                }
                $summary['ACTION'] = 'Page update';
                $summary['PAGE'] =& $page;
                $summary['URI'] = get_page_absuri($page);
                $summary['USER_AGENT'] = TRUE;
                $summary['REMOTE_ADDR'] = TRUE;
                pkwk_mail_notify($notify_subject, $str, $summary);
                //			pkwk_mail_notify($notify_subject, $str, $summary) or
                //				die('pkwk_mail_notify(): Failed');
            }
        }
    }
    is_page($page, TRUE);
    // Clear is_page() cache
}
Exemplo n.º 3
0
 /**
  *  Mail to administrator(s)
  */
 private static function pkwk_spamnotify($action, $page, $target = array('title' => ''), $progress = array(), $method = array())
 {
     global $notify, $notify_subject;
     if (!$notify) {
         return;
     }
     $asap = isset($method['asap']);
     $summary['ACTION'] = 'Blocked by: ' . self::summarize_spam_progress($progress, TRUE);
     if (!$asap) {
         $summary['METRICS'] = self::summarize_spam_progress($progress);
     }
     $tmp = self::summarize_detail_badhost($progress);
     if ($tmp != '') {
         $summary['DETAIL_BADHOST'] = $tmp;
     }
     $tmp = self::summarize_detail_newtral($progress);
     if (!$asap && $tmp != '') {
         $summary['DETAIL_NEUTRAL_HOST'] = $tmp;
     }
     $wiki = Factory::Wiki($page);
     $summary['COMMENT'] = $action;
     $summary['PAGE'] = '[blocked] ' . ($wiki->isValied() ? $page : '');
     $summary['URI'] = $wiki->uri();
     $summary['USER_AGENT'] = TRUE;
     $summary['REMOTE_ADDR'] = TRUE;
     pkwk_mail_notify($notify_subject, var_export($target, TRUE), $summary, TRUE);
 }
Exemplo n.º 4
0
function attach_doupload($file, $page, $pass = NULL, $temp)
{
    global $_attach_messages, $_string;
    global $notify, $notify_subject, $notify_exclude, $spam;
    $filename = Utility::encode($page) . '_' . Utility::encode($file);
    $type = Utility::getMimeInfo($temp);
    $must_compress = PLUGIN_ATTACH_UNKNOWN_COMPRESS !== 0 ? attach_is_compress($type, PLUGIN_ATTACH_UNKNOWN_COMPRESS) : false;
    // 不明なファイルを圧縮するか?
    // ファイル名の長さをチェック
    $filename_length = strlen($filename);
    if ($filename_length >= 255 || $must_compress && $filename_length >= 251) {
        return array('result' => FALSE, 'msg' => $_attach_messages['err_filename']);
    }
    // スパムチェック
    if ($spam !== 0) {
        // ファイルの内容でスパムチェック
        // if attach spam, filtering attach file.
        $vars['uploadname'] = $file['name'];
        $vars['uploadtext'] = attach_gettext($file['tmp_name']);
        if ($vars['uploadtext'] === '' || $vars['uploadtext'] === FALSE) {
            return FALSE;
        }
        if (isset($spam['method']['attach'])) {
            $_method =& $spam['method']['attach'];
        } else {
            if (isset($spam['method']['_default'])) {
                $_method =& $spam['method']['_default'];
            } else {
                $_method = array();
            }
        }
        $exitmode = isset($spam['exitmode']) ? $spam['exitmode'] : '';
        Spam::pkwk_spamfilter('File Attach', $page, $vars, $_method, $exitmode);
    }
    if ($must_compress) {
        // 添付ファイルを圧縮する
        switch (PLUGIN_ATTACH_COMPRESS_TYPE) {
            case 'GZ':
                if (!extension_loaded('zlib')) {
                    Utility::dieMessage('#attach: zlib extention has not loaded.');
                }
                $obj = new AttachFile($page, $file . '.gz');
                if ($obj->exist) {
                    return array('result' => FALSE, 'msg' => $_attach_messages['err_exists']);
                }
                $tp = fopen($file['tmp_name'], 'rb') or die_message($_attach_messages['err_load_file']);
                $zp = gzopen($obj->filename, 'wb') or die_message($_attach_messages['err_write_tgz']);
                while (!feof($tp)) {
                    gzwrite($zp, fread($tp, 8192));
                }
                gzclose($zp);
                fclose($tp);
                chmod($obj->filename, PLUGIN_ATTACH_FILE_MODE);
                break;
            case 'ZIP':
                if (!class_exists('ZipArchive')) {
                    Utility::dieMessage('#attach: ZipArchive class has not defined.');
                }
                $obj = new AttachFile($page, $file . '.zip');
                if ($obj->exist) {
                    return array('result' => FALSE, 'msg' => $_attach_messages['err_exists']);
                }
                $zip = new ZipArchive();
                $zip->addFile($temp, $file);
                // if ($zip->status !== ZIPARCHIVE::ER_OK)
                if ($zip->status !== 0) {
                    die_message($_attach_messages['err_upload'] . '(' . $zip->status . ').');
                }
                $zip->close();
                chmod($obj->filename, PLUGIN_ATTACH_FILE_MODE);
                break;
            case 'BZ2':
                if (!extension_loaded('bz2')) {
                    Utility::dieMessage('#attach: bz2 extention has not loaded.');
                }
                $obj = new AttachFile($page, $file . '.bz2');
                if ($obj->exist) {
                    return array('result' => FALSE, 'msg' => $_attach_messages['err_exists']);
                }
                $tp = fopen($file['tmp_name'], 'rb') or die_message($_attach_messages['err_load_file']);
                $zp = bzopen($obj->filename, 'wb') or die_message($_attach_messages['err_write_tgz']);
                while (!feof($tp)) {
                    bzwrite($zp, fread($tp, 8192));
                }
                bzclose($zp);
                fclose($tp);
                chmod($obj->filename, PLUGIN_ATTACH_FILE_MODE);
                break;
            default:
                //miko
                $obj = new AttachFile($page, $file);
                if ($obj->exist) {
                    return array('result' => FALSE, 'msg' => $_attach_messages['err_exists']);
                }
                if (move_uploaded_file($temp, $obj->filename)) {
                    chmod($obj->filename, PLUGIN_ATTACH_FILE_MODE);
                }
                break;
        }
    } else {
        // 通常添付
        $obj = new AttachFile($page, $file);
        if (isset($obj->exist)) {
            return array('result' => FALSE, 'msg' => $_attach_messages['err_exists']);
        }
        if (move_uploaded_file($temp, $obj->filename)) {
            chmod($obj->filename, PLUGIN_ATTACH_FILE_MODE);
        }
    }
    if (file_exists($temp)) {
        unlink($temp);
    }
    // ページのタイムスタンプを更新
    Factory::Wiki($page)->touch();
    $obj->status['pass'] = $pass !== TRUE && $pass !== NULL ? md5($pass) : '';
    if ($notify) {
        $notify_exec = TRUE;
        foreach ($notify_exclude as $exclude) {
            $exclude = preg_quote($exclude);
            if (substr($exclude, -1) == '.') {
                $exclude .= '*';
            }
            if (preg_match('/^' . $exclude . '/', get_remoteip())) {
                $notify_exec = FALSE;
                break;
            }
        }
        $footer['ACTION'] = 'File attached';
        $footer['FILENAME'] = $file['name'];
        $footer['FILESIZE'] = $file['size'];
        $footer['PAGE'] = $page;
        $footer['URI'] = get_cmd_uri('attach', '', array('refer' => $page, 'pcmd' => 'info', 'file' => $file['name']));
        $footer['USER_AGENT'] = TRUE;
        $footer['REMOTE_ADDR'] = TRUE;
        pkwk_mail_notify($notify_subject, "\n", $footer);
    }
    return array('result' => TRUE, 'msg' => $_attach_messages['msg_uploaded']);
}
Exemplo n.º 5
0
function pkwk_spamnotify($action, $page, $target = array('title' => ''), $progress = array(), $method = array())
{
    global $notify, $notify_subject;
    if (!$notify) {
        return;
    }
    $asap = isset($method['asap']);
    $summary['ACTION'] = 'Blocked by: ' . summarize_spam_progress($progress, TRUE);
    if (!$asap) {
        $summary['METRICS'] = summarize_spam_progress($progress);
    }
    $tmp = summarize_detail_badhost($progress);
    if ($tmp != '') {
        $summary['DETAIL_BADHOST'] = $tmp;
    }
    $tmp = summarize_detail_newtral($progress);
    if (!$asap && $tmp != '') {
        $summary['DETAIL_NEUTRAL_HOST'] = $tmp;
    }
    $summary['COMMENT'] = $action;
    $summary['PAGE'] = '[blocked] ' . (is_pagename($page) ? $page : '');
    $summary['URI'] = get_script_uri() . '?' . rawurlencode($page);
    $summary['USER_AGENT'] = TRUE;
    $summary['REMOTE_ADDR'] = TRUE;
    pkwk_mail_notify($notify_subject, var_export($target, TRUE), $summary, TRUE);
}
Exemplo n.º 6
0
 /**
  * 削除する
  */
 public function delete($pass)
 {
     global $notify, $notify_subject;
     if ($this->status['freeze']) {
         // ここではチェックしない
         return false;
     }
     // TODO
     if (Auth::check_role('role_contents_admin') && !Auth::login($pass)) {
         if (self::DELETE_ADMIN_ONLY || $this->age) {
             return attach_info('err_adminpass');
         } else {
             if (self::PASSWORD_REQUIRE && md5($pass) !== $this->status['pass']) {
                 return attach_info('err_password');
             }
         }
     }
     if ($this->age !== 0) {
         // 世代が指定されている場合は削除する
         unlink($this->basename . '.' . $this->age);
     } else {
         // バックアップ
         do {
             $age = ++$this->status['age'];
         } while (file_exists($this->basename . '.' . $this->age));
         // 世代を加算してリネーム
         if (!rename($this->basename, $this->basename . '.' . $this->age)) {
             // リネーム失敗?
             return false;
         }
     }
     $this->status['count'][$this->age] = $this->status['count'][0];
     $this->status['count'][0] = 0;
     $this->updateStatus();
     // ページのタイムスタンプを更新
     $wiki = Factory::Wiki($this->page);
     if ($wiki->has()) {
         $wiki->touch();
     }
     if ($notify) {
         $footer['ACTION'] = 'File deleted';
         $footer['FILENAME'] =& $this->file;
         $footer['PAGE'] =& $this->page;
         $footer['URI'] = get_page_absuri($this->page);
         $footer['USER_AGENT'] = TRUE;
         $footer['REMOTE_ADDR'] = TRUE;
         pkwk_mail_notify($notify_subject, "\n", $footer) or Utility::dieMessage('pkwk_mail_notify(): Failed');
     }
     return true;
 }
Exemplo n.º 7
0
Arquivo: file.php Projeto: big2men/qhm
function file_write($dir, $page, $str, $notimestamp = FALSE)
{
    global $notify, $notify_diff_only, $notify_subject;
    global $whatsdeleted, $maxshow_deleted;
    global $qblog_page_re;
    $qm = get_qm();
    if (PKWK_READONLY) {
        return;
    }
    // Do nothing
    if ($dir != DATA_DIR && $dir != DIFF_DIR) {
        die($qm->m['file']['err_invalid_dir']);
    }
    $page = strip_bracket($page);
    $file = $dir . encode($page) . '.txt';
    $file_exists = file_exists($file);
    // ----
    // Record last modified date for QHM cache func.
    $lm_file = CACHE_DIR . QHM_LASTMOD;
    file_put_contents($lm_file, date('Y-m-d H:i:s'));
    // ----
    // Delete?
    if ($dir == DATA_DIR && $str === '') {
        // Page deletion
        if (!$file_exists) {
            return;
        }
        // Ignore null posting for DATA_DIR
        // Update RecentDeleted (Add the $page)
        add_recent($page, $whatsdeleted, '', $maxshow_deleted);
        //QBlog 記事 であれば、削除処理を呼び出す
        if (preg_match($qblog_page_re, $page)) {
            qblog_remove_post($page);
        }
        // Remove the page
        unlink($file);
        // Update RecentDeleted, and remove the page from RecentChanges
        lastmodified_add($whatsdeleted, $page);
        // Clear is_page() cache
        is_page($page, TRUE);
        return;
    } else {
        if ($dir == DIFF_DIR && $str === " \n") {
            return;
            // Ignore null posting for DIFF_DIR
        }
    }
    // ----
    // File replacement (Edit)
    if (!is_pagename($page)) {
        die_message(str_replace('$1', htmlspecialchars($page), str_replace('$2', 'WikiName', $qm->m['fmt_err_invalidiwn'])));
    }
    $str = rtrim(preg_replace('/' . "\r" . '/', '', $str)) . "\n";
    $timestamp = $file_exists && $notimestamp ? filemtime($file) : FALSE;
    $fp = fopen($file, 'a') or die($qm->replace('file.err_not_writable', h(basename($dir)), encode($page)));
    set_file_buffer($fp, 0);
    flock($fp, LOCK_EX);
    ftruncate($fp, 0);
    rewind($fp);
    fputs($fp, $str);
    flock($fp, LOCK_UN);
    fclose($fp);
    if ($timestamp) {
        pkwk_touch_file($file, $timestamp);
    }
    // Optional actions
    if ($dir == DATA_DIR) {
        // Update RecentChanges (Add or renew the $page)
        if ($timestamp === FALSE) {
            lastmodified_add($page);
        }
        add_tinycode($page);
        // Command execution per update
        if (defined('PKWK_UPDATE_EXEC') && PKWK_UPDATE_EXEC) {
            system(PKWK_UPDATE_EXEC . ' > /dev/null &');
        }
    } else {
        if ($dir == DIFF_DIR && $notify) {
            if ($notify_diff_only) {
                $str = preg_replace('/^[^-+].*\\n/m', '', $str);
            }
            $footer['ACTION'] = 'Page update';
            $footer['PAGE'] =& $page;
            $footer['URI'] = get_script_uri() . '?' . rawurlencode($page);
            $footer['USER_AGENT'] = TRUE;
            $footer['REMOTE_ADDR'] = TRUE;
            if (isset($_SESSION['usr'])) {
                $str .= "\n\n " . $qm->replace('file.lbl_editor', $_SESSION['usr']) . "\n";
            }
            pkwk_mail_notify($notify_subject, $str, $footer) or die($qm->m['file']['err_mail_failed']);
        }
    }
    is_page($page, TRUE);
    // Clear is_page() cache
}
Exemplo n.º 8
0
function file_write($dir, $page, $str, $notimestamp = false)
{
    global $_msg_invalidiwn, $notify, $notify_diff_only, $notify_subject;
    global $whatsdeleted, $maxshow_deleted;
    if (PKWK_READONLY) {
        return;
    }
    // Do nothing
    if ($dir != DATA_DIR && $dir != DIFF_DIR) {
        die('file_write(): Invalid directory');
    }
    $page = strip_bracket($page);
    $file = $dir . encode($page) . '.txt';
    $file_exists = file_exists($file);
    // ----
    // Delete?
    if ($dir == DATA_DIR && $str === '') {
        // Page deletion
        if (!$file_exists) {
            return;
        }
        // Ignore null posting for DATA_DIR
        // Update RecentDeleted (Add the $page)
        add_recent($page, $whatsdeleted, '', $maxshow_deleted);
        // Remove the page
        unlink($file);
        // Update RecentDeleted, and remove the page from RecentChanges
        lastmodified_add($whatsdeleted, $page);
        // Clear is_page() cache
        is_page($page, true);
        return;
    } elseif ($dir == DIFF_DIR && $str === " \n") {
        return;
        // Ignore null posting for DIFF_DIR
    }
    // ----
    // File replacement (Edit)
    if (!is_pagename($page)) {
        die_message(str_replace('$1', htmlsc($page), str_replace('$2', 'WikiName', $_msg_invalidiwn)));
    }
    $str = rtrim(preg_replace('/' . "\r" . '/', '', $str)) . "\n";
    $timestamp = $file_exists && $notimestamp ? filemtime($file) : false;
    $fp = fopen($file, 'a') or die('fopen() failed: ' . htmlsc(basename($dir) . '/' . encode($page) . '.txt') . '<br />' . "\n" . 'Maybe permission is not writable or filename is too long');
    set_file_buffer($fp, 0);
    flock($fp, LOCK_EX);
    ftruncate($fp, 0);
    rewind($fp);
    fputs($fp, $str);
    flock($fp, LOCK_UN);
    fclose($fp);
    if ($timestamp) {
        pkwk_touch_file($file, $timestamp);
    }
    // Optional actions
    if ($dir == DATA_DIR) {
        // Update RecentChanges (Add or renew the $page)
        if ($timestamp === false) {
            lastmodified_add($page);
        }
        // Command execution per update
        if (defined('PKWK_UPDATE_EXEC') && PKWK_UPDATE_EXEC) {
            system(PKWK_UPDATE_EXEC . ' > /dev/null &');
        }
    } elseif ($dir == DIFF_DIR && $notify) {
        if ($notify_diff_only) {
            $str = preg_replace('/^[^-+].*\\n/m', '', $str);
        }
        $footer['ACTION'] = 'Page update';
        $footer['PAGE'] =& $page;
        $footer['URI'] = get_script_uri() . '?' . rawurlencode($page);
        $footer['USER_AGENT'] = true;
        $footer['REMOTE_ADDR'] = true;
        pkwk_mail_notify($notify_subject, $str, $footer) or die('pkwk_mail_notify(): Failed');
    }
    is_page($page, true);
    // Clear is_page() cache
}