Advertisement
Guest User

Untitled

a guest
May 26th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.85 KB | None | 0 0
  1.     /**
  2.     * addusers.cpp
  3.     * Written by Maxime Joanis
  4.     * (phpBB support forum user MaxJ84)
  5.     * 2008/10/21
  6.     *
  7.     * This program takes a list of user names (in a text file, one by row) and
  8.     * returns a file with automatically generated passwords for each user and a
  9.     * file addusers.php which can be placed in the root directory of a phpBB 3.x
  10.     * forum installation to add the users all at once to that forum.
  11.     *
  12.     * You can use and modify this program according to your needs. Giving credits
  13.     * for the original work is always appreciated!
  14.     **/
  15.  
  16.     #include <iostream>
  17.     #include <fstream>
  18.     #include <ctime>
  19.     #include <vector>
  20.     #include <string>
  21.     #include <iomanip>
  22.  
  23.     using namespace std;
  24.  
  25.     int main() {
  26.        // Defining constants.
  27.        const short PWD_LENGTH = 8;
  28.        const short FILENAMESIZE = 30;
  29.        const char passwordCharSet[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456798";
  30.  
  31.        // Declaring variables...
  32.        unsigned int userIndex = 0;
  33.        string user, tempString;
  34.        vector<string> users;
  35.        char password[PWD_LENGTH + 1], filename[FILENAMESIZE];
  36.        ifstream fUserList;
  37.        ofstream fUserPwdList("UsersPwds.txt");
  38.        ofstream fAddUsersPhp("addusers.php");
  39.        ofstream fMessages("messages.txt");
  40.  
  41.        // Defaults.
  42.        short groupId = 2, timeZone = -5, dst = 1;
  43.        string lang = "en";
  44.  
  45.        // Opening user list file.
  46.        cout << "File containing the user list: ";
  47.        cin >> setw(FILENAMESIZE) >> filename;
  48.        fUserList.open(filename);
  49.        if (!fUserList) {
  50.           cout << "Error: file not found!\n";
  51.           return 1;
  52.        }
  53.  
  54.        // Reading user list file.
  55.        while (fUserList >> user) {
  56.           users.push_back(user);
  57.           userIndex++;
  58.        }
  59.        cout << userIndex << " users found.\n";
  60.  
  61.        // Overriding defaults if needed.
  62.        cout << "You can override some default values here...\n";
  63.        cout << "Enter the group ID for these users [" << groupId << "]: ";
  64.        cin.ignore();
  65.        getline(cin, tempString);
  66.        if (tempString != "")
  67.           groupId = atoi(tempString.c_str());
  68.        cout << "Enter the time zone for these users [" << timeZone << "]: ";
  69.        getline(cin, tempString);
  70.        if (tempString != "")
  71.           timeZone = atoi(tempString.c_str());
  72.        cout << "Use DST? (0 for false) [" << dst << "]: ";
  73.        getline(cin, tempString);
  74.        if (tempString != "")
  75.           dst = atoi(tempString.c_str());
  76.        cout << "Enter the language code for these users [" << lang << "]: ";
  77.        getline(cin, tempString);
  78.        if (tempString != "")
  79.           lang = tempString;
  80.  
  81.        // Generate pseudo-random seed.
  82.        srand((int)time(0));
  83.  
  84.        // Generating output files.
  85.        cout << "Generating files...\n";
  86.        fAddUsersPhp << "<?php\ndefine(\'IN_PHPBB\', true);\n$phpbb_root_path = (d"
  87.           << "efined(\'PHPBB_ROOT_PATH\')) ? PHPBB_ROOT_PATH : \'./\';\n$phpEx ="
  88.           << " substr(strrchr(__FILE__, \'.\'), 1);\ninclude($phpbb_root_path . "
  89.           << "\'common.\' . $phpEx);\ninclude($phpbb_root_path . \'includes/func"
  90.           << "tions_user.\' . $phpEx);\n\n";
  91.        for (userIndex = 0;userIndex < users.size();userIndex++) {
  92.           for (int i = 0;i < PWD_LENGTH;i++) {
  93.              password[i] = passwordCharSet[rand() % (sizeof(passwordCharSet) - 1)];
  94.           }
  95.           password[PWD_LENGTH] = '\0';
  96.           fUserPwdList << users[userIndex] << "\t" << password << endl;
  97.           fAddUsersPhp << "$user_row = array(" << endl
  98.              << "\t\'username\'\t\t\t=> \"" << users[userIndex] << "\",\n"
  99.              << "\t\'user_password\'\t\t\t=> phpbb_hash(\"" << password << "\"),\n"
  100.              << "\t\'user_email\'\t\t\t=> \"\",\n"
  101.              << "\t\'group_id\'\t\t\t=> " << groupId << ",\n"
  102.              << "\t\'user_timezone\'\t\t\t=> " << timeZone << ",\n"
  103.              << "\t\'user_dst\'\t\t\t=> " << dst << ",\n"
  104.              << "\t\'user_lang\'\t\t\t=> \"" << lang << "\",\n"
  105.              << "\t\'user_type\'\t\t\t=> 0,\n"
  106.              << "\t\'user_actkey\'\t\t\t=> \"\",\n"
  107.              << "\t\'user_ip\'\t\t\t=> \"\",\n"
  108.              << "\t\'user_regdate\'\t\t\t=> time(),\n"
  109.              << "\t\'user_inactive_reason\'\t\t=> 0,\n"
  110.              << "\t\'user_inactive_time\'\t\t=> 0,\n);\n"
  111.              << "user_add($user_row, $cp_data);\n\n";
  112.           fMessages << "Here are your informations for the forum login:\n";
  113.           fMessages << "Username: " << users[userIndex] << "    Password: " << password << "\n\n";
  114.        }
  115.        fAddUsersPhp << "?>";
  116.        cout << "Done.\n\n";
  117.        cout << "Done.\n\n";
  118.  
  119.        // Closing files.
  120.        fUserList.close();
  121.        fUserPwdList.close();
  122.        fAddUsersPhp.close();
  123.        fMessages.close();
  124.        return 0;
  125.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement