Exemplo n.º 1
0
def panel_public():
    get = get_input();
    get.client_ip = public.GetClientIp();

    if get.fun in ['scan_login','login_qrcode','set_login','is_scan_ok','blind']:
        #检查是否验证过安全入口
        if get.fun in ['login_qrcode','is_scan_ok']:
            global admin_check_auth,admin_path,route_path,admin_path_file
            if admin_path != '/bt' and os.path.exists(admin_path_file) and  not 'admin_auth' in session: return 'False'
        import wxapp
        pluwx = wxapp.wxapp()
        checks = pluwx._check(get)
        if type(checks) != bool or not checks: return public.getJson(checks),json_header
        data = public.getJson(eval('pluwx.'+get.fun+'(get)'))
        return data,json_header
    
    import panelPlugin
    plu = panelPlugin.panelPlugin()
    get.s = '_check';
        
    checks = plu.a(get)
    if type(checks) != bool or not checks: return public.getJson(checks),json_header
    get.s = get.fun
    comm.setSession()
    comm.init()
    comm.checkWebType()
    comm.GetOS()
    result = plu.a(get)
    return public.getJson(result),json_header
Exemplo n.º 2
0
 def pobject(self):
     get = web.input()
     if not os.path.exists('/www/server/panel/plugin/webhook'):
         return public.getJson(public.returnMsg(False, '请先安装WebHook组件!'))
     sys.path.append('/www/server/panel/plugin/webhook')
     import webhook_main
     return public.getJson(webhook_main.webhook_main().RunHook(get))
Exemplo n.º 3
0
    def getDataListApi(self):
        stype = request.form.get('type', '').encode('utf-8')
        if stype == 'databases':
            db_list = {}
            db_list['orderOpt'] = []
            path = public.getServerDir() + '/mysql'
            if not os.path.exists(path + '/mysql.db'):
                db_list['data'] = []
            else:
                db_list['data'] = public.M('databases').dbPos(
                    path, 'mysql').field('name,ps').select()
            return public.getJson(db_list)

        data = {}
        data['data'] = public.M(stype).field('name,ps').select()
        data['orderOpt'] = []
        # try:
        #     tmp = public.readFile('data/libList.conf')
        #     libs = json.loads(tmp)
        #     import imp
        #     for lib in libs:
        #         imp.find_module(lib['module'])
        #         tmp = {}
        #         tmp['name'] = lib['name']
        #         tmp['value'] = lib['opt']
        #         data['orderOpt'].append(tmp)
        # except Exception as e:
        #     print e
        return public.getJson(data)
Exemplo n.º 4
0
def panel_public():
    get = get_input()
    get.client_ip = public.GetClientIp()
    if get.fun in [
            'scan_login', 'login_qrcode', 'set_login', 'is_scan_ok', 'blind'
    ]:
        import wxapp
        pluwx = wxapp.wxapp()
        checks = pluwx._check(get)
        if type(checks) != bool or not checks:
            return public.getJson(checks), json_header
        data = public.getJson(eval('pluwx.' + get.fun + '(get)'))
        return data, json_header

    import panelPlugin
    plu = panelPlugin.panelPlugin()
    get.s = '_check'

    checks = plu.a(get)
    if type(checks) != bool or not checks:
        return public.getJson(checks), json_header
    get.s = get.fun
    comm.setSession()
    comm.init()
    comm.checkWebType()
    comm.GetOS()
    result = plu.a(get)
    return public.getJson(result), json_header
Exemplo n.º 5
0
def panel_hook():
    get = get_input()
    if not os.path.exists('plugin/webhook'):
        return public.getJson(public.returnMsg(False, 'INIT_WEBHOOK_ERR'))
    sys.path.append('plugin/webhook')
    import webhook_main
    return public.getJson(webhook_main.webhook_main().RunHook(get))
Exemplo n.º 6
0
    def RequestFun(self):
        get = web.input()
        get.client_ip = web.ctx.ip
        if get.fun in [
                'scan_login', 'login_qrcode', 'set_login', 'is_scan_ok',
                'blind'
        ]:
            import wxapp
            pluwx = wxapp.wxapp()
            checks = pluwx._check(get)
            if type(checks) != bool or not checks:
                return public.getJson(checks)
            data = public.getJson(eval('pluwx.' + get.fun + '(get)'))
            return data

        import panelPlugin
        plu = panelPlugin.panelPlugin()
        get.s = '_check'

        checks = plu.a(get)
        if type(checks) != bool or not checks: return public.getJson(checks)
        get.s = get.fun
        self.SetSession()
        result = plu.a(get)
        return public.getJson(result)
Exemplo n.º 7
0
 def RequestFun(self):
     get = web.input()
     import panelPlugin
     plu = panelPlugin.panelPlugin()
     get.s = '_check'
     get.client_ip = web.ctx.ip
     checks = plu.a(get)
     if type(checks) != bool: return public.getJson(checks)
     get.s = get.fun
     result = plu.a(get)
     return public.getJson(result)
Exemplo n.º 8
0
def panel_safe():
    get = get_input()
    pluginPath = 'plugin/safelogin'
    if hasattr(get, 'check'):
        if os.path.exists(pluginPath + '/safelogin_main.py'): return 'True'
        return 'False'
    get.data = check_token(get.data)
    if not get.data: return public.returnJson(False, 'INIT_CHECK_ERR')
    comm.setSession()
    comm.init()
    comm.checkWebType()
    comm.GetOS()
    sys.path.append(pluginPath)
    import safelogin_main
    reload(safelogin_main)
    s = safelogin_main.safelogin_main()
    if not hasattr(s, get.data['action']):
        return public.returnJson(False, 'INIT_FUN_NOT_EXISTS')
    defs = ('GetServerInfo', 'add_ssh_limit', 'remove_ssh_limit',
            'get_ssh_limit', 'get_login_log', 'get_panel_limit',
            'add_panel_limit', 'remove_panel_limit', 'close_ssh_limit',
            'close_panel_limit', 'get_system_info', 'get_service_info',
            'get_ssh_errorlogin')
    if not get.data['action'] in defs: return 'False'
    return public.getJson(eval('s.' + get.data['action'] + '(get)'))
Exemplo n.º 9
0
    def POST(self):
        get = web.input(zunfile = {},data = [])
        if hasattr(get,'path'):
            get.path = get.path.replace('//','/').replace('\\','/');

        import files
        filesObject = files.files()
        defs = (
            'UploadFile',
            'GetDir',
            'CreateFile',
            'CreateDir',
            'DeleteDir',
            'DeleteFile',
            'CopyFile',
            'CopyDir',
            'MvFile',
            'GetFileBody',
            'SaveFileBody',
            'Zip',
            'UnZip',
            'GetFileAccess',
            'SetFileAccess',
            'GetDirSize',
            'SetBatchData',
            'BatchPaste',
            'DownloadFile',
            'setPassword'
            )
        for key in defs:
            if key == get.action:
                fun = 'filesObject.'+key+'(get)'
                return public.getJson(eval(fun))

        return public.returnJson(False,'Invalid specified parameter!')
Exemplo n.º 10
0
    def getDir(self, path, page=1, page_size=10, search=None):
        data = {}
        dirnames = []
        filenames = []

        info = {}
        info['count'] = self.getCount(path, search)
        info['row'] = page_size
        info['p'] = page
        info['tojs'] = 'getFiles'
        pageObj = public.getPageObject(info, '1,2,3,4,5,6,7,8')
        data['PAGE'] = pageObj[0]

        i = 0
        n = 0
        for filename in os.listdir(path):
            if search:
                if filename.lower().find(search) == -1:
                    continue
            i += 1
            if n >= pageObj[1].ROW:
                break
            if i < pageObj[1].SHIFT:
                continue

            try:
                filePath = (path + '/' + filename).encode('utf8')
                link = ''
                if os.path.islink(filePath):
                    filePath = os.readlink(filePath)
                    link = ' -> ' + filePath
                    if not os.path.exists(filePath):
                        filePath = path + '/' + filePath
                    if not os.path.exists(filePath):
                        continue

                stat = os.stat(filePath)
                accept = str(oct(stat.st_mode)[-3:])
                mtime = str(int(stat.st_mtime))
                user = ''
                try:
                    user = pwd.getpwuid(stat.st_uid).pw_name
                except:
                    user = str(stat.st_uid)
                size = str(stat.st_size)
                if os.path.isdir(filePath):
                    dirnames.append(filename + ';' + size + ';' +
                                    mtime + ';' + accept + ';' + user + ';' + link)
                else:
                    filenames.append(filename + ';' + size + ';' +
                                     mtime + ';' + accept + ';' + user + ';' + link)
                n += 1
            except:
                continue

        data['DIR'] = sorted(dirnames)
        data['FILES'] = sorted(filenames)
        data['PATH'] = path.replace('//', '/')
        return public.getJson(data)
Exemplo n.º 11
0
    def listApi(self):
        _list = public.M('crontab').where('', ()).field(
            self.field).limit('0,5').order('id desc').select()

        data = []
        for i in range(len(_list)):
            tmp = _list[i]
            if _list[i]['type'] == "day":
                tmp['type'] = '每天'
                tmp['cycle'] = public.getInfo('每天, {1}点{2}分 执行', (str(
                    _list[i]['where_hour']), str(_list[i]['where_minute'])))
            elif _list[i]['type'] == "day-n":
                tmp['type'] = public.getInfo('每{1}天',
                                             (str(_list[i]['where1']), ))
                tmp['cycle'] = public.getInfo(
                    '每隔{1}天, {2}点{3}分 执行',
                    (str(_list[i]['where1']), str(_list[i]['where_hour']),
                     str(_list[i]['where_minute'])))
            elif _list[i]['type'] == "hour":
                tmp['type'] = '每小时'
                tmp['cycle'] = public.getInfo(
                    '每小时, 第{1}分钟 执行', (str(_list[i]['where_minute']), ))
            elif _list[i]['type'] == "hour-n":
                tmp['type'] = public.getInfo('每{1}小时',
                                             (str(_list[i]['where1']), ))
                tmp['cycle'] = public.getInfo(
                    '每{1}小时, 第{2}分钟 执行',
                    (str(_list[i]['where1']), str(_list[i]['where_minute'])))
            elif _list[i]['type'] == "minute-n":
                tmp['type'] = public.getInfo('每{1}分钟',
                                             (str(_list[i]['where1']), ))
                tmp['cycle'] = public.getInfo('每隔{1}分钟执行',
                                              (str(_list[i]['where1']), ))
            elif _list[i]['type'] == "week":
                tmp['type'] = '每周'
                if not _list[i]['where1']:
                    _list[i]['where1'] = '0'
                tmp['cycle'] = public.getInfo(
                    '每周{1}, {2}点{3}分执行', (self.toWeek(int(
                        _list[i]['where1'])), str(_list[i]['where_hour']),
                                          str(_list[i]['where_minute'])))
            elif _list[i]['type'] == "month":
                tmp['type'] = '每月'
                tmp['cycle'] = public.getInfo(
                    '每月, {1}日 {2}点{3}分执行',
                    (str(_list[i]['where1']), str(_list[i]['where_hour']),
                     str(_list[i]['where_minute'])))
            data.append(tmp)

        _ret = {}
        _ret['data'] = data

        count = public.M('crontab').where('', ()).count()
        _page = {}
        _page['count'] = count
        _page['tojs'] = 'remind'

        _ret['page'] = public.getPage(_page)
        return public.getJson(_ret)
Exemplo n.º 12
0
def publicObject(toObject,defs):
    get = web.input();
    for key in defs:
        if key == get.action:
            fun = 'toObject.'+key+'(get)'
            return public.getJson(eval(fun))

    return public.returnJson(False,'Invalid specified parameter!')
Exemplo n.º 13
0
def getTrendData():
    try:
        args = getArgs()
        data = checkArgs(args, ['interval'])
        if not data[0]:
            return data[1]
        pdb = pMysqlDb()
        # interval = int(args['interval'])
        result = pdb.execute("show tables")
        isError = isSqlError(result)
        if isError:
            return isError
        one = getMinData(pdb, 2)
        two = getMinData(pdb, 5)
        three = getMinData(pdb, 10)
        return public.getJson([one, two, three])
    except Exception as e:
        print str(e)
        return public.getJson([0, 0, 0])
Exemplo n.º 14
0
    def POST(self):
        get = web.input()

        import crontab
        crontabObject = crontab.crontab()
        defs = ('GetCrontab','AddCrontab','GetDataList','GetLogs','DelLogs','DelCrontab','StartTask')
        for key in defs:
            if key == get.action:
                fun = 'crontabObject.'+key+'(get)'
                return public.getJson(eval(fun))

        return public.returnJson(False,'Invalid specified parameter!')
Exemplo n.º 15
0
def panel_public():
    get = get_input();
    get.client_ip = public.GetClientIp();
    if not hasattr(get,'name'): get.name = ''
    if not hasattr(get,'fun'): return abort(404)
    if not public.path_safe_check("%s/%s" % (get.name,get.fun)): return abort(404)
    if get.fun in ['scan_login', 'login_qrcode', 'set_login', 'is_scan_ok', 'blind','static']:
        if get.fun == 'static':
            if not 'filename' in get: return abort(404)
            if not public.path_safe_check("%s" % (get.filename)): return abort(404)
            s_file = '/www/server/panel/BTPanel/static/' + get.filename
            if s_file.find('..') != -1 or s_file.find('./') != -1: return abort(404)
            if not os.path.exists(s_file): return abort(404)
            return send_file(s_file, conditional=True, add_etags=True)

        #检查是否验证过安全入口
        if get.fun in ['login_qrcode','is_scan_ok']:
            global admin_check_auth,admin_path,route_path,admin_path_file
            if admin_path != '/bt' and os.path.exists(admin_path_file) and  not 'admin_auth' in session: return 'False'
        import wxapp
        pluwx = wxapp.wxapp()
        checks = pluwx._check(get)
        if type(checks) != bool or not checks: return public.getJson(checks),json_header
        data = public.getJson(eval('pluwx.'+get.fun+'(get)'))
        return data,json_header
    
    import panelPlugin
    plu = panelPlugin.panelPlugin()
    get.s = '_check';
    checks = plu.a(get)
    if type(checks) != bool or not checks: return public.getJson(checks),json_header
    get.s = get.fun
    comm.setSession()
    comm.init()
    comm.checkWebType()
    comm.GetOS()
    result = plu.a(get)
    session.clear()
    return public.getJson(result),json_header
Exemplo n.º 16
0
def publicObject(toObject,defs):
    get = web.input(zunfile = {},data = []);
    if hasattr(get,'path'):
            get.path = get.path.replace('//','/').replace('\\','/');
            if get.path.find('->') != -1:
                get.path = get.path.split('->')[0].strip();
    for key in defs:
        if key == get.action:
            fun = 'toObject.'+key+'(get)'
            if hasattr(get,'html'):
                return eval(fun)
            else:
                return public.getJson(eval(fun))
    return public.returnJson(False,'ARGS_ERR')
Exemplo n.º 17
0
def publicObject(toObject, defs):
    get = web.input(zunfile={}, data=[])
    if hasattr(get, 'path'):
        get.path = get.path.replace('//', '/').replace('\\', '/')
        if get.path.find('->') != -1:
            get.path = get.path.split('->')[0].strip()
    for key in defs:
        if key == get.action:
            fun = 'toObject.' + key + '(get)'
            if hasattr(get, 'html'):
                return eval(fun)
            else:
                return public.getJson(eval(fun))
    return public.returnJson(False, 'ARGS_ERR')
Exemplo n.º 18
0
 def pobject(self):
     get = web.input()
     pluginPath = '/www/server/panel/plugin/safelogin';
     if hasattr(get,'check'):
         if os.path.exists(pluginPath + '/safelogin_main.py'): return 'True';
         return 'False';
     get.data = self.check_token(get.data);
     if not get.data: return public.returnJson(False,'验证失败');
     sys.path.append(pluginPath);
     import safelogin_main;
     reload(safelogin_main);
     s = safelogin_main.safelogin_main();
     if not hasattr(s,get.data['action']): return public.returnJson(False,'方法不存在');
     defs = ('GetServerInfo','add_ssh_limit','remove_ssh_limit','get_ssh_limit','get_login_log','get_panel_limit','add_panel_limit','remove_panel_limit','close_ssh_limit','close_panel_limit','get_system_info','get_service_info','get_ssh_errorlogin')
     if not get.data['action'] in defs: return 'False';
     return public.getJson(eval('s.' + get.data['action'] + '(get)'));
Exemplo n.º 19
0
 def pobject(self):
     get = web.input()
     pluginPath = '/www/server/panel/plugin/safelogin';
     if hasattr(get,'check'):
         if os.path.exists(pluginPath + '/safelogin_main.py'): return 'True';
         return 'False';
     get.data = self.check_token(get.data);
     if not get.data: return public.returnJson(False,'验证失败');
     sys.path.append(pluginPath);
     import safelogin_main;
     reload(safelogin_main);
     s = safelogin_main.safelogin_main();
     if not hasattr(s,get.data['action']): return public.returnJson(False,'方法不存在');
     defs = ('GetServerInfo','add_ssh_limit','remove_ssh_limit','get_ssh_limit','get_login_log','get_panel_limit','add_panel_limit','remove_panel_limit','close_ssh_limit','close_panel_limit','get_system_info','get_service_info','get_ssh_errorlogin')
     if not get.data['action'] in defs: return 'False';
     return public.getJson(eval('s.' + get.data['action'] + '(get)'));
Exemplo n.º 20
0
def term_open():
    comReturn = comm.local()
    if comReturn: return comReturn
    args = get_input()
    if 'get_ssh_info' in args:
        key = 'ssh_' + args['host']
        if key in session:
            return public.getJson(session[key]),json_header
        return public.returnMsg(False,'Acquisition failed!')
    session['ssh_info'] = json.loads(args.data)
    key = 'ssh_' + session['ssh_info']['host']
    session[key] = session['ssh_info']
    s_file = '/www/server/panel/config/t_info.json'
    if 'is_save' in session['ssh_info']:
        public.writeFile(s_file,public.de_hexb(json.dumps(session['ssh_info'])))
        public.set_mode(s_file,600)
    else:
        if os.path.exists(s_file): os.remove(s_file)
    return public.returnJson(True,'Successful setup!');
Exemplo n.º 21
0
def publicObject(toObject,defs):
    get = web.input(zunfile = {},data = []);
    #get = web.input()
    if hasattr(get,'path'):
            get.path = get.path.replace('//','/').replace('\\','/');
            if get.path.find('->') != -1:
                get.path = get.path.split('->')[0].strip();
    for key in defs:
        if key == get.action:
            fun = 'toObject.'+ key+ '(get)'
            try:
                if hasattr(get,'html'):
                    return eval(bytes(fun, encoding='utf-8'))
                else:
                    t = eval(fun)
                    return public.getJson(t)
            except Exception as e:
                print('main.publicObject() exception,fun:', toObject.__class__.__name__ + '.' + key+'(get)')
                traceback.print_exc()
    return public.returnJson(False,'ARGS_ERR')
Exemplo n.º 22
0
 def funObj(self):
     import system,json
     get = web.input()
     sysObject = system.system()
     defs = (
         'GetNetWork',
         'GetDiskInfo',
         'GetCpuInfo',
         'GetBootTime',
         'GetSystemVersion',
         'GetMemInfo',
         'GetSystemTotal',
         'ServiceAdmin',
         'StatusNginx',
         'StatusMySQL',
         'StatusPHP',
         'PHPMyAdminExt',
         'RestartServer'
         )
     for key in defs:
         if key == get.action:
             fun = 'sysObject.'+key+'()'
             return public.getJson(eval(fun))
     return public.returnJson(False,'Invalid specified parameter!')
Exemplo n.º 23
0
 def fileAccessApi(self):
     filename = request.form.get('filename', '').encode('utf-8')
     data = self.getAccess(filename)
     return public.getJson(data)
Exemplo n.º 24
0
def panel_other(name=None, fun=None, stype=None):
    #插件公共动态路由 <name: 插件名称, fun: 被访问的插件方法名, stype:fun=static时则为文件相对于插件static目录下的路径>  访问方式:http://面板地址:端口/插件名称/插件方法.响应类型(html|json)
    '''
        插件静态文件存储目录: static  (允许多级目录,请不要将重要文件放在静态目录),访问方式:http://面板地址:端口/插件名称/static/相对于static的文件路径    如:http://demo.cn:8888/demo/static/js/test.js
        插件模板文件存储目录: templates (请不要在里面创建二级目录) 使用模板方法: http://demo.cn:8888/demo/get_logs.html
        插件模板文件格式:方法名.html (支持jinja2语法,但无法使用extends语句),请在被访问的方法中返回一个dict,它将被当作data参数传入到模板变量
        响应JSON数据: 示例: http://demo.cn:8888/demo/get_logs.json  注意:此处会将插件方法中返回的数据自动转换成JSON字符串响应
        直接响应: 示例:http://demo.cn:8888/demo/get_logs ,此时直接响应插件方法返回的数据,注意: 支持 int、float、string、list、redirect对象
    '''

    #前置准备

    if not name: name = 'btco'

    #是否响应面板默认静态文件
    if name == 'static':
        s_file = '/www/server/panel/BTPanel/static/' + fun + '/' + stype
        if not os.path.exists(s_file): return abort(404)
        return send_file(s_file, conditional=True, add_etags=True)

    if name.find('./') != -1 or not re.match("^[\w-]+$", name):
        return public.returnJson(False, '错误的请求!'), json_header
    if not name: return public.returnJson(False, '请传入插件名称!'), json_header
    p_path = '/www/server/panel/plugin/' + name
    if not os.path.exists(p_path): return abort(404)

    #是否响插件应静态文件
    if fun == 'static':
        if stype.find('./') != -1 or not os.path.exists(p_path + '/static'):
            return public.returnJson(False, '错误的请求!'), json_header
        s_file = p_path + '/static/' + stype
        if not os.path.exists(s_file):
            return public.returnJson(False,
                                     '指定文件不存在[' + stype + ']'), json_header
        return send_file(s_file, conditional=True, add_etags=True)

    #准备参数
    args = get_input()
    args.client_ip = public.GetClientIp()
    if not fun: fun = 'index.html'
    if not stype:
        tmp = fun.split('.')
        fun = tmp[0]
        if len(tmp) == 1: tmp.append('')
        stype = tmp[1]
    args.fun = fun

    #初始化插件对象
    try:
        sys.path.append(p_path)
        plugin_main = __import__(name + '_main')
        try:
            if sys.version_info[0] == 2:
                reload(plugin_main)
            else:
                from imp import reload
                reload(plugin_main)
        except:
            pass
        plu = eval('plugin_main.' + name + '_main()')
        if not hasattr(plu, fun):
            return public.returnJson(False, '指定方法不存在!'), json_header

        #检查访问权限
        comReturn = comm.local()
        if comReturn:
            if not hasattr(plu, '_check'):
                return public.returnJson(False, '指定插件不支持公共访问!'), json_header
            checks = plu._check(args)
            r_type = type(checks)
            if r_type == Response: return checks
            if r_type != bool or not checks:
                return public.getJson(checks), json_header

            #初始化面板数据
            comm.setSession()
            comm.init()
            comm.checkWebType()
            comm.GetOS()

            import panelPlugin
            plugins = panelPlugin.panelPlugin()
            args.name = name
            if not plugins.check_accept(args):
                return public.returnMsg(
                    False,
                    public.to_string([
                        24744, 26410, 36141, 20080, 91, 37, 115, 93, 25110,
                        25480, 26435, 24050, 21040, 26399, 33
                    ]) % (plugins.get_title_byname(args), ))

        #执行插件方法
        data = eval('plu.' + fun + '(args)')
        r_type = type(data)
        if r_type == Response: return data

        #处理响应
        if stype == 'json':  #响应JSON
            return public.getJson(data), json_header
        elif stype == 'html':  #使用模板
            t_path_root = p_path + '/templates/'
            t_path = t_path_root + fun + '.html'
            if not os.path.exists(t_path):
                return public.returnJson(False, '指定模板不存在!'), json_header
            t_body = public.readFile(t_path)

            #处理模板包含
            rep = '{%\s?include\s"(.+)"\s?%}'
            includes = re.findall(rep, t_body)
            for i_file in includes:
                filename = p_path + '/templates/' + i_file
                i_body = 'ERROR: File ' + filename + ' does not exists.'
                if os.path.exists(filename):
                    i_body = public.readFile(filename)
                t_body = re.sub(rep.replace('(.+)', i_file), i_body, t_body)

            return render_template_string(t_body, data=data)
        else:  #直接响应插件返回值,可以是任意flask支持的响应类型
            r_type = type(data)
            if r_type == dict:
                return public.returnJson(False,
                                         '错误的返回类型[%s]' % r_type), json_header
            return data
    except:
        return public.get_error_info().replace('\n', '<br>\n')
Exemplo n.º 25
0
 def pobject(self):
     get = web.input()
     if not os.path.exists('/www/server/panel/plugin/webhook'): return public.getJson(public.returnMsg(False,'请先安装WebHook组件!'));
     sys.path.append('/www/server/panel/plugin/webhook');
     import webhook_main
     return public.getJson(webhook_main.webhook_main().RunHook(get));
Exemplo n.º 26
0
def panel_other(name=None,fun = None,stype=None):
    if not name: name = 'coll'
    if not public.path_safe_check("%s/%s/%s" % (name,fun,stype)): return abort(404)
    if name.find('./') != -1 or not re.match("^[\w-]+$",name): return abort(404)
    if not name: return public.returnJson(False,public.GetMsg("PLUGIN_INPUT_A")),json_header
    p_path = '/www/server/panel/plugin/' + name
    if not os.path.exists(p_path): return abort(404)


    #是否响插件应静态文件
    if fun == 'static':
        if stype.find('./') != -1 or not os.path.exists(p_path + '/static'): return abort(404)
        s_file = p_path + '/static/' + stype
        if s_file.find('..') != -1: return abort(404)
        if not re.match("^[\w\./-]+$",s_file): return abort(404)
        if not public.path_safe_check(s_file): return abort(404)
        if not os.path.exists(s_file): return abort(404)
        return send_file(s_file,conditional=True,add_etags=True)

    #准备参数
    args = get_input();
    args.client_ip = public.GetClientIp();
    if not fun: fun = 'index.html'
    if not stype:
        tmp = fun.split('.')
        fun = tmp[0]
        if len(tmp) == 1:  tmp.append('')
        stype = tmp[1]
    args.fun = fun
    
    #初始化插件对象
    try:
        is_php = os.path.exists(p_path + '/index.php')
        if not is_php:
            sys.path.append(p_path);
            plugin_main = __import__(name+'_main')
            try:
                if sys.version_info[0] == 2:
                    reload(plugin_main)
                else:
                    from imp import reload
                    reload(plugin_main)
            except:pass
            plu = eval('plugin_main.' + name + '_main()')
            if not hasattr(plu,fun): return public.returnJson(False,'SPECIFY_METHOD'),json_header

        #检查访问权限
        comReturn = comm.local()
        if comReturn:
            if not is_php:
                if not hasattr(plu,'_check'):
                    session.clear()
                    return public.returnJson(False,'SPECIFY_PLUG_ERR'),json_header
                checks = plu._check(args)
                r_type = type(checks)
                if r_type == Response: return checks
                if r_type != bool or not checks: return public.getJson(checks),json_header

            #初始化面板数据
            comm.setSession()
            comm.init()
            comm.checkWebType()
            comm.GetOS()

            import panelPlugin
            plugins = panelPlugin.panelPlugin()
            args.name = name
            if not plugins.check_accept(args):
                return public.returnMsg(False,public.to_string([24744, 26410, 36141, 20080, 91, 37, 115, 93, 25110, 25480, 26435, 24050, 21040, 26399, 33]) % (plugins.get_title_byname(args),))

        #执行插件方法
        if not is_php:
            data = eval('plu.'+fun+'(args)')
        else:
            import panelPHP
            args.s = fun
            args.name = name
            data = panelPHP.panelPHP(name).exec_php_script(args)

        r_type = type(data)
        if r_type == Response: return data

        #处理响应
        if stype == 'json':  #响应JSON
            return public.getJson(data),json_header
        elif stype == 'html':   #使用模板
            t_path_root = p_path + '/templates/'
            t_path = t_path_root + fun + '.html'
            if not os.path.exists(t_path): return public.returnJson(False,public.GetMsg("SPECIFY_TEMPLATE")), json_header
            t_body = public.readFile(t_path)

            #处理模板包含
            rep = '{%\s?include\s"(.+)"\s?%}'
            includes = re.findall(rep,t_body)
            for i_file in includes:
                filename = p_path + '/templates/' + i_file
                i_body = 'ERROR: File '+filename+' does not exists.'
                if os.path.exists(filename):
                    i_body = public.readFile(filename)
                t_body = re.sub(rep.replace('(.+)',i_file),i_body,t_body)

            return render_template_string(t_body,data = data)
        else:  #直接响应插件返回值,可以是任意flask支持的响应类型
            r_type = type(data)
            if r_type == dict: return public.returnJson(False,public.GetMsg("RETURN_TYPE_ERR") + '[%s]' % r_type), json_header
            return data
    except:
        error_info = public.get_error_info()
        public.submit_error(error_info)
        return error_info.replace('\n','<br>\n')
Exemplo n.º 27
0
 def getCrondFindApi(self):
     sid = request.form.get('id', '')
     data = public.M('crontab').where('id=?',
                                      (sid, )).field(self.field).find()
     return public.getJson(data)