Beispiel #1
0
    def create(self, request):
        """Create a group.
        One POST parameter required, the group identifier (a string)
        ---
        # YAML
        omit_serializer: true
        parameters:
        - name: gid
          description: Group identifier
          required: true
          type: string
          paramType: form
        """
        telnet = request.telnet
        telnet.sendline('group -a')
        telnet.expect(r'Adding a new Group(.+)\n' + INTERACTIVE_PROMPT)
        if not 'gid' in request.data:
            raise MissingKeyError('Missing gid (group identifier)')

        set_ikeys(telnet, {"gid": request.data["gid"]})

        telnet.sendline('persist')
        telnet.expect(r'.*' + STANDARD_PROMPT)
        if settings.JASMIN_DOCKER or settings.JASMIN_K8S:
            sync_conf_instances(request.telnet_list)
        return JsonResponse({'name': request.data["gid"]})
Beispiel #2
0
    def partial_update(self, request, uid):
        """Update some user attributes

        JSON requests only. The updates parameter is a list of lists.
        Each list is a list of valid arguments to user update. For example:

        * ["gid", "mygroup"] will set the user's group to mygroup
        * ["mt_messaging_cred", "authorization", "smpps_send", "False"]
        will remove the user privilege to send SMSs through the SMPP API.
        ---
        # YAML
        omit_serializer: true
        parameters:
        - name: updates
          description: Items to update
          required: true
          type: array
          paramType: body
        """
        telnet = request.telnet
        telnet.sendline('user -u ' + uid)
        matched_index = telnet.expect([
            r'.*Updating User(.*)' + INTERACTIVE_PROMPT,
            r'.*Unknown User: (.*)' + STANDARD_PROMPT,
            r'.+(.*)(' + INTERACTIVE_PROMPT + '|' + STANDARD_PROMPT + ')',
        ])
        if matched_index == 1:
            raise UnknownError(detail='Unknown user:'******'updates should be a list')
        for update in updates:
            if not ((type(update) is list) and (len(update) >= 1)):
                raise JasminSyntaxError("Not a list: %s" % update)
            telnet.sendline(" ".join([x for x in update]))
            matched_index = telnet.expect([
                r'.*(Unknown User key:.*)' + INTERACTIVE_PROMPT,
                r'.*(Error:.*)' + STANDARD_PROMPT,
                r'.*' + INTERACTIVE_PROMPT,
                r'.+(.*)(' + INTERACTIVE_PROMPT + '|' + STANDARD_PROMPT + ')',
            ])
            if matched_index != 2:
                raise JasminSyntaxError(
                    detail=" ".join(telnet.match.group(1).split()))
        telnet.sendline('ok')
        ok_index = telnet.expect([
            r'(.*)' + INTERACTIVE_PROMPT,
            r'.*' + STANDARD_PROMPT,
        ])
        if ok_index == 0:
            raise JasminSyntaxError(
                detail=" ".join(telnet.match.group(1).split()))
        telnet.sendline('persist\n')
        # Not sure why this needs to be repeated
        telnet.expect(r'.*' + STANDARD_PROMPT)
        if settings.JASMIN_DOCKER or settings.JASMIN_K8S:
            sync_conf_instances(request.telnet_list)
        return JsonResponse({'user': self.get_user(telnet, uid)})
Beispiel #3
0
    def create(self, request):
        """Create a group.
        One POST parameter required, the group identifier (a string)
        ---
        # YAML
        omit_serializer: true
        parameters:
        - name: gid
          description: Group identifier
          required: true
          type: string
          paramType: form
        """
        telnet = request.telnet
        telnet.sendline('group -a')
        telnet.expect(r'Adding a new Group(.+)\n' + INTERACTIVE_PROMPT)
        if not 'gid' in request.data:
            raise MissingKeyError('Missing gid (group identifier)')
        telnet.sendline('gid ' + request.data['gid'] + '\n')
        telnet.expect(INTERACTIVE_PROMPT)
        telnet.sendline('ok\n')

        matched_index = telnet.expect([
            r'.+Successfully added(.+)\[(.+)\][\n\r]+' + STANDARD_PROMPT,
            r'.+Error: (.+)[\n\r]+' + INTERACTIVE_PROMPT,
            r'.+(.*)(' + INTERACTIVE_PROMPT + '|' + STANDARD_PROMPT + ')',
        ])
        if matched_index == 0:
            gid = telnet.match.group(2).strip()
            telnet.sendline('persist\n')
            if settings.JASMIN_DOCKER:
                sync_conf_instances(request.telnet_list)
            return JsonResponse({'name': gid})
        else:
            raise ActionFailed(telnet.match.group(1))
Beispiel #4
0
    def partial_update(self, request, uid):
        """Update some user attributes

        JSON requests only. The updates parameter is a list of lists.
        Each list is a list of valid arguments to user update. For example:

        * ["gid", "mygroup"] will set the user's group to mygroup
        * ["mt_messaging_cred", "authorization", "smpps_send", "False"]
        will remove the user privilege to send SMSs through the SMPP API.
        ---
        # YAML
        omit_serializer: true
        parameters:
        - name: updates
          description: Items to update
          required: true
          type: array
          paramType: body
        """
        telnet = request.telnet
        telnet.sendline('user -u ' + uid)
        matched_index = telnet.expect([
            r'.*Updating User(.*)' + INTERACTIVE_PROMPT,
            r'.*Unknown User: (.*)' + STANDARD_PROMPT,
            r'.+(.*)(' + INTERACTIVE_PROMPT + '|' + STANDARD_PROMPT + ')',
        ])
        if matched_index == 1:
            raise UnknownError(detail='Unknown user:'******'updates should be a list')
        for update in updates:
            if not ((type(update) is list) and (len(update) >= 1)):
                raise JasminSyntaxError("Not a list: %s" % update)
            telnet.sendline(" ".join([x for x in update]))
            matched_index = telnet.expect([
                r'.*(Unknown User key:.*)' + INTERACTIVE_PROMPT,
                r'.*(Error:.*)' + STANDARD_PROMPT,
                r'.*' + INTERACTIVE_PROMPT,
                r'.+(.*)(' + INTERACTIVE_PROMPT + '|' + STANDARD_PROMPT + ')',
            ])
            if matched_index != 2:
                raise JasminSyntaxError(
                    detail=" ".join(telnet.match.group(1).split()))
        telnet.sendline('ok')
        ok_index = telnet.expect([
            r'(.*)' + INTERACTIVE_PROMPT,
            r'.*' + STANDARD_PROMPT,
        ])
        if ok_index == 0:
            raise JasminSyntaxError(
                detail=" ".join(telnet.match.group(1).split()))
        telnet.sendline('persist\n')
        # Not sure why this needs to be repeated
        telnet.expect(r'.*' + STANDARD_PROMPT)
        if settings.JASMIN_DOCKER:
            sync_conf_instances(request.telnet_list)
        return JsonResponse({'user': self.get_user(telnet, uid)})
Beispiel #5
0
    def create(self, request):
        """Create an SMPP Client Connector.
        Required parameter: cid (connector id)
        ---
        # YAML
        omit_serializer: true
        parameters:
        - name: cid
          description: Connector identifier
          required: true
          type: string
          paramType: form
        """
        telnet = request.telnet

        telnet.sendline('smppccm -a')
        telnet.expect(r'Adding a new connector(.+)\n' + INTERACTIVE_PROMPT)
        updates = request.data
        if not 'cid' in request.data:
            raise MissingKeyError('Missing cid (connector identifier)')

        set_ikeys(telnet, {"cid": request.data["cid"]})

        telnet.sendline('persist\n')
        telnet.expect(r'.*' + STANDARD_PROMPT)
        if settings.JASMIN_DOCKER or settings.JASMIN_K8S:
            sync_conf_instances(request.telnet_list)
        return JsonResponse({'cid': request.data['cid']})
Beispiel #6
0
 def simple_mtrouter_action(self,
                            telnet,
                            telnet_list,
                            action,
                            order,
                            return_mtroute=True):
     telnet.sendline('mtrouter -%s %s' % (action, order))
     matched_index = telnet.expect([
         r'.+Successfully(.+)' + STANDARD_PROMPT,
         r'.+Unknown MT Route: (.+)' + STANDARD_PROMPT,
         r'.+(.*)' + STANDARD_PROMPT,
     ])
     if matched_index == 0:
         telnet.sendline('persist\n')
         if return_mtroute:
             telnet.expect(r'.*' + STANDARD_PROMPT)
             if settings.JASMIN_DOCKER or settings.JASMIN_K8S:
                 sync_conf_instances(telnet_list)
             return JsonResponse(
                 {'mtrouter': self.get_router(telnet, order)})
         else:
             if settings.JASMIN_DOCKER or settings.JASMIN_K8S:
                 sync_conf_instances(telnet_list)
             return JsonResponse({'order': order})
     elif matched_index == 1:
         raise UnknownError(detail='No router:' + order)
     else:
         raise JasminError(telnet.match.group(1))
Beispiel #7
0
 def simple_user_action(self,
                        telnet,
                        telnet_list,
                        action,
                        uid,
                        return_user=True):
     telnet.sendline('user -%s %s' % (action, uid))
     matched_index = telnet.expect([
         r'.+Successfully(.+)' + STANDARD_PROMPT,
         r'.+Unknown User: (.+)' + STANDARD_PROMPT,
         r'.+(.*)' + STANDARD_PROMPT,
     ])
     if matched_index == 0:
         telnet.sendline('persist\n')
         if settings.JASMIN_DOCKER or settings.JASMIN_K8S:
             sync_conf_instances(telnet_list)
         if return_user:
             telnet.expect(r'.*' + STANDARD_PROMPT)
             return JsonResponse({'user': self.get_user(telnet, uid)})
         else:
             return JsonResponse({'uid': uid})
     elif matched_index == 1:
         raise UnknownError(detail='No user:' + uid)
     else:
         raise JasminError(telnet.match.group(1))
Beispiel #8
0
    def partial_update(self, request, cid):
        """Update some SMPP connector attributes

        JSON requests only. The updates parameter is a key value array
        ---
        # YAML
        omit_serializer: true
        parameters:
        - name: updates
          description: Items to update
          required: true
          type: array
          paramType: body
        """
        telnet = request.telnet
        telnet.sendline('smppccm -u ' + cid)
        matched_index = telnet.expect([
            r'.*Updating connector(.*)' + INTERACTIVE_PROMPT,
            r'.*Unknown connector: (.*)' + STANDARD_PROMPT,
            r'.+(.*)(' + INTERACTIVE_PROMPT + '|' + STANDARD_PROMPT + ')',
        ])
        if matched_index == 1:
            raise UnknownError(detail='Unknown connector:' + cid)
        if matched_index != 0:
            raise JasminError(detail=" ".join(telnet.match.group(0).split()))
        updates = request.data
        for k, v in updates.items():
            if not ((type(updates) is dict) and (len(updates) >= 1)):
                raise JasminSyntaxError(
                    'updates should be a a key value array')
            telnet.sendline("%s %s\n" % (k, v))
            matched_index = telnet.expect([
                r'.*(Unknown SMPPClientConfig key:.*)' + INTERACTIVE_PROMPT,
                r'.*(Error:.*)' + STANDARD_PROMPT,
                r'.*' + INTERACTIVE_PROMPT,
                r'.+(.*)(' + INTERACTIVE_PROMPT + '|' + STANDARD_PROMPT + ')',
            ])
            if matched_index != 2:
                raise JasminSyntaxError(
                    detail=" ".join(telnet.match.group(1).split()))
        telnet.sendline('ok\n')
        ok_index = telnet.expect([
            r'.*(Error:.*)' + STANDARD_PROMPT,
            r'(.*)' + INTERACTIVE_PROMPT,
            r'.*' + STANDARD_PROMPT,
        ])
        if ok_index == 0:
            raise JasminSyntaxError(
                detail=" ".join(telnet.match.group(1).split()))
        telnet.sendline('persist\n')
        # Not sure why this needs to be repeated, just as with user
        telnet.expect(r'.*' + STANDARD_PROMPT)
        if settings.JASMIN_DOCKER or settings.JASMIN_K8S:
            sync_conf_instances(request.telnet_list)

        return JsonResponse(
            {'connector': self.get_smppccm(telnet, cid, silent=False)})
Beispiel #9
0
    def partial_update(self, request, cid):
        """Update some SMPP connector attributes

        JSON requests only. The updates parameter is a key value array
        ---
        # YAML
        omit_serializer: true
        parameters:
        - name: updates
          description: Items to update
          required: true
          type: array
          paramType: body
        """
        telnet = request.telnet
        telnet.sendline('smppccm -u ' + cid)
        matched_index = telnet.expect([
            r'.*Updating connector(.*)' + INTERACTIVE_PROMPT,
            r'.*Unknown connector: (.*)' + STANDARD_PROMPT,
            r'.+(.*)(' + INTERACTIVE_PROMPT + '|' + STANDARD_PROMPT + ')',
        ])
        if matched_index == 1:
            raise UnknownError(detail='Unknown connector:' + cid)
        if matched_index != 0:
            raise JasminError(detail=" ".join(telnet.match.group(0).split()))
        updates = request.data
        for k, v in updates.items():
            if not ((type(updates) is dict) and (len(updates) >= 1)):
                raise JasminSyntaxError('updates should be a a key value array')
            telnet.sendline("%s %s" % (k, v))
            matched_index = telnet.expect([
                r'.*(Unknown SMPPClientConfig key:.*)' + INTERACTIVE_PROMPT,
                r'.*(Error:.*)' + STANDARD_PROMPT,
                r'.*' + INTERACTIVE_PROMPT,
                r'.+(.*)(' + INTERACTIVE_PROMPT + '|' + STANDARD_PROMPT + ')',
            ])
            if matched_index != 2:
                raise JasminSyntaxError(
                    detail=" ".join(telnet.match.group(1).split()))
        telnet.sendline('ok')
        ok_index = telnet.expect([
            r'.*(Error:.*)' + STANDARD_PROMPT,
            r'(.*)' + INTERACTIVE_PROMPT,
            r'.*' + STANDARD_PROMPT,
        ])
        if ok_index == 0:
            raise JasminSyntaxError(
                detail=" ".join(telnet.match.group(1).split()))
        telnet.sendline('persist\n')
        # Not sure why this needs to be repeated, just as with user
        telnet.expect(r'.*' + STANDARD_PROMPT)
        if settings.JASMIN_DOCKER:
            sync_conf_instances(request.telnet_list)

        return JsonResponse(
            {'connector': self.get_smppccm(telnet, cid, silent=False)})
Beispiel #10
0
 def flush(self, request):
     "Flush entire routing table"
     telnet = request.telnet
     telnet.sendline('mtrouter -f')
     telnet.expect([r'(.+)\n' + STANDARD_PROMPT])
     telnet.sendline('persist\n')
     telnet.expect(r'.*' + STANDARD_PROMPT)
     if settings.JASMIN_DOCKER:
         sync_conf_instances(request.telnet_list)
     return JsonResponse({'mtrouters': []})
Beispiel #11
0
 def flush(self, request):
     "Flush entire routing table"
     telnet = request.telnet
     telnet.sendline('mtrouter -f')
     telnet.expect([r'(.+)\n' + STANDARD_PROMPT])
     telnet.sendline('persist\n')
     telnet.expect(r'.*' + STANDARD_PROMPT)
     if settings.JASMIN_DOCKER or settings.JASMIN_K8S:
         sync_conf_instances(request.telnet_list)
     return JsonResponse({'mtrouters': []})
Beispiel #12
0
 def create(self, request):
     """Create a User.
     Required parameters: username, password, uid (user identifier), gid (group identifier),
     ---
     # YAML
     omit_serializer: true
     parameters:
     - name: uid
       description: Username identifier
       required: true
       type: string
       paramType: form
     - name: gid
       description: Group identifier
       required: true
       type: string
       paramType: form
     - name: username
       description: Username
       required: true
       type: string
       paramType: form
     - name: password
       description: Password
       required: true
       type: string
       paramType: form
     """
     telnet = request.telnet
     data = request.data
     try:
         uid, gid, username, password = \
             data['uid'], data['gid'], data['username'], data['password']
     except Exception:
         raise MissingKeyError(
             'Missing parameter: uid, gid, username and/or password required'
         )
     telnet.sendline('user -a')
     telnet.expect(r'Adding a new User(.+)\n' + INTERACTIVE_PROMPT)
     set_ikeys(telnet, {
         'uid': uid,
         'gid': gid,
         'username': username,
         'password': password
     })
     telnet.sendline('persist\n')
     telnet.expect(r'.*' + STANDARD_PROMPT)
     if settings.JASMIN_DOCKER or settings.JASMIN_K8S:
         sync_conf_instances(request.telnet_list)
     return JsonResponse({'user': self.get_user(telnet, uid)})
Beispiel #13
0
 def create(self, request):
     """Create a User.
     Required parameters: username, password, uid (user identifier), gid (group identifier),
     ---
     # YAML
     omit_serializer: true
     parameters:
     - name: uid
       description: Username identifier
       required: true
       type: string
       paramType: form
     - name: gid
       description: Group identifier
       required: true
       type: string
       paramType: form
     - name: username
       description: Username
       required: true
       type: string
       paramType: form
     - name: password
       description: Password
       required: true
       type: string
       paramType: form
     """
     telnet = request.telnet
     data = request.data
     try:
         uid, gid, username, password = \
             data['uid'], data['gid'], data['username'], data['password']
     except Exception:
         raise MissingKeyError('Missing parameter: uid, gid, username and/or password required')
     telnet.sendline('user -a')
     telnet.expect(r'Adding a new User(.+)\n' + INTERACTIVE_PROMPT)
     set_ikeys(
         telnet,
         {
             'uid': uid, 'gid': gid, 'username': username,
             'password': password
         }
     )
     telnet.sendline('persist\n')
     telnet.expect(r'.*' + STANDARD_PROMPT)
     if settings.JASMIN_DOCKER:
         sync_conf_instances(request.telnet_list)
     return JsonResponse({'user': self.get_user(telnet, uid)})
Beispiel #14
0
 def simple_httpccm_action(self, telnet, telnet_list, action, cid):
     telnet.sendline('httpccm -%s %s' % (action, cid))
     matched_index = telnet.expect([
         r'.+Successfully(.+)' + STANDARD_PROMPT,
         r'.+Unknown connector: (.+)' + STANDARD_PROMPT,
         r'(.*)' + STANDARD_PROMPT,
     ])
     if matched_index == 0:
         telnet.sendline('persist\n')
         if settings.JASMIN_DOCKER:
             sync_conf_instances(telnet_list)
         return JsonResponse({'name': cid})
     elif matched_index == 1:
         raise ObjectNotFoundError('Unknown HTTP Connector: %s' % cid)
     else:
         raise ActionFailed(telnet.match.group(1))
Beispiel #15
0
 def simple_smppccm_action(self, telnet, telnet_list, action, cid):
     telnet.sendline('smppccm -%s %s' % (action, cid))
     matched_index = telnet.expect([
         r'.+Successfully(.+)' + STANDARD_PROMPT,
         r'.+Unknown connector: (.+)' + STANDARD_PROMPT,
         r'(.*)' + STANDARD_PROMPT,
     ])
     if matched_index == 0:
         telnet.sendline('persist\n')
         if settings.JASMIN_DOCKER or settings.JASMIN_K8S:
             sync_conf_instances(telnet_list)
         return JsonResponse({'name': cid})
     elif matched_index == 1:
         raise ObjectNotFoundError('Unknown SMPP Connector: %s' % cid)
     else:
         raise ActionFailed(telnet.match.group(1))
Beispiel #16
0
    def create(self, request):
        """Create an HTTP Client Connector.
        Required parameter: cid (connector id)
        ---
        # YAML
        omit_serializer: true
        parameters:
        - name: cid
          description: Connector identifier
          required: true
          type: string
          paramType: form
        - name: url
          description: URL to be called with message parameters
          required: true
          type: string
          paramType: form
        - name: method
          description: Calling method (GET or POST)
          required: true
          type: string
          paramType: form
        """
        telnet = request.telnet

        telnet.sendline('httpccm -a')
        data = request.data
	
        for k, v in data.items():
            telnet.sendline("%s %s" % (k, v))
        telnet.sendline('ok')
        matched_index = telnet.expect([
            r'.*(HttpConnector url syntax is invalid.*)' + INTERACTIVE_PROMPT,
            r'.*(HttpConnector method syntax is invalid, must be GET or POST.*)' + INTERACTIVE_PROMPT,
            r'.*' + INTERACTIVE_PROMPT,
            r'.+(.*)(' + INTERACTIVE_PROMPT + '|' + STANDARD_PROMPT + ')',
        ])
        if matched_index != 2:
            raise JasminSyntaxError(
                detail=" ".join(telnet.match.group(1).split()))
        telnet.sendline('persist\n')
        telnet.expect(r'.*' + STANDARD_PROMPT)
        if settings.JASMIN_DOCKER:
            sync_conf_instances(request.telnet_list)
        return JsonResponse({'cid': request.data['cid']})
Beispiel #17
0
    def create(self, request):
        """Create an HTTP Client Connector.
        Required parameter: cid (connector id)
        ---
        # YAML
        omit_serializer: true
        parameters:
        - name: cid
          description: Connector identifier
          required: true
          type: string
          paramType: form
        - name: url
          description: URL to be called with message parameters
          required: true
          type: string
          paramType: form
        - name: method
          description: Calling method (GET or POST)
          required: true
          type: string
          paramType: form
        """
        telnet = request.telnet

        telnet.sendline('httpccm -a')
        data = request.data
	
        for k, v in data.items():
            telnet.sendline("%s %s" % (k, v))
        telnet.sendline('ok')
        matched_index = telnet.expect([
            r'.*(HttpConnector url syntax is invalid.*)' + INTERACTIVE_PROMPT,
            r'.*(HttpConnector method syntax is invalid, must be GET or POST.*)' + INTERACTIVE_PROMPT,
            r'.*' + INTERACTIVE_PROMPT,
            r'.+(.*)(' + INTERACTIVE_PROMPT + '|' + STANDARD_PROMPT + ')',
        ])
        if matched_index != 2:
            raise JasminSyntaxError(
                detail=" ".join(telnet.match.group(1).split()))
        telnet.sendline('persist\n')
        telnet.expect(r'.*' + STANDARD_PROMPT)
        if settings.JASMIN_DOCKER or settings.JASMIN_K8S:
            sync_conf_instances(request.telnet_list)
        return JsonResponse({'cid': request.data['cid']})
Beispiel #18
0
 def simple_user_action(self, telnet, telnet_list, action, uid, return_user=True):
     telnet.sendline('user -%s %s' % (action, uid))
     matched_index = telnet.expect([
         r'.+Successfully(.+)' + STANDARD_PROMPT,
         r'.+Unknown User: (.+)' + STANDARD_PROMPT,
         r'.+(.*)' + STANDARD_PROMPT,
     ])
     if matched_index == 0:
         telnet.sendline('persist\n')
         if settings.JASMIN_DOCKER:
             sync_conf_instances(telnet_list)
         if return_user:
             telnet.expect(r'.*' + STANDARD_PROMPT)
             return JsonResponse({'user': self.get_user(telnet, uid)})
         else:
             return JsonResponse({'uid': uid})
     elif matched_index == 1:
         raise UnknownError(detail='No user:' + uid)
     else:
         raise JasminError(telnet.match.group(1))
Beispiel #19
0
 def simple_mtrouter_action(self, telnet, telnet_list, action, order, return_mtroute=True):
     telnet.sendline('mtrouter -%s %s' % (action, order))
     matched_index = telnet.expect([
         r'.+Successfully(.+)' + STANDARD_PROMPT,
         r'.+Unknown MT Route: (.+)' + STANDARD_PROMPT,
         r'.+(.*)' + STANDARD_PROMPT,
     ])
     if matched_index == 0:
         telnet.sendline('persist\n')
         if return_mtroute:
             telnet.expect(r'.*' + STANDARD_PROMPT)
             if settings.JASMIN_DOCKER:
                 sync_conf_instances(telnet_list)
             return JsonResponse({'mtrouter': self.get_router(telnet, order)})
         else:
             if settings.JASMIN_DOCKER:
                 sync_conf_instances(telnet_list)
             return JsonResponse({'order': order})
     elif matched_index == 1:
         raise UnknownError(detail='No router:' +  order)
     else:
         raise JasminError(telnet.match.group(1))
Beispiel #20
0
    def create(self, request):
        """Create an SMPP Client Connector.
        Required parameter: cid (connector id)
        ---
        # YAML
        omit_serializer: true
        parameters:
        - name: cid
          description: Connector identifier
          required: true
          type: string
          paramType: form
        """
        telnet = request.telnet

        telnet.sendline('smppccm -a')
        updates = request.data
        for k, v in updates.items():
            if not ((type(updates) is dict) and (len(updates) >= 1)):
                raise JasminSyntaxError('updates should be a a key value array')
            telnet.sendline("%s %s" % (k, v))
            matched_index = telnet.expect([
                r'.*(Unknown SMPPClientConfig key:.*)' + INTERACTIVE_PROMPT,
                r'.*(Error:.*)' + STANDARD_PROMPT,
                r'.*' + INTERACTIVE_PROMPT,
                r'.+(.*)(' + INTERACTIVE_PROMPT + '|' + STANDARD_PROMPT + ')',
            ])
            if matched_index != 2:
                raise JasminSyntaxError(
                    detail=" ".join(telnet.match.group(1).split()))
        telnet.sendline('ok')
        telnet.sendline('persist\n')
        telnet.expect(r'.*' + STANDARD_PROMPT)
        if settings.JASMIN_DOCKER:
            sync_conf_instances(request.telnet_list)
        return JsonResponse({'cid': request.data['cid']})
Beispiel #21
0
 def create(self, request):
     """Create MTRouter.
     Required parameters: type, order, smppconnectors, httpconnectors
     More than one connector is allowed only for RandomRoundrobinMTRoute
     ---
     # YAML
     omit_serializer: true
     parameters:
     - name: type
       description: One of DefaultRoute, StaticMTRoute, RandomRoundrobinMTRoute
       required: true
       type: string
       paramType: form
     - name: order
       description: Router order, also used to identify router
       required: true
       type: string
       paramType: form
     - name: rate
       description: Router rate, may be zero for free
       required: true
       type: float
       paramType: form
     - name: smppconnectors
       description: List of SMPP connector ids.
       required: false
       type: array
       paramType: form
     - name: httpconnectors
       description: List of HTTP connector ids. 
       required: false
       type: array
       paramType: form
     - name: filters
       description: List of filters, required except for DefaultRoute
       required: false
       type: array
       paramType: form
     """
     telnet = request.telnet
     data = request.data
     try:
         rtype, order, rate = data['type'], data['order'], data['rate']
     except IndexError:
         raise MissingKeyError(
             'Missing parameter: type or order required')
     rtype = rtype.lower()
     telnet.sendline('mtrouter -a')
     telnet.expect(r'Adding a new MT Route(.+)\n' + INTERACTIVE_PROMPT)
     ikeys = OrderedDict({'type': rtype})
     if rtype != 'defaultroute':
         try:
             filters = data['filters'].split(',')
         except MultiValueDictKeyError:
             raise MissingKeyError('%s router requires filters' % rtype)
         ikeys['filters'] = ';'.join(filters)
         ikeys['order'] = order
     smppconnectors = data.get('smppconnectors', '')
     httpconnectors = data.get('httpconnectors', '')
     connectors = ['smppc(%s)' % c.strip()
             for c in smppconnectors.split(',') if c.strip()
         ] + ['http(%s)' % c for c in httpconnectors.split(',') if c.strip()]
     if rtype == 'randomroundrobinmtroute':
         if len(connectors) < 2:
             raise MutipleValuesRequiredKeyError(
                 'Round Robin route requires at least two connectors')
         ikeys['connectors'] = ';'.join(connectors)
     else:
         if len(connectors) != 1:
             raise MissingKeyError('one and only one connector required')
         ikeys['connector'] = connectors[0]
     ikeys['rate'] = rate
     print ikeys
     set_ikeys(telnet, ikeys)
     telnet.sendline('persist\n')
     telnet.expect(r'.*' + STANDARD_PROMPT)
     if settings.JASMIN_DOCKER:
         sync_conf_instances(request.telnet_list)
     return JsonResponse({'mtrouter': self.get_router(telnet, order)})
Beispiel #22
0
 def create(self, request):
     """Create Filter.
     Required parameters: type, fid, parameters
     ---
     # YAML
     omit_serializer: true
     parameters:
     - name: type
       description: One of TransparentFilter, ConnectorFilter, UserFilter, GroupFilter, SourceAddrFilter, DestinationAddrFilter, ShortMessageFilter, DateIntervalFilter, TimeIntervalFilter, TagFilter, EvalPyFilter
       required: true
       type: string
       paramType: form
     - name: fid
       description: Filter id, used to identify filter
       required: true
       type: string
       paramType: form
     - name: parameter
       description: Parameter
       required: false
       type: string
       paramType: form
     """
     telnet = request.telnet
     data = request.data
     try:
         ftype, fid = data['type'], data['fid']
     except IndexError:
         raise MissingKeyError(
             'Missing parameter: type or fid required')
     ftype = ftype.lower()
     telnet.sendline('filter -a')
     telnet.expect(r'Adding a new Filter(.+)\n' + INTERACTIVE_PROMPT)
     ikeys = OrderedDict({'type': ftype, 'fid': fid})
     if ftype != 'transparentfilter':
         try:
             parameter = data['parameter']
         except MultiValueDictKeyError:
             raise MissingKeyError('%s filter requires parameter' % ftype)
         if ftype == 'connectorfilter':
             ikeys['cid'] = parameter
         elif ftype == 'userfilter':
             ikeys['uid'] = parameter
         elif ftype == 'groupfilter':
             ikeys['gid'] = parameter
         elif ftype == 'sourceaddrfilter':
             ikeys['source_addr'] = parameter
         elif ftype == 'destinationaddrfilter':
             ikeys['destination_addr'] = parameter
         elif ftype == 'shortmessagefilter':
             ikeys['short_message'] = parameter
         elif ftype == 'dateintervalfilter':
             ikeys['dateInterval'] = parameter
         elif ftype == 'timeintervalfilter':
             ikeys['timeInterval'] = parameter
         elif ftype == 'tagfilter':
             ikeys['tag'] = parameter
         elif ftype == 'evalpyfilter':
             ikeys['pyCode'] = parameter
     set_ikeys(telnet, ikeys)
     telnet.sendline('persist\n')
     telnet.expect(r'.*' + STANDARD_PROMPT)
     if settings.JASMIN_DOCKER:
         sync_conf_instances(request.telnet_list)
     return JsonResponse({'filter': self.get_filter(telnet, fid)})
Beispiel #23
0
 def create(self, request):
     """Create MTRouter.
     Required parameters: type, order, smppconnectors, httpconnectors
     More than one connector is allowed only for RandomRoundrobinMTRoute
     ---
     # YAML
     omit_serializer: true
     parameters:
     - name: type
       description: One of DefaultRoute, StaticMTRoute, RandomRoundrobinMTRoute
       required: true
       type: string
       paramType: form
     - name: order
       description: Router order, also used to identify router
       required: true
       type: string
       paramType: form
     - name: rate
       description: Router rate, may be zero for free
       required: true
       type: float
       paramType: form
     - name: smppconnectors
       description: List of SMPP connector ids.
       required: false
       type: array
       paramType: form
     - name: httpconnectors
       description: List of HTTP connector ids. 
       required: false
       type: array
       paramType: form
     - name: filters
       description: List of filters, required except for DefaultRoute
       required: false
       type: array
       paramType: form
     """
     telnet = request.telnet
     data = request.data
     try:
         rtype, order, rate = data['type'], data['order'], data['rate']
     except IndexError:
         raise MissingKeyError('Missing parameter: type or order required')
     rtype = rtype.lower()
     telnet.sendline('mtrouter -a')
     telnet.expect(r'Adding a new MT Route(.+)\n' + INTERACTIVE_PROMPT)
     ikeys = OrderedDict({'type': rtype})
     if rtype != 'defaultroute':
         try:
             filters = data['filters'].split(',')
         except MultiValueDictKeyError:
             raise MissingKeyError('%s router requires filters' % rtype)
         ikeys['filters'] = ';'.join(filters)
         ikeys['order'] = order
     smppconnectors = data.get('smppconnectors', '')
     httpconnectors = data.get('httpconnectors', '')
     connectors = [
         'smppc(%s)' % c.strip()
         for c in smppconnectors.split(',') if c.strip()
     ] + ['http(%s)' % c for c in httpconnectors.split(',') if c.strip()]
     if rtype == 'randomroundrobinmtroute':
         if len(connectors) < 2:
             raise MutipleValuesRequiredKeyError(
                 'Round Robin route requires at least two connectors')
         ikeys['connectors'] = ';'.join(connectors)
     else:
         if len(connectors) != 1:
             raise MissingKeyError('one and only one connector required')
         ikeys['connector'] = connectors[0]
     ikeys['rate'] = rate
     print ikeys
     set_ikeys(telnet, ikeys)
     telnet.sendline('persist\n')
     telnet.expect(r'.*' + STANDARD_PROMPT)
     if settings.JASMIN_DOCKER or settings.JASMIN_K8S:
         sync_conf_instances(request.telnet_list)
     return JsonResponse({'mtrouter': self.get_router(telnet, order)})
Beispiel #24
0
 def create(self, request):
     """Create Filter.
     Required parameters: type, fid, parameters
     ---
     # YAML
     omit_serializer: true
     parameters:
     - name: type
       description: One of TransparentFilter, ConnectorFilter, UserFilter, GroupFilter, SourceAddrFilter, DestinationAddrFilter, ShortMessageFilter, DateIntervalFilter, TimeIntervalFilter, TagFilter, EvalPyFilter
       required: true
       type: string
       paramType: form
     - name: fid
       description: Filter id, used to identify filter
       required: true
       type: string
       paramType: form
     - name: parameter
       description: Parameter
       required: false
       type: string
       paramType: form
     """
     telnet = request.telnet
     data = request.data
     try:
         ftype, fid = data['type'], data['fid']
     except IndexError:
         raise MissingKeyError(
             'Missing parameter: type or fid required')
     ftype = ftype.lower()
     telnet.sendline('filter -a')
     telnet.expect(r'Adding a new Filter(.+)\n' + INTERACTIVE_PROMPT)
     ikeys = OrderedDict({'type': ftype, 'fid': fid})
     if ftype != 'transparentfilter':
         try:
             parameter = data['parameter']
         except MultiValueDictKeyError:
             raise MissingKeyError('%s filter requires parameter' % ftype)
         if ftype == 'connectorfilter':
             ikeys['cid'] = parameter
         elif ftype == 'userfilter':
             ikeys['uid'] = parameter
         elif ftype == 'groupfilter':
             ikeys['gid'] = parameter
         elif ftype == 'sourceaddrfilter':
             ikeys['source_addr'] = parameter
         elif ftype == 'destinationaddrfilter':
             ikeys['destination_addr'] = parameter
         elif ftype == 'shortmessagefilter':
             ikeys['short_message'] = parameter
         elif ftype == 'dateintervalfilter':
             ikeys['dateInterval'] = parameter
         elif ftype == 'timeintervalfilter':
             ikeys['timeInterval'] = parameter
         elif ftype == 'tagfilter':
             ikeys['tag'] = parameter
         elif ftype == 'evalpyfilter':
             ikeys['pyCode'] = parameter
     set_ikeys(telnet, ikeys)
     telnet.sendline('persist\n')
     telnet.expect(r'.*' + STANDARD_PROMPT)
     if settings.JASMIN_DOCKER or settings.JASMIN_K8S:
         sync_conf_instances(request.telnet_list)
     return JsonResponse({'filter': self.get_filter(telnet, fid)})