コード例 #1
0
ファイル: listsockets.cpp プロジェクト: sctigercat1/znc
    bool OnWebRequest(CWebSock& WebSock, const CString& sPageName,
                      CTemplate& Tmpl) override {
        if (sPageName == "index") {
            if (CZNC::Get().GetManager().empty()) {
                return false;
            }

            std::priority_queue<CSocketSorter> socks = GetSockets();

            while (!socks.empty()) {
                Csock* pSocket = socks.top().GetSock();
                socks.pop();

                CTemplate& Row = Tmpl.AddRow("SocketsLoop");
                Row["Name"] = pSocket->GetSockName();
                Row["Created"] = GetCreatedTime(pSocket);
                Row["State"] = GetSocketState(pSocket);
                Row["SSL"] = pSocket->GetSSL() ? "Yes" : "No";
                Row["Local"] = GetLocalHost(pSocket, true);
                Row["Remote"] = GetRemoteHost(pSocket, true);
                Row["In"] = CString::ToByteStr(pSocket->GetBytesRead());
                Row["Out"] = CString::ToByteStr(pSocket->GetBytesWritten());
            }

            return true;
        }

        return false;
    }
コード例 #2
0
ファイル: listsockets.cpp プロジェクト: sctigercat1/znc
    void ShowSocks(bool bShowHosts) {
        if (CZNC::Get().GetManager().empty()) {
            PutStatus("You have no open sockets.");
            return;
        }

        std::priority_queue<CSocketSorter> socks = GetSockets();

        CTable Table;
        Table.AddColumn("Name");
        Table.AddColumn("Created");
        Table.AddColumn("State");
#ifdef HAVE_LIBSSL
        Table.AddColumn("SSL");
#endif
        Table.AddColumn("Local");
        Table.AddColumn("Remote");
        Table.AddColumn("In");
        Table.AddColumn("Out");

        while (!socks.empty()) {
            Csock* pSocket = socks.top().GetSock();
            socks.pop();

            Table.AddRow();
            Table.SetCell("Name", pSocket->GetSockName());
            Table.SetCell("Created", GetCreatedTime(pSocket));
            Table.SetCell("State", GetSocketState(pSocket));

#ifdef HAVE_LIBSSL
            Table.SetCell("SSL", pSocket->GetSSL() ? "Yes" : "No");
#endif

            Table.SetCell("Local", GetLocalHost(pSocket, bShowHosts));
            Table.SetCell("Remote", GetRemoteHost(pSocket, bShowHosts));
            Table.SetCell("In", CString::ToByteStr(pSocket->GetBytesRead()));
            Table.SetCell("Out",
                          CString::ToByteStr(pSocket->GetBytesWritten()));
        }

        PutModule(Table);
        return;
    }
コード例 #3
0
    void ShowSocks(bool bShowHosts) {
        CSockManager& m = CZNC::Get().GetManager();
        if (!m.size()) {
            PutStatus("You have no open sockets.");
            return;
        }

        std::priority_queue<CSocketSorter> socks;

        for (unsigned int a = 0; a < m.size(); a++) {
            socks.push(m[a]);
        }

        CTable Table;
        Table.AddColumn("Name");
        Table.AddColumn("Created");
        Table.AddColumn("State");
#ifdef HAVE_LIBSSL
        Table.AddColumn("SSL");
#endif
        Table.AddColumn("Local");
        Table.AddColumn("Remote");

        while (!socks.empty()) {
            Csock* pSocket = socks.top().GetSock();
            socks.pop();

            Table.AddRow();

            switch (pSocket->GetType()) {
            case Csock::LISTENER:
                Table.SetCell("State", "Listen");
                break;
            case Csock::INBOUND:
                Table.SetCell("State", "Inbound");
                break;
            case Csock::OUTBOUND:
                if (pSocket->IsConnected())
                    Table.SetCell("State", "Outbound");
                else
                    Table.SetCell("State", "Connecting");
                break;
            default:
                Table.SetCell("State", "UNKNOWN");
                break;
            }

            unsigned long long iStartTime = pSocket->GetStartTime();
            time_t iTime = iStartTime / 1000;
            Table.SetCell("Created", FormatTime("%Y-%m-%d %H:%M:%S", iTime));

#ifdef HAVE_LIBSSL
            if (pSocket->GetSSL()) {
                Table.SetCell("SSL", "Yes");
            } else {
                Table.SetCell("SSL", "No");
            }
#endif


            Table.SetCell("Name", pSocket->GetSockName());
            CString sVHost;
            if (bShowHosts) {
                sVHost = pSocket->GetBindHost();
            }
            if (sVHost.empty()) {
                sVHost = pSocket->GetLocalIP();
            }
            Table.SetCell("Local", sVHost + " " + CString(pSocket->GetLocalPort()));

            CString sHost;
            if (!bShowHosts) {
                sHost = pSocket->GetRemoteIP();
            }
            // While connecting, there might be no ip available
            if (sHost.empty()) {
                sHost = pSocket->GetHostName();
            }

            u_short uPort;
            // While connecting, GetRemotePort() would return 0
            if (pSocket->GetType() == Csock::OUTBOUND) {
                uPort = pSocket->GetPort();
            } else {
                uPort = pSocket->GetRemotePort();
            }
            if (uPort != 0) {
                Table.SetCell("Remote", sHost + " " + CString(uPort));
            } else {
                Table.SetCell("Remote", sHost);
            }
        }

        PutModule(Table);
        return;
    }