Exemplo n.º 1
0
def setup_channel_set(channel_set):
    """Configures an amfast.remoting.channel.ChannelSet object."""

    # Setup database
    schema = persistent.Schema()
    schema.createSchema()
    schema.createMappers()

    # Setup DB based connection_manager and subscription_manager
    channel_set.connection_manager = SaConnectionManager(
        persistent.engine, persistent.metadata)
    channel_set.connection_manager.createTables()

    channel_set.subscription_manager = SaSubscriptionManager(
        persistent.engine, persistent.metadata)
    channel_set.subscription_manager.createTables()

    # Send log messages to STDOUT
    handler = logging.StreamHandler(sys.stdout)
    handler.setLevel(logging.DEBUG)
    amfast.logger.addHandler(handler)

    # Map class aliases
    # These same aliases must be
    # registered in the client
    # with the registClassAlias function,
    # or the RemoteClass metadata tag.
    class_mapper = ClassDefMapper()
    class_mapper.mapClass(SaClassDef(models.User, 'models.User'))
    class_mapper.mapClass(SaClassDef(models.Email, 'models.Email'))
    class_mapper.mapClass(SaClassDef(models.PhoneNumber, 'models.PhoneNumber'))

    # Expose class_mapper to our controller
    sa_obj = controller.SAObject()
    sa_obj.class_def_mapper = class_mapper

    # Set Channel options
    # We're going to use the same
    # Encoder and Decoder for all channels
    encoder = Encoder(use_collections=True,
                      use_proxies=True,
                      class_def_mapper=class_mapper,
                      use_legacy_xml=True)
    decoder = Decoder(class_def_mapper=class_mapper)
    for channel in channel_set:
        channel.endpoint.encoder = encoder
        channel.endpoint.decoder = decoder

    # Map service targets to controller methods
    service = Service('ExampleService')
    service.mapTarget(SaCallableTarget(sa_obj.load, 'load'))
    service.mapTarget(SaCallableTarget(sa_obj.loadAttr, 'loadAttr'))
    service.mapTarget(SaCallableTarget(sa_obj.loadAll, 'loadAll'))
    service.mapTarget(SaCallableTarget(sa_obj.saveList, 'saveList'))
    service.mapTarget(SaCallableTarget(sa_obj.save, 'save'))
    service.mapTarget(SaCallableTarget(sa_obj.remove, 'remove'))
    service.mapTarget(SaCallableTarget(sa_obj.removeList, 'removeList'))
    service.mapTarget(
        SaCallableTarget(sa_obj.insertDefaultData, 'insertDefaultData'))
    channel_set.service_mapper.mapService(service)
Exemplo n.º 2
0
def createserver(config, jobqueue, db):
    channel_set = TornadoChannelSet()
    polling_channel = TornadoChannel('amf')
    channel_set.mapChannel(polling_channel)
    class_mapper = ClassDefMapper()
    encoder = Encoder(amf3=True, use_collections=True, use_proxies=True, use_references=True, class_def_mapper=class_mapper)
    decoder = Decoder(amf3=True, class_def_mapper=class_mapper)
    for channel in channel_set:
        channel.endpoint.encoder = encoder
        channel.endpoint.decoder = decoder

    srcpath = os.path.join(os.environ["CUREGAME_ROOT"], "../flex/lib/")
    if not os.path.exists(srcpath):
        srcpath = None

    for klass in EXPOSE_SERVICES:
        as3rpc.bind_amfast_service(klass, channel_set, class_mapper, args=(config, jobqueue, db), srcpath=srcpath)

    bin_path = os.path.join(os.environ["CUREGAME_ROOT"], "../flex/Dashboard/bin")
    static_path = os.path.join(os.environ["CUREGAME_ROOT"], "media")
    template_path = os.path.join(os.environ["CUREGAME_ROOT"], "media/html")
    return tornado.web.Application([
            (r"/dashboard/amf/", polling_channel.request_handler),
            (r"/(.*)", tornado.web.StaticFileHandler, {"path": bin_path}),
            ], static_path=static_path, template_path=template_path)
Exemplo n.º 3
0
def open_connection(server, port):

    username = "******"
    password = "******"

    udata = {'user': username, 'pwd': password}
    data = {'cmd': 'login', 'data': udata}

    enc = Encoder(amf3=True)
    obj = enc.encode(data)
    bytes_send = str(len(obj)) + obj

    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock.connect((server, int(port)))
    sent = sock.send(bytes_send)
    print("Send Data : ", bytes_send)
    data = sock.recv(1024)
    print("Received Data : ", data)
Exemplo n.º 4
0
    def __init__(self, encoder=None, decoder=None):
        if encoder is None:
            from amfast.encoder import Encoder
            encoder = Encoder()
        self.encoder = encoder

        if decoder is None:
            from amfast.decoder import Decoder
            decoder = Decoder()
        self.decoder = decoder
Exemplo n.º 5
0
def setup_channel_set(channel_set):
    """Configures an amfast.remoting.channel.ChannelSet object."""

    # Send log messages to STDOUT
    handler = logging.StreamHandler(sys.stdout)
    handler.setLevel(logging.DEBUG)
    amfast.logger.addHandler(handler)

    # These classes are for interacting with the Red5 echo test client.
    class_mapper = ClassDefMapper()
    class_mapper.mapClass(
        DynamicClassDef(RemoteClass,
                        'org.red5.server.webapp.echo.RemoteClass',
                        amf3=False))
    class_mapper.mapClass(
        ExternClassDef(ExternClass,
                       'org.red5.server.webapp.echo.ExternalizableClass'))

    # Set Channel options
    # We're going to use the same
    # Encoder and Decoder for all channels
    encoder = Encoder(use_collections=True,
                      use_proxies=True,
                      class_def_mapper=class_mapper,
                      use_legacy_xml=True)
    decoder = Decoder(class_def_mapper=class_mapper)
    for channel in channel_set:
        channel.endpoint.encoder = encoder
        channel.endpoint.decoder = decoder

    # Map service targets to controller methods
    channel_set.service_mapper.default_service.mapTarget(
        CallableTarget(echo, 'echo'))
    service = Service('Red5Echo')
    service.mapTarget(CallableTarget(echo, 'echo'))
    channel_set.service_mapper.mapService(service)
Exemplo n.º 6
0
from simplejson import loads, dumps
from freepybx.model import *
from freepybx.model import meta
from freepybx.model.meta import *

from datetime import datetime
import pyamf
import sys

Session = scoped_session(
    sessionmaker(autoflush=True, autocommit=True, expire_on_commit=False))
Session.configure(
    bind=create_engine('postgresql://*****:*****@127.0.0.1/pbx'))

decoder = Decoder(amf3=True)
encoder = Encoder(amf3=True)

ESL_HOST = "127.0.0.1"
ESL_PORT = "8021"
ESL_PASS = "******"


def make_message(type, command, context, data, ext=None):
    m = Message()
    m.type = type
    m.command = command
    m.context = context
    m.data = data
    m.ext = ext

Exemplo n.º 7
0
	def send_rsp(self, cmd, playerid, rqstid, pkt):
		encoder = Encoder(amf3=True)
		amf3_data = encoder.encode(pkt)
		self.forward_msg(cmd, amf3_data, playerid, rqstid, flag = 0)
Exemplo n.º 8
0
def encodeAmf3Data(data):
	encoder = Encoder(amf3=True)
	amf3_data = encoder.encode(data)
	return amf3_data
Exemplo n.º 9
0
 def serialise(self, parent, **kwargs):
     encoder = Encoder(amf3=True)
     encoded = encoder.encode(kwargs)
     return encoded
Exemplo n.º 10
0
# -*- coding: utf-8 -*- 
from twisted.internet import reactor
from twisted.internet.protocol import Protocol, Factory
import struct
import time

from amfast.decoder import Decoder
from amfast.encoder import Encoder

encoder = Encoder(amf3=True)
decoder = Decoder(amf3=True)

KEY = 'a780'
CHANNEL_ID = 0
CHANNEL_NAME = 'player'
fmt = '!II%ssI%ss' % (len(CHANNEL_NAME), len(KEY))



#MAX VALUE = 65025*65025
	   #4228250625
PLAYER_ID = 1000000000

#MAX VALUE	= 65025
#  'H' format requires 0 <= number <= 65535
MSG_CHANNEL = 55555

CMD		= 0x00000001
#CMD	 = 0x00000009
#CMD	 = 0x00000003 
Exemplo n.º 11
0
def createserver(config, rootdir, db):
    channel_set = TornadoChannelSet()
    polling_channel = TornadoChannel('amf')
    channel_set.mapChannel(polling_channel)
    class_mapper = ClassDefMapper()
    encoder = Encoder(amf3=True,
                      use_collections=True,
                      use_proxies=True,
                      use_references=True,
                      class_def_mapper=class_mapper)
    decoder = Decoder(amf3=True, class_def_mapper=class_mapper)
    for channel in channel_set:
        channel.endpoint.encoder = encoder
        channel.endpoint.decoder = decoder

    srcpath = os.path.join(rootdir, "../flex/lib/")
    if not os.path.exists(srcpath):
        srcpath = None

    for klass in EXPOSE_SERVICES:
        as3rpc.bind_amfast_service(klass,
                                   channel_set,
                                   class_mapper,
                                   args=(config, db),
                                   srcpath=srcpath)

    swf_path = os.path.join(rootdir, "media/swf")
    static_path = os.path.join(rootdir, "media")
    template_path = os.path.join(rootdir, "media/html")
    pcms_md5 = hashlib.md5(
        open(os.path.join(swf_path, "pcms.swf"), "rb").read()).hexdigest()

    return tornado.web.Application(
        [
            (r"/remotepy/rpc/", remotepy.RemotePyHandler),
            (r"/pcms/amf/", polling_channel.request_handler),
            (r"/pcms/excel/", GeneratePatientExcelHandler, {
                "db": db
            }),
            (r"/admin/login/", AdminLoginHandler),
            (r"/admin/logout/", AdminLogoutHandler),
            (r"/admin/list/", AdminListStationsHandler, {
                "db": db
            }),
            (r"/admin/reset/sync/", AdminResetClientSyncHandler, {
                "db": db
            }),
            (r"/admin/status/", AdminStatusCheckHandler, {
                "db": db
            }),
            (r"/", FlashAppHandler, {
                "config": config,
                "title": _("VRS Analytics"),
                "flash_id": "pcms",
                "flash_version": "10.1.0",
                "flash_movie": "pcms.swf",
                "movie_md5": pcms_md5
            }),
            (r"/(.*)", tornado.web.StaticFileHandler, {
                "path": swf_path
            }),
        ],
        login_url="/admin/login/",
        cookie_secret="529397d22d7bd16a1f4616726f3312fe4d4b48c1",
        static_path=static_path,
        template_path=template_path)
Exemplo n.º 12
0
class Amf0EncoderTestCase(unittest.TestCase):
    class Spam(object):
        def __init__(self):
            self.spam = 'eggs'

    def setUp(self):
        self.class_mapper = class_def.ClassDefMapper()
        self.encoder = Encoder()

    def testFalse(self):
        self.assertEquals('\x01\x00', encode.encode(False))

    def testEncoderContext(self):
        self.assertEquals('\x01\x00', encode.encode(False, EncoderContext()))

    def testEncoderObj(self):
        self.assertEquals('\x01\x00', self.encoder.encode(False))

    def testTrue(self):
        self.assertEquals('\x01\x01', encode.encode(True))

    def testNumber(self):
        tests = {
            0: '\x00\x00\x00\x00\x00\x00\x00\x00\x00',
            0.2: '\x00\x3f\xc9\x99\x99\x99\x99\x99\x9a',
            1: '\x00\x3f\xf0\x00\x00\x00\x00\x00\x00',
            42: '\x00\x40\x45\x00\x00\x00\x00\x00\x00',
            -123: '\x00\xc0\x5e\xc0\x00\x00\x00\x00\x00',
            1.23456789: '\x00\x3f\xf3\xc0\xca\x42\x83\xde\x1b'
        }

        for number, encoding in tests.iteritems():
            self.assertEquals(encoding, encode.encode(number))

    def testString(self):
        tests = {
            '': '\x02\x00\x00',
            'hello': '\x02\x00\x05hello'
        }

        for string, encoding in tests.iteritems():
            self.assertEquals(encoding, encode.encode(string))

    def testLongString(self):
        decoded = 's' * 65537
        encoded = '\x0C\x00\x01\x00\x01' + decoded

        self.assertEquals('\x0C\x00\x01\x00\x01', encode.encode(decoded)[0:5])
        self.assertEquals(65537 + 5, len(encode.encode(decoded)))

    def testNull(self):
        self.assertEquals('\x05', encode.encode(None))

    def testTuple(self):
        decoded = (0, 1, 1.23456789)
        encoded = '\x0A\x00\x00\x00\x03' # 3 element array header
        encoded += '\x00\x00\x00\x00\x00\x00\x00\x00\x00' # element 1
        encoded += '\x00\x3f\xf0\x00\x00\x00\x00\x00\x00' #element 2
        encoded += '\x00\x3f\xf3\xc0\xca\x42\x83\xde\x1b' #element 3

        self.assertEquals(encoded, encode.encode(decoded))

    def testList(self):
        decoded = [0, 1, 1.23456789]
        encoded = '\x0A\x00\x00\x00\x03' # 3 element array header
        encoded += '\x00\x00\x00\x00\x00\x00\x00\x00\x00' # element 1
        encoded += '\x00\x3f\xf0\x00\x00\x00\x00\x00\x00' #element 2
        encoded += '\x00\x3f\xf3\xc0\xca\x42\x83\xde\x1b' #element 3

        self.assertEquals(encoded, encode.encode(decoded))

    def testCollection(self):
        from amfast.class_def.as_types import AsProxy
        decoded = [0, 1, 1.23456789]
        encoded = '\x0A\x00\x00\x00\x03' # 3 element array header
        encoded += '\x00\x00\x00\x00\x00\x00\x00\x00\x00' # element 1
        encoded += '\x00\x3f\xf0\x00\x00\x00\x00\x00\x00' #element 2
        encoded += '\x00\x3f\xf3\xc0\xca\x42\x83\xde\x1b' #element 3

        self.assertEquals(encoded, encode.encode(AsProxy(decoded)))

    def testNoCollection(self):
        from amfast.class_def.as_types import AsNoProxy
        decoded = [0, 1, 1.23456789]
        encoded = '\x0A\x00\x00\x00\x03' # 3 element array header
        encoded += '\x00\x00\x00\x00\x00\x00\x00\x00\x00' # element 1
        encoded += '\x00\x3f\xf0\x00\x00\x00\x00\x00\x00' #element 2
        encoded += '\x00\x3f\xf3\xc0\xca\x42\x83\xde\x1b' #element 3

        self.assertEquals(encoded, encode.encode(AsNoProxy(decoded)))

    def testDict(self):
        encoded = '\x03' #header
        encoded += '\x00\x04spam\x02\x00\x04eggs' #values
        encoded += '\x00\x00\t' # terminator
        self.assertEquals(encoded, encode.encode({'spam': 'eggs'}))

    def testNoProxy(self):
        from amfast.class_def.as_types import AsProxy
        encoded = '\x03' #header
        encoded += '\x00\x04spam\x02\x00\x04eggs' #values
        encoded += '\x00\x00\t' # terminator
        self.assertEquals(encoded, encode.encode(AsNoProxy({'spam': 'eggs'})))

    def testProxy(self):
        from amfast.class_def.as_types import AsProxy
        encoded = '\x03' #header
        encoded += '\x00\x04spam\x02\x00\x04eggs' #values
        encoded += '\x00\x00\t' # terminator
        self.assertEquals(encoded, encode.encode(AsProxy({'spam': 'eggs'})))

    def testNoProxy(self):
        from amfast.class_def.as_types import AsNoProxy
        encoded = '\x03' #header
        encoded += '\x00\x04spam\x02\x00\x04eggs' #values
        encoded += '\x00\x00\t' # terminator
        self.assertEquals(encoded, encode.encode(AsNoProxy({'spam': 'eggs'})))

    def testDate(self):
        import datetime
        decoded = datetime.datetime(2005, 3, 18, 1, 58, 31)
        encoded = '\x0BBp+6!\x15\x80\x00\x00\x00'
        self.assertEquals(encoded, encode.encode(decoded))

    def testXml(self):
        import xml.dom.minidom
        
        xml_str = '<?xml version="1.0" ?><test>\n            <test_me>tester</test_me>\n           </test>' # encoded XML
        decoded = xml.dom.minidom.parseString(xml_str)

        encoded = '\x0F' # XML header
        encoded += '\x00\x00\x00\x55' # String header
        encoded += xml_str

        self.assertEquals(encoded, encode.encode(decoded))

    def testAnonymousObj(self):
        decoded = self.Spam()
        decoded.spam = 'eggs'

        encoded = '\x03' #header
        encoded += '\x00\x04spam\x02\x00\x04eggs' #values
        encoded += '\x00\x00\t' # terminator
        self.assertEquals(encoded, encode.encode(decoded))

    def testDynamicObj(self):
        self.class_mapper.mapClass(class_def.DynamicClassDef(self.Spam, alias='alias.spam',
            static_attrs=(), amf3=False))

        decoded = self.Spam()
        decoded.spam = 'eggs'

        encoded = '\x10\x00\x0Aalias.spam'
        encoded += '\x00\x04spam\x02\x00\x04eggs\x00\x00\x09' # dynamic attrs

        context = EncoderContext(class_def_mapper=self.class_mapper)
        self.assertEquals(encoded, encode.encode(decoded, context))
        self.class_mapper.unmapClass(self.Spam)

    def testStaticObj(self):
        self.class_mapper.mapClass(class_def.ClassDef(self.Spam, alias='alias.spam',
            static_attrs=('spam', ), amf3=False))

        decoded = self.Spam()
        decoded.spam = 'eggs'

        encoded = '\x10\x00\x0Aalias.spam'
        encoded += '\x00\x04spam\x02\x00\x04eggs\x00\x00\x09' # dynamic attrs

        context = EncoderContext(class_def_mapper=self.class_mapper)
        self.assertEquals(encoded, encode.encode(decoded, context))
        self.class_mapper.unmapClass(self.Spam)

    def testReferences(self):
        obj = {'spam': 'eggs'}
        decoded = [obj, obj, obj]
        decoded.append(decoded)

        encoded = '\x0A\x00\x00\x00\x04' # 3 element array header
        encoded += '\x03\x00\x04spam\x02\x00\x04eggs\x00\x00\t' # obj 1
        encoded += '\x07\x00\x01' # ref to obj 1
        encoded += '\x07\x00\x01' # ref to obj 1
        encoded += '\x07\x00\x00' # circular ref

        self.assertEquals(encoded, encode.encode(decoded))
Exemplo n.º 13
0
 def setUp(self):
     self.class_mapper = class_def.ClassDefMapper()
     self.encoder = Encoder()
Exemplo n.º 14
0
 def testDecodeAmf3(self):
      return
      self._testDecoder(Decoder(amf3=True), Encoder(amf3=True), 'sample_2.log')
Exemplo n.º 15
0
 def testDecodeAmf0(self):
      return
      self._testDecoder(Decoder(), Encoder(), 'sample.log')
Exemplo n.º 16
0
 def testEncodeAmf3(self):
      return
      self._testEncoder(Encoder(amf3=True), 'sample.log')