本文目錄一覽:
- 1、請問這些網頁是用什麼語言來編寫的???
- 2、Provider (0x8002000A) 超出當前範圍。
- 3、golang 在文本文檔中查找到指定內容要怎麼才能讀取整行
- 4、php和go語言哪個好
- 5、iris 真的是最快的Golang 路由框架嗎
- 6、幫我看看這代碼是不是zend加密的?該如何解密?
請問這些網頁是用什麼語言來編寫的???
純HTML啊,原文件如下:
!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “”
html xmlns=””
head
meta http-equiv=”Content-Type” content=”text/html; charset=gb2312″ /
title5q校園網/title
link href=”” rel=”stylesheet” type=”text/css” media=”all” /
link rel=”stylesheet” href=”” type=”text/css” media=”all” /
link rel=”stylesheet” href=”” type=”text/css” media=”all” /
link href=”” rel=”stylesheet” type=”text/css”
style type=”text/css”
#menu a.login{
background:url() no-repeat 0 -2px;
display:inline-block;
width:51px;
text-align:center;
color:#0087C5;
}
#menu a.help{
background:url() no-repeat;
display:inline-block;
width:51px;
text-align:center;
color:#0087C5;
}
#content{ margin-left:4px; margin-top:10px; }
#login_content_1{
margin:0px;
padding:0px;
border:0px;
height:601px;
width:191px;
float:left;
background-image: url();
background-repeat: no-repeat;
}
#login_content_2{ margin:0px; padding:0px; border:0px; background:url(); height:601px; width:191px;background-repeat: no-repeat; float:left;}
#login_content_3{ margin:0px; padding:0px; border:0px; background:url(); height:601px; width:179px;background-repeat: no-repeat; float:left;}
#login_content_5{ margin:0px; padding:0px; border:0px; background:url(); height:601px; width:163px;background-repeat: no-repeat; float:left;}
#login_content_6{ margin:0px; padding:0px; border:0px; background:url(); height:601px; width:272px;background-repeat: no-repeat; float:left;}
#login_name{margin-top:60px; margin-left:60px; color:#FFFFFF;}
.login_input{border:1px solid #78827d; width:135px; height:18px; line-height:18px; margin-bottom:3px;}
#login_name div{color:#FFFFFF;}
#login_name a{color:#FFFFFF;}
#login_name a:hover{text-decoration:none;color:#FFFFFF;}
.button01{margin:10px 20px;}
.button02{margin:10px;}
#login_name a.glowTxt{font-size: 12pt; font-weight: bold; color: #FFFC1C; }
#footer {
WIDTH: auto
}
#footer P {
PADDING-RIGHT: 10px; PADDING-LEFT: 10px; PADDING-BOTTOM: 10px; PADDING-TOP: 10px
}
#footer .f1 {
BORDER-RIGHT: #dfe6ec 1px; BORDER-TOP: #dfe6ec 1px solid; BACKGROUND: #f5f5f5; BORDER-LEFT: #dfe6ec 1px; COLOR: #0085c0; BORDER-BOTTOM: #dfe6ec 1px solid
}
#footer .f1 A {
COLOR: #0085c0; TEXT-DECORATION: none
}
/style
script src=””/script
script
var imAccount = “”;
var imPassword = “”;
String.prototype.trim = function() {
return this.replace(/^\s*|\s*$/g,””);
}
function isValidateTag(tag){
var tagReg= /[+-()~*:|]/;
if(tag.indexOf(“\n”)!=-1||tag.indexOf(“\r”)!=-1||tag.indexOf(“\\”)!=-1)
return false;
else if(tag.indexOf(“‘”)!=-1||tag.indexOf(‘”‘)!=-1)
return false;
else if(tag.indexOf(“+”)!=-1
||tag.indexOf(“-“)!=-1||tag.indexOf(“”)!=-1
||tag.indexOf(“”)!=-1
||tag.indexOf(“(“)!=-1
||tag.indexOf(“)”)!=-1
||tag.indexOf(“~”)!=-1
||tag.indexOf(“*”)!=-1
||tag.indexOf(“:”)!=-1
||tag.indexOf(“”)!=-1
||tag.indexOf(“|”)!=-1){
return false;
}
return true;
}
function check_login(obj){
try{
var user_name = obj.user_name.value.trim() ;
var password = obj.password.value.trim() ;
if(user_name==””){
alert(“請輸入登陸帳號”) ;
obj.user_name.focus() ;
return false;
}
if(obj.user_name.value.trim().length4){
alert(“登錄id 不能小於4位”) ;
obj.user_name.focus() ;
return false ;
}
if(obj.user_name.value.trim().length20){
alert(“登錄id 不能大於20位”) ;
obj.user_name.focus() ;
return false ;
}
if(!isValidateTag(user_name)){
alert(“請不要在帳號中輸入以下字元「+ -()~*:| 」”) ;
obj.user_name.focus() ;
return false;
}
if(password==””){
alert(“請輸入登陸密碼”) ;
obj.password.focus() ;
return false;
}
}catch(e){alert(e);}
imAccount = user_name;
imPassword = password;
var url = “/login/LoginAjax.jsp?rnd=”+Math.random()+”user_name=”+escape(user_name)+”password=”+escape(password);
Request.sendPOST(url, “{status:-1,errno:5}”, doLoginRes, true, doLoginFailed);
return false ;
}
function doLoginRes(req, data) {
var stat = {status:-100};
eval(“stat=”+req.responseText);
if(stat.status==0){
try { web5q.Start5QIM(imAccount, imPassword); } catch(e) {}
var str=stat.mop_status ;
window.location=”/society/SocietyUserFirst.do” ;
}else{
if(stat.errno==4){
window.location=”/regist/redirect.jsp” ;
return ;
}else if(stat.errno==5){
window.location=”/login/LoginActivation.jsp?user_name=”+document.LoginForm.user_name.value.trim() ;
return ;
}else
doLoginFailed(stat) ;
}
}
function doLoginFailed(stat) {
var errmsg = “未知錯誤”;
switch (stat.errno) {
case 1:
errmsg = “用戶不存在”;
break;
case 2:
errmsg = “密碼錯誤”;
break;
case 3:
errmsg = “異常錯誤”;
break;
case 5:
errmsg = “您的郵箱還沒有激活您不能登陸”;
break;
}
alert(errmsg) ;
document.LoginForm.user_name.focus() ;
}
function setFoc(){
document.LoginForm.user_name.focus() ;
}
//瀏覽器信息統計 wanghw add since 2006-8-7
function browserTotal(type){
if(null==type||type==””)return;
var info = “”;
if(type==”flash”){
var installedVersion = com.deconcept.FlashObjectUtil.getPlayerVersion();
info = installedVersion.major+”.”+installedVersion.minor+”.”+installedVersion.rev;
}else if(type==”ie”){
info = getBrowserVer();
}else if(type==”timeout”){
info = window.location.href;
}else{return;}
var url = “”+type+”info=”+info;
var divId = document.getElementById(“browser”);
if(divId) {
divId.src = url;
}else{
var stat = document.createElement(“img id=’browser’ src='” + url + “‘ style=’display:none;’ /”);
document.body.insertBefore(stat);
}
}
//取得瀏覽器版本 wanghw add since 2006-8-7
function getBrowserVer(){
var o;
o=window.navigator.appName
var s=window.navigator.appVersion;
if(s.indexOf(“MSIE”)!=-1){
s=s.slice(s.indexOf(“MSIE”)+4).slice(1,4);
}else{
alert(“您好,目前5q系統僅支持IE6(Internet Explorer 6.0.),我們檢測到您的瀏覽器不是IE,為了保障你的順暢試用,我們建議您更換瀏覽器進行瀏覽。\n我們會儘快解決兼容性的問題,給你造成不便,敬請諒解”);//2006-8-8
s=s.slice(0,3);
}
return o+”:”+s;
}
//超時處理統計函數 wanghw add since 2006-8-7
function timeOut(){
if(Hi.loadingTmr==0)return;
hideCoverAllFrm();
$(“loadingMsg”).style.display = “none”;
if (Hi.loadingTmr 0) {
clearTimeout(Hi.loadingTmr);
Hi.loadingTmr = 0;
}
//wanghw add since 2006-08-03
browserTotal(“timeout”);
}
/script
/head
body onload=”setFoc();browserTotal(‘ie’);browserTotal(‘flash’)”
noscriptiframe id=”noscript” src=”;info=not_js” style=”display:none”/iframe/noscript
div id=”head”
div style=height:4px;font-size:0;background:#D5D5D5 /div
div id=”menu” span class=”rr” a href=”javascript:document.LoginForm.user_name.focus()” class=”login”登錄/a a href=”” target=”_blank” class=”help”幫助/a /span /div
table cellpadding=0 cellspacing=0 width=100% height=39
tr
td width=159div id=”logo”img src=”” border=”0″ style=”cursor:pointer” //div/td
td valign=bottom width=”280″div id=”menu1″
li id=”m1″a href=”javascript:void(0)” 首頁 /a/li
img align=absmiddle src=;
li id=”m12″a href=”/regist/L.do?a=2efe4070dcb14fb2″ 註冊 /a/li
img align=absmiddle src=;
li id=”m5″a href=”/login/LoginList.jsp” 學校 /a/li
img align=absmiddle src=;
li id=”m13″a href=”” target=”_blank” 幫助 /a/li
/td
td valign=”bottom” style=”padding-top:0px; margin:10px; position:relative; top:2px; background:url(”) repeat-x; vertical-align:bottom”
span onclick=”$(‘tmp’).src=”;”a href=”tour.jsp” target=”_blank”img src=”” border=”0″ alt=”” style=” position:relative; top:-2px; ” //a/span
/td
/tr
/table
/div
img id=”tmp” style=”display:none”/
div id=”content”
div id=”login_content_1″/divdiv id=”login_content_2″/divdiv id=”login_content_3″/divdiv id=”login_content_5″div style=”top:191px;”img src=”” border=”0″ usemap=”#Map” /
map name=”Map” id=”Map”area shape=”rect” coords=”11,10,152,45″ href=”” target=”_blank” onfocus=”blur();” onclick=”$(‘tjimg’).src=”;”//map/div/div
div id=”login_content_6″
form name=”LoginForm” action=”/login/LoginDo.jsp” method=”post” onsubmit=”return check_login(this);”
div id=”login_name”
登錄id input name=”user_name” type=”text” class=”login_input” /br /
密碼 input name=”password” type=”password” class=”login_input” /
div class=”button01″input type=”image” src=”” border=”0″ align=”absmiddle” height=”28″/ a href=”/passwd/pw_email.jsp” target=”_blank”找回密碼/a/div
!–divimg src=”” border=”0″ align=”absmiddle” / 還沒加入啊,是06級新生么?/div–
divbr/ span onclick=”$(‘tmp’).src=”;”a href=”tour.jsp” target=”_blank”還沒加入?了解一下先!/a/span/div
!–div class=”button02″Yes→ a href=”” target=”_blank” onclick=”$(‘tjimg’).src=”;”img src=”” border=”0″ align=”absmiddle” //a/div–
!–div class=”button02″No→ a href=”/regist/L.do?a=2efe4070dcb14fb2″img src=”” border=”0″ align=”absmiddle” //a/div–
div class=”button02″a href=”” onclick=”$(‘tjimg’).src=”;” target=”_blank”img src=”” border=”0″ align=”absmiddle” //a/div
/div
/form
/div
div style=”background: url() no-repeat; MARGIN-LEFT: 2px; WIDTH: 989px; HEIGHT: 82px”
TABLE style=”margin-top:0px; LINE-HEIGHT: 22px” align=center
TBODY
TR
TD style=”COLOR: #808080″ align=middleA href=”” target=_blank新手課堂/A | A href=”” target=_blank主頁美化圈/A | A href=”” target=_blank5q官方活動圈/A | A href=”” target=_blank圈主俱樂部/A | A href=”” target=_blank改進5q/A | A href=”” target=_blank問題報告/A | A href=”” target=_blank給我們留言/A | A href=”” target=_blank關於我們/A | A href=”” target=_blank隱私條款/A | A href=”” target=_blank舉報中心/A/TD
/TR
TR
TD style=”COLOR: #808080″ align=center千橡公司 京ICP證041489號 Copyright? 1997-2006 All Rights Reserved./TD
/TR
/TBODY
/TABLE
/DIV
OBJECT ID=”web5q” CLASSID=”CLSID:5C56F4A7-71FC-4FFD-A9D7-18FB87A9DFC6″ /OBJECT
!–圖片輔助統計–
img name=”tjimg” style=”display:none”/
/body
script
!–
var requiredVersion = new com.deconcept.PlayerVersion([8,0,0]);
var installedVersion = com.deconcept.FlashObjectUtil.getPlayerVersion();
if(installedVersion.versionIsValid(requiredVersion) == false)
{
alert(“沒有安裝Flash 8,自動安裝需要時間,請稍候,並在彈出窗口選擇確定安裝”);
document.write(‘object style=”display:none” id=”shell_object” name=”shell” classid=”clsid:D27CDB6E-AE6D-11cf-96B8-444553540000″ \
codebase=”” width=”0″ height=”0″\
param name=”movie” value=”” /\
param name=FlashVars value=”loc=en_USrequired_version=8,0,24,0″ /\
embed id=”shell_object” name=”shell” type=”application/x-shockwave-flash” src=”” flashvars=”loc=en_USrequired_version=8,0,24,0″width=”0″ height=”0″ pluginspage=””/embed\
/object’);
}
—
/script
/html
Provider (0x8002000A) 超出當前範圍。
仔細看下資料庫 tel這個欄位
是不是設置為 INT 類型
如果是 改正為 CHAR 或者 VARchar 類型
否則就更正 contact 欄位 把位元組長度變大一些
golang 在文本文檔中查找到指定內容要怎麼才能讀取整行
package main
import (
“fmt”
“io/ioutil”
“log”
“strings”
)
func main() {
content, err := ioutil.ReadFile(“/usr/share/applications/gvim.desktop”)
if err != nil {
log.Fatal(err)
}
lines := strings.Split(string(content), “\n”)
for _, v := range lines {
trimline := strings.TrimSpace(v)
if strings.Contains(trimline, “text/plain”) {
fmt.Println(trimline)
}
}
}
php和go語言哪個好
前言
最近工作中遇到的一個場景,php項目中需要使用一個第三方的功能,而恰好有一個用Golang寫好的類庫。那麼問題就來了,要如何實現不同語言之間的通信呢?下面就來一起看看吧。
常規的方案
1、 用Golang寫一個http/TCP服務,php通過http/TCP與Golang通信
2、將Golang經過較多封裝,做為php擴展。
3、PHP通過系統命令,調取Golang的可執行文件
存在的問題
1、http請求,網路I/O將會消耗大量時間
2、需要封裝大量代碼
3、PHP每調取一次Golang程序,就需要一次初始化,時間消耗很多
優化目標
1、Golang程序只初始化一次(因為初始化很耗時)
2、所有請求不需要走網路
3、盡量不大量修改代碼
解決方案
1、簡單的Golang封裝,將第三方類庫編譯生成為一個可執行文件
2、PHP與Golang通過雙向管道通信
使用雙向管道通信優勢
1:只需要對原有Golang類庫進行很少的封裝
2:性能最佳 (IPC通信是進程間通信的最佳途徑)
3:不需要走網路請求,節約大量時間
4:程序只需初始化一次,並一直保持在內存中
具體實現步驟
1:類庫中的原始調取demo
package main
import (
“fmt”
“github.com/yanyiwu/gojieba”
“strings”
)
func main() {
x := gojieba.NewJieba()
defer x.Free()
s := “小明碩士畢業於中國科學院計算所,後在日本京都大學深造”
words := x.CutForSearch(s, true)
fmt.Println(strings.Join(words, “/”))
}
保存文件為main.go,就可以運行
2:調整後代碼為:
package main
import (
“bufio”
“fmt”
“github.com/yanyiwu/gojieba”
“io”
“os”
“strings”
)
func main() {
x := gojieba.NewJieba(
“/data/tmp/jiebaDict/jieba.dict.utf8”,
“/data/tmp/jiebaDict/hmm_model.utf8”,
“/data/tmp/jiebaDict/user.dict.utf8”
)
defer x.Free()
inputReader := bufio.NewReader(os.Stdin)
for {
s, err := inputReader.ReadString(‘\n’)
if err != nil err == io.EOF {
break
}
s = strings.TrimSpace(s)
if s != “” {
words := x.CutForSearch(s, true)
fmt.Println(strings.Join(words, ” “))
} else {
fmt.Println(“get empty \n”)
}
}
}
只需要簡單的幾行調整,即可實現:從標準輸入接收字元串,經過分詞再輸出
測試:
# go build test
# ./test
# //等待用戶輸入,輸入」這是一個測試「
# 這是 一個 測試 //程序
3:使用cat與Golang通信做簡單測試
//準備一個title.txt,每行是一句文本
# cat title.txt | ./test
正常輸出,表示cat已經可以和Golang正常交互了
4:PHP與Golang通信
以上所示的cat與Golang通信,使用的是單向管道。即:只能從cat向Golang傳入數據,Golang輸出的數據並沒有傳回給cat,而是直接輸出到屏幕。但文中的需求是:php與Golang通信。即php要傳數據給Golang,同時Golang也必須把執行結果返回給php。因此,需要引入雙向管道。
在PHP中管道的使用:popen(“/path/test”) ,具體就不展開說了,因為此方法解決不了文中的問題。
雙向管道:
$descriptorspec = array(
0 = array(“pipe”, “r”),
1 = array(“pipe”, “w”)
);
$handle = proc_open(
‘/webroot/go/src/test/test’,
$descriptorspec,
$pipes
);
fwrite($pipes[‘0’], “這是一個測試文本\n”);
echo fgets($pipes[1]);
解釋:使用proc_open打開一個進程,調用Golang程序。同時返回一個雙向管道pipes數組,php向$pipe[‘0’]中寫數據,從$pipe[‘1’]中讀數據。
好吧,也許你已經發現,我是標題檔,這裡重點要講的並不只是PHP與Golang如何通信。而是在介紹一種方法: 通過雙向管道讓任意語言通信。(所有語言都會實現管道相關內容)
測試:
通過對比測試,計算出各個流程佔用的時間。下面提到的title.txt文件,包含100萬行文本,每行文本是從b2b平台取的商品標題
1: 整體流程耗時
time cat title.txt | ./test /dev/null
耗時:14.819秒,消耗時間包含:
進程cat讀出文本
通過管道將數據傳入Golang
Golang處理數據,將結果返回到屏幕
2:計算分詞函數耗時。方案:去除分詞函數的調取,即:注釋掉Golang源代碼中的調取分詞那行的代碼
time cat title.txt | ./test /dev/null
耗時:1.817秒時間,消耗時間包含:
進程cat讀出文本
通過管道將數據傳入Golang
Golang處理數據,將結果返回到屏幕
分詞耗時 = (第一步耗時) – (以上命令所耗時)
分詞耗時 : 14.819 – 1.817 = 13.002秒
3:測試cat進程與Golang進程之間通信所佔時間
time cat title.txt /dev/null
耗時:0.015秒,消耗時間包含:
進程cat讀出文本
通過管道將數據傳入Golang
go處理數據,將結果返回到屏幕
管道通信耗時:(第二步耗時) – (第三步耗時)
管道通信耗時: 1.817 – 0.015 = 1.802秒
4:PHP與Golang通信的時間消耗
編寫簡單的php文件:
?php
$descriptorspec = array(
0 = array(“pipe”, “r”),
1 = array(“pipe”, “w”)
);
$handle = proc_open(
‘/webroot/go/src/test/test’,
$descriptorspec,
$pipes
);
$fp = fopen(“title.txt”, “rb”);
while (!feof($fp)) {
fwrite($pipes[‘0’], trim(fgets($fp)).”\n”);
echo fgets($pipes[1]);
}
fclose($pipes[‘0’]);
fclose($pipes[‘1’]);
proc_close($handle);
流程與上面基本一致,讀出title.txt內容,通過雙向管道傳入Golang進程分詞後,再返回給php (比上面的測試多一步:數據再通過管道返回)
time php popen.php /dev/null
耗時:24.037秒,消耗時間包含:
進程PHP讀出文本
通過管道將數據傳入Golang
Golang處理數據
Golang將返回結果再寫入管道,PHP通過管道接收數據
將結果返回到屏幕
結論:
1 :整個分詞過程中的耗時分布
使用cat控制邏輯耗時: 14.819 秒
使用PHP控制邏輯耗時: 24.037 秒(比cat多一次管道通信)
單向管道通信耗時: 1.8 秒
Golang中的分詞函數耗時: 13.002 秒
2:分詞函數的性能: 單進程,100萬商品標題分詞,耗時13秒
以上時間只包括分詞時間,不包括詞典載入時間。但在本方案中,詞典只載入一次,所以載入詞典時間可以忽略(1秒左右)
3:PHP比cat慢 (這結論有點多餘了,呵呵)
語言層面慢: (24.037 – 1.8 – 14.819) / 14.819 = 50%
單進程對比測試的話,應該不會有哪個語言比cat更快。
相關問題:
1:以上Golang源碼中寫的是一個循環,也就是會一直從管道中讀數據。那麼存在一個問題:是不是php進程結束後,Golang的進程還會一直存在?
管道機制自身可解決此問題。管道提供兩個介面:讀、寫。當寫進程結束或者意外掛掉時,讀進程也會報錯,以上Golang源代碼中的err邏輯就會執行,Golang進程結束。
但如果PHP進程沒有結束,只是暫時沒有數據傳入,此時Golang進程會一直等待。直到php結束後,Golang進程才會自動結束。
2:能否多個php進程並行讀寫同一個管道,Golang進程同時為其服務?
不可以。管道是單向的,如果多個進程同時向管道中寫,那Golang的返回值就會錯亂。
可以多開幾個Golang進程實現,每個php進程對應一個Golang進程。
最後,上面都是瞎扯的。如果你了解管道、雙向管道,上面的解釋對你基本沒啥用。但如果你不了解管道,調試上面的代碼沒問題,但稍有修改就有可能掉坑裡。
iris 真的是最快的Golang 路由框架嗎
對各種Go http路由框架的比較, Iris明顯勝出,它的性能遠遠超過其它Golang http路由框架。
但是,在真實的環境中,Iris真的就是最快的Golang http路由框架嗎?
Benchmark測試分析
在那篇文章中我使用的是Julien Schmidt的 測試代碼,他模擬了靜態路由、Github API、Goolge+ API、Parse API的各種情況,因為這些API是知名網站的開放的API,看起來測試挺真實可靠的。
但是,這個測試存在著一個嚴重的問題,就是Handler的業務邏輯非常的簡單,各個框架的handler類似,比如Iris的Handler的實現:
funcirisHandler(_ *iris.Context) {}funcirisHandlerWrite(c *iris.Context) { io.WriteString(c.ResponseWriter, c.Param(“name”))}funcirisHandlerTest(c *iris.Context) { io.WriteString(c.ResponseWriter, c.Request.RequestURI)}
幾乎沒有任何的業務邏輯,最多是往Response中寫入一個字元串。
這和生產環境中的情況嚴重不符!
實際的產品肯定會有一些業務的處理,比如參數的校驗,數據的計算,本地文件的讀取、遠程服務的調用、緩存的讀取、資料庫的讀取和寫入等,有些操作可能花費的時間很多,一兩個毫秒就可以搞定,有的卻很耗時,可能需要幾十毫秒,比如:
從一個網路連接中讀取數據 寫數據到硬碟中 調用其它服務,等待服務結果的返回 ……
這才是我們常用的case,而不是一個簡單的寫字元串。
因此那個測試框架的Handler還應該加入時間花費的情況。
模擬真實的Handler的情況
我們模擬一下真實的情況,看看Iris框架和Golang內置的Http路由框架的性能如何。
首先使用Iris實現一個Http Server:
packagemainimport(“os””strconv””time””github.com/kataras/iris”)funcmain() { api := iris.New() api.Get(“/rest/hello”,func(c *iris.Context) { sleepTime, _ := strconv.Atoi(os.Args[1])ifsleepTime 0{ time.Sleep(time.Duration(sleepTime) * time.Millisecond) } c.Text(“Hello world”) }) api.Listen(“:8080”)}
我們可以傳遞給它一個時間花費的參數sleepTime,模擬這個Handler在處理業務時要花費的時間,它會讓處理這個Handler的暫停sleepTime毫秒,如果為0,則不需要暫停,這種情況類似上面的測試。
然後我們使用Go內置的路由功能實現一個Http Server:
packagemainimport(“log””net/http””os””strconv””time”)// There are some golang RESTful libraries and mux libraries but i use the simplest to test.funcmain() { http.HandleFunc(“/rest/hello”,func(w http.ResponseWriter, r *http.Request) { sleepTime, _ := strconv.Atoi(os.Args[1])ifsleepTime 0{ time.Sleep(time.Duration(sleepTime) * time.Millisecond) } w.Write([]byte(“Hello world”)) }) err := http.ListenAndServe(“:8080”,nil)iferr !=nil{ log.Fatal(“ListenAndServe: “, err) }}
編譯兩個程序進行測試。
1、首先進行業務邏輯時間花費為0的測試
運行程序 iris 0,然後執行 wrk -t16 -c100 -d30s 進行並發100,持續30秒的測試。
iris的吞吐率為46155 requests/second。
運行程序 gomux 0,然後執行 wrk -t16 -c100 -d30s 進行並發100,持續30秒的測試。
Go內置的路由程序的吞吐率為55944 requests/second。
兩者的吞吐量差別不大,iris略差一點
2、然後進行業務邏輯時間花費為10的測試
運行程序 iris 10,然後執行 wrk -t16 -c100 -d30s 進行並發100,持續30秒的測試。
iris的吞吐率為97 requests/second。
運行程序 gomux 10,然後執行 wrk -t16 -c100 -d30s 進行並發100,持續30秒的測試。
Go內置的路由程序的吞吐率為9294 requests/second。
3、最後進行業務邏輯時間花費為1000的測試
這次模擬一個極端的情況,業務處理很慢,處理一個業務需要1秒的時間。
運行程序 iris 1000,然後執行 wrk -t16 -c100 -d30s 進行並發100,持續30秒的測試。
iris的吞吐率為1 requests/second。
運行程序 gomux 1000,然後執行 wrk -t16 -c100 -d30s 進行並發100,持續30秒的測試。
Go內置的路由程序的吞吐率為95 requests/second。
可以看到,如果加上業務邏輯的處理時間,Go內置的路由功能要遠遠好於Iris, 甚至可以說Iris的路由根本無法應用的有業務邏輯的產品中,隨著業務邏輯的時間耗費加大,iris的吞吐量急劇下降。
而對於Go的內置路由來說,業務邏輯的時間耗費加大,單個client會等待更長的時間,但是並發量大的網站來說,吞吐率不會下降太多。
比如我們用1000的並發量測試 gomux 10和 gomux 1000。
gomux 10: 吞吐率為47664 gomux 1000: 吞吐率為979
這才是Http網站真實的情況,因為我們要應付的網站的並發量,網站應該支持同時有儘可能多的用戶訪問,即使單個用戶得到返回頁面需要上百毫秒也可以接受。
而Iris在業務邏輯的處理時間增大的情況下,無法支持大的吞吐率,即使在並發量很大的情況下(比如1000),吞吐率也很低。
深入了解Go http server的實現
Go http server實現的是每個request對應一個goroutine (goroutine per request), 考慮到Http Keep-Alive的情況,更準確的說是每個連接對應一個goroutine(goroutine per connection)。
因為goroutine是非常輕量級的,不會像Java那樣 Thread per request會導致伺服器資源不足,無法創建很多的Thread, Golang可以創建足夠多的goroutine,所以goroutine per request的方式在Golang中沒有問題。而且這還有一個好處,因為request是在一個goroutine中處理的,不必考慮對同一個Request/Response並發讀寫的問題。
如何查看Handler是在哪一個goroutine中執行的呢?我們需要實現一個函數來獲取goroutine的Id:
funcgoID()int{varbuf[64]byte n := runtime.Stack(buf[:], false) idField := strings.Fields(strings.TrimPrefix(string(buf[:n]),”goroutine “))[0] id, err := strconv.Atoi(idField)iferr !=nil{panic(fmt.Sprintf(“cannot get goroutine id: %v”, err)) }returnid}
然後在handler中列印出當前的goroutine id:
func(c *iris.Context) { fmt.Println(goID()) ……}
和
func(w http.ResponseWriter, r *http.Request) { fmt.Println(goID()) ……}
啟動 gomux 0,然後運行 ab -c 5 -n 5 測試一下,apache的ab命令使用5個並發並且每個並發兩個請求訪問伺服器。
可以看到伺服器的輸出:
因為沒有指定 -k參數,每個client發送兩個請求會創建兩個連接。
你可以加上 -k參數,可以看出會有重複的goroutine id出現,表明同一個持久連接會使用同一個goroutine處理。
以上是通過實驗驗證我們的理論,下面是代碼分析。
net/http/server.go的 第2146行 go c.serve()表明,對於一個http連接,會啟動一個goroutine:
func(srv *Server) Serve(l net.Listener) error {deferl.Close()iffn := testHookServerServe; fn !=nil{ fn(srv, l) }vartempDelay time.Duration// how long to sleep on accept failureiferr := srv.setupHTTP2(); err !=nil{returnerr }for{ rw, e := l.Accept() …… tempDelay =0 c := srv.newConn(rw) c.setState(c.rwc, StateNew) // before Serve can returngoc.serve() }}
而這個 c.serve方法會從連接中 讀取request交由handler處理:
func(c *conn) serve() { ……for{ w, err := c.readRequest() …… req := w.req serverHandler{c.server}.ServeHTTP(w, w.req)ifc.hijacked() {return } w.finishRequest()if!w.shouldReuseConnection() {ifw.requestBodyLimitHit || w.closedRequestBodyEarly() { c.closeWriteAndWait() }return } c.setState(c.rwc, StateIdle) }}
而 ServeHTTP的實現如下,如果沒有配置handler或者路由器,則使用預設的 DefaultServeMux。
func(sh serverHandler) ServeHTTP(rw ResponseWriter, req *Request) { handler := sh.srv.Handlerifhandler ==nil{ handler = DefaultServeMux }ifreq.RequestURI ==”*” req.Method ==”OPTIONS”{ handler = globalOptionsHandler{} } handler.ServeHTTP(rw, req)}
可以看出這裡並沒有新開goroutine,而是在同一個connection對應的goroutine中執行的。如果試用Keep-Alive,還是在這個connection對應的goroutine中執行。
正如注釋中所說的那樣:
// HTTP cannot have multiple simultaneous active requests.[*] // Until the server replies to this request, it can’t read another, // so we might as well run the handler in this goroutine. // [*] Not strictly true: HTTP pipelining. We could let them all process // in parallel even if their responses need to be serialized. serverHandler{c.server}.ServeHTTP(w, w.req)
因此業務邏輯的時間花費會影響單個goroutine的執行時間,並且反映到客戶的瀏覽器是是延遲時間latency增大了,如果並發量足夠多,影響的是系統中的goroutine的數量以及它們的調度,吞吐率不會劇烈影響。
Iris的分析
如果你使用Iris查看每個Handler是使用哪一個goroutine執行的,會發現每個連接也會用不同的goroutine執行,可是性能差在哪兒呢?
或者說,是什麼原因導致Iris的性能急劇下降呢?
Iris伺服器的監聽和為連接啟動一個goroutine沒有什麼明顯不同,重要的不同在與Router處理Request的邏輯。
原因在於Iris為了提供性能,緩存了context,對於相同的請求url和method,它會從緩存中使用相同的context。
func(r *MemoryRouter) ServeHTTP(res http.ResponseWriter, req *http.Request) {ifctx := r.cache.GetItem(req.Method, req.URL.Path); ctx !=nil{ ctx.Redo(res, req)return } ctx := r.getStation().pool.Get().(*Context) ctx.Reset(res, req)ifr.processRequest(ctx) {//if something found and served then add it’s clone to the cache r.cache.AddItem(req.Method, req.URL.Path, ctx.Clone()) } r.getStation().pool.Put(ctx)}
由於並發量較大的時候,多個client的請求都會進入到上面的 ServeHTTP方法中,導致相同的請求會進入下面的邏輯:
ifctx := r.cache.GetItem(req.Method, req.URL.Path); ctx !=nil{ ctx.Redo(res, req)return}
ctx.Redo(res, req)導致不斷循環,直到每個請求處理完畢,將context放回到池子中。
所以對於Iris來說,並發量大的情況下,對於相同的請求(req.URL.Path和Method相同)會進入排隊的狀態,導致性能低下。
幫我看看這代碼是不是zend加密的?該如何解密?
//沒有具體調試,中間有個別亂字元,反正這樣已經可以看清楚很多了,你自己再細看,細改
?php
/*********************/
/* */
/* Version : 5.1.0 */
/* Author : RM */
/* Comment : 071223 */
/* */
/*********************/
function _obfuscate_cWwfD2UGW3ZycCZxCmQZE2Vd( )
{
global $skyuc;
$_obfuscate_fMfssw = array( );
$_obfuscate_3y0Y = “SELECT user_id, user_name, email, join_time, last_time FROM “.TABLE_PREFIX.”admin ORDER BY user_id DESC”;
$_obfuscate_fMfssw = array( );
$_obfuscate_TZ9ZmTEoi3QY5E = $skyuc-db-_obfuscate_O2QPeG5mYRBuO18BfwU9Ew( $_obfuscate_3y0Y );
while ( $_obfuscate_gkt = $skyuc-db-fetch_array( $_obfuscate_TZ9ZmTEoi3QY5E ) )
{
$_obfuscate_gkt[‘join_time’] = _obfuscate_ej0lcF0vcgh5bw( $skyuc-options[‘date_format’].” “.$skyuc-options[‘time_format’], $_obfuscate_gkt[‘join_time’], FALSE, FALSE );
$_obfuscate_gkt[‘last_time’] = _obfuscate_ej0lcF0vcgh5bw( $skyuc-options[‘date_format’].” “.$skyuc-options[‘time_format’], $_obfuscate_gkt[‘last_time’], FALSE, FALSE );
$_obfuscate_fMfssw[] = $_obfuscate_gkt;
}
$skyuc-db-free_result( $_obfuscate_TZ9ZmTEoi3QY5E );
return $_obfuscate_fMfssw;
}
require( dirname( __FILE__ ).”/global.php” );
if ( empty( $skyuc-GPC[‘act’] ) )
{
$skyuc-GPC[‘act’] = “login”;
}
$exc = new _l8o1a75( TABLE_PREFIX.”admin”, $skyuc-db, “user_id”, “user_name” );
if ( $skyuc-GPC[‘act’] == “logout” )
{
_obfuscate_AVxyeGtkKBUndG44YXlm( “cpsession”, “”, FALSE, TRUE, TRUE );
_obfuscate_AVxyeGtkKBUndG44YXlm( “adminid”, “”, FALSE, TRUE, TRUE );
_obfuscate_AVxyeGtkKBUndG44YXlm( “admin_pass”, “”, FALSE, TRUE, TRUE );
$db-_obfuscate_dDtscngYEGltXHg( “DELETE FROM “.TABLE_PREFIX.”cpsession WHERE adminid = “.$skyuc-session-vars[‘adminid’].” AND hash = ‘”.$db-escape_string( $skyuc-GPC[COOKIE_PREFIX.”cpsession”] ).”‘” );
$skyuc-session-_obfuscate_JiMofFtzGWM2GB1ybjYT( );
if ( !empty( $skyuc-session-vars[‘sessionurl_js’] ) )
{
_obfuscate_BgwNNztob2cEdgwmG3oHPxERCyA( “privilege.php?act=login”.$skyuc-session-vars[‘sessionurl_js’] );
}
else
{
_obfuscate_BgwNNztob2cEdgwmG3oHPxERCyA( “privilege.php?act=login” );
}
}
if ( $skyuc-GPC[‘act’] == “login” )
{
if ( intval( $skyuc-options[‘humanverify’] ) HV_ADMIN )
{
require_once( DIR.”/includes/class_humanverify.php” );
$verification = u18a5lewy4k::_obfuscate_YyRoZG8idX94DhEyEg( $skyuc );
$human_verify = $verification-_obfuscate_CHYdBnR5FGEsHGx1CGg( );
$smarty-assign( “humanverify”, $human_verify );
}
$smarty-assign( “sessionhash”, $skyuc-session-vars[‘dbsessionhash’] );
$smarty-assign( “scriptpath”, $skyuc-scriptpath );
$smarty-assign( “securitytoken”, $skyuc-userinfo[‘securitytoken’] );
$smarty-_obfuscate_E2Iicm4fNA( “login.tpl” );
}
if ( $skyuc-GPC[‘act’] == “signin” )
{
$skyuc-input-_obfuscate_c3sMXXFzZBIkeW94aV0X( “p”, array(
“username” = TYPE_STR,
“password” = TYPE_STR,
“humanverify” = TYPE_ARRAY_STR
) );
if ( !empty( $skyuc-GPC[‘humanverify’] ) )
{
require_once( DIR.”/includes/class_humanverify.php” );
$verify = u18a5lewy4k::_obfuscate_YyRoZG8idX94DhEyEg( $skyuc );
if ( !$verify-_obfuscate_dnNrf2kdfhMLBSg4( $skyuc-GPC[‘humanverify’] ) )
{
_obfuscate_Xmd6d3IbBg( $_LANG[‘captcha_error’], 1 );
}
}
$sql = “SELECT user_id, user_name, password, action_list, last_time\n \t\t\t\tFROM “.TABLE_PREFIX.”admin\n \t\t\t WHERE user_name = ‘”.$db-escape_string( $skyuc-GPC[‘username’] ).”‘ AND password = ‘”.md5( $skyuc-GPC[‘password’] ).”‘”;
$row = $skyuc-db-_obfuscate_bmdgO2klIzAaOXF6J3oLJ3o( $sql );
if ( $row )
{
define( “NOSHUTDOWNFUNC”, 1 );
_obfuscate_N3MES84AxZjNWF7L1sTZSo( $row[‘user_id’], $row[‘user_name’], $row[‘action_list’], $row[‘last_time’] );
$cpsession = $skyuc-session-_obfuscate_dy4_P3JxJiBmcGg9GW40Gnk( );
$skyuc-db-_obfuscate_dDtscngYEGltXHg( “INSERT INTO “.TABLE_PREFIX.”cpsession (adminid, hash, dateline) VALUES (“.$row[‘user_id’].”, ‘”.$skyuc-db-escape_string( $cpsession ).”‘, “.TIMENOW.”)” );
_obfuscate_AVxyeGtkKBUndG44YXlm( “cpsession”, $cpsession, FALSE, TRUE, TRUE );
$skyuc-db-query( “UPDATE “.TABLE_PREFIX.”admin SET last_time=”.TIMENOW.”, last_ip='”.ALT_IP.”‘ WHERE user_id=”.$row[‘user_id’] );
if ( empty( $skyuc-GPC[COOKIE_PREFIX.”adminid”] ) )
{
_obfuscate_AVxyeGtkKBUndG44YXlm( “adminid”, $row[‘user_id’], TRUE, TRUE, TRUE );
_obfuscate_AVxyeGtkKBUndG44YXlm( “admin_pass”, md5( $row[‘password’].COOKIE_SALT ), FALSE, TRUE, TRUE );
}
_obfuscate_BgwNNztob2cEdgwmG3oHPxERCyA( “index.php” );
}
else
{
include_once( DIR.”/includes/functions_log_error.php” );
log_skyuc_error( $skyuc-GPC[‘username’], “security” );
_obfuscate_Xmd6d3IbBg( $_LANG[‘login_faild’], 1 );
}
}
else if ( $skyuc-GPC[‘act’] == “list” )
{
$smarty-assign( “ur_here”, $_LANG[’03_admin_list’] );
$smarty-assign( “action_link”, array(
“href” = “privilege.php?act=add”,
“text” = $_LANG[’02_admin_add’]
) );
$smarty-assign( “full_page”, 1 );
$smarty-assign( “admin_list”, _obfuscate_cWwfD2UGW3ZycCZxCmQZE2Vd( ) );
_obfuscate_HDx0NH9rBGYePDsiYiMoHhI( );
$smarty-_obfuscate_E2Iicm4fNA( “privilege_list.tpl” );
}
else if ( $skyuc-GPC[‘act’] == “query” )
{
$smarty-assign( “admin_list”, _obfuscate_cWwfD2UGW3ZycCZxCmQZE2Vd( ) );
_obfuscate_e3YWEXZncjJtExFsOAQaNA( $smarty-fetch( “privilege_list.tpl” ) );
}
else if ( $skyuc-GPC[‘act’] == “add” )
{
_obfuscate_LWNyCzttbwgWJw( “admin_manage” );
$smarty-assign( “ur_here”, $_LANG[’02_admin_add’] );
$smarty-assign( “action_link”, array(
“href” = “privilege.php?act=list”,
“text” = $_LANG[’03_admin_list’]
) );
$smarty-assign( “form_act”, “insert” );
$smarty-assign( “action”, “add” );
_obfuscate_HDx0NH9rBGYePDsiYiMoHhI( );
$smarty-_obfuscate_E2Iicm4fNA( “privilege_info.tpl” );
}
else if ( $skyuc-GPC[‘act’] == “insert” )
{
_obfuscate_LWNyCzttbwgWJw( “admin_manage” );
$skyuc-input-_obfuscate_c3sMXXFzZBIkeW94aV0X( “p”, array(
“user_name” = TYPE_STR,
“email” = TYPE_STR,
“password” = TYPE_STR
) );
if ( $skyuc-GPC_exists[‘user_name’] )
{
$is_only = $exc-_obfuscate_Bn00DmVndg( “user_name”, $skyuc-GPC[‘user_name’] );
if ( !$is_only )
{
_obfuscate_Xmd6d3IbBg( sprintf( $_LANG[‘user_name_exist’], $skyuc-GPC[‘user_name’] ), 1 );
}
}
if ( $skyuc-GPC_exists[’email’] )
{
$is_only = $exc-_obfuscate_Bn00DmVndg( “email”, $skyuc-GPC[’email’] );
if ( !$is_only )
{
_obfuscate_Xmd6d3IbBg( sprintf( $_LANG[’email_exist’], $skyuc-GPC[’email’] ), 1 );
}
}
$join_time = TIMENOW;
$password = md5( $skyuc-GPC[‘password’] );
$sql = “INSERT INTO “.TABLE_PREFIX.”admin (user_name, email, password, join_time) VALUES (‘”.$skyuc-GPC[‘user_name’].”‘, ‘”.$skyuc-GPC[’email’].( “‘, ‘”.$password.”‘, ‘{$join_time}’)” );
$skyuc-db-_obfuscate_dDtscngYEGltXHg( $sql );
$new_id = $skyuc-db-insert_id( );
$link[0][‘text’] = $_LANG[‘go_allot_priv’];
$link[0][‘href’] = “privilege.php?act=allotid=”.$new_id.”user=”.$skyuc-GPC[‘user_name’].””;
$link[1][‘text’] = $_LANG[‘continue_add’];
$link[1][‘href’] = “privilege.php?act=add”;
_obfuscate_Xmd6d3IbBg( $_LANG[‘add’].” “.$skyuc-GPC[‘user_name’].” “.$_LANG[‘action_succeed’], 0, $link );
admin_log( $skyuc-GPC[‘user_name’], “add”, “privilege” );
}
else if ( $skyuc-GPC[‘act’] == “edit” )
{
$admin_name = _obfuscate_BxJtK280anUHKGwyLH5zeRUSYTw( $skyuc-session-vars[‘adminid’].”_admin_name” );
if ( $admin_name == “demo” )
{
$link[] = array(
“text” = $_LANG[‘back_list’],
“href” = “privilege.php?act=list”
);
_obfuscate_Xmd6d3IbBg( $_LANG[‘edit_admininfo_cannot’], 0, $link );
}
$id = $skyuc-input-_obfuscate_ZAo_ZCRcNAhk( “r”, “id”, TYPE_UINT );
if ( $skyuc-session-vars[‘adminid’] !== $id )
{
_obfuscate_LWNyCzttbwgWJw( “admin_manage” );
}
$sql = “SELECT user_id, user_name, email, password FROM “.TABLE_PREFIX.”admin WHERE user_id = ‘”.$id.”‘”;
$user_info = $skyuc-db-_obfuscate_bmdgO2klIzAaOXF6J3oLJ3o( $sql );
$smarty-assign( “ur_here”, $_LANG[‘admin_edit’] );
$smarty-assign( “action_link”, array(
“text” = $_LANG[’03_admin_list’],
“href” = “privilege.php?act=list”
) );
$smarty-assign( “user”, $user_info );
$smarty-assign( “form_act”, “update” );
$smarty-assign( “action”, “edit” );
_obfuscate_HDx0NH9rBGYePDsiYiMoHhI( );
$smarty-_obfuscate_E2Iicm4fNA( “privilege_info.tpl” );
}
else if ( $skyuc-GPC[‘act’] == “update” )
{
_obfuscate_LWNyCzttbwgWJw( “admin_manage” );
$admin_id = $skyuc-input-_obfuscate_ZAo_ZCRcNAhk( “p”, “id”, TYPE_UINT );
$admin_name = $skyuc-input-_obfuscate_ZAo_ZCRcNAhk( “p”, “user_name”, TYPE_STR );
$admin_email = $skyuc-input-_obfuscate_ZAo_ZCRcNAhk( “p”, “email”, TYPE_STR );
$skyuc-input-_obfuscate_c3sMXXFzZBIkeW94aV0X( “p”, array(
“nav_list” = TYPE_ARRAY_STR,
“new_password” = TYPE_STR,
“pwd_confirm” = TYPE_STR,
“old_password” = TYPE_STR
) );
$nav_list = _obfuscate_fRE5( !empty( $skyuc-GPC[‘nav_list’] ), “, nav_list = ‘”.@join( “,”, $skyuc-GPC[‘nav_list’] ).”‘”, “” );
$password = _obfuscate_fRE5( !empty( $skyuc-GPC[‘new_password’] ), “, password = ‘”.md5( $skyuc-GPC[‘new_password’] ).”‘”, “” );
if ( !empty( $admin_name ) )
{
$is_only = $exc-num( “user_name”, $admin_name, $admin_id );
if ( $is_only == 1 )
{
_obfuscate_Xmd6d3IbBg( sprintf( $_LANG[‘user_name_exist’], $admin_name ), 1 );
}
}
if ( !empty( $admin_email ) )
{
$is_only = $exc-num( “email”, $admin_email, $admin_id );
if ( $is_only == 1 )
{
_obfuscate_Xmd6d3IbBg( sprintf( $_LANG[’email_exist’], $admin_email ), 1 );
}
}
$pwd_modified = FALSE;
if ( !empty( $skyuc-GPC[‘new_password’] ) )
{
$sql = “SELECT password FROM “.TABLE_PREFIX.”admin”.( ” WHERE user_id = ‘”.$admin_id.”‘” );
$row = $skyuc-db-_obfuscate_bmdgO2klIzAaOXF6J3oLJ3o( $sql );
$old_password = $row[‘password’];
if ( $old_password != md5( $skyuc-GPC[‘old_password’] ) )
{
$link[] = array(
“text” = $_LANG[‘go_back’],
“href” = “javascript:history.back(-1)”
);
_obfuscate_Xmd6d3IbBg( $_LANG[‘pwd_error’], 0, $link );
}
if ( $skyuc-GPC[‘new_password’] != $skyuc-GPC[‘pwd_confirm’] )
{
$link[] = array(
“text” = $_LANG[‘go_back’],
“href” = “javascript:history.back(-1)”
);
_obfuscate_Xmd6d3IbBg( $_LANG[‘js_languages’][‘password_error’], 0, $link );
}
else
{
$pwd_modified = TRUE;
}
}
$sql = “UPDATE “.TABLE_PREFIX.”admin”.( ” SET user_name = ‘”.$admin_name.”‘, email = ‘{$admin_email}’ \t{$password} \t{$nav_list} ” ).” WHERE user_id =”.$admin_id;
$skyuc-db-_obfuscate_dDtscngYEGltXHg( $sql );
admin_log( $admin_name, “edit”, “privilege” );
if ( $pwd_modified )
{
$skyuc-db-_obfuscate_dDtscngYEGltXHg( “DELETE FROM “.TABLE_PREFIX.”session WHERE adminid = ‘”.$skyuc-session-vars[‘adminid’].”‘” );
$msg = $_LANG[‘edit_password_succeed’];
}
else
{
$msg = $_LANG[‘edit_profile_succeed’];
}
$link[] = array(
“text” = $_LANG[‘back_admin_list’],
“href” = “privilege.php?act=list”
);
_obfuscate_Xmd6d3IbBg( $_LANG[‘edit’].”{$msg}scriptparent.document.getElementById(‘header-frame’).contentWindow.document.location.reload();/script”, 0, $link );
}
else if ( $skyuc-GPC[‘act’] == “modif” )
{
$admin_name = _obfuscate_BxJtK280anUHKGwyLH5zeRUSYTw( $skyuc-session-vars[‘adminid’].”_admin_name” );
if ( $admin_name == “demo” )
{
$link[] = array(
“text” = $_LANG[‘back_admin_list’],
“href” = “privilege.php?act=list”
);
_obfuscate_Xmd6d3IbBg( $_LANG[‘edit_admininfo_cannot’], 0, $link );
}
include_once( ADM.”/inc_menu.php” );
foreach ( $modules as $key = $value )
{
ksort( $modules[$key] );
}
ksort( $modules );
foreach ( $modules as $key = $val )
{
$menus[$key][‘label’] = $_LANG[$key];
if ( is_array( $val ) )
{
foreach ( $val as $k = $v )
{
$menus[$key][‘children’][$k][‘label’] = $_LANG[$k];
$menus[$key][‘children’][$k][‘action’] = $v;
}
}
else
{
$menus[$key][‘action’] = $val;
}
}
$sql = “SELECT user_id, user_name, email, nav_list FROM “.TABLE_PREFIX.”admin WHERE user_id = “.$skyuc-session-vars[‘adminid’];
$user_info = $skyuc-db-_obfuscate_bmdgO2klIzAaOXF6J3oLJ3o( $sql );
$nav_arr = trim( $user_info[‘nav_list’] ) == “” ? array( ) : explode( “,”, $user_info[‘nav_list’] );
$nav_lst = array( );
foreach ( $nav_arr as $val )
{
$arr = explode( “|”, $val );
$nav_lst[$arr[1]] = $arr[0];
}
$smarty-assign( “lang”, $_LANG );
$smarty-assign( “ur_here”, $_LANG[‘modif_info’] );
$smarty-assign( “action_link”, array(
“text” = $_LANG[’03_admin_list’],
“href” = “privilege.php?act=list”
) );
$smarty-assign( “user”, $user_info );
$smarty-assign( “menus”, $modules );
$smarty-assign( “nav_arr”, $nav_lst );
$smarty-assign( “form_act”, “update” );
$smarty-assign( “action”, “modif” );
_obfuscate_HDx0NH9rBGYePDsiYiMoHhI( );
$smarty-_obfuscate_E2Iicm4fNA( “privilege_info.tpl” );
}
else if ( $skyuc-GPC[‘act’] == “allot” )
{
require( DIR.”/languages/”.$skyuc-options[‘lang’].”/admincp/priv_action.php” );
_obfuscate_LWNyCzttbwgWJw( “allot_priv” );
$id = $skyuc-input-_obfuscate_ZAo_ZCRcNAhk( “g”, “id”, TYPE_UINT );
$priv_str = $skyuc-db-_obfuscate_aH8afmpdBnVfGWU( “SELECT action_list FROM “.TABLE_PREFIX.”admin WHERE user_id =”.$id.”” );
if ( $priv_str[‘action_list’] == “all” )
{
$link[] = array(
“text” = $_LANG[‘back_admin_list’],
“href” = “privilege.php?act=list”
);
_obfuscate_Xmd6d3IbBg( $_LANG[‘edit_admininfo_cannot’], 0, $link );
}
$sql = “SELECT action_id, parent_id, action_code FROM “.TABLE_PREFIX.”admin_action WHERE parent_id = 0”;
$res = $skyuc-db-_obfuscate_aSRoDjhcKmZdYQ( $sql );
while ( $rows = $skyuc-db-fetch_array( $res ) )
{
$priv_arr[$rows[‘action_id’]] = $rows;
}
$sql = “SELECT action_id, parent_id, action_code FROM “.TABLE_PREFIX.”admin_action WHERE parent_id “._obfuscate_XGMVcmkUDQNdjgN( array_keys( $priv_arr ) );
$result = $skyuc-db-_obfuscate_aSRoDjhcKmZdYQ( $sql );
while ( $priv = $skyuc-db-fetch_array( $result ) )
{
$priv_arr[$priv[‘parent_id’]][‘priv’][$priv[‘action_code’]] = $priv;
}
foreach ( $priv_arr as $action_id = $action_group )
{
$priv_arr[$action_id][‘priv_list’] = join( “,”, @array_keys( $action_group[‘priv’] ) );
foreach ( $action_group[‘priv’] as $key = $val )
{
$priv_arr[$action_id][‘priv’][$key][‘cando’] = strpos( $priv_str[‘action_list’], $val[‘action_code’] ) !== FALSE || $priv_str[‘action_list’] == “all” ? 1 : 0;
}
}
$smarty-assign( “lang”, $_LANG );
$smarty-assign( “ur_here”, $_LANG[‘allot_priv’].” [ “.$skyuc-input-_obfuscate_ZAo_ZCRcNAhk( “g”, “user”, TYPE_STR ).” ] ” );
$smarty-assign( “action_link”, array(
“href” = “privilege.php?act=list”,
“text” = $_LANG[’03_admin_list’]
) );
$smarty-assign( “priv_arr”, $priv_arr );
$smarty-assign( “form_act”, “update_allot” );
$smarty-assign( “user_id”, $id );
_obfuscate_HDx0NH9rBGYePDsiYiMoHhI( );
$smarty-_obfuscate_E2Iicm4fNA( “privilege_allot.tpl” );
}
else if ( $skyuc-GPC[‘act’] == “update_allot” )
{
_obfuscate_LWNyCzttbwgWJw( “admin_manage” );
$id = $skyuc-input-_obfuscate_ZAo_ZCRcNAhk( “p”, “id”, TYPE_UINT );
$admin = $skyuc-db-_obfuscate_aH8afmpdBnVfGWU( “SELECT user_name FROM “.TABLE_PREFIX.”admin”.( ” WHERE user_id = “.$id ) );
$admin_name = $admin[‘user_name’];
$act_list = @join( “,”, @$skyuc-input-_obfuscate_ZAo_ZCRcNAhk( “p”, “action_code”, TYPE_ARRAY_STR ) );
$sql = “UPDATE “.TABLE_PREFIX.”admin”.( ” SET action_list = ‘”.$act_list.”‘ ” ).( “WHERE user_id = “.$id );
$skyuc-db-_obfuscate_dDtscngYEGltXHg( $sql );
if ( $skyuc-session-vars[‘adminid’] === $id )
{
_obfuscate_LQIbX3kUIWEKfXozXGpyCTsSCmc( $id.”_action_list”, $act_list );
}
admin_log( $admin_name, “edit”, “privilege” );
$link[] = array(
“text” = $_LANG[‘back_admin_list’],
“href” = “privilege.php?act=list”
);
_obfuscate_Xmd6d3IbBg( $_LANG[‘edit’].” “.$admin_name.” “.$_LANG[‘action_succeed’], 0, $link );
}
else if ( $skyuc-GPC[‘act’] == “remove” )
{
_obfuscate_OCEuGngTZWJzGw1vZH4teg( “admin_manage” );
$id = $skyuc-input-_obfuscate_ZAo_ZCRcNAhk( “g”, “id”, TYPE_UINT );
$admin_name = $skyuc-db-_obfuscate_aH8afmpdBnVfGWU( “SELECT user_name FROM “.TABLE_PREFIX.”admin”.( ” WHERE user_id=”.$id ) );
if ( $admin_name == “demo” )
{
_obfuscate_fwJ5Cw8qQHY9W18_YXMp( $_LANG[‘edit_remove_cannot’] );
}
if ( $id == 1 )
{
_obfuscate_fwJ5Cw8qQHY9W18_YXMp( $_LANG[‘remove_cannot’] );
}
if ( $exc-drop( $id ) )
{
$skyuc-db-_obfuscate_dDtscngYEGltXHg( “DELETE FROM “.TABLE_PREFIX.( “session WHERE adminid =”.$id ) );
admin_log( $admin_name, “remove”, “privilege” );
}
$url = “privilege.php?act=query”.str_replace( “act=remove”, “”, $_SERVER[‘QUERY_STRING’] );
_obfuscate_BgwNNztob2cEdgwmG3oHPxERCyA( $url );
}
?
原創文章,作者:PRBM,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/135726.html