CentOS 7 搭建 Mantis 集成 DokuWiki 实现mantis单点登录

  • 内容
  • 评论
  • 相关

mantis + dokuwiki DokuWiki

在度娘想找 Mantis + Dokuwiki 实现mantis单点登录 真的难, 在加上官方文档上面许多的坑, 所有把自己的配置过程记录下来, 方便有需要的朋友. 我的环境是Centos 7 LNMP, mysql与nginx的安装这里就不多介绍了. LAMP环境请参考:http://www.mantis.org.cn/393.html

软件:

MantisBT: https://sourceforge.net/projects/mantisbt/files/mantis-stable/
DokuWiki: https://download.dokuwiki.org/
SendMail: yum 安装

1. mantis 安装

1.1 安装sendmail
yum install sendmail
1.2 Mysql配置
创建mantis的Mysql数据库mantisdb,数据库排序规则为utf8_general_ci

添加mantisdb库用户mantis

1.3 nginx 配置

vim /usr/local/nginx/conf/mantis.PandaMan.com
server {
listen 80;
server_name mantis.PandaMan.com bug.PandaMan.com;
access_log /data/wwwlogs/mantis.PandaMan.com_nginx.log combined;
index index.html index.htm index.php;
root /data/wwwroot/mantis.PandaMan.com;

# wiki 安全要求,参考:https://www.dokuwiki.org/security#deny_directory_access_in_nginx
location ~ /wiki/(data|conf|bin|inc)/ {
      deny all;
    }
location ~ [^/]\.php(/|$) {
    #fastcgi_pass remote_php_ip:9000;
    fastcgi_pass unix:/dev/shm/php-cgi.sock;
    fastcgi_index index.php;
    include fastcgi.conf;
    }
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|ico)$ {
    expires 30d;
    access_log off;
    }
location ~ .*\.(js|css)?$ {
    expires 7d;
    access_log off;
    }
}

1.4 复制mantis
将mantis解压到/data/wwwroot/mantis.PandaMan.com目录下

浏览器http://mantis.PandaMan.com/admin/install.php,按提示安装

用户名:administrator
密码:root

注意:正式环境安装完毕请删除 admin 目录.建议新建超级用户,删除administartor用户.

1.5 添加自定义配置

vim /data/wwwroot/mantis.PandaMan.com/config/config_inc.php 

在文件最后一行添加


# 显示真实姓名
$g_show_realname = ON;

#Email配置(我这里用的是office 365)
# --- Email Configuration --- #
$g_webmaster_email              = 'webmaster@PandaMan.com';
$g_from_email                   = 'system@PandaMan.com';
$g_from_name                    = 'PandaMan[Bug Tracker]';
$g_return_path_email    = 'i@PandaMan.com';
$g_enable_email_notification    = ON;
$g_phpMailer_method = PHPMAILER_METHOD_MAIL;
$g_smtp_host = 'office365提供的MX记录地址';
$g_smtp_username = 'system@PandaMan.com';
$g_smtp_password = '';
$g_smtp_connection_mode = '';
$g_smtp_port = 587;

#集成 dokuwiki
# --- Wiki Configuration --- #
# Wiki Integration Enabled?
$g_wiki_enable = ON;

# Wiki Engine
$g_wiki_engine = 'dokuwiki';

# Wiki namespace to be used as root for all pages relating to this mantis installation.
$g_wiki_root_namespace = 'PandaMan';

# URL under which the wiki engine is hosted.  Must be on the same server.
$g_wiki_engine_url = $t_protocol . $t_host . '/wiki/';

注:$g_wiki_engine_url 请参考自己wiki目录修改,我这里的地址是 http://mantis.PandaMan.com/wiki
参考: http://www.mantisbt.org/wiki/doku.php/mantisbt:issue:7075:integration_with_dokuwiki#mantis_configuration

2. 安装dokuwiki

https://download.dokuwiki.org/
默认 Stable (Recommended) 下载
全语言+插件压缩包下载链接:

复制链接到浏览器或者迅雷下载

温馨提示:此处内容需要评论本文后才能查看!(评论后请刷新页面)

2.1 把dokuwiki文件解压到/data/wwwroot/mantis.PandaMan.com/wiki

http://mantis.PandaMan.com/wiki/install.php
语言:zh
标题:PandaWiki
用户名: wikiadmin
邮箱:webmaster@PandaMan.com
密码:********
选择关闭的wiki
取消注册

2.2 删除安装文件

rm -rf /data/wwwroot/mantis.PandaMan.com/wiki/install.php 

2.3 设置dokuwiki集成mantis
新建local.protected.php

vim /data/wwwroot/mantis.PandaMan.com/wiki/conf/local.protected.php 

添加以下内容

 /* for intergrating with Mantis */
define( 'MANTIS_ROOT', '/data/wwwroot/mantis.PandaMan.com/' );
define( 'MANTIS_URL', 'http://bug.PandaMan.com/' );
require_once( MANTIS_ROOT . 'core.php' );
# add mantis admin as wiki admin and lock superuser to mantis & dokuwiki admin
# 锁定后台超级管理员组, 需要修改,请注释或删除本行
$conf['superuser'] = '@admin, @ADMINISTRATOR';

修改权限

sudo chown nginx:nginx /data/wwwroot/mantis.PandaMan.com/wiki/conf/local.protected.php 

2.4 为dokuwiki添加mantis用户权限

vim /data/wwwroot/mantis.PandaMan.com/wiki/conf/acl.auth.php 
注释 #* @user 8
在文件结尾添加
#
# configure for mantis
* @VIEWER 1
* @REPORTER 2
* @UPDATER 4
* @DEVELOPER 8
* @MANAGER 16
* @ADMINISTRATOR 16

2.5 配置mantis单点登录(此方法适用于2013-05-10之后的版本)
参考:https://www.dokuwiki.org/plugin:authmantis

mkdir /data/wwwroot/mantis.PandaMan.com/wiki/lib/plugins/authmantis
vim /data/wwwroot/mantis.PandaMan.com/wiki/lib/plugins/authmantis/auth.php

 * Original integration guide: http://www.mantisbt.org/wiki/doku.php/mantisbt:issue:7075:integration_with_dokuwiki
 */
// must be run within Dokuwiki
if(!defined('DOKU_INC')) die();
class auth_plugin_authmantis extends DokuWiki_Auth_Plugin {
    public function __construct() {
        parent::__construct(); // for compatibility
        $this->cando['external'] = true;
        $this->cando['logoff'] = true;
        $this->success = true;
    }
    /**
     * Log off the current user
     */
    public function logOff() {
        auth_logout();
    }
    /**
     * Do all authentication
     *
     * @param   string  $user    Username
     * @param   string  $pass    Cleartext Password
     * @param   bool    $sticky  Cookie should not expire
     * @return  bool             true on successful auth
     */
    public function trustExternal($user, $pass, $sticky = false) {
        global $USERINFO;
        global $conf;
        $ValidUser = false;
        if (!function_exists('auth_prepare_username')) return true;
        // Manage HTTP authentication with Negotiate protocol enabled
        $user = auth_prepare_username($user);
        $pass = auth_prepare_password($pass);
        // This is necessary in all cases where Authorization HTTP header is always set
        if (auth_is_user_authenticated()) {
            $user = '';
        }
        // Has a user name been provided?
        if (!empty($user)) {
            // User name provided, so login via form in progress...
            // Are the specified user name and password valid?
            if (auth_attempt_login($user, $pass, $sticky)) {
                // Credential accepted...
                $_SERVER['REMOTE_USER'] = $user; // Set the user name (makes things work...)
                $ValidUser = true; // Report success.
            } else {
                // Invalid credentials
                if (!$silent) {
                    msg($this->lang ['badlogin'], -1);
                }
                $ValidUser = false;
            }
        } else {
            // No user name provided.
            // Is a user already logged in?
            if (auth_is_user_authenticated()) {
                // Yes, a user is logged in, so set the globals...
                // is it a media display or a page?
                if (isset($_REQUEST['media'])) {
                    //media
                    $t_project_name = explode(':', getNS(getID("media", false)));
                } else {
                    // normal page
                    $t_project_name = explode(':', getNS(getID()));
                }
                $t_project_id = project_get_id_by_name($t_project_name[1]);
                $t_access_level = access_get_project_level($t_project_id);
                $t_access_level_string = strtoupper(MantisEnum::getLabel(config_get('access_levels_enum_string'), $t_access_level)); // mantis 1.2.0rc
                // $t_access_level_string = strtoupper( get_enum_to_string( config_get( 'access_levels_enum_string' ),  $t_access_level ) );
                $t_access_level_string_ex = strtoupper($t_project_name[1]) . '_' . $t_access_level_string;
                $USERINFO['grps'] = array($t_access_level_string, $t_access_level_string_ex);
                $USERINFO['pass'] = current_user_get_field('password');
                $USERINFO['name'] = current_user_get_field('username');
                $USERINFO['mail'] = current_user_get_field('email');
                $_SERVER['REMOTE_USER'] = $USERINFO['name'];
                $_SESSION[$conf['title']]['auth']['user'] = $USERINFO['name'];
                $_SESSION[$conf['title']]['auth']['info'] = $USERINFO;
                $ValidUser = true;
            } else {
                $ValidUser = false;
            }
        }
        // Is there a valid user login?
        if (true != $ValidUser) {
            // No, so make sure any existing authentication is revoked.
            auth_logoff();
        }
        return $ValidUser;
    }
}
vim /data/wwwroot/mantis.PandaMan.com/wiki/lib/plugins/authmantis/plugin.info.txt 
base authmantis
author Ventzy Kunev
email v.kunev@gmail.com
date 2015-03-23
name AuthMantis plugin
desc Mantis authentication integration
url https://www.dokuwiki.org/plugin:authmantis

修改权限 authmantis 目录文件

sudo chown -R nginx:nginx /data/wwwroot/mantis.PandaMan.com/wiki/lib/plugins/authmantis/ 

2.6 增加 Mantis Syntax Plug-in

mkdir /data/wwwroot/mantis.PandaMan.com/wiki/lib/plugins/mantis
vim /data/wwwroot/mantis.PandaMan.com/wiki/lib/plugins/mantis/syntax.php 
 'Victor Boctor',
            'email'  => 'vboctor at users . sourceforge . net',
            'date'   => '2006-05-18',
            'name'   => 'Mantis Issues Plugin',
            'desc'   => 'Support References to Mantis Issues',
            'url'    => 'http://www.futureware.biz',
        );
    }
 
    /**
     * What kind of syntax are we?
     */
    function getType(){
        return 'substition';  # typo is intentional
    }
 
    /**
     * What about paragraphs?
     */
    function getPType(){
        return 'normal';
    }
 
    /**
     * Where to sort in?
     */ 
    function getSort(){
        return 156;
    }
 
 
    /**
     * Connect pattern to lexer
     */
    function connectTo($mode) {
        $this->Lexer->addSpecialPattern('~~Mantis:[0-9]+~~', $mode, 'plugin_mantis');
    }
 
 
    /**
     * Handle the match
     */
    function handle($match, $state, $pos, &$handler){
        $match = substr( $match, 9, -2 ); // strip "~~Mantis:" from start and "~~" from end
        return array( strtolower( $match ) );
    }
 
    /**
     * Create output
     */
    function render($format, &$renderer, $data) {
        if ( $format == 'xhtml' ) {
            $renderer->externallink( MANTIS_URL . 'view.php?id=' . $data[0], $data[0] );
            return true;
        }
        return false;
    }
}

修改权限

sudo chown -R nginx:nginx /data/wwwroot/mantis.PandaMan.com/wiki/lib/plugins/mantis/ 

配置完毕,实现mantis与dokuwiki单点登录,锁定wiki后台无法修改超级管理员用户组

评论

0条评论

发表评论

电子邮件地址不会被公开。 必填项已用*标注