Esempio n. 1
0
 /**
  * 自動リンクの正規表現パターンを生成
  * @return string
  */
 private function getAutoLinkPattern($force = false)
 {
     global $cache;
     static $pattern;
     // キャッシュ処理
     if ($force) {
         unset($pattern);
         $cache['wiki']->removeItem(self::AUTO_LINK_PATTERN_CACHE);
     } else {
         if (!empty($pattern)) {
             return $pattern;
         } else {
             if ($cache['wiki']->hasItem(self::AUTO_LINK_PATTERN_CACHE)) {
                 $pattern = $cache['wiki']->getItem(self::AUTO_LINK_PATTERN_CACHE);
                 $cache['wiki']->touchItem(self::AUTO_LINK_PATTERN_CACHE);
                 return $pattern;
             }
         }
     }
     // 用語マッチパターンキャッシュを生成
     global $autolink, $nowikiname;
     $config = new Config('AutoLink');
     // FIXME
     $config->read();
     $ignorepages = $config->get('IgnoreList');
     $forceignorepages = $config->get('ForceIgnoreList');
     unset($config);
     $auto_pages = array_merge($ignorepages, $forceignorepages);
     foreach (Listing::pages('wiki') as $page) {
         if (preg_match('/^' . RendererDefines::WIKINAME_PATTERN . '$/', $page) ? $nowikiname : strlen($page) >= $autolink) {
             $auto_pages[] = $page;
         }
     }
     if (empty($auto_pages)) {
         $result = $result_a = $nowikiname ? '(?!)' : RendererDefines::WIKINAME_PATTERN;
     } else {
         $auto_pages = array_unique($auto_pages);
         sort($auto_pages, SORT_STRING);
         $auto_pages_a = array_values(preg_grep('/^[A-Z]+$/i', $auto_pages));
         $auto_pages = array_values(array_diff($auto_pages, $auto_pages_a));
         // 正規表現を最適化
         $result = Trie::regex($auto_pages);
         $result_a = Trie::regex($auto_pages_a);
     }
     $pattern = array($result, $result_a, $forceignorepages);
     $cache['wiki']->setItem(self::AUTO_LINK_PATTERN_CACHE, $pattern);
     return $pattern;
 }
Esempio n. 2
0
function plugin_remoteip_inline()
{
    global $auth_api;
    if (!isset($auth_api['remoteip']['use'])) {
        return '';
    }
    if (!$auth_api['remoteip']['use']) {
        return '';
    }
    // 処理済みか?
    $obj = new auth_remoteip();
    $msg = $obj->getSession();
    if (!empty($msg['api']) && $obj->auth_name !== $msg['api']) {
        return '';
    }
    if (!empty($msg['uid'])) {
        return '';
    }
    $ip =& $_SERVER['REMOTE_ADDR'];
    if (!count($config_remoteip)) {
        $obj_cfg = new Config(REMOTEIP_CONFIG_PAGE);
        $obj_cfg->read();
        $config_remoteip = $obj_cfg->get('IP');
        unset($obj_cfg);
    }
    foreach ($config_remoteip as $data) {
        if ($ip !== $data[0]) {
            continue;
        }
        // UID not set.
        if (empty($data[1])) {
            return '';
        }
        $obj->response['uid'] = $data[1];
        $obj->response['name'] = $data[2];
        $obj->response['note'] = $data[3];
        break;
    }
    // if (empty($obj->response['uid'])) return '';
    $obj->setSession();
    return '';
}
Esempio n. 3
0
function auth_mixi_get_role_config($type, $id)
{
    static $config_mixi = array();
    // PLUGIN_AUTH_MIXI_MY_ID
    // mixi
    if (!isset($config_mixi[$type])) {
        $config = new Config(CONFIG_AUTH_OPENID_MIXI);
        $config->read();
        switch ($type) {
            case 2:
                $config_mixi[2] = $config->get('friends');
                $config_mixi[2][][0] = PLUGIN_AUTH_MIXI_MY_ID;
                break;
            case 3:
                $config_mixi[3] = $config->get('community');
                break;
            default:
                return Auth::ROLE_AUTH_OPENID;
        }
        unset($config);
    }
    // 登録されたIDでの認証に限って、登録者に昇格させる
    foreach ($config_mixi[$type] as $x) {
        if ($x[0] === $id) {
            return Auth::ROLE_ENROLLEE;
        }
    }
    return Auth::ROLE_AUTH_OPENID;
}
Esempio n. 4
0
function plugin_csv2newpage_action()
{
    global $vars, $num;
    $config_name = empty($vars['_config']) ? '' : $vars['_config'];
    $config = new Config('plugin/tracker/' . $config_name);
    if (!$config->read()) {
        return '<p>config file (' . htmlsc($config_name) . ') not found.</p>';
    }
    $config->config_name = $config_name;
    $source = $config->page . '/page';
    $refer = empty($vars['_refer']) ? '' : $vars['_refer'];
    if (!is_pagename($refer)) {
        return array('msg' => 'cannot write', 'body' => 'page name (' . htmlsc($refer) . ') is not valid.');
    }
    if (!is_page($source)) {
        return array('msg' => 'cannot write', 'body' => 'page template (' . htmlsc($source) . ') is not exist.');
    }
    $upload = empty($vars['_upload']) ? 0 : $vars['_upload'];
    $csvlines = $upload ? plugin_csv2newpage_upload($refer) : plugin_csv2newpage_from_page($refer);
    $csv_fields = plugin_csv2newpage_extract_fields($csvlines);
    // ページデータを生成
    $postdata_template = join('', get_source($source));
    $np = array('*Newpages under [[' . $refer . ']]');
    foreach ($csv_fields as $csv_field) {
        $csv_ct = 1;
        $ary = array();
        foreach ($csv_field as $csv_f) {
            $key = 'csv_field' . $csv_ct;
            if (!array_key_exists($key, $vars)) {
                $csv_ct++;
                continue;
            }
            $tracker_key = trim($vars[$key]);
            $ary[$tracker_key] = trim($csv_f);
            //			array_push($np, '+' . $tracker_key . ' --- ' . $csv_f);
            $csv_ct++;
        }
        $np_name = plugin_csv2newpage_write($ary, $refer, $postdata_template, $config);
        $line = join(',', $csv_field);
        array_push($np, '+' . '[[' . $np_name . ']] ---' . $line);
    }
    return array('msg' => 'csv2newpage complete', 'body' => RendererFactory::factory($np));
}
Esempio n. 5
0
 /**
  * Referer元spamかのチェック
  * @return boolean
  */
 private function is_refspam()
 {
     global $open_uri_in_new_window_servername;
     // リファラーをパース
     $parse_url = parse_url($this->referer);
     // フラグ
     $is_refspam = true;
     // リファラースパムか?
     $hit_bl = false;
     // ブラックリストに入っているか?
     $BAN = false;
     // バンするか?
     $condition = $parse_url['host'] . $parse_url['path'];
     // ドメインは小文字にする。(ドメインの大文字小文字は区別しないのと、strposとstriposで速度に倍ぐらい違いがあるため)
     // 独自ドメインでない場合を考慮してパス(/~hoge/)を評価する。
     // QueryString(?aa=bb)は評価しない。
     // ホワイトリストに入っている場合はチェックしない
     $WhiteList = new Config(CONFIG_REFERER_WL);
     $WhiteList->read();
     $WhiteListLines = $WhiteList->get('WhiteList');
     foreach (array_merge($open_uri_in_new_window_servername, $WhiteListLines) as $WhiteListLine) {
         //		if (preg_match('/'.$WhiteListLine[0].'/i', $condition) !== 0){
         if (stripos($condition, $WhiteListLine[0]) !== false) {
             $is_refspam = false;
             break;
         }
     }
     if ($is_refspam !== false) {
         $NewBlackListLine = array();
         // ブラックリストを確認
         $BlackList = new Config(CONFIG_REFERER_BL);
         $BlackList->read();
         $BlackListLines = $BlackList->get('BlackList');
         // |~referer|~count|~ban|h
         foreach ($BlackListLines as $BlackListLine) {
             //			if (preg_match('/'.$BlackListLine[0].'/i', $condition) !== 0){
             if (stripos($condition, $BlackListLine[0]) !== false) {
                 // 過去に同じリファラーからアクセスがあった場合
                 $BlackListLine[1]++;
                 if ($BlackListLine[2] == 1 || $BlackListLine[1] <= self::REFFRER_BAN_COUNT) {
                     // バンフラグが立っている場合か、しきい値を超えた場合バン
                     $BAN = true;
                     // わざと反応を遅らせる
                     sleep(2);
                 }
                 $hit_bl = true;
                 $is_refspam = true;
             }
             $NewBlackListLine[] = array($BlackListLine[0], $BlackListLine[1], $BlackListLine[2]);
         }
         // ブラックリストにヒットしなかった場合
         if ($hit_bl === false) {
             // リファラーにサイトへのアドレスが存在するかを確認
             $is_refspam = $this->is_not_valid_referer();
             if ($is_refspam === true) {
                 // 存在しない場合はスパムリストに追加
                 $NewBlackListLine[] = array($condition, 1, 0);
             } else {
                 // 存在した場合はホワイトリストに追加
                 //				$WhiteListLines[] = array($condition);
                 //				$WhiteList->put('WhiteList',$WhiteListLines);
                 //				$WhiteList->write();
             }
         }
         // ブラックリストを更新
         $BlackList->set('BlackList', $NewBlackListLine);
         $BlackList->write();
         unset($BlackList, $BlackListLines, $BlackListLine, $NewBlackListLine, $hit_bl);
         unset($WhiteList, $WhiteListLines, $WhiteListLine);
         if ($is_refspam === true || $BAN === true) {
             // スパムだった場合、ログに環境を保存する。
             $log = array(UTIME, $url, $_SERVER['HTTP_USER_AGENT'], $_SERVER['REMOTE_ADDR']);
             error_log(join("\t", $lines) . "\n", 3, CACHE_DIR . self::REFERER_SPAM_LOG);
             Utility::dieMessage('Spam Protection', 'Spam Protection', 500);
         }
     }
     return $is_refspam;
 }
Esempio n. 6
0
function i18n_ConfMsgGet($lang, $msg, $no = 0)
{
    // ex. :config/i18n/text/zh_TW
    $ConfName = 'i18n/text/' . $lang[0];
    if (!is_page(':config/' . $ConfName)) {
        // ex. :config/i18n/text/zh
        $ConfName = 'i18n/text/' . $lang[1];
        if (!is_page(':config/' . $ConfName)) {
            return $msg;
        }
    }
    $obj = new Config($ConfName);
    $obj->read();
    $i18n_msg = $obj->get('TEXT');
    unset($obj);
    $ret_no = $no == 0 ? 1 : 0;
    foreach ($i18n_msg as $text) {
        if ($text[$no] == $msg) {
            return $text[$ret_no];
        }
    }
    return $msg;
}
Esempio n. 7
0
 /**
  * ファイルのMIMEタイプを取得
  */
 public function getMime()
 {
     // finfo関数の出力を優先
     if (function_exists('finfo_file')) {
         $finfo = finfo_open(FILEINFO_MIME_TYPE);
         $mimetype = finfo_file($finfo, $this->basename);
         finfo_close($finfo);
         return $mimetype;
     }
     //return preg_replace("/ [^ ]*/", "", trim(shell_exec('file -bi '.escapeshellcmd($path))));
     $f = new File($this->basename);
     try {
         // @をつけると処理が重いのでtry-catch文を使う
         $size = getimagesize($f->getRealPath());
         // 画像の場合
         switch ($size[2]) {
             case IMAGETYPE_BMP:
                 return 'image/bmp';
             case IMAGETYPE_GIF:
                 return 'image/gif';
             case IMAGETYPE_ICO:
                 return 'image/vnd.microsoft.icon';
             case IMAGETYPE_IFF:
                 return 'image/iff';
             case IMAGETYPE_JB2:
                 return 'image/jbig2';
             case IMAGETYPE_JP2:
                 return 'image/jp2';
             case IMAGETYPE_JPC:
                 return 'image/jpc';
             case IMAGETYPE_JPEG:
                 return 'image/jpeg';
             case IMAGETYPE_JPX:
                 return 'image/jpx';
             case IMAGETYPE_PNG:
                 return 'image/png';
             case IMAGETYPE_PSD:
                 return 'image/psd';
             case IMAGETYPE_SWC:
             case IMAGETYPE_SWF:
                 return 'application/x-shockwave-flash';
             case IMAGETYPE_TIFF_II:
             case IMAGETYPE_TIFF_MM:
                 return 'image/tiff';
             case IMAGETYPE_WBMP:
                 return 'image/vnd.wap.wbmp';
             case IMAGETYPE_XBM:
                 return 'image/xbm';
         }
     } catch (Exception $e) {
         // 画像でない場合エラーが発生するので例外処理で投げる
     }
     // mime-type一覧表を取得
     $config = new Config(self::ATTACH_CONFIG_PAGE_MIME);
     $table = $config->read() ? $config->get('mime-type') : array();
     unset($config);
     // メモリ節約
     foreach ($table as $row) {
         $_type = trim($row[0]);
         $exts = preg_split('/\\s+|,/', trim($row[1]), -1, PREG_SPLIT_NO_EMPTY);
         foreach ($exts as $ext) {
             if (preg_match('/\\.' . $ext . '$/i', $this->filename)) {
                 return $_type;
             }
         }
     }
     return self::DEFAULT_MIME_TYPE;
 }
Esempio n. 8
0
function adm_auth_wkgrp_get_page()
{
    global $auth_api;
    $config = new Config(CONFIG_AUTH_WKGRP);
    $config->read();
    $wkgrp_user = array();
    foreach ($auth_api as $name => $val) {
        // if (! $val['use']) continue;
        // if ($name === 'plus' || $name === 'remoteip') continue;
        $temp = $config->get($name);
        foreach ($temp as $val) {
            $wkgrp_user[$name][$val[0]]['role'] = is_numeric($val[1]) ? adm_auth_wkgrp_role2define($val[1]) : $val[1];
            $wkgrp_user[$name][$val[0]]['displayname'] = $val[2];
            $wkgrp_user[$name][$val[0]]['group'] = $val[3];
            $wkgrp_user[$name][$val[0]]['mypage'] = $val[4];
            $wkgrp_user[$name][$val[0]]['home'] = $val[5];
        }
    }
    unset($config);
    return $wkgrp_user;
}
Esempio n. 9
0
function plugin_addline_action()
{
    global $_addline_messages, $_string, $vars;
    if (Auth::check_role('readonly')) {
        die_message($_string['prohibit']);
    }
    $refer = $vars['refer'];
    $wiki = Factory::Wiki($refer);
    $postdata_old = $wiki->get();
    $configname = $vars['configname'];
    $above = $vars['above'];
    $block_plugin = 1;
    if (array_key_exists('addline_inno', $vars)) {
        $addline_no = $vars['addline_inno'];
        $block_plugin = 0;
    } else {
        if (array_key_exists('addline_no', $vars)) {
            $addline_no = $vars['addline_no'];
        }
    }
    $config = new Config('plugin/addline/' . $configname);
    if (!$config->read()) {
        return array('msg' => $_addline_messages['error'], 'body' => '<p class="alert alert-warning">' . sprintf($_addline_messages['config_notfound'], Utility::htmlsc($configname)) . '</p>');
    }
    $config->config_name = $configname;
    $template = addline_get_source($config->page);
    if (!$template) {
        return array('msg' => $_addline_messages['error'], 'body' => '<p class="alert alert-warning">' . sprintf($_addline_messages['config_notfound'], Utility::htmlsc($config->page)) . '</p>');
    }
    $addline = rtrim(join("\n", $template));
    if ($block_plugin) {
        $postdata = addline_block($addline, $postdata_old, $addline_no, $above);
    } else {
        $postdata = addline_inline($addline, $postdata_old, $addline_no, $above);
    }
    $title = $_title_updated;
    $body = '';
    if (md5(join('', $postdata_old)) !== $vars['digest']) {
        $title = $_addline_messages['title_collided'];
        $body = $_addline_messages['msg_collided'] . make_pagelink($refer);
    }
    //	$body = $postdata; // debug
    //	foreach ( $vars as $k=>$v ){$body .= "[$k:$v]&br;";}
    $wiki->set($postdata);
    $retvars['msg'] = $title;
    $retvars['body'] = $body;
    //	$post['page'] = $get['page'] = $vars['page'] = $refer;
    $post['refer'] = $get['refer'] = $vars['refer'] = $refer;
    return $retvars;
}
Esempio n. 10
0
function plugin_referer_ignore_check($url)
{
    static $ignore_url;
    // config.php
    if (!isset($ignore_url)) {
        $config = new Config(CONFIG_REFERER);
        $config->read();
        $ignore_url = $config->get('IGNORE');
        unset($config);
    }
    foreach ($ignore_url as $x) {
        if (strpos($url, $x) !== FALSE) {
            return 1;
        }
    }
    return 0;
}
Esempio n. 11
0
function MyNetCheck($ip)
{
    global $log_common, $log_ua;
    $config = new Config(CONFIG_SPAM_WL_PRIVATE_NET);
    $config->read();
    $private_ip = $config->get('IP');
    $dynm_host = $config->get('DYNAMIC_HOST');
    // $hosts = $config->get('HOST');
    unset($config);
    $dynm_ip = array();
    foreach ($dynm_host as $host) {
        $tmp = gethostbyname($host);
        if ($host == $tmp) {
            continue;
        }
        // IPが求まらない
        $dynm_ip[] = $tmp;
    }
    unset($tmp);
    $obj = new IPBL();
    if (!empty($log_common['nolog_ip'])) {
        $obj->setMyNetList(array(array_merge($private_ip, $log_common['nolog_ip'], $dynm_ip)));
    } else {
        $obj->setMyNetList(array(array_merge($private_ip, $dynm_ip)));
    }
    $hosts = !is_array($ip) ? array($ip) : $ip;
    foreach ($hosts as $host) {
        $obj->setName($host);
        if ($obj->isMyNet()) {
            return true;
        }
    }
    return false;
}
Esempio n. 12
0
 function loadConfig($config = null)
 {
     if (isset($this->config)) {
         return TRUE;
     }
     $config = trim($config);
     if ($config == null) {
         $config = PLUGIN_TRACKER_DEFAULT_CONFIG;
     }
     $obj_config = new Config('plugin/tracker/' . $config);
     if ($obj_config->read()) {
         $this->config = $obj_config;
         $this->config_name = $config;
         return TRUE;
     } else {
         $this->error = "Config not found: " . $obj_config->page;
         return FALSE;
     }
 }
Esempio n. 13
0
 /**
  * AutoAliasの正規表現パターンを生成
  * @return string
  */
 private function getAutoAliasPattern($force = false)
 {
     global $cache, $aliaspage;
     static $pattern;
     $wiki = Factory::Wiki($aliaspage);
     if (!$wiki->has()) {
         return null;
     }
     // AutoAliasNameの更新チェック
     if ($cache['wiki']->hasItem(self::AUTOALIAS_PATTERN_CACHE)) {
         $term_cache_meta = $cache['wiki']->getMetadata(self::AUTOALIAS_PATTERN_CACHE);
         if ($term_cache_meta['mtime'] < $wiki->time()) {
             $force = true;
         }
     }
     // キャッシュ処理
     if ($force) {
         unset($pattern);
         $cache['wiki']->removeItem(self::AUTOALIAS_PATTERN_CACHE);
     } else {
         if (!empty($pattern)) {
             return $pattern;
         } else {
             if ($cache['wiki']->hasItem(self::AUTOALIAS_PATTERN_CACHE)) {
                 $pattern = $cache['wiki']->getItem(self::AUTOALIAS_PATTERN_CACHE);
                 $cache['wiki']->touchItem(self::AUTOALIAS_PATTERN_CACHE);
                 return $pattern;
             }
         }
     }
     global $WikiName, $autolink, $nowikiname;
     $config = new Config('AutoAlias');
     $config->read();
     $ignorepages = $config->get('IgnoreList');
     $forceignorepages = $config->get('ForceIgnoreList');
     unset($config);
     $auto_pages = array_merge($ignorepages, $forceignorepages);
     foreach (self::getAutoAliasDict($force) as $term => $val) {
         if (preg_match('/^' . $WikiName . '$/', $term) ? $nowikiname : mb_strlen($term) >= $autolink) {
             $auto_terms[] = $term;
         }
     }
     if (empty($auto_terms)) {
         $result = $result_a = $nowikiname ? '(?!)' : $WikiName;
     } else {
         $auto_terms = array_unique($auto_terms);
         sort($auto_terms, SORT_STRING);
         $auto_terms_a = array_values(preg_grep('/^[A-Z]+$/i', $auto_terms));
         $auto_terms = array_values(array_diff($auto_terms, $auto_terms_a));
         $result = Trie::regex($auto_terms);
         $result_a = Trie::regex($auto_terms_a);
     }
     $pattern = array($result, $result_a, $forceignorepages);
     $cache['wiki']->setItem(self::AUTOALIAS_PATTERN_CACHE, $pattern);
     return $pattern;
 }