예제 #1
0
/**
 * @fn setWorkDirectory
 */
void QueuedProcess::setWorkDirectory(const QString &_workDirectory)
{
    qCDebug(LOG_LIB) << "Set working directory to" << _workDirectory;

    m_definitions.workingDirectory
        = _workDirectory.isEmpty()
              ? QStandardPaths::writableLocation(QStandardPaths::StandardLocation::TempLocation)
              : _workDirectory;
    setLogError("");
    setLogOutput("");
    setWorkingDirectory(m_definitions.workingDirectory);
}
예제 #2
0
bool CFileNode::start()
{
    QVariant filename = getConfig().getParameter("file")->value;

    // Check if the user supplied file exists before we start processing.
    QFile file(filename.toString());
    if(!file.exists()) {
        qCritical() << "File" << filename.toString() << "does not exist.";
        QString error = "File " + filename.toString() + " does not exist.";
        setLogError(error);
        return false;
    }

    return true;
}
bool CMawiLabelsNode::parseMawiXml(const QByteArray &bytes,
                                   QSharedPointer<CTableData> &table_data)
{
    QXmlStreamReader xml(bytes);
    qint32 number = -1;          // The anomaly number (index)
    QString type;                // Either 'anomalous' or 'suspicious'
    QString value;
    double from = -1.0;          // Starting time of the anomaly
    double to = -1.0;            // End time of the anomaly
    QList<QList<QString>> flows; // The flows involved in one anomaly
    QString src_ip;
    QString src_port;
    QString dst_ip;
    QString dst_port;

    while(!xml.atEnd()) {
        xml.readNext();
        if(xml.isStartElement()) {
            if(xml.name() == "anomaly") {
                // Set the initial attributes of the 'anomaly'.
                number++;
                type = xml.attributes().value("type").toString();
                value = xml.attributes().value("value").toString();
                from = -1.0;
                to = -1.0;
                flows.clear();
                // Read all the contents inside the 'anomaly' tag.
                while(!xml.atEnd()) {
                    xml.readNext();
                    // The start of an element.
                    if(xml.isStartElement()) {
                        if(xml.name() == "from") {
                            from = xml.attributes().value("sec").toDouble() +
                                    (xml.attributes().value("usec").toDouble() * 0.000001);
                        }
                        else if(xml.name() == "to") {
                            to = xml.attributes().value("sec").toDouble() +
                                    (xml.attributes().value("usec").toDouble() * 0.000001);
                        }
                        else if(xml.name() == "filter") {
                            // src_ip, src_port, dst_ip, dst_port
                            QList<QString> flow = {"", "", "", ""};
                            flow[0] = xml.attributes().value("src_ip").toString();
                            flow[1] = xml.attributes().value("src_port").toString();
                            flow[2] = xml.attributes().value("dst_ip").toString();
                            flow[3] = xml.attributes().value("dst_port").toString();
                            flows.append(flow);
                        }
                    }
                    // The end of an element.
                    else if(xml.isEndElement()) {
                        if(xml.name() == "anomaly") {
                            // All values within one anomaly tag parsed. Create the
                            // ... table rows for each flow.
                            for(QList<QString> &flow : flows) {
                                // Create a new row in the table of anomalies.
                                QList<QVariant> &row = table_data->newRow();
                                row.append(number);
                                row.append(type);
                                row.append(value);
                                row.append(from);
                                row.append(to);
                                row.append(flow[0]);
                                row.append(flow[1]);
                                row.append(flow[2]);
                                row.append(flow[3]);
                            }
                            // Break out of reading the anomaly tag.
                            break;
                        }
                    }
                }
            }
        }
    }
    if(xml.hasError()) {
        QString error = "Errors found while parsing MAWI XML labels.";
        qCritical() << error;
        setLogError(error);
        // Return stating that there was an error.
        return false;
    }

    // No errors, exit with a true status.
    return true;
}