Esempio n. 1
0
            mimetype = "text/xml"

        stringio = StringIO.StringIO()
        stringio.write(s)
        stringio.seek(0)

        response = Message()
        response.compose(code="200", reason="Ok",
          mimetype=mimetype, body=stringio)
        stream.send_response(request, response)

CONFIG.register_defaults({
    "rendezvous.server.address": "0.0.0.0",
    "rendezvous.server.daemonize": True,
    "rendezvous.server.ports": "9773,8080",
    "rendezvous.server.update_uri": "http://www.neubot.org/download",
    "rendezvous.server.update_version": common.VERSION,
    "rendezvous.geoip_wrapper.country_database": "/usr/local/share/GeoIP/GeoIP.dat",
    "rendezvous.server.default": "master.neubot.org",
})

def run(poller, conf):
    """ Load MaxMind database and register our child server """

    GEOLOCATOR.open_or_die()
    LOG.info("This product includes GeoLite data created by MaxMind, "
             "available from <http://www.maxmind.com/>.")

    server = ServerRendezvous(None)
    server.configure(conf)
    HTTP_SERVER.register_child(server, "/rendezvous")
Esempio n. 2
0
        stream.attach(self, sock, nconf)
        self.connection_ready(stream)

    def connection_ready(self, stream):
        ''' Invoked when the connection is ready '''

    def accept_failed(self, listener, exception):
        ''' Print a warning if accept() fails (often due to SSL) '''
        logging.warning("ServerHTTP: accept() failed: %s", str(exception))

HTTP_SERVER = ServerHTTP(POLLER)

CONFIG.register_defaults({
    "http.server.address": "",
    "http.server.class": "",
    "http.server.mime": True,
    "http.server.ports": "8080,",
    "http.server.rootdir": "",
    "http.server.ssi": False,
})

def main(args):

    ''' main() function of this module '''

    CONFIG.register_descriptions({
        "http.server.address": "Address to listen to",
        "http.server.class": "Use alternate ServerHTTP-like class",
        "http.server.mime": "Enable code that guess mime types",
        "http.server.ports": "List of ports to listen to",
        "http.server.rootdir": "Root directory for static pages",
        "http.server.ssi": "Enable server-side includes",
Esempio n. 3
0
    def send_complete(self):
        if self.kind == "echo":
            self.start_recv()
            return
        self.start_send(self.buffer)

CONFIG.register_defaults({
    # General variables
    "net.stream.certfile": "",
    "net.stream.ipv6": False,
    "net.stream.key": "",
    "net.stream.secure": False,
    "net.stream.server_side": False,
    "net.stream.rcvbuf": 0,
    "net.stream.sndbuf": 0,
    # For main()
    "net.stream.address": "127.0.0.1",
    "net.stream.chunk": 262144,
    "net.stream.clients": 1,
    "net.stream.daemonize": False,
    "net.stream.duration": 10,
    "net.stream.listen": False,
    "net.stream.port": 12345,
    "net.stream.proto": "",
})

def main(args):

    CONFIG.register_descriptions({
        # General variables
        "net.stream.certfile": "Set SSL certfile path",
Esempio n. 4
0
    sys.exit("This command runs under 'posix' only")

import pwd
import subprocess

if __name__ == "__main__":
    sys.path.insert(0, ".")

from neubot.config import CONFIG
from neubot.log import LOG
from neubot.main import common

CONFIG.register_defaults({
    "net.CA.basedir": "/etc/neubot",
    "net.CA.bits": 4096,
    "net.CA.cacert": "_cacert.pem",
    "net.CA.days": 1095,
    "net.CA.privkey": "_privkey.pem",
})

def main(args):
    """ Generate private key and certificate file for Neubot server """

    CONFIG.register_descriptions({
        "net.CA.bits": "Set private key bits number",
        "net.CA.cacert": "Set certificate file path",
        "net.CA.days": "Set days before expire",
        "net.CA.privkey": "Set private key file path",
    })

    common.main("net.CA", "generate test certificates", args)
Esempio n. 5
0
                             mimetype="application/json")
        else:
            response.compose(code="404", reason="Not Found")

        stream.send_response(request, response)

#
# Register default values in the global scope so that
# their variable names are always defined and the rules
# for casting the types apply.
#
CONFIG.register_defaults({
    "server.bittorrent": True,
    "server.daemonize": True,
    'server.debug': False,
    "server.negotiate": True,
    "server.rendezvous": False,         # Not needed on the random server
    "server.sapi": True,
    "server.speedtest": True,
})

def main(args):
    """ Starts the server module """

    #
    # Register descriptions in main() only so that
    # we don't advertise the name of knobs that aren't
    # relevant in the current context.
    #
    CONFIG.register_descriptions({
        "server.bittorrent": "Start up BitTorrent test and negotiate server",
Esempio n. 6
0
        while self.streams:
            #
            # Override child Time-To-Connect (TTC) with our TTC
            # so for the child it's like it really performed the
            # connect(), not us.
            #
            self.child.rtts = self.rtts
            self.child.connection_ready(self.streams.popleft())
            if justone:
                break


CONFIG.register_defaults(
    {
        "speedtest.client.uri": "http://master.neubot.org/",
        "speedtest.client.nconn": 1,
        "speedtest.client.latency_tries": 10,
    }
)


def main(args):
    """ Main function """
    try:
        options, arguments = getopt.getopt(args[1:], "6A:fp:v")
    except getopt.error:
        sys.exit("usage: neubot speedtest [-6fv] [-A address] [-p port]")
    if arguments:
        sys.exit("usage: neubot speedtest [-6fv] [-A address] [-p port]")

    prefer_ipv6 = 0
Esempio n. 7
0
#
# You should have received a copy of the GNU General Public License
# along with Neubot.  If not, see <http://www.gnu.org/licenses/>.
#

""" Negotiate module """

from neubot.config import CONFIG
from neubot.negotiate.server_speedtest import NEGOTIATE_SERVER_SPEEDTEST
from neubot.negotiate.server_bittorrent import NEGOTIATE_SERVER_BITTORRENT
from neubot.negotiate.server_raw import NEGOTIATE_SERVER_RAW
from neubot.negotiate.server_skype import NEGOTIATE_SERVER_SKYPE
from neubot.negotiate.server import NEGOTIATE_SERVER
from neubot.http.server import HTTP_SERVER

CONFIG.register_defaults({"negotiate.parallelism": 7, "negotiate.min_thresh": 32, "negotiate.max_thresh": 64})


def run(poller, conf):
    """ Start the negotiate server """

    NEGOTIATE_SERVER.register_module("speedtest", NEGOTIATE_SERVER_SPEEDTEST)
    NEGOTIATE_SERVER.register_module("bittorrent", NEGOTIATE_SERVER_BITTORRENT)
    NEGOTIATE_SERVER.register_module("raw", NEGOTIATE_SERVER_RAW)
    NEGOTIATE_SERVER.register_module("skype", NEGOTIATE_SERVER_SKYPE)

    HTTP_SERVER.register_child(NEGOTIATE_SERVER, "/negotiate/")
    HTTP_SERVER.register_child(NEGOTIATE_SERVER, "/collect/")

    CONFIG.register_descriptions(
        {
Esempio n. 8
0
    ''' Returns True if we are allowed to collect a result into the
        database, and False otherwise '''

    if type(m) != types.DictType:
        #
        # XXX This is a shame therefore put the oops() and hope that
        # it does its moral suasion job as expected.
        #
        LOG.oops("TODO: please pass me a dictionary!", LOG.debug)
        m = m.__dict__
    return (not utils.intify(m["privacy_informed"])
            or utils.intify(m["privacy_can_collect"]))

CONFIG.register_defaults({
                          'privacy.init_informed': 0,
                          'privacy.init_can_collect': 0,
                          'privacy.init_can_share': 0,
                          'privacy.overwrite': 0,
                         })

def main(args):

    ''' Will initialize privacy settings '''

    CONFIG.register_descriptions({
        'privacy.init_informed': "You've read privacy policy",
        'privacy.init_can_collect': 'We can collect your IP address',
        'privacy.init_can_share': 'We can share your IP address',
        'privacy.overwrite': 'Overwrite old settings',
                                 })

    common.main('privacy', 'Initialize privacy settings', args)
Esempio n. 9
0
            body = marshal.marshal_object(obody, "application/json")
            mimetype = "application/json"
        else:
            body = compat.adhoc_marshaller(obody)
            mimetype = "text/xml"

        response = Message()
        response.compose(code="200", reason="Ok", mimetype=mimetype, body=body)
        stream.send_response(request, response)


CONFIG.register_defaults(
    {
        "rendezvous.server.address": "",
        "rendezvous.server.ports": "9773,8080",
        "rendezvous.server.update_version": "0.4.15.6",
        "rendezvous.geoip_wrapper.country_database": "/usr/local/share/GeoIP/GeoIP.dat",
        "rendezvous.server.default": "master.neubot.org",
    }
)


def run():
    """ Load MaxMind database and register our child server """

    GEOLOCATOR.open_or_die()
    logging.info("This product includes GeoLite data created by MaxMind, " "available from <http://www.maxmind.com/>.")

    server = ServerRendezvous(None)
    server.configure(CONFIG)
    HTTP_SERVER.register_child(server, "/rendezvous")
Esempio n. 10
0
            body = None
            if request.uri == "/speedtest/negotiate":
                body = FAKE_NEGOTIATION
            response.compose(code="200", reason="Ok", body=body)
            stream.send_response(request, response)

        else:
            response = Message()
            body = "500 Internal Server Error"
            response.compose(code="500", reason="Internal Server Error",
                             body=body, mimetype="text/plain")
            stream.send_response(request, response)

CONFIG.register_defaults({
    "speedtest.server.address": "0.0.0.0",
    "speedtest.server.daemonize": True,
    "speedtest.server.port": "80",
})

def main(args):

    common.main("speedtest.server", "Speedtest Test Server", args)

    conf = CONFIG.copy()

    server = ServerTest(POLLER)
    server.configure(conf)
    server.listen((conf["speedtest.server.address"],
                  conf["speedtest.server.port"]))

    if conf["speedtest.server.daemonize"]:
Esempio n. 11
0
        m = marshal.unmarshal_object(s, "text/xml", compat.SpeedtestCollect)

        if privacy.collect_allowed(m):
            table_speedtest.insertxxx(DATABASE.connection(), m)

        response = Message()
        response.compose(code="200", reason="Ok")
        stream.send_response(request, response)

    def connection_lost(self, stream):
        TRACKER.unregister_connection(stream)
        NOTIFIER.publish(RENEGOTIATE)

CONFIG.register_defaults({
    "speedtest.negotiate.address": "0.0.0.0",
    "speedtest.negotiate.auth_only": True,
    "speedtest.negotiate.daemonize": True,
    "speedtest.negotiate.port": "80",
})

def main(args):

    CONFIG.register_descriptions({
        "speedtest.negotiate.address": "Address to listen to",
        "speedtest.negotiate.auth_only": "Enable doing tests for authorized clients only",
        "speedtest.negotiate.daemonize": "Enable going in background",
        "speedtest.negotiate.port": "Port to listen to",
    })

    common.main("speedtest.negotiate", "Speedtest negotiation server", args)

    conf = CONFIG.copy()
Esempio n. 12
0
                    STATE.update("test", "speedtest")
            else:
                STATE.update(self.state)
            LOG.start("* speedtest: %s" % self.state)
        elif self.state == "negotiate":
            LOG.start("* speedtest: %s" % self.state)

        self.measurer.start(self.state)
        while self.streams:
            self.child.connection_ready(self.streams.popleft())
            if justone:
                break

CONFIG.register_defaults({
    "speedtest.client.uri": "http://neubot.blupixel.net/",
    "speedtest.client.nconn": 1,
    "speedtest.client.latency_tries": 10,
})

def main(args):

    CONFIG.register_descriptions({
        "speedtest.client.uri": "Base URI to connect to",
        "speedtest.client.nconn": "Number of concurrent connections to use",
        "speedtest.client.latency_tries": "Number of latency measurements",
    })

    common.main("speedtest.client", "Speedtest client", args)
    conf = CONFIG.copy()
    client = ClientSpeedtest(POLLER)
    client.configure(conf)
Esempio n. 13
0
#
# You should have received a copy of the GNU General Public License
# along with Neubot.  If not, see <http://www.gnu.org/licenses/>.
#

''' Negotiate module '''

from neubot.config import CONFIG
from neubot.negotiate.server_speedtest import NEGOTIATE_SERVER_SPEEDTEST
from neubot.negotiate.server_bittorrent import NEGOTIATE_SERVER_BITTORRENT
from neubot.negotiate.server import NEGOTIATE_SERVER
from neubot.http.server import HTTP_SERVER

CONFIG.register_defaults({
    'negotiate.parallelism': 3,
    'negotiate.min_thresh': 32,
    'negotiate.max_thresh': 64,
})

def run(poller, conf):
    ''' Start the negotiate server '''

    NEGOTIATE_SERVER.register_module('speedtest', NEGOTIATE_SERVER_SPEEDTEST)
    NEGOTIATE_SERVER.register_module('bittorrent', NEGOTIATE_SERVER_BITTORRENT)

    HTTP_SERVER.register_child(NEGOTIATE_SERVER, '/negotiate/')
    HTTP_SERVER.register_child(NEGOTIATE_SERVER, '/collect/')

    CONFIG.register_descriptions({
        'negotiate.parallelism': 'Number of parallel tests',
        'negotiate.min_thresh': 'Minimum trehshold for RED',
Esempio n. 14
0
        interval = CONFIG["agent.interval"]
        if not interval:
            if not self._interval:
                self._interval = 1380 + random.randrange(0, 240)
            interval = self._interval

        LOG.info("* Next rendezvous in %d seconds" % interval)

        fn = lambda *args, **kwargs: self.connect_uri()
        self._task = POLLER.sched(interval, fn)

        STATE.update("idle", publish=False)
        STATE.update("next_rendezvous", self._task.timestamp)


CONFIG.register_defaults({"rendezvous.client.debug": False, "rendezvous.client.version": common.VERSION})


def main(args):

    CONFIG.register_descriptions(
        {
            "rendezvous.client.debug": "Do not perform any test",
            "rendezvous.client.version": "Set rendezvous client version",
        }
    )

    common.main("rendezvous.client", "Rendezvous client", args)
    conf = CONFIG.copy()

    client = ClientRendezvous(POLLER)
Esempio n. 15
0
        t = dictionary["t"]
        if not type(t) == types.IntType and not type(t) == types.LongType:
            raise ValueError("Invalid type for current event time")
        if t < 0:
            raise ValueError("Invalid value for current event time")

        self.timestamp = t
        self.process_dictionary(dictionary)

    def process_dictionary(self, dictionary):
        octets = json.dumps(dictionary)
        sys.stdout.write(octets)
        sys.stdout.write("\n\n")

CONFIG.register_defaults({
    "api.client.address": "127.0.0.1",
    "api.client.port": "9774",
})

def main(args):

    CONFIG.register_descriptions({
        "api.client.address": "Set address to connect to",
        "api.client.port": "Set port to connect to",
    })

    common.main("api.client", "Minimal client for JSON API", args)
    client = APIStateTracker(POLLER)
    client.configure(CONFIG.copy())
    client.loop()

if __name__ == "__main__":
Esempio n. 16
0
        response = Message()
        if method == "GET" and not stdout:
            fpath = uri.split("/")[-1]
            if os.path.exists(fpath):
                logging.error("* Local file already exists: %s", fpath)
                sys.exit(1)
            response.body = open(fpath, "wb")
        else:
            response.body = sys.stdout

        stream.send_request(request, response)

CONFIG.register_defaults({
    "http.client.class": "",
    "http.client.method": "GET",
    "http.client.stdout": False,
    "http.client.uri": "",
})

def main(args):

    ''' main() of this module '''

    CONFIG.register_descriptions({
        "http.client.class": "Specify alternate ClientHTTP-like class",
        "http.client.method": "Specify alternate HTTP method",
        "http.client.stdout": "Enable writing response to stdout",
        "http.client.uri": "Specify URI to download from/upload to",
    })

    common.main("http.client", "Simple Neubot HTTP client", args)
Esempio n. 17
0
    def recv_complete(self, octets):
        self.start_recv()
        if self.kind == "echo":
            self.start_send(octets)

    def send_complete(self):
        if self.kind == "echo":
            self.start_recv()
            return
        self.start_send(self.buffer)

CONFIG.register_defaults({
    "net.stream.certfile": "",
    "net.stream.ipv6": False,
    "net.stream.key": "",
    "net.stream.obfuscate": False,
    "net.stream.secure": False,
    "net.stream.server_side": False,
    "net.stream.rcvbuf": 0,
    "net.stream.sndbuf": 0,
})
CONFIG.register_defaults({
    "net.stream.address": "",
    "net.stream.chunk": 32768,
    "net.stream.clients": 1,
    "net.stream.daemonize": False,
    "net.stream.duration": 10,
    "net.stream.listen": False,
    "net.stream.port": 12345,
    "net.stream.proto": "",
})