Example #1
0
    def add_ignore(self, mobile=None, item_id=None):
        """
        Ignore and release a mobile phone number.

        :param mobile:
        :param item_id:
        :return:
        """
        mobile = mobile or self._mobile
        item_id = item_id or self._item_id
        if self._cli:
            cp.about_t('IGNORE and RELEASE mobile phone number', mobile)

        if self._get_success({
            'action': 'addignore',
            'token': self._token,
            'itemid': item_id,
            'mobile': mobile,
            'release': 1,
        }):
            if self._cli:
                cp.success('Okay.')
            self._mobile = None
            return True

        return
Example #2
0
    def release_mobile(self, mobile=None, item_id=None):
        """
        Release a mobile phone number.

        :param mobile:
        :param item_id:
        :return:
        """
        mobile = mobile or self._mobile
        item_id = item_id or self._item_id

        if self._cli:
            cp.about_t('Releasing the mobile phone number', mobile)

        # release the mobile phone number
        if self._get_success({
            'action': 'release',
            'token': self._token,
            'itemid': item_id,
            'mobile': mobile,
        }):
            if self._cli:
                cp.success('Done.')
            self._mobile = None
            return True

        return
Example #3
0
    def __is_port_open(port: int):
        cp.about_t('Checking', 'local port #.{}'.format(port))

        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        try:
            s.connect(('127.0.0.1', port))
            s.shutdown(2)
            cp.success('is open')
            return True
        except:
            cp.success('is down')
            return False
Example #4
0
    def write_config_file(self, path_to_file=None, by_ip: bool = False, plain_to_console: bool = False):
        # check attributes
        if self.invalid_attributes:
            return None

        if path_to_file:
            self._path_to_ssr_conf = path_to_file

        cp.about_t('Generating', self.path_to_ssr_conf, 'for shadowsocksr')
        with open(self.path_to_ssr_conf, 'wb') as f:
            json_string = self.get_config_json_string(by_ip=by_ip)
            f.write(json_string.encode('utf-8'))
            cp.success()
            if plain_to_console:
                cp.plain_text(json_string)
Example #5
0
    def __ip_query(self, hint: str):
        cp.about_t('Start a sub progress of SSR', hint)

        # sub progress
        self._sub_progress = subprocess.Popen(
            self._cmd.split(),
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE,
            preexec_fn=os.setsid,
        )

        # Group PID
        gpid = os.getpgid(self._sub_progress.pid)
        cp.wr(cp.Fore.LIGHTYELLOW_EX +
              '(G)PID {}:{} '.format(gpid, self.local_port))

        # wait, during the progress launching.
        for i in range(0, 5):
            cp.wr(cp.Fore.LIGHTBLUE_EX + '.')
            cp.fi()
            time.sleep(1)
        cp.success(' Next.')

        # Request for IP
        ip = None
        try:
            cp.about_t('Try to request for the IP address')

            ip = ip_query.ip_query(requests_proxies=proxy_fn.requests_proxies(
                host=self.local_address,
                port=self.local_port,
            ))

            if ip:
                cp.success('{} {}'.format(ip['ip'], ip['country']))
            else:
                cp.fx()

        except Exception as e:
            # ConnectionError?
            cp.fx()
            cp.error(e)

        finally:
            cp.about_t('Kill SSR sub progress', 'PID {pid}'.format(pid=gpid))
            os.killpg(gpid, 9)
            cp.success('Done.')

        if ip:
            self._exit_ip = ip
            return ip

        return None
Example #6
0
 def __remove_ssr_conf(self):
     cp.about_t('Deleting', self.path_to_ssr_conf, 'config file')
     os.remove(self.path_to_ssr_conf)
     cp.success()
Example #7
0
#!/usr/bin/env python
# encoding: utf-8

import cli_print as cp

cp.success()