Esempio n. 1
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))
Esempio n. 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)})
Esempio n. 3
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))
Esempio n. 4
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
        """
        for telnet in request.telnet_list:
            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)

        return JsonResponse({
            'connector':
            self.get_smppccm(request.telnet_list[0], cid, silent=False)
        })
Esempio n. 5
0
 def simple_filter_action(self, telnet, action, fid, return_filter=True):
     telnet.sendline('filter -%s %s' % (action, fid))
     matched_index = telnet.expect([
         r'.+Successfully(.+)' + STANDARD_PROMPT,
         r'.+Unknown Filter: (.+)' + STANDARD_PROMPT,
         r'.+(.*)' + STANDARD_PROMPT,
     ])
     if matched_index == 0:
         telnet.sendline('persist\n')
         if return_filter:
             telnet.expect(r'.*' + STANDARD_PROMPT)
             return JsonResponse({'filter': self.get_filter(telnet, fid)})
         else:
             return JsonResponse({'fid': fid})
     elif matched_index == 1:
         raise UnknownError(detail='No filter:' +  fid)
     else:
         raise JasminError(telnet.match.group(1))
Esempio n. 6
0
 def simple_morouter_action(self, telnet, action, order, return_moroute=True):
     telnet.sendline('morouter -%s %s' % (action, order))
     matched_index = telnet.expect([
         r'.+Successfully(.+)' + STANDARD_PROMPT,
         r'.+Unknown MO Route: (.+)' + STANDARD_PROMPT,
         r'.+(.*)' + STANDARD_PROMPT,
     ])
     if matched_index == 0:
         telnet.sendline('persist\n')
         if return_moroute:
             telnet.expect(r'.*' + STANDARD_PROMPT)
             return JsonResponse({'morouter': self.get_router(telnet, fid)})
         else:
             return JsonResponse({'order': order})
     elif matched_index == 1:
         raise UnknownError(detail='No router:' +  order)
     else:
         raise JasminError(telnet.match.group(1))