Importare degli utenti in Mantis

From RVM Wiki
Revision as of 13:31, 6 August 2009 by Gabriele.vivinetto (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Importazione da LDAP

    #!/bin/sh

    # dump all the ldap Users and add them to the userdb
    # most config stuff (db user, etc) is taken from mantis
    # while this script works fine, it probably doesn't perform well
    # with lots of users. in my scenario i only have a couple hundred
    # users and i dont expect any problems.

    # configure the following line so it knows how to access your server
    LDAP="ldapsearch -LLL -D cn=Manager,dc=example,dc=com -wsecretpasswd "

    for LDAP_UID in `$LDAP '(&(objectClass=inetOrgPerson)(uid=*))' uid | awk '/^uid:/ {print $2}'`; do

       REALNAME=`$LDAP "(&(objectClass=inetOrgPerson)(uid=$LDAP_UID))" cn | awk -F ": " '/^cn:/ {print $2}'`
       EMAIL=`$LDAP "(&(objectClass=inetOrgPerson)(uid=$LDAP_UID))" mail | awk '/^mail:/ {print $2}'`

       MANTIS_USER_ID=`php -r 'include("/var/www/localhost/htdocs/mantisbt/config_defaults_inc.php");
          include("/var/www/localhost/htdocs/mantisbt/config_inc.php");
          include("/var/www/localhost/htdocs/mantisbt/core.php");
          echo user_get_id_by_name("'$LDAP_UID'");'`

       if [[ "$MANTIS_USER_ID" -eq "" ]]; then
          echo '<?php
             include("/var/www/localhost/htdocs/mantisbt/core/constant_inc.php");
             include("/var/www/localhost/htdocs/mantisbt/config_defaults_inc.php");
             include("/var/www/localhost/htdocs/mantisbt/config_inc.php");
             include("/var/www/localhost/htdocs/mantisbt/core.php");
             user_create("'$LDAP_UID'", "", "'$EMAIL'");
             $user_id = user_get_id_by_name("'$LDAP_UID'");
             user_set_field($user_id, "realname", "'$REALNAME'");' | php

       else
          echo '<?php
             include("/var/www/localhost/htdocs/mantisbt/core/constant_inc.php");
             include("/var/www/localhost/htdocs/mantisbt/config_defaults_inc.php");
             include("/var/www/localhost/htdocs/mantisbt/config_inc.php");
             include("/var/www/localhost/htdocs/mantisbt/core.php");
             user_set_field('$MANTIS_USER_ID', "username", "'$LDAP_UID'");
             user_set_field('$MANTIS_USER_ID', "realname", "'$REALNAME'");
             user_set_field('$MANTIS_USER_ID', "email", "'$EMAIL'");' | php
       fi
    done


Riferimenti