Skip to content

Commit

Permalink
Fix and Update
Browse files Browse the repository at this point in the history
  • Loading branch information
Jidoer committed Jan 5, 2022
1 parent 834c157 commit 5f52860
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 22 deletions.
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ module MyPHPServer

go 1.17

require github.com/kangc666/file v0.0.0-20220105082348-a73d1bc34fbd

require (
github.com/BurntSushi/toml v0.3.1 // indirect
github.com/CloudyKit/fastprinter v0.0.0-20200109182630-33d98a066a53 // indirect
Expand All @@ -15,7 +17,6 @@ require (
github.com/iris-contrib/pongo2 v0.0.1 // indirect
github.com/iris-contrib/schema v0.0.1 // indirect
github.com/json-iterator/go v1.1.9 // indirect
github.com/kangc666/file v0.0.0-20211213141134-3a1e7f19eea9
github.com/kataras/golog v0.0.10 // indirect
github.com/kataras/iris/v12 v12.1.8 // indirect
github.com/kataras/pio v0.0.2 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ github.com/json-iterator/go v1.1.9 h1:9yzud/Ht36ygwatGx56VwCZtlI/2AD15T1X2sjSuGn
github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
github.com/kangc666/file v0.0.0-20211213141134-3a1e7f19eea9 h1:RIAyyQnkhmIZEZ4n2QBvVJn5tqTMaKjyS0X4Ru2unYs=
github.com/kangc666/file v0.0.0-20211213141134-3a1e7f19eea9/go.mod h1:2gscbprCk4QejPadqr/hddouURmsl9jwVP7yzcuG2Y0=
github.com/kangc666/file v0.0.0-20220105082348-a73d1bc34fbd h1:hAw9PDVIqSdo7XHMMu+EV4gyOTiEs5S5T1B3mGAK2+Q=
github.com/kangc666/file v0.0.0-20220105082348-a73d1bc34fbd/go.mod h1:2gscbprCk4QejPadqr/hddouURmsl9jwVP7yzcuG2Y0=
github.com/kataras/golog v0.0.10 h1:vRDRUmwacco/pmBAm8geLn8rHEdc+9Z4NAr5Sh7TG/4=
github.com/kataras/golog v0.0.10/go.mod h1:yJ8YKCmyL+nWjERB90Qwn+bdyBZsaQwU3bTVFgkFIp8=
github.com/kataras/iris/v12 v12.1.8 h1:O3gJasjm7ZxpxwTH8tApZsvf274scSGQAUpNe47c37U=
Expand Down
64 changes: 43 additions & 21 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ func main() {
if file.Exists(Root + path) {
//!
if lastname == ".php" {
loadphp(ctx, Root,path)
loadphp(ctx, Root, path)
} else if lastname == ".html" || lastname == ".css" || lastname == ".js" {
ctx.HTML(file.Reader(Root + path))
} else if lastname == ".zip" || lastname == ".mp3" || lastname ==".png" || lastname ==".gif" {
ctx.Write([]byte(file.Reader(Root + path)))
} else if lastname == ".zip" || lastname == ".mp3" || lastname == ".png" || lastname == ".gif" {
log.Print("File:" + Root + path)
// /c.mp3 or cc/c.mp3
if strings.Contains(path, "/") {
Expand All @@ -61,17 +61,16 @@ func main() {
} else {
//No file or cc/bb/index
if file.Exists(Root + path + "/index.php") {
loadphp(ctx, Root,path+"/index.php")
loadphp(ctx, Root, path+"/index.php")
} else if file.Exists(Root + path + "/index.html") {
ctx.HTML(file.Reader(Root + path + "/index.html"))
ctx.Write([]byte(file.Reader(Root + path + "/index.html")))
} else if file.Exists(Root + path + "/index.htm") {
ctx.HTML(file.Reader(Root + path + "/index.htm"))
ctx.Write([]byte(file.Reader(Root + path + "/index.htm")))
} else if file.Exists(Root + path + "/index.c") {
ctx.HTML(file.Reader(Root + path + "/index.c"))
ctx.Write([]byte(file.Reader(Root + path + "/index.c")))
} else {
//403!
ctx.Header("HTTP/1.1", "403")
ctx.HTML("403 ERROR!")
ctx.HTML(ListFile(Root,path))
}
}

Expand Down Expand Up @@ -144,12 +143,39 @@ func main() {
}
}

func loadphp(ctx iris.Context ,/*path string*/Root string, Path string) bool {
PHPcgi(ctx.ResponseWriter(), ctx.Request() /*cgibin*/, "/usr/lib/cgi-bin/php7.4",Root, Path)
func ListFile(ROOT, Path string) string {
dir_list, e := ioutil.ReadDir(ROOT + Path)
if e != nil {
fmt.Println("read dir error")
return "error"
}
/*
for i, v := range dir_list {
fmt.Println(i, "=", v.Name())
}*/
tatol := "<hr>"
for i, v := range dir_list {
var myname string
if file.IsDir(ROOT + Path + "/" + v.Name()) {
myname = v.Name() + "/"
} else {
myname = v.Name()
}

tatol = tatol + "<a href='/" + Path + "/" + v.Name() + "'>" + myname /*v.Name()*/ + "</a><hr>"
//log.Print(i,string(rune(i)))
fmt.Println(i, v.Name()+string(rune(i)))
}
//log.Print(tatol)
return "<h1>Index Of</h1>" + tatol + "<p align='center'>Powered By: FlyKO</p>"
}

func loadphp(ctx iris.Context /*path string*/, Root string, Path string) bool {
PHPcgi(ctx.ResponseWriter(), ctx.Request() /*cgibin*/, "/usr/lib/cgi-bin/php7.4", Root, Path)
return true
}

func PHPcgi(w http.ResponseWriter, r *http.Request, cgiBin string, /*scriptFile string*/Root string, Path string) {
func PHPcgi(w http.ResponseWriter, r *http.Request, cgiBin string /*scriptFile string*/, Root string, Path string) {
//scriptFile:PHPFilePath
scriptFile := Root + Path
handler := new(cgi.Handler)
Expand All @@ -163,10 +189,10 @@ func PHPcgi(w http.ResponseWriter, r *http.Request, cgiBin string, /*scriptFile
var DOCUMENT_ROOT string
var SCRIPT_NAME string
/*GetDOCUMENT_ROOT*/
if(strings.Contains(Path,"/")){
DOCUMENT_ROOT = string(scriptFile[:strings.LastIndex(scriptFile,"/")])
SCRIPT_NAME = string(scriptFile[strings.LastIndex(scriptFile,"/"):])
}else{
if strings.Contains(Path, "/") {
DOCUMENT_ROOT = string(scriptFile[:strings.LastIndex(scriptFile, "/")])
SCRIPT_NAME = string(scriptFile[strings.LastIndex(scriptFile, "/"):])
} else {
// xxx.php index.php
DOCUMENT_ROOT = Root
SCRIPT_NAME = Path
Expand All @@ -175,11 +201,7 @@ func PHPcgi(w http.ResponseWriter, r *http.Request, cgiBin string, /*scriptFile
handler.Env = append(handler.Env, "SCRIPT_NAME="+SCRIPT_NAME)
handler.Env = append(handler.Env, "DOCUMENT_ROOT="+DOCUMENT_ROOT)





print("DOCUMENT_ROOT="+DOCUMENT_ROOT+"\n")
print("DOCUMENT_ROOT=" + DOCUMENT_ROOT + "\n")
//log.Print(r.Host)
handler.ServeHTTP(w, r)
}
Binary file added screenshot/MyPHPServer1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshot/MyPHPServer2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshot/MyPHPServer3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 5f52860

Please sign in to comment.