Exemple #1
0
ActionReply Helper::defaults(QVariantMap args)
{
    Q_UNUSED(args)
//Disable security
    QString filePath(QString(GRUB_CONFIGDIR)+QString(GRUB_SECURITY));
    QFile::Permissions permissions = QFile::permissions(filePath);
    permissions &= ~(QFile::ExeOwner | QFile::ExeUser | QFile::ExeGroup | QFile::ExeOther);
    QFile::setPermissions(filePath, permissions);
    
    ActionReply reply;
    QString configFileName = GRUB_CONFIG;
    QString originalConfigFileName = configFileName + ".original";
        
    if (!QFile::exists(originalConfigFileName)) {
        reply = ActionReply::HelperErrorReply();
        reply.addData("errorDescription", i18nc("@info", "Original configuration file <filename>%1</filename> does not exist.", originalConfigFileName));
        return reply;
    }
    if (!QFile::remove(configFileName)) {
        reply = ActionReply::HelperErrorReply();
        reply.addData("errorDescription", i18nc("@info", "Cannot remove current configuration file <filename>%1</filename>.", configFileName));
        return reply;
    }
    if (!QFile::copy(originalConfigFileName, configFileName)) {
        reply = ActionReply::HelperErrorReply();
        reply.addData("errorDescription", i18nc("@info", "Cannot copy original configuration file <filename>%1</filename> to <filename>%2</filename>.", originalConfigFileName, configFileName));
        return reply;
    }
    return reply;
}
Exemple #2
0
ActionReply SambaHelper::mount(QVariantMap args)
{
    QString ip = args["ip"].toString();
    QString uid = args["uid"].toString();
    QString sambaDir = args["sambaDir"].toByteArray();
    QString mountPoint = args["mountPoint"].toByteArray();
    QString locale = args["locale"].toString();
    QString path = args["path"].toString();
    QString username = args["username"].toString();
    QString password = args["password"].toString();

    setenv("LANG", locale.toLocal8Bit(), 1);
    setenv("PATH", path.toLocal8Bit(), 1);
    setlocale(LC_CTYPE, locale.toLocal8Bit());

    QProcess proc;
    proc.start("samba-realmounter", {ip, sambaDir, mountPoint, uid, username, password });
    proc.waitForFinished();

    ActionReply reply;
    reply.addData("output", proc.readAllStandardOutput());
    reply.addData("error", proc.readAllStandardError());
    reply.addData("exitCode", proc.exitCode());

    return reply;
}
Exemple #3
0
ActionReply Helper::install(QVariantMap args)
{
    ActionReply reply;
    QString partition = args.value("partition").toString();
    QString mountPoint = args.value("mountPoint").toString();
    bool mbrInstall = args.value("mbrInstall").toBool();

    if (mountPoint.isEmpty()) {
        for (int i = 0; QDir(mountPoint = QString("%1/kcm-grub2-%2").arg(QDir::tempPath(), QString::number(i))).exists(); i++);
        if (!QDir().mkpath(mountPoint)) {
            reply = ActionReply::HelperErrorReply();
            reply.addData("errorDescription", i18nc("@info", "Failed to create temporary mount point."));
            return reply;
        }
        ActionReply mountReply = executeCommand(QStringList() << "mount" << partition << mountPoint);
        if (mountReply.failed()) {
            return mountReply;
        }
    }

    QStringList grub_installCommand;
    grub_installCommand << GRUB_INSTALL_EXE << "--root-directory" << mountPoint;
    if (mbrInstall) {
        grub_installCommand << partition.remove(QRegExp("\\d+"));
    } else {
        grub_installCommand << "--force" << partition;
    }
    return executeCommand(grub_installCommand);
}
ActionReply WritableFilesystemHelper::detect(const QVariantMap &args)
{
    Q_UNUSED(args)

    ActionReply reply = ActionReply::SuccessReply();
    reply.addData("writable", QFile::exists("/userdata/.writable_image"));

    return reply;
}
Exemple #5
0
ActionReply Helper::executeCommand(const QStringList &command)
{
    KProcess process;
    process.setProgram(command);
    process.setOutputChannelMode(KProcess::MergedChannels);

    qDebug() << "Executing" << command.join(" ");
    int exitCode = process.execute();

    ActionReply reply;
    if (exitCode != 0) {
        reply = ActionReply::HelperErrorReply();
        //TO BE FIXED
        reply.setErrorCode(ActionReply::Error::InvalidActionError);
    }
    reply.addData("command", command);
    reply.addData("output", process.readAll());
    return reply;
}
Exemple #6
0
ActionReply Helper::save(const QVariantMap& args)
{
  ActionReply reply;
  QVariantMap files = args["files"].toMap();
  
  for(QVariantMap::const_iterator iter = files.begin(); iter != files.end(); ++iter)
  {
    QString contents = iter.value().toString();
    QFile file(args["etcDir"].toString() + "/" + iter.key());
    if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
      reply = ActionReply::HelperErrorReply();
      reply.addData("errorDescription", file.errorString());
      // reply.setErrorCode(file.error());
      reply.addData("filename", iter.key());
      return reply;
    }
    QTextStream stream(&file);
    stream << contents;
    file.close();
  }
  
  // return a reply
  return reply;
}
Exemple #7
0
ActionReply Helper::probe(QVariantMap args)
{
    ActionReply reply;
    QStringList mountPoints = args.value("mountPoints").toStringList();

    QStringList grubPartitions;
    HelperSupport::progressStep(0);
    for (int i = 0; i < mountPoints.size(); i++) {
        ActionReply grub_probeReply = executeCommand(QStringList() << GRUB_PROBE_EXE << "-t" << "drive" << mountPoints.at(i));
        if (grub_probeReply.failed()) {
            return grub_probeReply;
        }
        grubPartitions.append(grub_probeReply.data().value("output").toString().trimmed());
        HelperSupport::progressStep((i + 1) * 100. / mountPoints.size());
    }

    reply.addData("grubPartitions", grubPartitions);
    return reply;
}
Exemple #8
0
ActionReply MyHelper::read(QVariantMap args)
{
    ActionReply reply;
    QString filename = args["filename"].toString();
    QFile file(filename);
    if (!file.open(QIODevice::ReadOnly)) {
        reply = ActionReply::HelperErrorReply;
        reply.setErrorCode(file.error());

        return reply;
    }

    QTextStream stream(&file);
    QString contents;
    contents = stream.readAll();
    reply.addData("contents", contents);

    return reply;
}
Exemple #9
0
ActionReply Helper::load(QVariantMap args)
{
    ActionReply reply;
    QString fileName;
    switch (args.value("grubFile").toInt()) {
    case GrubMenuFile:
        fileName = GRUB_MENU;
        break;
    case GrubConfigurationFile:
        fileName = GRUB_CONFIG;
        break;
    case GrubEnvironmentFile:
        fileName = GRUB_ENV;
        break;
//Security
    case GrubGroupFile:
        fileName = GRUB_CONFIGDIR + args.value("groupFile").toString();
        if (args.value("groupFile").toString() == GRUB_SECURITY) {
            if (!QFile::exists(fileName)) 
                executeCommand(QStringList() << "touch" << fileName);
            bool security = QFile::exists(fileName);
            reply.addData("security", security);
            reply.addData("securityOn", (bool)(QFile::permissions(fileName) & (QFile::ExeOwner | QFile::ExeGroup | QFile::ExeOther)));
            if (!security)
                qDebug() << "Unable to create" << fileName << ", please check file permissions.";
        }
        break;
    case GrubMemtestFile:
        bool memtest = QFile::exists(GRUB_MEMTEST);
        reply.addData("memtest", memtest);
        if (memtest) {
            reply.addData("memtestOn", (bool)(QFile::permissions(GRUB_MEMTEST) & (QFile::ExeOwner | QFile::ExeGroup | QFile::ExeOther)));
        }
        return reply;
    }
    
    QFile file(fileName);
    if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
        reply = ActionReply::HelperErrorReply();
        reply.addData("errorDescription", file.errorString());
        return reply;
    }
    reply.addData("rawFileContents", file.readAll());
    return reply;
}
Exemple #10
0
ActionReply Helper::probevbe(QVariantMap args)
{
    Q_UNUSED(args)
    ActionReply reply;

#if HAVE_HD
    QStringList gfxmodes;
    hd_data_t hd_data;
    memset(&hd_data, 0, sizeof(hd_data));
    hd_t *hd = hd_list(&hd_data, hw_framebuffer, 1, NULL);
    for (hd_res_t *res = hd->res; res; res = res->next) {
        if (res->any.type == res_framebuffer) {
            gfxmodes += QString("%1x%2x%3").arg(QString::number(res->framebuffer.width), QString::number(res->framebuffer.height), QString::number(res->framebuffer.colorbits));
        }
    }
    hd_free_hd_list(hd);
    hd_free_hd_data(&hd_data);
    reply.addData("gfxmodes", gfxmodes);
#else
    reply = ActionReply::HelperErrorReply();
#endif

    return reply;
}
Exemple #11
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;
}