void TreeButton::setReadyToConnect() { this->setEnabled(true); this->setText(QObject::tr("Connect")); this->getParentItem()->setText(4, QLatin1String ("0")); this->state = 0; this->getParentItem()->setText(2, QObject::tr("Ready to connect.")); this->getParentItem()->setToolTip(2, QLatin1String("")); this->getParentItemCast()->getOpenVPN()->setIsError(false); this->getParentItemCast()->getOpenVPN()->setErrorString(QLatin1String("")); QColor bg ("#FFFFFF"); // weiss this->getParentItem()->setBackgroundColor(1, bg); this->getParentItem()->setBackgroundColor(2, bg); this->getParentItem()->setBackgroundColor(3, bg); OpenVpn *obj = this->getParentItemCast()->getOpenVPN(); this->getParentItem()->setText(1, obj->getConfigName() + obj->getAdvName()); this->timer.stop(); }
void Configs::searchLinkedConfigs() { QFile linkedOvpn (AppFunc::getAppSavePath() + QLatin1String ("/configs.txt")); if (linkedOvpn.exists()) { if (!linkedOvpn.open(QIODevice::ReadOnly | QIODevice::Text)) { return; } // Offen einlesen QTextStream in (&linkedOvpn); while (!in.atEnd()) { QString line = in.readLine(); if (!this->isConfigInList(line)) { // Add to list QFile linkFileExists (line.trimmed()); if (linkFileExists.exists()) { int _id (this->id++); QString configName = line.trimmed().right(line.trimmed().size() - line.trimmed().lastIndexOf("/") - 1); configName = configName.left(configName.size()-5); OpenVpn* myObj = new OpenVpn(); myObj->setConfigStable(false); myObj->setConfigLinked(true); myObj->setConfigName(configName); myObj->setConfigPath(line.trimmed().left(line.lastIndexOf("/"))); myObj->setId(_id); // An die Liste anfügen this->myList.append(qMakePair(_id, myObj)); } } } linkedOvpn.close(); } }
bool Configs::isConfigInList(const QString &path) { // // Ist die Konfiguration bereits in der Liste // if (path.isEmpty()) { return false; } QListIterator<QPair<int, OpenVpn*> > i(this->myList); while (i.hasNext()) { QPair <int, OpenVpn*> entry = i.next(); OpenVpn *obj = entry.second; // Den Pfad kontrollieren if (path == obj->getConfigFullPath()) { return true; } } return false; }
void Configs::searchConfigs (QString sDir) { // Dateien im aktuellen Verzeichnis suchen QDir dir (sDir); //qDebug() << "searchConfigs() sDir =" << sDir; dir.setFilter(QDir::Files | QDir::AllDirs | QDir::NoSymLinks); QFileInfoList list = dir.entryInfoList(); for (int i = 0; i < list.size(); ++i) { QFileInfo fileInfo = list.at(i); //qDebug() << "searchConfigs() fileInfo.filename =" << fileInfo.fileName(); if (fileInfo.isDir()) { // Verzeichnis auf Configs durchsuchen if (fileInfo.fileName() != "." && fileInfo.fileName() != QLatin1String("..")) { this->searchConfigs(sDir + QLatin1String ("/") + fileInfo.fileName()); } } else { // Ist eine Datei, auch eine VPN Config? if (fileInfo.suffix() == QLatin1String("ovpn")){ if (!this->isConfigInList(sDir.replace("\\", "/") + QLatin1String ("/") + fileInfo.fileName())) { int _id (this->id++); //qDebug("searchConfigs() OVPN config #%d",i); //qDebug() << " found:" << fileInfo.fileName(); OpenVpn* myObj = new OpenVpn(); myObj->setConfigStable(false); myObj->setConfigLinked(false); myObj->setConfigName(fileInfo.fileName().replace(QLatin1String(".ovpn"), QLatin1String(""))); myObj->setConfigPath(sDir); myObj->setId(_id); this->myList.append(qMakePair(_id, myObj)); } } } } }
void Configs::clearConfigs() { this->refreshConnectionPath.clear(); // OD: Mutable List statt foreach QMutableListIterator<QPair<int, OpenVpn*> > i(this->myList); while (i.hasNext()) { QPair <int, OpenVpn*> entry = i.next(); OpenVpn *obj = entry.second; if (!obj->isConnectionStable() && !obj->isConnecting() && !obj->isError() && obj->getAdvName().isEmpty() && !obj->isDelayed()) { // Objekt löschen delete obj; obj = 0; // Nun aus der Liste entfernen i.remove(); } else { // Pfad merken this->refreshConnectionPath = obj->getConfigFullPath(); } } }
void SslServerConnection::slotStartRead() { // // Read the block until the complete block is avaiable // Debug::log (QLatin1String("Start reading")); this->blockSize = 0; QDataStream in(socket); in.setVersion(QDataStream::Qt_4_6); if (blockSize == 0) { if ((quint32) socket->bytesAvailable() < sizeof(qint64)) { return; } in >> blockSize; } if (socket->bytesAvailable() < blockSize) { return; } QString command(""); QString params(""); in >> command; in >> params; // // Ab hier kann man munter drauf los mit den Daten ;) // // Den Befehl auswerten if (command.isEmpty()) { // Kein Befehl keine Aktion return; } // Debug::log(QLatin1String("Command: ") + command); Debug::log(QLatin1String("Params: ") + params); // command = command.trimmed().toUpper(); if (command == QLatin1String("OPEN")) { // // Öffnet eine Verbindung // // Hat die Parameterliste die richtige Länge QStringList fields (params.split(";")); if (fields.size() == 4) { // 0: ID; 1: Config Path; 2: Interact // Ist der Eintrag schon in der Liste int configId (fields.at(0).toInt()); OpenVpn *item = this->foundItemInList(configId); Q_ASSERT(item); if (!item) { Debug::log(QLatin1String("Open: No valid item. Build new one")); } else { // Objekt ist schon in der Liste, nicht gut = Fehler this->removeItemFromList(fields.at(0).toInt()); Debug::error(QLatin1String("Open: Object is already in list. Id: ") + fields.at(0)); //SrvCLI::instance()->send(fields.at(0) + QLatin1String(";") + QLatin1String("Object is already in list."), QLatin1String("ERROR")); Debug::log(QLatin1String("Remove item from list: Id: ") + fields.at(0)); Sleep(150); } // Alls ok, wir bauen us ein neues Objekt OpenVpn *sslVpn = new OpenVpn (); // Nun die Parameter setzen QString configPath = fields.at(1).left(fields.at(1).lastIndexOf("/")); QString configName = fields.at(1).right(fields.at(1).size() - fields.at(1).lastIndexOf("/") - 1); configName = configName.left(configName.size() - 5); sslVpn->setConfigPath(configPath); sslVpn->setConfigName(configName); sslVpn->setUseInteract(fields.at(2)); sslVpn->setProxyString(fields.at(3)); sslVpn->setId(configId); QObject::connect(sslVpn, SIGNAL(foobar(int)), this, SLOT(recDig(int))); // Noch ein paar Signale binden // // Das Objekt hat sich zum löschen markiert QObject::connect(sslVpn, SIGNAL(removeItemFromList(int)), this, SLOT(removeItemFromList(int))); // // Nachrichten aus dem Objekt senden QObject::connect(sslVpn, SIGNAL(sendMessage(QString,QString)), SrvCLI::instance(), SLOT(send(QString,QString))); Debug::log(QLatin1String("Add item to list")); // Nun das Objekt an die Liste anfügen vpnList.append(qMakePair(configId, sslVpn)); // // Nun das OpenVpn verbinden Debug::log(QLatin1String("Start connection")); SrvCLI::instance()->send(QString("%2;Try to start OpenVPN connection %1").arg(configName).arg(configId), QLatin1String("LOG")); // Ohne Verzögerung den connect aufrufen sslVpn->connectToVpn(); // }