Exemplo n.º 1
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)
        return JsonResponse({'user': self.get_user(telnet, uid)})
Exemplo n.º 2
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)

        return JsonResponse(
            {'connector': self.get_smppccm(telnet, cid, silent=False)})
Exemplo n.º 3
0
 def simple_mtrouter_action(self, action, order, return_mtroute=True):
     self.telnet.sendline('mtrouter -%s %s' % (action, order))
     matched_index = self.telnet.expect([
         r'.+Successfully(.+)' + STANDARD_PROMPT,
         r'.+Unknown MT Route: (.+)' + STANDARD_PROMPT,
         r'.+(.*)' + STANDARD_PROMPT,
     ])
     if matched_index == 0:
         self.telnet.sendline('persist\n')
         if return_mtroute:
             self.telnet.expect(r'.*' + STANDARD_PROMPT)
             return {'mtrouter': self.get_router(fid)}
         else:
             return {'order': order}
     elif matched_index == 1:
         raise UnknownError(detail='No router:' +  order)
     else:
         raise JasminError(self.telnet.match.group(1))
Exemplo n.º 4
0
 def simple_user_action(self, telnet, 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 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))
Exemplo n.º 5
0
 def simple_filter_action(self, action, fid, return_filter=True):
     self.telnet.sendline('filter -%s %s' % (action, fid))
     matched_index = self.telnet.expect([
         r'.+Successfully(.+)' + STANDARD_PROMPT,
         r'.+Unknown Filter: (.+)' + STANDARD_PROMPT,
         r'.+(.*)' + STANDARD_PROMPT,
     ])
     if matched_index == 0:
         self.telnet.sendline('persist\n')
         if return_filter:
             self.telnet.expect(r'.*' + STANDARD_PROMPT)
             return {'filter': self.get_filter(fid)}
         else:
             return {'fid': fid}
     elif matched_index == 1:
         raise UnknownError(detail='No filter:' + fid)
     else:
         raise JasminError(self.telnet.match.group(1))