Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * addusers.cpp
- * Written by Maxime Joanis
- * (phpBB support forum user MaxJ84)
- * 2008/10/21
- *
- * This program takes a list of user names (in a text file, one by row) and
- * returns a file with automatically generated passwords for each user and a
- * file addusers.php which can be placed in the root directory of a phpBB 3.x
- * forum installation to add the users all at once to that forum.
- *
- * You can use and modify this program according to your needs. Giving credits
- * for the original work is always appreciated!
- **/
- #include <iostream>
- #include <fstream>
- #include <ctime>
- #include <vector>
- #include <string>
- #include <iomanip>
- using namespace std;
- int main() {
- // Defining constants.
- const short PWD_LENGTH = 8;
- const short FILENAMESIZE = 30;
- const char passwordCharSet[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456798";
- // Declaring variables...
- unsigned int userIndex = 0;
- string user, tempString;
- vector<string> users;
- char password[PWD_LENGTH + 1], filename[FILENAMESIZE];
- ifstream fUserList;
- ofstream fUserPwdList("UsersPwds.txt");
- ofstream fAddUsersPhp("addusers.php");
- ofstream fMessages("messages.txt");
- // Defaults.
- short groupId = 2, timeZone = -5, dst = 1;
- string lang = "en";
- // Opening user list file.
- cout << "File containing the user list: ";
- cin >> setw(FILENAMESIZE) >> filename;
- fUserList.open(filename);
- if (!fUserList) {
- cout << "Error: file not found!\n";
- return 1;
- }
- // Reading user list file.
- while (fUserList >> user) {
- users.push_back(user);
- userIndex++;
- }
- cout << userIndex << " users found.\n";
- // Overriding defaults if needed.
- cout << "You can override some default values here...\n";
- cout << "Enter the group ID for these users [" << groupId << "]: ";
- cin.ignore();
- getline(cin, tempString);
- if (tempString != "")
- groupId = atoi(tempString.c_str());
- cout << "Enter the time zone for these users [" << timeZone << "]: ";
- getline(cin, tempString);
- if (tempString != "")
- timeZone = atoi(tempString.c_str());
- cout << "Use DST? (0 for false) [" << dst << "]: ";
- getline(cin, tempString);
- if (tempString != "")
- dst = atoi(tempString.c_str());
- cout << "Enter the language code for these users [" << lang << "]: ";
- getline(cin, tempString);
- if (tempString != "")
- lang = tempString;
- // Generate pseudo-random seed.
- srand((int)time(0));
- // Generating output files.
- cout << "Generating files...\n";
- fAddUsersPhp << "<?php\ndefine(\'IN_PHPBB\', true);\n$phpbb_root_path = (d"
- << "efined(\'PHPBB_ROOT_PATH\')) ? PHPBB_ROOT_PATH : \'./\';\n$phpEx ="
- << " substr(strrchr(__FILE__, \'.\'), 1);\ninclude($phpbb_root_path . "
- << "\'common.\' . $phpEx);\ninclude($phpbb_root_path . \'includes/func"
- << "tions_user.\' . $phpEx);\n\n";
- for (userIndex = 0;userIndex < users.size();userIndex++) {
- for (int i = 0;i < PWD_LENGTH;i++) {
- password[i] = passwordCharSet[rand() % (sizeof(passwordCharSet) - 1)];
- }
- password[PWD_LENGTH] = '\0';
- fUserPwdList << users[userIndex] << "\t" << password << endl;
- fAddUsersPhp << "$user_row = array(" << endl
- << "\t\'username\'\t\t\t=> \"" << users[userIndex] << "\",\n"
- << "\t\'user_password\'\t\t\t=> phpbb_hash(\"" << password << "\"),\n"
- << "\t\'user_email\'\t\t\t=> \"\",\n"
- << "\t\'group_id\'\t\t\t=> " << groupId << ",\n"
- << "\t\'user_timezone\'\t\t\t=> " << timeZone << ",\n"
- << "\t\'user_dst\'\t\t\t=> " << dst << ",\n"
- << "\t\'user_lang\'\t\t\t=> \"" << lang << "\",\n"
- << "\t\'user_type\'\t\t\t=> 0,\n"
- << "\t\'user_actkey\'\t\t\t=> \"\",\n"
- << "\t\'user_ip\'\t\t\t=> \"\",\n"
- << "\t\'user_regdate\'\t\t\t=> time(),\n"
- << "\t\'user_inactive_reason\'\t\t=> 0,\n"
- << "\t\'user_inactive_time\'\t\t=> 0,\n);\n"
- << "user_add($user_row, $cp_data);\n\n";
- fMessages << "Here are your informations for the forum login:\n";
- fMessages << "Username: " << users[userIndex] << " Password: " << password << "\n\n";
- }
- fAddUsersPhp << "?>";
- cout << "Done.\n\n";
- cout << "Done.\n\n";
- // Closing files.
- fUserList.close();
- fUserPwdList.close();
- fAddUsersPhp.close();
- fMessages.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement