Wondering the best way to mass-import users

Get help from other users here.

Moderators: Contributor, Developer

mushu
Posts: 145
Joined: Jan 04, 2017 12:41 pm

Wondering the best way to mass-import users

Post by mushu » Jan 17, 2019 6:07 pm

Mantis 2.18.0
adLogin 1.01 plugin
mysql Ver 14.14 Distrib 5.7.13, for Win64 (x86_64)

Wondering the best way to do the following:

Right now we have $g_enable_email_notification = ON in config file. We have the LDAP authentication working such that people automatically get "logged in" when they go to Mantis URL. We want to pre-load the mySQL user table with all accounts in our Active Directory (about 900), but do not have access to each user's password.

Can we just turn OFF the config email notification variable then add those users to the table without setting the password field hash? Or do we need to set a default password hash in place? If so, what happens when the user goes to Mantis the first time after the account was imported into mySQL (because we use LDAP to auto-log them in)?

Finally, can we get away with only adding their info to the bugtracker.mantis_user_table table or do we have to populate the other user tables at the same time to avoid errors when they first hit our Mantis website?

*EDIT* I just found this plugin, do you think it will work as-is or will it require code changes due to age? http://litig.free.fr/MantisImportUser.php5?menu=1

cas
Posts: 483
Joined: Mar 11, 2006 11:08 am
Contact:

Re: Wondering the best way to mass-import users

Post by cas » Jan 18, 2019 5:15 am

That plugin is written for version 1.2.x so will not work on version 2.x.

When using LDAP you can setup the user without a password. The cookie_string must be filled, simply use the username which is also unique (I hope).

There is a setting within mantis called "$g_allow_signup" (which defaults to ON).
Not sure if this also works with LDAP but you can test.
If the setting is ON, the account may be created if they logon with correct credentials.

mushu
Posts: 145
Joined: Jan 04, 2017 12:41 pm

Re: Wondering the best way to mass-import users

Post by mushu » Jan 18, 2019 10:25 am

So....that means I only have to populate that one user table then?

And what about the settings on those two $g variables I mentioned, are they important? I don't want to force everyone to have to access our Mantis site in order to get a working account.

N.B. if there was a tutorial on writing plugins I might try that, but just going through and trying to figure out how the code in an existing plugin works is too difficult and takes a lot of time that I don't have, especially since I don't know the nuances of PHP. :-(

cas
Posts: 483
Joined: Mar 11, 2006 11:08 am
Contact:

Re: Wondering the best way to mass-import users

Post by cas » Jan 18, 2019 11:05 am

You still need to set the authorisations.
Did you try the setting and logging on with an AD account?

mushu
Posts: 145
Joined: Jan 04, 2017 12:41 pm

Re: Wondering the best way to mass-import users

Post by mushu » Jan 18, 2019 11:14 am

I don't understand what you mean.

We use the adLogin plugin, so that everyone who "hits" the Mantis website is automatically logged in as a Reporter without having to enter a password, and if they are not in the mySQL user table an account is created for them. I assume that Mantis grabs the user's NTLM password hash and stores that in the mySQL user table for future authentication, but not positive.

We want to pre-create every account that exists in Active Directory in the Mantis database so that ticket Monitors can be set when a ticket is emailed to us with a CC: address (using the EmailReporting plugin.)

So I can change that variable setting, sure, but then what does that do when *I* go to our Mantis website, since I already have an account? Do you mean we need to get someone who doesn't have an account to hit the website after I change that variable?

EDIT: I just looked and $g_allow_signup is set to ON already in the default config file, we do not override that setting in our custom config file.

cas
Posts: 483
Joined: Mar 11, 2006 11:08 am
Contact:

Re: Wondering the best way to mass-import users

Post by cas » Jan 18, 2019 12:37 pm

Ah, well I created that plugin so now I no exactly what you are using. When creating users upfront you do need to set a password otherwise there is a potential security risk.
In principle it is pretty easy to write a program to add users from a csv file. There is a plug-in @ mantishub but that has not been released for public☹️
Let me have a look over the weekend to pull some together😁

cas
Posts: 483
Joined: Mar 11, 2006 11:08 am
Contact:

Re: Wondering the best way to mass-import users

Post by cas » Jan 19, 2019 9:22 am

Attached a simple version to load users from a csv file, have a go at.
Have tested it on 2.15 and it runs fine.
Users will receive an email of their account activation (standard Mantis )
As always with these kind of actions, backup your database first....
Look forward to have your comments :mrgreen:
Attachments
import_user.zip
(4.19 KiB) Downloaded 20 times

mushu
Posts: 145
Joined: Jan 04, 2017 12:41 pm

Re: Wondering the best way to mass-import users

Post by mushu » Jan 22, 2019 1:19 pm

Thank you, I'll take a look!

Questions:
1. we changed the access levels and values a bit, do I use the updated values we have or the default you supplied at runtime?
2. Since we use active directory, we do not know what people's passwords are. When we add everyone to the Mantis user table, we cannot set a default password because the adLogin plugin will attempt to log them in using their existing NTLM hash and it will not match. Can we leave the password column blank and have it update when they hit the website the first time?
Last edited by mushu on Jan 22, 2019 1:37 pm, edited 1 time in total.

cas
Posts: 483
Joined: Mar 11, 2006 11:08 am
Contact:

Re: Wondering the best way to mass-import users

Post by cas » Jan 22, 2019 1:33 pm

The answers:
1. Use your own level codes
2. Just put a random password there. The adLogin will not use it. It is only needed to reduce the security risk which you would create using empty passwords in combination with this plugin.

mushu
Posts: 145
Joined: Jan 04, 2017 12:41 pm

Re: Wondering the best way to mass-import users

Post by mushu » Jan 22, 2019 6:05 pm

Please see this post: viewtopic.php?f=3&t=26097

I think this is due to hitting the [Install] button on this plugin. :-(

So I either need to add some imports to the plugin code, or I need to figure out how to manually uninstall a plugin from Mantis. Thoughts?

cas
Posts: 483
Joined: Mar 11, 2006 11:08 am
Contact:

Re: Wondering the best way to mass-import users

Post by cas » Jan 23, 2019 6:13 am

Noop, this plugin does not have this statement in. So I think you have installed another plugin that uses such event.
Please scan your plugin directory for this text.
Once found the plugin disable this in the mantis management console.
if that does not work follow the advice of SL-gundam:
Open your sql editor (eg. PHPmyAdmin)
Go to the table mantis_plugin_table
Modify "enabled" to "0" for the offending plugin

mushu
Posts: 145
Joined: Jan 04, 2017 12:41 pm

Re: Wondering the best way to mass-import users

Post by mushu » Jan 23, 2019 2:42 pm

Found it and removed via editing database table, thanks for that! Now that it is back to running, trying to install this plugin gives me the following error:

Code: Select all

SYSTEM NOTICE

'Use of undefined constant ERROR_IMPORT_FILE_FORMAT - assumed 'ERROR_IMPORT_FILE_FORMAT'' in 'C:\MantisBT2180\plugins\import_user\lang\strings_english.txt' line 15

Please use the "Back" button in your web browser to return to the previous page. There you can correct whatever problems were identified in this error or select another action. You can also click an option from the menu bar to go directly to a new section.

cas
Posts: 483
Joined: Mar 11, 2006 11:08 am
Contact:

Re: Wondering the best way to mass-import users

Post by cas » Jan 24, 2019 2:20 am

fixed that also in attached update :mrgreen:
Attachments
import_user201.zip
(4.04 KiB) Downloaded 13 times

mushu
Posts: 145
Joined: Jan 04, 2017 12:41 pm

Re: Wondering the best way to mass-import users

Post by mushu » Jan 24, 2019 11:02 am

Thanks, will take a look today and let you know.

EDIT: so, I get an error when trying to install the new version, but it is not installed and the mySQL plugins table shows a zero in the "enabled" column for it:

Code: Select all

APPLICATION WARNING #2501

Plugin "import_user" is already installed. (in 'C:\MantisBT2180\core\plugin_api.php' line 604)

Please use the "Back" button in your web browser to return to the previous page. There you can correct whatever problems were identified in this error or select another action. You can also click an option from the menu bar to go directly to a new section.
EDIT-EDIT: never mind, I went into the mySQL plugins table and deleted the row with this plugin name on it after looking at the code in the plugins_api file and saw that it looks for just the name of a plugin to decide if that plugin is installed (I wouldn't have done it that way...) It installed just fine after that. But now I get this error when going into the new plugin tab:

Code: Select all

SYSTEM NOTICE

'Undefined variable: import_file' in 'C:\MantisBT2180\plugins\import_user\pages\import_users_page.php' line 11

Please use the "Back" button in your web browser to return to the previous page. There you can correct whatever problems were identified in this error or select another action. You can also click an option from the menu bar to go directly to a new section.
Okay, so I added the variable to define it and it then let me into the setting tab now:

Code: Select all

<?php
	# Mantis - a php based bugtracking system
	require_once( 'core.php' );
	access_ensure_project_level( ADMINISTRATOR );
	layout_page_header( lang_get( 'manage_import_users' ) );
	layout_page_begin( ); 
	print_manage_menu();

	$import_file='';
?>
<br />
<form method="post" enctype="multipart/form-data" action="<?php echo plugin_page('import_users')?>">
<input type="hidden" name="import_file" value="<?php echo $import_file;  ?>">

cas
Posts: 483
Joined: Mar 11, 2006 11:08 am
Contact:

Re: Wondering the best way to mass-import users

Post by cas » Jan 24, 2019 2:38 pm

which Mantis version are you using and which OS?

Post Reply