示例#1
0
                            help='Need set new password')
        args = parser.parse_args()

        old_password = md5(args['password'].encode()).hexdigest()
        new_password = args.get('new_password', None)

        cred = Credentials.query.first()
        cred.name = args['login']

        # verify old password
        if new_password and not cred.password == old_password:
            return {
                'result_status': False,
                'message': 'Old password is invalid'
            }, 400
        elif new_password and cred.password == old_password:
            # set new_password
            cred.password = md5(new_password.encode()).hexdigest()

        connection.session.commit()

        # logout (maybe on client)
        return {
            'result_status': True,
            'message': 'Your account has been updated successfully'
        }


api.add_resource(SettingsAPI, '/settings')
api.add_resource(PasswordAPI, '/password')
示例#2
0
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from emcweb.emcweb_webapi.login_resource import LoginResource

from emcweb.emcweb_webapi.views import api
from emcweb.emcweb.utils import get_block_status


class BlocksAPI(LoginResource):
    @staticmethod
    def get():
        """
        Get blocks loading status
        """
        status, blocks, error_str = get_block_status()

        if error_str:
            return {'result_status': False, 'message': error_str}, 500

        return {
            'result_status': True,
            'result': {
                'blocks_ready': status,
                'blocks': blocks
            }
        }


api.add_resource(BlocksAPI, '/blocks')
示例#3
0
        if data.get('error', False):
            return {
                'result_status': False,
                'message': data['error']['message']
            }, 400

        address = data['result'][0]

        try:
            data = lc_client.call('post', '/payment/out/coin', {
                'amount': args['amount'],
                'currency': 'EMC',
                'wallet': address
            })

            if not data['amount']:
                return {
                    'result_status': False,
                    'message': 'Your payment has been declined'
                }, 400

            return {'result_status': True, 'result': 'Received'}
        except APIError:
            return {
                'result_status': False,
                'message': 'Your payment has been declined'
            }, 400


api.add_resource(LiveCoinAPI, '/live_coin')
示例#4
0
文件: emclnx.py 项目: Emercoin/emcweb
        connection.session.commit()

        return {'result_status': True, 'result': 'Created'}

    @staticmethod
    def delete(name):
        contract = Contracts.query.filter(Contracts.user_id == current_user.id, Contracts.name == name).first()
        if not contract:
            abort(404)

        nvs_name = 'lnx:{0}'.format(contract.name)

        nvs_data = client.name_show(nvs_name)
        if not nvs_data.get('error', False) \
                and not nvs_data['result'].get('deleted', False) \
                and not nvs_data['result'].get('transferred', False)\
                and nvs_is_mine(nvs_name):

            data = client.name_delete(nvs_name)
            if data.get('error', False):
                return {'result_status': False, 'message': data['error']['message']}, 400

        contract.txt.delete()
        connection.session.delete(contract)
        connection.session.commit()

        return {'result_status': True}


api.add_resource(EMCLNXAPI, '/emc_lnx', '/emc_lnx/<string:name>')
示例#5
0
文件: blocks.py 项目: Emercoin/emcweb
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from emcweb.emcweb_webapi.login_resource import LoginResource

from emcweb.emcweb_webapi.views import api
from emcweb.emcweb.utils import get_block_status


class BlocksAPI(LoginResource):

    @staticmethod
    def get():
        """
        Get blocks loading status
        """
        status, blocks, error_str = get_block_status()

        if error_str:
            return {'result_status': False, 'message': error_str}, 500

        return {'result_status': True, 'result': {'blocks_ready': status,
                                                  'blocks': blocks}}

api.add_resource(BlocksAPI, '/blocks')
示例#6
0
文件: emcssl.py 项目: Emercoin/emcweb
        resp = client.getinfo()
        if not resp.get('error', False) and resp['result']:
            ip = resp['result']['ip']

    return ip


def get_ovpn_content(pkey, crt):
    result = ''
    ovpn_file = os.path.join(os.path.dirname(__file__),
                             '..', '..', '..', 'settings',
                             'client.ovpn.example')
    with open(ovpn_file, mode='r') as o_f:
        result = o_f.read()

    if os.path.isdir('/etc/emervpn'):
        ip = get_ip_address()
        if ip:
            result = result.replace(r'%YOUR_EMERVPN_SERVER_IP%',
                                    ip)
    result = re.sub('<cert>.*</cert>',
                    '<cert>\n{}</cert>'.format(crt.decode()),
                    result, flags=re.S)
    result = re.sub('<key>.*</key>',
                    '<key>\n{}</key>'.format(pkey.decode()),
                    result, flags=re.S)
    return result


api.add_resource(EMCSSLAPI, '/certs', '/certs/<string:filename>')
示例#7
0
    def put():
        parser = reqparse.RequestParser()
        parser.add_argument('login', type=str, required=True, help='Need set login')
        parser.add_argument('password', type=str, required=False, help='Need set old password')
        parser.add_argument('new_password', type=str, required=False, help='Need set new password')
        args = parser.parse_args()

        old_password = md5(args['password'].encode()).hexdigest()
        new_password = args.get('new_password', None)

        cred = Credentials.query.first()
        cred.name = args['login']

        # verify old password
        if new_password and not cred.password == old_password:
            return {'result_status': False,
                    'message': 'Old password is invalid'}, 400
        elif new_password and cred.password == old_password:
            # set new_password
            cred.password = md5(new_password.encode()).hexdigest()

        connection.session.commit()

        # logout (maybe on client)
        return {'result_status': True,
                'message': 'Your account has been updated successfully'}


api.add_resource(SettingsAPI, '/settings')
api.add_resource(PasswordAPI, '/password')
示例#8
0
from emcweb.emcweb_webapi.views import api


class InfoAPI(LoginResource):
    @staticmethod
    def get():
        info = client.getinfo()
        if info.get('error', False):
            return {
                'result_status': False,
                'message': info['error']['message']
            }, 400

        infodif = client.getdifficulty()
        if infodif.get('error', False):
            return {
                'result_status': False,
                'message': infodif['error']['message']
            }, 400

        return {
            'result_status': True,
            'result': {
                'info': info['result'],
                'infodif': infodif['result']
            }
        }


api.add_resource(InfoAPI, '/info')
示例#9
0
        return {'result_status': True, 'result': 'Uploaded'}, 201

    @staticmethod
    def put(filename):
        """
        Sets selecting wallet as active
        """
        try:
            result = change_wallet.delay(filename)
        except Exception:
            return {
                'result_status': False,
                'message': 'Celery transport connection refused'
            }, 500
        for i in range(60):
            if result.ready():
                time.sleep(10)
                return {'result_status': True, 'result': 'Wallet changed'}
            time.sleep(1)

        time.sleep(10)

        return {
            'result_status': False,
            'message': 'Celery hasn\'t reported about finish'
        }, 500


api.add_resource(WalletsAPI, '/wallets', '/wallets/<string:filename>')
示例#10
0
                transaction['time']).strftime('%Y-%m-%d %H:%M:%S')
            if 'address' not in transaction:
                transaction['address'] = 'Network fee'

        return {'result_status': True, 'result': transactions}

    @staticmethod
    def post():
        parser = reqparse.RequestParser()
        parser.add_argument('address',
                            required=True,
                            help='Andress must be set',
                            type=str)
        parser.add_argument('amount',
                            required=True,
                            help='Amount must be set',
                            type=float)
        args = parser.parse_args()

        data = client.sendtoaddress(args.address, args.amount)
        if data.get('error', False):
            error = 'Your payment has been declined' if data['error']['message'] == 'Insufficient funds' else \
                data['error']['message']

            return {'result_status': False, 'message': error}, 400

        return {'result_status': True, 'result': 'Sent'}


api.add_resource(TransactionsAPI, '/transactions')
示例#11
0
from emcweb.emcweb_webapi.views import api


class AddressAPI(LoginResource):

    @staticmethod
    def get():
        """
        Get addresses
        """
        data = client.getaddressesbyaccount('')

        if data.get('error', False):
            return {'result_status': False, 'message': data['error']['message']}, 400

        return {'result_status': True, 'result': data['result']}

    @staticmethod
    def post():
        """
        Create new address
        """
        data = client.getnewaddress()
        if data.get('error', False):
            return {'result_status': False, 'message': data['error']['message']}, 400

        return {'result_status': True, 'result': data['result']}


api.add_resource(AddressAPI, '/address')
from emcweb.emcweb_webapi.login_resource import LoginResource

from emcweb.emcweb_webapi.views import api


class BackupListAPI(LoginResource):
    @staticmethod
    def get():
        backup_modules = dict()
        for backup_module in current_app.config.get('BACKUP_MODULES', []):
            backup_modules[backup_module] = importlib.import_module(
                'emcweb.emcweb.backups.%s' % backup_module)

        if not backup_modules:
            return {
                'result_status': False,
                'message': 'Not found any backup modules'
            }

        return {
            'result_status':
            True,
            'result': [{
                'title': value.__name__,
                'module': key
            } for key, value in backup_modules.items()]
        }


api.add_resource(BackupListAPI, '/backup_list')
示例#13
0
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from emcweb.emcweb_webapi.login_resource import LoginResource

from emcweb.emcweb_webapi.utils import client
from emcweb.emcweb_webapi.views import api


class BalanceAPI(LoginResource):

    @staticmethod
    def get():
        data = client.getbalance()
        if data.get('error', False):
            return {'result_status': False, 'message': data['error']['message']}, 400

        return {'result_status': True, 'result': float(format(data['result'], '.8f')) if data['result'] else 0}


api.add_resource(BalanceAPI, '/balance')
示例#14
0
                                   '/etc/emercoin/emcssh.keys.d'),
            current_app.config.get('EMERVPN_EMCSSH', 'emervpn'))
        try:
            create_res = save_to_file.delay(emervpn_keys, args.data)
        except Exception:
            return {
                'result_status': False,
                'message': 'Celery transport connection refused'
            }, 400
        else:
            seconds = 200
            while seconds > 0:
                if create_res.ready():
                    result = create_res.result
                    if result['result_status']:
                        return result
                    else:
                        return result, 400
                    break
                time.sleep(1)
                seconds -= 1
            return {
                'result_status': False,
                'message': 'Celery hasn\'t reported about finish'
            }, 400

        return {'result_status': True, 'result': 'Saved'}


api.add_resource(EMERVPNAPI, '/emervpn')
示例#15
0
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from emcweb.emcweb_webapi.login_resource import LoginResource

from emcweb.emcweb_webapi.utils import client
from emcweb.emcweb_webapi.views import api


class BalanceAPI(LoginResource):
    @staticmethod
    def get():
        data = client.getbalance()
        if data.get('error', False):
            return {
                'result_status': False,
                'message': data['error']['message']
            }, 400

        return {
            'result_status': True,
            'result':
            float(format(data['result'], '.8f')) if data['result'] else 0
        }


api.add_resource(BalanceAPI, '/balance')
示例#16
0
        except FileNotFoundError:
            return {'result_status': False, 'message': 'File not found'}, 400

        return {'result_status': True, 'result': emcssh_keys_text}

    @staticmethod
    def post():
        parser = reqparse.RequestParser()
        parser.add_argument('data', required=False, type=str, default='')
        args = parser.parse_args()

        emcssh_keys = os.path.join(current_app.config.get('EMCSSH_KEYS_DIR', '/etc/emercoin/emcssh.keys.d'),
                                   current_app.config.get('EMCSSH_VERIFY_USER', 'emc'))

        try:
            with open(emcssh_keys, 'w') as f:
                f.write(args.data)
        except FileNotFoundError:
            return {'result_status': False, 'message': 'Emcssh file doesn\'t found'}, 400
        except PermissionError:
            return {'result_status': False, 'message': 'Emcssh file permission denied'}, 400
        except IsADirectoryError:
            return {'result_status': False, 'message': 'Emcssh file is a directory'}, 400
        except OSError:
            return {'result_status': False, 'message': 'Emcssh file access problem'}, 400

        return {'result_status': True, 'result': 'Saved'}


api.add_resource(EMCSSHAPI, '/emc_ssh')
示例#17
0
        parser = reqparse.RequestParser()
        parser.add_argument('data', required=False, type=str, default='')
        args = parser.parse_args()

        emervpn_keys = os.path.join(current_app.config.get('EMCSSH_KEYS_DIR',
                                                          '/etc/emercoin/emcssh.keys.d'),
                                    current_app.config.get('EMERVPN_EMCSSH',
                                                          'emervpn'))
        try:
            create_res = save_to_file.delay(emervpn_keys, args.data)
        except Exception:
            return {'result_status': False, 'message': 'Celery transport connection refused'}, 400
        else:
            seconds = 200
            while seconds > 0:
                if create_res.ready():
                    result = create_res.result
                    if result['result_status']:
                        return result
                    else:
                        return result, 400
                    break
                time.sleep(1)
                seconds -= 1
            return {'result_status': False, 'message': 'Celery hasn\'t reported about finish'}, 400

        return {'result_status': True, 'result': 'Saved'}


api.add_resource(EMERVPNAPI, '/emervpn')
示例#18
0
        parser.add_argument('address',
                            type=str,
                            required=False,
                            help='Need set address')
        parser.add_argument('typeOfData',
                            type=str,
                            required=False,
                            help='Need set type of data')
        args = parser.parse_args()

        addr = args.address if args.address else ''
        datatype = ''
        if args.typeOfData and not args.typeOfData == 'utf8':
            datatype = args.typeOfData
        params = [args.name, args.value, args.days, addr, datatype]

        data = client.name_update(*params)
        if data.get('error', False):
            return {
                'result_status': False,
                'message': data['error']['message']
            }, 400

        return {
            'result_status': True,
            'message': 'Name updated: {}'.format(data['result'])
        }


api.add_resource(NVSAPI, '/nvs')
示例#19
0
文件: email.py 项目: Emercoin/emcweb
            with open(template_path, 'r') as f:
                template_text = f.read()
        except FileNotFoundError:
            return {'result_status': False, 'message': 'Template doesn\'t found'}, 400
        except PermissionError:
            return {'result_status': False, 'message': 'Template permission denied'}, 400
        except IsADirectoryError:
            return {'result_status': False, 'message': 'Template is a directory'}, 400
        except OSError:
            return {'result_status': False, 'message': 'Template unknown error'}, 400

        try:
            template = Template(template_text)
            data = template.render(message=args.get('message', ''),
                                   amount=args.get('amount'),
                                   address=args.get('address'))
        except TemplateSyntaxError:
            return {'result_status': False, 'message': 'Template syntax error'}, 400
        except TemplateError:
            return {'result_status': False, 'message': 'Template render error'}, 400

        try:
            sendmail.delay(args.email, data)
        except Exception:
            return {'result_status': False, 'message': 'Celery transport connection refused'}, 500

        return {'result_status': True, 'result': 'Task created'}


api.add_resource(EmailAPI, '/email')
示例#20
0
        data = client.listtransactions()
        if data.get('error', False):
            return {'result_status': False, 'message': data['error']['message']}, 400

        transactions = data['result'] if data['result'] else []
        for transaction in transactions:
            transaction['sexy_time'] = datetime.fromtimestamp(transaction['time']).strftime('%Y-%m-%d %H:%M:%S')
            if 'address' not in transaction:
                transaction['address'] = 'Network fee'

        return {'result_status': True, 'result': transactions}

    @staticmethod
    def post():
        parser = reqparse.RequestParser()
        parser.add_argument('address', required=True, help='Andress must be set', type=str)
        parser.add_argument('amount', required=True, help='Amount must be set', type=float)
        args = parser.parse_args()

        data = client.sendtoaddress(args.address, args.amount)
        if data.get('error', False):
            error = 'Your payment has been declined' if data['error']['message'] == 'Insufficient funds' else \
                data['error']['message']

            return {'result_status': False, 'message': error}, 400

        return {'result_status': True, 'result': 'Sent'}


api.add_resource(TransactionsAPI, '/transactions')
示例#21
0
        parser = reqparse.RequestParser()
        parser.add_argument('amount', required=True, help='Amount must bu set', type=float)
        args = parser.parse_args()

        lc_client = LiveCoinClient(current_app.config.get('LIVECOIN_API_KEY', ''),
                                   current_app.config.get('LIVECOIN_SECRET_KEY', ''))

        data = client.getaddressesbyaccount('')
        if data.get('error', False):
            return {'result_status': False, 'message': data['error']['message']}, 400

        address = data['result'][0]

        try:
            data = lc_client.call('post', '/payment/out/coin', {
                'amount': args['amount'],
                'currency': 'EMC',
                'wallet': address
            })

            if not data['amount']:
                return {'result_status': False, 'message': 'Your payment has been declined'}, 400

            return {'result_status': True, 'result': 'Received'}
        except APIError:
            return {'result_status': False, 'message': 'Your payment has been declined'}, 400


api.add_resource(LiveCoinAPI, '/live_coin')
示例#22
0
文件: info.py 项目: Emercoin/emcweb
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from emcweb.emcweb_webapi.login_resource import LoginResource
from emcweb.emcweb_webapi.utils import client
from emcweb.emcweb_webapi.views import api


class InfoAPI(LoginResource):
    @staticmethod
    def get():
        info = client.getinfo()
        if info.get('error', False):
            return {'result_status': False, 'message': info['error']['message']}, 400

        infodif = client.getdifficulty()
        if infodif.get('error', False):
            return {'result_status': False, 'message': infodif['error']['message']}, 400

        return {'result_status': True, 'result': {'info': info['result'], 'infodif': infodif['result']}}


api.add_resource(InfoAPI, '/info')
示例#23
0
    @staticmethod
    def post():
        parser = reqparse.RequestParser()
        parser.add_argument('address', required=True, help='Address must be set')
        parser.add_argument('message', required=True, help='Message must be set')
        args = parser.parse_args()

        data = client.signmessage(args['address'], args['message'])
        if data.get('error', False):
            return {'result_status': False, 'message': data['error']['message']}, 400

        return {'result_status': True, 'result': data['result']}

    @staticmethod
    def get():
        parser = reqparse.RequestParser()
        parser.add_argument('address', required=True, help='Address must be set')
        parser.add_argument('signature', required=True, help='Signature must be set')
        parser.add_argument('message', required=True, help='Message must be set')
        args = parser.parse_args()

        data = client.verifymessage(args['address'], args['signature'], args['message'])
        if data.get('error', False):
            return {'result_status': False, 'message': data['error']['message']}, 400

        return {'result_status': True, 'result': data['result']}


api.add_resource(MessagesAPI, '/messages')
示例#24
0
        new_wallet = Wallets(user_id=current_user.id,
                             name=secure_filename(args['filename']),
                             path=file_path)
        connection.session.add(new_wallet)
        connection.session.commit()

        return {'result_status': True, 'result': 'Uploaded'}, 201

    @staticmethod
    def put(filename):
        """
        Sets selecting wallet as active
        """
        try:
            result = change_wallet.delay(filename)
        except Exception:
            return {'result_status': False, 'message': 'Celery transport connection refused'}, 500
        for i in range(60):
            if result.ready():
                time.sleep(10)
                return {'result_status': True, 'result': 'Wallet changed'}
            time.sleep(1)

        time.sleep(10)

        return {'result_status': False, 'message': 'Celery hasn\'t reported about finish'}, 500


api.add_resource(WalletsAPI, '/wallets', '/wallets/<string:filename>')
示例#25
0
    @staticmethod
    def delete(name):
        contract = Contracts.query.filter(Contracts.user_id == current_user.id,
                                          Contracts.name == name).first()
        if not contract:
            abort(404)

        nvs_name = 'lnx:{0}'.format(contract.name)

        nvs_data = client.name_show(nvs_name)
        if not nvs_data.get('error', False) \
                and not nvs_data['result'].get('deleted', False) \
                and not nvs_data['result'].get('transferred', False)\
                and nvs_is_mine(nvs_name):

            data = client.name_delete(nvs_name)
            if data.get('error', False):
                return {
                    'result_status': False,
                    'message': data['error']['message']
                }, 400

        contract.txt.delete()
        connection.session.delete(contract)
        connection.session.commit()

        return {'result_status': True}


api.add_resource(EMCLNXAPI, '/emc_lnx', '/emc_lnx/<string:name>')
示例#26
0
文件: nvs.py 项目: Emercoin/emcweb
        data = client.name_delete(args.name)
        if data.get('error', False):
            return {'result_status': False, 'message': data['error']['message']}, 400

        return {'result_status': True, 'message': 'Name deleted: {}'.format(data['result'])}

    @staticmethod
    def put():
        parser = reqparse.RequestParser()
        parser.add_argument('name', type=str, required=True, help='Need set name')
        parser.add_argument('value', type=str, required=True, help='Need set value')
        parser.add_argument('days', type=int, required=True, help='Need set days')
        parser.add_argument('address', type=str, required=False, help='Need set address')
        parser.add_argument('typeOfData', type=str, required=False, help='Need set type of data')
        args = parser.parse_args()

        addr = args.address if args.address else ''
        datatype = ''
        if args.typeOfData and not args.typeOfData=='utf8':
            datatype = args.typeOfData
        params = [args.name, args.value, args.days, addr, datatype]
        
        data = client.name_update(*params)
        if data.get('error', False):
            return {'result_status': False, 'message': data['error']['message']}, 400

        return {'result_status': True, 'message': 'Name updated: {}'.format(data['result'])}


api.add_resource(NVSAPI, '/nvs')
                'result_status': False,
                'message': 'File create problems'
            }, 400

        return {'result_status': True, 'result': 'Saved'}

    @staticmethod
    def delete():
        parser = reqparse.RequestParser()
        parser.add_argument('name',
                            required=True,
                            type=str,
                            help='Name must be set')
        args = parser.parse_args()

        emcssh_key = os.path.join(
            current_app.config.get('EMCSSH_KEYS_DIR',
                                   '/etc/emercoin/emcssh.keys.d'), args.name)
        try:
            os.unlink(emcssh_key)
        except OSError:
            return {
                'result_status': False,
                'message': 'File remove problems'
            }, 400

        return {'result_status': True, 'result': 'Deleted'}


api.add_resource(EMCSSHUsersAPI, '/emc_ssh_users')
示例#28
0
    @staticmethod
    def put():
        parser = reqparse.RequestParser()
        parser.add_argument('pass', required=True, help='Password')
        args = parser.parse_args()

        filename = os.path.basename(os.path.realpath(os.path.join(current_app.config['EMC_HOME'], 'wallet.dat')))
        data = client.encryptwallet(args['pass'])

        if data.get('error', False):
            return {'result_status': False, 'message': data['error']['message']}, 400

        time.sleep(10)
        try:
            result = make_wallet_link_encrypt.delay(filename)
        except Exception:
            return {'result_status': False, 'message': 'Celery transport connection refused'}, 500
        for i in range(60):
            if result.ready():
                time.sleep(10)
                return {'result_status': True}
            time.sleep(1)

        time.sleep(10)

        return {'result_status': True}


api.add_resource(EncryptAPI, '/encrypt')
示例#29
0
        parser.add_argument('data', required=False, type=str, default='')
        args = parser.parse_args()

        emcssh_key = os.path.join(current_app.config.get('EMCSSH_KEYS_DIR', '/etc/emercoin/emcssh.keys.d'),
                                  args.name)
        try:
            with open(emcssh_key, 'w') as f:
                f.write(args.data)
        except OSError:
            return {'result_status': False, 'message': 'File create problems'}, 400

        return {'result_status': True, 'result': 'Saved'}

    @staticmethod
    def delete():
        parser = reqparse.RequestParser()
        parser.add_argument('name', required=True, type=str, help='Name must be set')
        args = parser.parse_args()

        emcssh_key = os.path.join(current_app.config.get('EMCSSH_KEYS_DIR', '/etc/emercoin/emcssh.keys.d'),
                                  args.name)
        try:
            os.unlink(emcssh_key)
        except OSError:
            return {'result_status': False, 'message': 'File remove problems'}, 400

        return {'result_status': True, 'result': 'Deleted'}


api.add_resource(EMCSSHUsersAPI, '/emc_ssh_users')
示例#30
0
        resp = client.getinfo()
        if not resp.get('error', False) and resp['result']:
            ip = resp['result']['ip']

    return ip


def get_ovpn_content(pkey, crt):
    result = ''
    ovpn_file = os.path.join(os.path.dirname(__file__), '..', '..', '..',
                             'settings', 'client.ovpn.example')
    with open(ovpn_file, mode='r') as o_f:
        result = o_f.read()

    if os.path.isdir('/etc/emervpn'):
        ip = get_ip_address()
        if ip:
            result = result.replace(r'%YOUR_EMERVPN_SERVER_IP%', ip)
    result = re.sub('<cert>.*</cert>',
                    '<cert>\n{}</cert>'.format(crt.decode()),
                    result,
                    flags=re.S)
    result = re.sub('<key>.*</key>',
                    '<key>\n{}</key>'.format(pkey.decode()),
                    result,
                    flags=re.S)
    return result


api.add_resource(EMCSSLAPI, '/certs', '/certs/<string:filename>')
示例#31
0
            }, 400

        try:
            template = Template(template_text)
            data = template.render(message=args.get('message', ''),
                                   amount=args.get('amount'),
                                   address=args.get('address'))
        except TemplateSyntaxError:
            return {
                'result_status': False,
                'message': 'Template syntax error'
            }, 400
        except TemplateError:
            return {
                'result_status': False,
                'message': 'Template render error'
            }, 400

        try:
            sendmail.delay(args.email, data)
        except Exception:
            return {
                'result_status': False,
                'message': 'Celery transport connection refused'
            }, 500

        return {'result_status': True, 'result': 'Task created'}


api.add_resource(EmailAPI, '/email')
示例#32
0
import importlib

from flask import current_app
from emcweb.emcweb_webapi.login_resource import LoginResource

from emcweb.emcweb_webapi.views import api


class BackupListAPI(LoginResource):

    @staticmethod
    def get():
        backup_modules = dict()
        for backup_module in current_app.config.get('BACKUP_MODULES', []):
            backup_modules[backup_module] = importlib.import_module('emcweb.emcweb.backups.%s' % backup_module)

        if not backup_modules:
            return {
                'result_status': False,
                'message': 'Not found any backup modules'
            }

        return {
            'result_status': True,
            'result': [{'title': value.__name__, 'module': key} for key, value in backup_modules.items()]
        }


api.add_resource(BackupListAPI, '/backup_list')