Beispiel #1
0
int WUserManager::FindUser(std::string searchString) {
#ifndef NOT_BBS
    // TODO(rushfan): Put back in a binary search, but test with user.lst the size of frank's.
    const size_t user_count = application()->GetStatusManager()->GetUserCount();
    for (std::size_t i = 0; i < user_count; i++) {
        if (wwiv::strings::IsEqualsIgnoreCase(searchString.c_str(), (const char*)smallist[i].name)) {
            return smallist[i].number;
        }
    }
#else
    std::unique_ptr<File> usersFile(new File(m_dataDirectory, USER_LST));
    usersFile->Open(File::modeBinary | File::modeReadOnly);
    smalrec userRec;
    if (usersFile->IsOpen()) {
        bool done = false;
        while (!done) {
            int bytesRead = usersFile->Read(&userRec, sizeof(smalrec));
            if (bytesRead != sizeof(smalrec)) {
                done = true;
            } else if (!wwiv::strings::StringCompareIgnoreCase(searchString.c_str(), (const char *)userRec.name)) {
                return (userRec.number);
            }
        }
    }
#endif // NOT_BBS
    return 0;
}
QString MessageManager::handleLogin(QString username)
{
    bool userExists = false;

    //Read through the user database and check whether the user exists
    QFile usersFile(USERS_DATABASE_FILE);
    if(!usersFile.open(QIODevice::ReadOnly)) {
        qDebug() << "error" << usersFile.errorString();
    }

    QTextStream usersFileIn(&usersFile);

    QString line;
    while(!usersFileIn.atEnd()) {
        line = usersFileIn.readLine();
        QStringList userFields = line.split(PIPE_DELIMETER);
        QString lineUName = QString::fromLocal8Bit(userFields.at(1).toLocal8Bit());
        if(lineUName == username){
            userExists = true;
            break;
        }
    }
    usersFile.close();

    //User found return the full user info
    if(userExists){
        line.prepend(VALID_USER_HEADER);
        return line;
    }
    //Invalid User
    else{
        QString noUserMessage = INVALID_USER_HEADER;
        return noUserMessage;
    }
}
void EducationSystemDataModel::flushToFiles()
{
    // =======================================
    //       Writing users to file
    // =======================================
    ofstream usersFile(USERS_FILE);
    list<UserModel>::iterator userItem;
    for(userItem = users.begin(); userItem != users.end(); userItem++){
        UserModel user = *userItem;
        usersFile << UserModel::serialize(user, FIELD_DELIM) << endl;
    }
    usersFile.flush();
    usersFile.close();

    // =======================================
    //       Writing courses to file
    // =======================================
    ofstream coursesFile(COURSES_FILE);
    list<CourseModel>::iterator courseItem;
    for(courseItem = courses.begin(); courseItem != courses.end(); courseItem++){
        CourseModel course = *courseItem;
        coursesFile << CourseModel::serialize(course, FIELD_DELIM) << endl;
    }
    coursesFile.flush();
    coursesFile.close();

    // =======================================
    //       Writing takes to file
    // =======================================
    ofstream takesFile(TAKES_FILE);
    list<TakeModel>::iterator takeItem;
    for(takeItem = takes.begin(); takeItem != takes.end(); takeItem++){
        TakeModel take = *takeItem;
        takesFile << TakeModel::serialize(take, FIELD_DELIM) << endl;
    }
    takesFile.flush();
    takesFile.close();
}
Beispiel #4
0
ActionReply Helper::save(QVariantMap args)
{
    ActionReply reply;
    QString configFileName = GRUB_CONFIG;
    QByteArray rawConfigFileContents = args.value("rawConfigFileContents").toByteArray();
    QByteArray rawDefaultEntry = args.value("rawDefaultEntry").toByteArray();
    bool memtest = args.value("memtest").toBool();
    bool security = args.value("security").toBool();

    QFile::copy(configFileName, configFileName + ".original");

    QFile file(configFileName);
    if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
        reply = ActionReply::HelperErrorReply();
        reply.addData("errorDescription", file.errorString());
        return reply;
    }
    file.write(rawConfigFileContents);
    file.close();

    if (args.contains("memtest")) {
        QFile::Permissions permissions = QFile::permissions(GRUB_MEMTEST);
        if (memtest) {
            permissions |= (QFile::ExeOwner | QFile::ExeUser | QFile::ExeGroup | QFile::ExeOther);
        } else {
            permissions &= ~(QFile::ExeOwner | QFile::ExeUser | QFile::ExeGroup | QFile::ExeOther);
        }
        QFile::setPermissions(GRUB_MEMTEST, permissions);
    }
    
    if (args.contains("security")) {
        QString filePath(QString(GRUB_CONFIGDIR)+QString(GRUB_SECURITY));
        QFile::Permissions permissions = QFile::permissions(filePath);
        if (security) {
            permissions |= (QFile::ExeOwner | QFile::ExeUser | QFile::ExeGroup | QFile::ExeOther);
        } else {
            permissions &= ~(QFile::ExeOwner | QFile::ExeUser | QFile::ExeGroup | QFile::ExeOther);
        }
        QFile::setPermissions(filePath, permissions);
    }
    
    if (args.contains("securityUsers")) {
        QByteArray rawUsersFileContents = args.value("securityUsers").toByteArray();
        //qDebug() << rawUsersFileContents;
        QFile usersFile(QString(GRUB_CONFIGDIR)+QString(GRUB_SECURITY));
        usersFile.open(QIODevice::WriteOnly | QIODevice::Text);
        usersFile.write(rawUsersFileContents);
        usersFile.close();
        
    }
    
    if (args.contains("securityGroupsList")) {
        QStringList groupFilesList = args.value("securityGroupsList").toString().split("/");
        for ( int i=0; i<groupFilesList.count(); ++i ) {
            QByteArray rawGroupFileContent = args.value(QString("GroupContent_")+groupFilesList[i]).toByteArray();
            //qDebug() << groupFilesList[i] << rawGroupFileContent;
            QFile groupFile(QString(GRUB_CONFIGDIR)+groupFilesList[i]);
            groupFile.open(QIODevice::WriteOnly | QIODevice::Text);
            groupFile.write(rawGroupFileContent);
            groupFile.close();
        }
        //qDebug() << "Groups modified :" << groupFilesList;
    }
    
    ActionReply grub_mkconfigReply = executeCommand(QStringList() << GRUB_MKCONFIG_EXE << "-o" << GRUB_MENU);
    if (grub_mkconfigReply.failed()) {
        return grub_mkconfigReply;
    }

    ActionReply grub_set_defaultReply = executeCommand(QStringList() << GRUB_SET_DEFAULT_EXE << rawDefaultEntry);
    if (grub_set_defaultReply.failed()) {
        return grub_set_defaultReply;
    }

    return grub_mkconfigReply;
}
void EducationSystemDataModel::loadFromFiles()
{
    // =======================================
    //       Reading users from file
    // =======================================
    ifstream usersFile(USERS_FILE);
    string userItem;
    while(getline(usersFile, userItem)){
        vector<string> fields = Utils::split(userItem, FIELD_DELIM);

        // User ID
        int id = stoi(fields[0]);
        // Password
        string password = fields[1];
        // First Name
        string firstName = fields[2];
        // Last Name
        string lastName = fields[3];
        // status (type of user)
        int status = stoi(fields[4]);

        // Add to list
        users.push_back(UserModel(id, password, firstName, lastName, status));
    }
    usersFile.close();

    // =======================================
    //       Reading courses from file
    // =======================================
    ifstream coursesFile(COURSES_FILE);
    string courseItem;
    while(getline(coursesFile, courseItem)){
        vector<string> fields = Utils::split(courseItem, FIELD_DELIM);

        // Course ID
        int id = stoi(fields[0]);
        // Name
        string name = fields[1];
        // Instructor ID
        int instructorId = stoi(fields[2]);

        // Add to list
        courses.push_back(CourseModel(id, name, instructorId));
    }
    coursesFile.close();

    // =======================================
    //       Reading takes from file
    // =======================================
    ifstream takesFile(TAKES_FILE);
    string takeItem;
    while(getline(takesFile, takeItem)){
        vector<string> fields = Utils::split(takeItem, FIELD_DELIM);

        // Course ID
        int courseId = stoi(fields[0]);
        // Instructor ID
        int instructorId = stoi(fields[1]);
        // Student ID
        int studentId = stoi(fields[2]);
        // Grade
        float grade = stof(fields[3]);

        // Add to list
        takes.push_back(TakeModel(courseId, instructorId, studentId, grade));
    }
    takesFile.close();
}
QString MessageManager::handleDataRequest(QTcpSocket *socket)
{
    QByteArray returnData;

    //Patient Info
    QFile patientsFile(PATIENTS_DATABASE_FILE);
    if(!patientsFile.open(QIODevice::ReadOnly)) {
        qDebug() << "error" << patientsFile.errorString();
    }

    QTextStream patientsFileIn(&patientsFile);

    QString line;
    while(!patientsFileIn.atEnd()) {
        line = patientsFileIn.readLine();
        line.prepend(PATIENT_HEADER);
        returnData.append(line);
        returnData.append(TILDA_DELIMETER);
    }
    returnData.chop(1);
    returnData.append("::");

    patientsFile.close();

    //Consultation Info
    QFile consultsFile(CONSULTATIONS_DATABASE_FILE);
    if(!consultsFile.open(QIODevice::ReadOnly)) {
        qDebug() << "error" << consultsFile.errorString();
    }

    QTextStream consultsFileIn(&consultsFile);

    QString line2;
    while(!consultsFileIn.atEnd()) {
        line2 = consultsFileIn.readLine();
        line2.prepend(CONSULTATION_HEADER);
        returnData.append(line2);
        returnData.append(TILDA_DELIMETER);
    }
    returnData.chop(1);
    returnData.append("::");

    consultsFile.close();

    //FollowUp Info
    QFile followUpsFile(FOLLOWUPS_DATABASE_FILE);
    if(!followUpsFile.open(QIODevice::ReadOnly)) {
        qDebug() << "error" << followUpsFile.errorString();
    }

    QTextStream followUpsFileIn(&followUpsFile);

    QString line3;
    while(!followUpsFileIn.atEnd()) {
        line3 = followUpsFileIn.readLine();
        line3.prepend(FOLLOWUP_HEADER);
        returnData.append(line3);
        returnData.append(TILDA_DELIMETER);
    }
    returnData.chop(1);
    returnData.append("::");
    followUpsFile.close();

    //Physician Info
    QFile usersFile(USERS_DATABASE_FILE);
    if(!usersFile.open(QIODevice::ReadOnly)) {
        qDebug() << "error" << usersFile.errorString();
    }

    QTextStream usersFileIn(&usersFile);

    QString line4;
    while(!usersFileIn.atEnd()) {
        line4 = usersFileIn.readLine();
        QStringList lineSplit = line4.split(PIPE_DELIMETER);
        if(QString::fromLocal8Bit(lineSplit.at(4).toLocal8Bit()) == "Physician"){
            line4.prepend(PHYSICIAN_HEADER);
            returnData.append(line4);
            returnData.append(TILDA_DELIMETER);
        }
    }
    returnData.chop(1);
    usersFile.close();

    socket->write(returnData);

    return DATA_RETRIEVAL_SUCCESS;
}