def Entry(url): if not url in ['', '/']: url = config.entry_url + url params = entryService.find_by_url(entryService.types.entry, url) if params.entry == None: return template('error', params=params, config=config) else: return template('entry', params=params, config=config) params = entryService.search(entryService.types.index, url) return template('index', params=params, config=config)
def Raw(url): url = config.raw_url + url raw = entryService.find_raw(url) if not raw == None: response.headers['Content-Type'] = 'text/plain' response.headers['Content-Encoding'] = 'utf-8' return raw.strip() params = entryService.archive(entryService.types.raw, url) if params.entries == None: return template('error', params=params, config=config) return template('archive', params=params, config=config)
def Search(): type = request.GET.get('type', entryService.types.query) value = request.GET.get('value', '') limit = int(request.GET.get('limit', config.limit)) start = int(request.GET.get('start', config.start)) url = '%s/?type=%s&value=%s&start=%d&limit=%d' % (config.search_url, type, value, start, limit) params = entryService.search(type, url, value, start, limit) if not params.entries == None: return template('search', params=params, config=config) return template('error', params=params, config=config)
def Search(url): print url.split("/") type,value,startStr,limitStr = url.split("/") limit = int(limitStr) start = int(startStr) url = '%s/?type=%s&value=%s&start=%d&limit=%d' % (config.search_url, type, value, start, limit) params = entryService.search(type, url, value, start, limit) if not params.entries == None: return template('search', params=params, config=config) return template('error', params=params, config=config)
def PrivateRaw(url): url = config.raw_url + url raw = entryService.find_raw(url) if not raw == None: response.headers['Content-Type'] = 'text/plain' response.headers['Content-Encoding'] = 'utf-8' return raw.strip() params = entryService.archive(entryService.types.raw, url, private=True) if params.entries == None: return template('error', params=params, config=config) return template('private', params=params, config=config)
def Search(url): print url.split("/") type, value, startStr, limitStr = url.split("/") limit = int(limitStr) start = int(startStr) url = '%s/?type=%s&value=%s&start=%d&limit=%d' % (config.search_url, type, value, start, limit) params = entryService.search(type, url, value, start, limit) if not params.entries == None: return template('search', params=params, config=config) return template('error', params=params, config=config)
def PrivateRaw(url): session = get_current_session() username = session.get('username', '') url = config.raw_url + url raw = entryService.find_raw(url) if not raw == None: response.headers['Content-Type'] = 'text/plain' response.headers['Content-Encoding'] = 'utf-8' return raw.strip() params = entryService.archive(entryService.types.raw, url, private=True, username=username) if params.entries == None: return template('error', params=params, config=config) return template('private', params=params, config=config)
def nginx_tree(): jsonlist = [] # jsondict = {"id": 1, "pId": 0, "name": "nginx_conf"} # jsonlist.append(jsondict) f_id=1 for file in os.listdir(config.nginx_conf_path): jsonlist.append({"id": f_id, "pId": 0, "name": file}) # f_id=f_id+1 c = nginx.loadf(config.nginx_conf_path+file) jsonlist.append({"id": int(str(f_id)+"2"), "pId": f_id, "name": "upstream"}) jsonlist.append({"id": int(str(f_id)+"3"), "pId": f_id, "name": "servers"}) Upstreams = c.filter(btype="Upstream") u_id = 0 s_id = 0 for i in Upstreams: id = int(str(f_id)+"2" + str(u_id + 1)) jsondict = {"id": id, "pId": int(str(f_id)+"2"), "name": i.value} u_id = u_id + 1 # print type(u_id),u_id jsonlist.append(jsondict) Servers = c.filter(btype="Server", name='') for i in Servers: server_name = i.filter("key", "server_name")[0].value id = int(str(f_id)+"3" + str(s_id + 1)) jsondict = {"id": id, "pId": int(str(f_id)+"3"), "name": server_name} s_id = s_id + 1 # print type(s_id),s_id jsonlist.append(jsondict) f_id = f_id + 1 # mylocation = c.children # print Upstreams,"-----------",Servers return template('nginx_tree',nginx_tree=json.dumps(jsonlist),media_prefix=media_prefix)
def db_tree(): from over_view import get_all_trees import config try: cur_server_index = int(request.GET.get('s', '0')) cur_db_index = int(request.GET.get('db', '0')) cur_scan_cursor = int(request.GET.get('cursor', '0')) except: cur_server_index = 0 cur_db_index = 0 cur_scan_cursor = 0 key = request.GET.get('k', '*') all_trees = get_all_trees(cur_server_index, key, db=cur_db_index, cursor=cur_scan_cursor) if type(all_trees) == list: next_scan_cursor, count = all_trees.pop() all_trees_json = json_dumps(all_trees) error_msg = '' else: next_scan_cursor, count = 0, 0 all_trees_json = [] error_msg = all_trees m_config = config.base return template('db_tree', all_trees=all_trees_json, config=m_config, cur_server_index=cur_server_index, cur_db_index=cur_db_index, cur_scan_cursor=next_scan_cursor, pre_scan_cursor=cur_scan_cursor, cur_search_key=(key != '*' and key or ''), count=count, error_msg=error_msg, media_prefix=media_prefix )
def db_tree(): from over_view import get_all_trees import config try: cur_server_index = int(request.GET.get('s', '0')) cur_db_index = int(request.GET.get('db', '0')) cur_scan_cursor = int(request.GET.get('cursor', '0')) except: cur_server_index = 0 cur_db_index = 0 cur_scan_cursor = 0 key = request.GET.get('k', '*') all_trees = get_all_trees(cur_server_index, key, db=cur_db_index, cursor=cur_scan_cursor) if type(all_trees)==list: next_scan_cursor, count = all_trees.pop() all_trees_json = json_dumps(all_trees) else: next_scan_cursor, count = 0, 0 all_trees_json = [] m_config = config.base return template('db_tree', all_trees=all_trees_json, config=m_config, cur_server_index=cur_server_index, cur_db_index=cur_db_index, cur_scan_cursor=next_scan_cursor, pre_scan_cursor=cur_scan_cursor, cur_search_key= (key!='*' and key or ''), count = count, media_prefix=media_prefix )
def parse_category(self, category): from mole.template import template _categorys = self.by_categories.get(category) if _categorys: entries, total = self._find_by_page(_categorys.urls, 1, 100) else: entries = [] return template('parse/parse_category.html', entries=entries)
def parse_tag(self, tag): from mole.template import template _tags = self.by_tags.get(tag) if _tags: entries, total = self._find_by_page(_tags.urls, 1, 100) else: entries = [] return template('parse/parse_tag.html', entries=entries)
def db_view(): try: cur_server_index = int(request.GET.get('s', 'server0').replace('server','')) cur_db_index = int(request.GET.get('db', 'db0').replace('db','')) except: cur_server_index = 0 cur_db_index = 0 key = request.GET.get('k', '*') return template("db_view",media_prefix=media_prefix, cur_server_index=cur_server_index, cur_db_index=cur_db_index, keyword=key)
def index(): from over_view import get_all_levels import config try: cur_server_index = int(request.GET.get('s', '0')) except: cur_server_index = 0 all_levels_tree = get_all_levels(cur_server_index) m_config = config.base return template('index', all_levels_tree=all_levels_tree, config=m_config, cur_server_index=cur_server_index)
def db_view(): try: cur_server_index = int(request.GET.get("s", "server0").replace("server", "")) cur_db_index = int(request.GET.get("db", "db0").replace("db", "")) except: cur_server_index = 0 cur_db_index = 0 key = request.GET.get("k", "*") return template( "db_view", media_prefix=media_prefix, cur_server_index=cur_server_index, cur_db_index=cur_db_index, keyword=key )
def login(): if request.method == 'POST': username = request.POST.get("username", '') password = request.POST.get("password", '') if password == config.admin_pwd and username == config.admin_user: session = get_current_session() session['username'] = username return {'code': 0, 'msg': 'OK'} else: return {'code': -1, 'msg': '用户名或密码错误'} else: return template('auth/login.html', config=config, media_prefix=media_prefix)
def login(): if request.method == "POST": username = request.POST.get("username", "") password = request.POST.get("password", "") if password == config.admin_pwd and username == config.admin_user: session = get_current_session() session["username"] = username return {"code": 0, "msg": "OK"} else: return {"code": -1, "msg": "用户名或密码错误"} else: return template("auth/login.html", config=config, media_prefix=media_prefix)
def upstream_edit(): upstream_name = request.GET.get('upstream_name', '') file_name = request.GET.get('file_name', '') path_file_name = config.nginx_conf_path + file_name c = nginx.loadf(path_file_name) u = c.filter(btype="Upstream", name=upstream_name) keys=u[0].keys rows=len(keys) upstream_value="" for i in keys: upstream_value= upstream_value+i.name+" "+i.value+"\r\n" return template('upstream_edit',upstream_name=upstream_name,upstream_value=upstream_value,path_file_name=path_file_name,rows=rows+5,media_prefix=media_prefix)
def db_tree(): from over_view import get_all_trees import config try: cur_server_index = int(request.GET.get('s', '0')) cur_db_index = int(request.GET.get('db', '0')) except: cur_server_index = 0 cur_db_index = 0 key = request.GET.get('k', '*') all_trees = get_all_trees(cur_server_index, key, db=cur_db_index) m_config = config.base return template('db_tree', all_trees=json_dumps(all_trees), config=m_config, cur_server_index=cur_server_index,cur_db_index=cur_db_index, media_prefix=media_prefix)
def nginxview(): nginx_version_status,nginx_version=commands.getstatusoutput(config.nginx_cmd+" -v") configure_arguments_status,configure_arguments=commands.getstatusoutput(config.nginx_cmd+" -V") configure_arguments=configure_arguments.split(":")[-1] nginx_version=nginx_version.split(":")[1] last_save_time=time.ctime(os.path.getctime(config.nginx_cmd.rstrip())) status, stime = commands.getstatusoutput("ps -A -opid,stime,etime,args |grep /usr/local/nginx/sbin/nginx|grep -v grep|awk {'print $2'}") status, etime = commands.getstatusoutput("ps -A -opid,stime,etime,args |grep /usr/local/nginx/sbin/nginx|grep -v grep|awk {'print $3'}") return template('nginxview', nginx_version=nginx_version, stime=stime, etime=etime, last_save_time=last_save_time, configure_arguments=configure_arguments, media_prefix=media_prefix)
def view(): from data_view import general_html,title_html fullkey = request.GET.get('key', '') refmodel = request.GET.get('refmodel',None) cl,cur_server_index,cur_db_index = get_cl() if cl.exists(fullkey): title_html = title_html(fullkey, cur_server_index, cur_db_index) general_html = general_html(fullkey, cur_server_index, cur_db_index, cl) out_html = title_html + general_html if refmodel: return out_html else: return template('view', out_html=out_html, media_prefix=media_prefix) else: return ' This key does not exist.'
def db_tree(): from over_view import get_all_trees import config try: cur_server_index = int(request.GET.get('s', '0')) cur_db_index = int(request.GET.get('db', '0')) except: cur_server_index = 0 cur_db_index = 0 key = request.GET.get('k', '*') all_trees = get_all_trees(cur_server_index, key, db=cur_db_index) m_config = config.base return template('db_tree', all_trees=json_dumps(all_trees), config=m_config, cur_server_index=cur_server_index, cur_db_index=cur_db_index, media_prefix=media_prefix)
def server_edit(): server_name = request.GET.get('server_name', '') file_name = request.GET.get('file_name', '') path_file_name=config.nginx_conf_path+file_name c = nginx.loadf(path_file_name) servers = c.filter("Server") for i in servers: if server_name==i.filter("key","server_name")[0].value: # print type(i),222222,server_name server_value = "".join(i.as_strings) rows=len(i.as_strings) # server_value=json.dumps(server_value) # if server_name== # keys=u[0].keys # upstream_value="" # for i in keys: # upstream_value= upstream_value+i.name+" "+i.value+"\r\n" return template('server_edit',server_name=server_name,server_value=server_value,path_file_name=path_file_name,rows=rows+5,media_prefix=media_prefix)
def view(): from config import base from redis_api import get_client from data_view import general_html,title_html try: sid = int(request.GET.get('s', '0')) except: sid = 0 fullkey = request.GET.get('key', '') server = base['servers'][sid] cl = get_client()#get_client(host=server['host'], port=server['port']) if cl.exists(fullkey): title_html = title_html(fullkey, sid) general_html = general_html(fullkey, sid, cl) out_html = title_html + general_html #return template('view',template_adapter=Jinja2Template, out_html=out_html ) return template('view', out_html=out_html ) else: return ' This key does not exist.'
def db_tree(): from over_view import get_all_trees import config try: cur_server_index = int(request.GET.get("s", "0")) cur_db_index = int(request.GET.get("db", "0")) cur_scan_cursor = int(request.GET.get("cursor", "0")) except: cur_server_index = 0 cur_db_index = 0 cur_scan_cursor = 0 key = request.GET.get("k", "*") all_trees = get_all_trees(cur_server_index, key, db=cur_db_index, cursor=cur_scan_cursor) if type(all_trees) == list: next_scan_cursor, count = all_trees.pop() all_trees_json = json_dumps(all_trees) error_msg = "" else: next_scan_cursor, count = 0, 0 all_trees_json = [] error_msg = all_trees m_config = config.base return template( "db_tree", all_trees=all_trees_json, config=m_config, cur_server_index=cur_server_index, cur_db_index=cur_db_index, cur_scan_cursor=next_scan_cursor, pre_scan_cursor=cur_scan_cursor, cur_search_key=(key != "*" and key or ""), count=count, error_msg=error_msg, media_prefix=media_prefix, )
def index(): return template('index')
def Subscribe(): params = entryService.search(entryService.types.index, config.subscribe_url) response.headers['Content-Type'] = 'text/xml' return template('atom', params=params, config=config)
def About(): url = config.about_url params = entryService.find_by_url(entryService.types.page, url) if params.entry == None: return template('error', params=params, config=config) return template('entry', params=params, config=config)
def Archive(url): url = config.archive_url + url params = entryService.archive(entryService.types.entry, url) if params.entries == None: return template('error', params=params, config=config) return template('archive', params=params, config=config)
def Index(): limit = int(request.GET.get('limit', 10)) start = int(request.GET.get('start', 1)) params = entryService.search(entryService.types.index, config.index_url, '', start, limit) return template('index', params=params, config=config)
def server_view(): return template("main",media_prefix=media_prefix)
def server_view(): return template("main", media_prefix=media_prefix)
def Update(url): url = config.raw_url + url return template('update', raw_url=url)
def JTemplate(*args, **kwargs): kwargs['template_adapter'] = Jinja2Template return template(*args, **kwargs)
def server_tree(): from over_view import get_db_trees all_trees = get_db_trees() return template("server_tree", all_trees=json_dumps(all_trees), media_prefix=media_prefix)
def overview(): from over_view import get_redis_info return template('overview', redis_info=get_redis_info(), media_prefix=media_prefix)
def nginx_check(): status, output = commands.getstatusoutput(config.nginx_cmd+"-t") print status,output return template('shell',status=status,output=output,media_prefix=media_prefix)
def sitemap(): params = entryService.search(entryService.types.index, config.subscribe_url, limit=10000) response.headers['Content-Type'] = 'text/xml' return template('sitemap.html', params=params, config=config)
def robots(): response.headers['Content-Type'] = 'text/plain' return template('robots.html', config=config)
def editor(): return template('editor')
def render_to_response(*args, **kwargs): kwargs['template_adapter'] = Jinja2Template return template(*args, **kwargs)
def server_tree(): from over_view import get_db_trees all_trees = get_db_trees() return template("server_tree",all_trees=json_dumps(all_trees),media_prefix=media_prefix)
def Archive(url): url= config.archive_url + url params = entryService.archive(entryService.types.entry, url) if params.entries == None: return template('error', params=params, config=config) return template('archive', params=params, config=config)