Exemplo n.º 1
0
def post(environ, template):
    ctype = 'text/html; charset=utf-8'
    length = int(environ['CONTENT_LENGTH'])
    #response_body = environ['wsgi.input'].read(length)
    data = cgi.parse_qs(environ['wsgi.input'].read(length))
    data3 = {}
    data3['ServerName'] = split.ServerName(data['ServerName'][0])
    data3['ServerAlias'] = split.ServerAlias(data['ServerAlias'][0])
    data3['ServerAdmin'] = split.ServerAdmin(data['ServerAdmin'][0])
    data3['AliasLog'] = split.AliasLog(data['AliasLog'][0])
    data3['MC'] = split.MC(data['MC'][0])
    data3['RW'] = split.RW(data['RW'][0])
    data3['DB'] = split.DB(data['DB'][0])
    data1 = augs.Role().read(name="vip.book.sina.com.cn")['result']['data'][0]
    data2 = data1['configuration']['files'][0]['data']
    args = ['ServerName', 'ServerAlias', 'ServerAdmin', 'AliasLog', 'MC', 'RW', 'DB']
    d = 0
    for arg in args:
        if data2[arg] != data3[arg]:
            data2[arg] = data3[arg]
            data1['configuration']['files'][0]['data'] = data2
            d = 1
    if d == 1:
        augs.Role().updata(data1)
        val = 'update ok'
    else:
        val = 'no change'
    #response_body += '%s' % data3['ServerAlias']
    #for key, value in data.items():
    #    response_body += '%s: %s\n' % (key, value)
    tdict = {'val': val}
    response_body = script.response(os.path.join(template, 'post.html'), tdict)
    return (ctype, response_body)
Exemplo n.º 2
0
def resp(info):
  data = json.loads(info.replace('\'', '\"').replace('=pl_Steve28_lq=', '/'))
  room = data['room']
  msg = data['msg']
  sender = data['sender']
  isGroupChat = data['isGroupChat']
  packageName = data['packageName']
  isDebugChat = data['isDebugChat']
  
  r = replier(packageName, room, isDebugChat)
  r.clear()
  k = KakaoLink()
  return str(response(room, msg, sender, isGroupChat, r, packageName, k))
Exemplo n.º 3
0
Arquivo: blog.py Projeto: bagel/pyblog
def blog(environ, template, sql, bdict={}):
    ctype = 'text/html'
    try:
        user_ip = environ['HTTP_X_FORWARDED_FOR']
    except:
        user_ip = environ['REMOTE_ADDR']
    counts = count(user_ip)
    blogs = blogdb(sql)
    tdict = {'ip': user_ip, 'count': counts, 'blog': blogs, \
             'url': environ['HTTP_HOST'] + '/blog', \
             'path': environ['PATH_INFO']}
    tdict.update(bdict)
    response_body = script.response(os.path.join(template, 'blog.html'), tdict)
    return (ctype, response_body)
Exemplo n.º 4
0
Arquivo: blog.py Projeto: bagel/pyblog
def blog(environ, template, sql, bdict={}):
    ctype = 'text/html'
    try:
        user_ip = environ['HTTP_X_FORWARDED_FOR']
    except:
        user_ip = environ['REMOTE_ADDR']
    counts = count(user_ip)
    blogs = blogdb(sql)
    tdict = {'ip': user_ip, 'count': counts, 'blog': blogs, \
             'url': environ['HTTP_HOST'] + '/blog', \
             'path': environ['PATH_INFO']}
    tdict.update(bdict)
    response_body = script.response(os.path.join(template, 'blog.html'), tdict)
    return (ctype, response_body)
Exemplo n.º 5
0
Arquivo: blog.py Projeto: bagel/pyblog
def edit(environ, template):
    ctype = 'text/html'
    id = os.path.basename(environ['PATH_INFO'].rstrip('/'))
    date = title = content = category = tags = str()
    if id.isdigit():
        sql = 'select id,date,title,content,category,tags from blog where id=%s' % id
        blog = blogdb(sql)[int(id)]
        date, title, content, category, tags = blog[1:]
    else:
        tdict = {'id': 0}
    #if content:
    #    content = content.replace('<br>', '\n')
    tdict = {'id': id, 'date': date, 'title': title, 'content': content, \
             'category': category, 'tags': tags}
    response_body = script.response(os.path.join(template, 'edit.html'), tdict)
    return (ctype, response_body)
Exemplo n.º 6
0
Arquivo: blog.py Projeto: bagel/pyblog
def edit(environ, template):
    ctype = 'text/html'
    id = os.path.basename(environ['PATH_INFO'].rstrip('/'))
    date = title = content = category = tags = str()
    if id.isdigit():
        sql = 'select id,date,title,content,category,tags from blog where id=%s' % id
        blog = blogdb(sql)[int(id)]
        date, title, content, category, tags = blog[1:]
    else:
        tdict = {'id': 0}
    #if content:
    #    content = content.replace('<br>', '\n')
    tdict = {'id': id, 'date': date, 'title': title, 'content': content, \
             'category': category, 'tags': tags}
    response_body = script.response(os.path.join(template, 'edit.html'), tdict)
    return (ctype, response_body)
Exemplo n.º 7
0
def purge(environ):
    ctype = 'text/plain; charset=utf-8'
    response_body = ''
    request_uri = environ['REQUEST_URI']
    if not re.match("/purge\?url=.*", request_uri):
        response_body = script.response(os.path.join(environ['DOCUMENT_ROOT'], 'app/purge/README'), {'host': environ['HTTP_HOST']})
        return (ctype, response_body)
    url = request_uri.split('/purge?url=')[1]
    mc = memcache.Client(environ['SINASRV_MEMCACHED_SERVERS'].split(' '))
    try:
        client = environ['HTTP_X_FORWARDED_FOR']
    except:
        client = environ['REMOTE_ADDR']
    #for url in query['url']:
    if mc.get(url) or mc.get(client):
        print mc.get(client)
        response_body = '%s: Purge too often.\n' % url
        clientlog(environ, client, response_body)
        return (ctype, response_body)
    mc.set(client, 1, time=60)
    name, path = urllib2.splithost('//' + url.split('//')[-1])
    response = {}
    try:
        ip_list = query['ip']
    except:
        ip_list = getip(environ, mc)
    print ip_list
    for ip in ip_list:
        response.update({ip: request(environ, ip, 8899, name, path, client, url)})
    if 1 not in response.values():
        response_body += '%s: Purge OK.\n' % url
        mc.set(url, 1, time=300)
    else:
        response_body += '%s: Purge Failed.\n' % url
    clientlog(environ, client, response_body)
    return (ctype, response_body) 
Exemplo n.º 8
0
Arquivo: mon.py Projeto: bagel/cluster
 def response(self):
     if self.channel == "sum":
         title = ""
     else:
         title = self.channel
     return (self.ctype, script.response(os.path.join(self.template, "mon.html"), {"user": self.environ["USER"], "channel": self.channel, "title": title}))
Exemplo n.º 9
0
def html(environ, template):
    ctype = 'text/html'
    ip = environ['HTTP_X_FORWARDED_FOR']
    response_body = script.response(os.path.join(template, 'test.html'), {'val': 'Hello It works!', 'n': 20, 'ip': ip, 'code': '成功'})
    return (ctype, response_body)
Exemplo n.º 10
0
def edit(environ, template):
    ctype = 'text/html'
    data = augs.Role().read(name="vip.book.sina.com.cn")['result']['data'][0]['configuration']['files'][0]['data']
    tdict = {"ServerName": data['ServerName'], "ServerAlias": [ str(alias) for alias in data['ServerAlias'] ], "ServerAdmin": data['ServerAdmin'], "AliasLog": data['AliasLog'], "RW": data['RW'], "MC": data['MC'], "DB": data['DB']}
    response_body = script.response(os.path.join(template, 'vhost.html'), tdict)
    return (ctype, response_body)