Ejemplo n.º 1
0
void ShellProcess::run() {
//    QStringList sshArguments;
//    sshArguments << "-o" << "PasswordAuthentication=no" << "-o" << "ChallengeResponseAuthentication=no" << "-o" << "ConnectTimeout=2";
//    sshArguments << "-o" << "UserKnownHostsFile=/dev/null" << "-o" << "StrictHostKeyChecking=no" << "[email protected]" << "-i" << "/Users/qichunren/RubymineProjects/luna_scanner/lib/keys/yu_pri";
//    sshArguments << " touch /tmp/qichunren_qqqqqq";

//    int shellExitCode = QProcess::execute("ssh", sshArguments);
//    return;


        QString ip;
        foreach( ip, ipRange ){
            qDebug() << "ping " + ip;
            int exitCode;
       #ifdef Q_OS_WIN
            //启动一个ping进程,然后等待该进程结束。
//              exitCode = QProcess::execute("ping", QStringList() << ip << "-n 1" << "-i 2");
            QString strArg = "ping " + ip + " -n 1 -i 2";
            exitCode = QProcess::execute(strArg);
       #else
            exitCode = QProcess::execute("ping", QStringList() << "-c 1" << "-t 2" << ip);
       #endif

            if (0 == exitCode) {
                // it's alive
                qDebug() << "shell ping " + ip + " success";
                emit commandSuccess(ip);
            } else {
                qDebug() << "shell ping " + ip + " failed";
                emit commandFailed(ip);
            }
        }
Ejemplo n.º 2
0
void DlvClient::finishedCommandReply()
{
    m_isCommandBlock = false;
    QJsonRpcServiceReply *reply = (QJsonRpcServiceReply*)(sender());
    m_lastJsonData = reply->response().result().toVariant();
    if (reply->response().type() == QJsonRpcMessage::Error) {
        int code = reply->response().errorCode();
        QString msg = reply->response().errorMessage();
        if (msg.isEmpty()) {
            ResponseError resp;
            resp.fromMap(reply->response().toObject().toVariantMap());
            msg = resp.error;
        }
        emit commandError(code,msg);
    } else {
        CommandOut out;
        QVariant data = reply->response().result().toVariant();
        out.fromMap(data.toMap());
        emit commandSuccess(m_lastCommand.Name,out.State,data.toMap());
    }
}
Ejemplo n.º 3
0
static int proccessLineOfInput(Interface * interface) {
	int ret = 1;
	char * line = interface->buffer+interface->bufferPos;

	if(interface->bufferLength - interface->bufferPos > 1) {
		if(interface->buffer[interface->bufferLength-2] == '\r') {
			interface->buffer[interface->bufferLength-2] = '\0';
		}
	}

	if(interface->commandList) {
		if(strcmp(line, INTERFACE_LIST_MODE_END)==0) {
			DEBUG("interface %i: process command "
					"list\n",interface->num);
			ret = proccessListOfCommands(
					interface->fp,
					&(interface->permission),
					&(interface->expired),
                                        interface->commandListOK,
					interface->commandList);
			DEBUG("interface %i: process command "
					"list returned %i\n",
					interface->num,
					ret);
			if(ret==0) commandSuccess(interface->fp);
			else if(ret==COMMAND_RETURN_CLOSE || interface->expired)
			{
						
				closeInterface(interface);
			}

			printInterfaceOutBuffer(interface);
			freeList(interface->commandList);
			interface->commandList = NULL;
		}
		else {
			interface->commandListSize+= sizeof(ListNode);
			interface->commandListSize+= strlen(line)+1;
			if(interface->commandListSize > 
					interface_max_command_list_size)
			{
				ERROR("interface %i: command "
						"list size (%zu) is "
						"larger than the max "
						"(%zu)\n",
						interface->num,
						interface->
						commandListSize,
						interface_max_command_list_size)
					;
				closeInterface(interface);
			}
			else {
				insertInListWithoutKey(interface->commandList,
							strdup(line));
			}
		}
	}
	else {
		if(strcmp(line, INTERFACE_LIST_MODE_BEGIN) == 0) {
			interface->commandList = makeList(free, 1);
			interface->commandListSize = sizeof(List);
                        interface->commandListOK = 0;
			ret = 1;
		}
		else if(strcmp(line, INTERFACE_LIST_OK_MODE_BEGIN) == 0) {
			interface->commandList = makeList(free, 1);
			interface->commandListSize = sizeof(List);
                        interface->commandListOK = 1;
			ret = 1;
		}
		else {
			DEBUG("interface %i: process command \"%s\"\n",
					interface->num, line);
			ret = processCommand(interface->fp,
						&(interface->permission),
						line);
			DEBUG("interface %i: command returned %i\n",
						interface->num, ret);
			if(ret==0) commandSuccess(interface->fp);
			else if(ret==COMMAND_RETURN_CLOSE || interface->expired)
			{
				closeInterface(interface);
			}
			printInterfaceOutBuffer(interface);
		}
	}

	return ret;
}