2014-08-14 08:15:52 +02:00
|
|
|
package controllers
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
2014-12-23 02:19:11 +01:00
|
|
|
"fmt"
|
2014-08-14 08:15:52 +02:00
|
|
|
"github.com/astaxie/beego"
|
2014-12-23 02:19:11 +01:00
|
|
|
"net"
|
2015-12-27 11:53:43 +01:00
|
|
|
"os"
|
2014-08-14 08:15:52 +02:00
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
type MainController struct {
|
|
|
|
beego.Controller
|
|
|
|
}
|
|
|
|
|
|
|
|
func (this *MainController) GetForwarded() {
|
|
|
|
if len(this.Ctx.Request.Header["X-Forwarded-For"]) > 0 {
|
|
|
|
this.Data["Value"] = this.Ctx.Request.Header["X-Forwarded-For"][0]
|
|
|
|
}
|
2016-11-15 07:08:59 +01:00
|
|
|
this.TplName = "value.tpl"
|
2014-08-14 08:15:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (this *MainController) GetHost() {
|
2014-12-23 02:19:11 +01:00
|
|
|
ip := this.Ctx.Input.IP()
|
|
|
|
names, err := net.LookupAddr(ip)
|
|
|
|
if err != nil || len(names) == 0 {
|
|
|
|
this.Data["Value"] = ""
|
|
|
|
} else {
|
|
|
|
var value string
|
|
|
|
for _, v := range names {
|
|
|
|
value += fmt.Sprintf("%s\n", v)
|
|
|
|
}
|
|
|
|
this.Data["Value"] = value
|
|
|
|
}
|
2016-11-15 07:08:59 +01:00
|
|
|
this.TplName = "value.tpl"
|
2014-08-14 08:15:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (this *MainController) GetIP() {
|
|
|
|
this.Data["Value"] = this.Ctx.Input.IP()
|
2016-11-15 07:08:59 +01:00
|
|
|
this.TplName = "value.tpl"
|
2014-08-14 08:15:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (this *MainController) GetPort() {
|
|
|
|
remote_addr := []byte(this.Ctx.Request.RemoteAddr)
|
|
|
|
pos := bytes.IndexByte(remote_addr, ':')
|
|
|
|
this.Data["Value"] = string(remote_addr[pos+1:])
|
2016-11-15 07:08:59 +01:00
|
|
|
this.TplName = "value.tpl"
|
2014-08-14 08:15:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (this *MainController) GetVia() {
|
|
|
|
if len(this.Ctx.Request.Header["Via"]) > 0 {
|
|
|
|
this.Data["Value"] = this.Ctx.Request.Header["Via"][0]
|
|
|
|
}
|
2016-11-15 07:08:59 +01:00
|
|
|
this.TplName = "value.tpl"
|
2014-08-14 08:15:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (this *MainController) GetMime() {
|
|
|
|
if len(this.Ctx.Request.Header["Accept"]) > 0 {
|
|
|
|
this.Data["Value"] = this.Ctx.Request.Header["Accept"][0]
|
|
|
|
}
|
2016-11-15 07:08:59 +01:00
|
|
|
this.TplName = "value.tpl"
|
2014-08-14 08:15:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (this *MainController) GetLang() {
|
|
|
|
if len(this.Ctx.Request.Header["Accept-Language"]) > 0 {
|
|
|
|
this.Data["Value"] = this.Ctx.Request.Header["Accept-Language"][0]
|
|
|
|
}
|
2016-11-15 07:08:59 +01:00
|
|
|
this.TplName = "value.tpl"
|
2014-08-14 08:15:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (this *MainController) GetCharset() {
|
|
|
|
if len(this.Ctx.Request.Header["Charset"]) > 0 {
|
|
|
|
this.Data["Value"] = this.Ctx.Request.Header["Charset"][0]
|
|
|
|
}
|
2016-11-15 07:08:59 +01:00
|
|
|
this.TplName = "value.tpl"
|
2014-08-14 08:15:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (this *MainController) GetEncoding() {
|
|
|
|
if len(this.Ctx.Request.Header["Accept-Encoding"]) > 0 {
|
|
|
|
this.Data["Value"] = this.Ctx.Request.Header["Accept-Encoding"][0]
|
|
|
|
}
|
2016-11-15 07:08:59 +01:00
|
|
|
this.TplName = "value.tpl"
|
2014-08-14 08:15:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (this *MainController) GetUserAgent() {
|
|
|
|
this.Data["Value"] = this.Ctx.Request.UserAgent()
|
2016-11-15 07:08:59 +01:00
|
|
|
this.TplName = "value.tpl"
|
2014-08-14 08:15:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (this *MainController) GetConnection() {
|
|
|
|
if len(this.Ctx.Request.Header["Connection"]) > 0 {
|
|
|
|
this.Data["Value"] = this.Ctx.Request.Header["Connection"][0]
|
|
|
|
}
|
2016-11-15 07:08:59 +01:00
|
|
|
this.TplName = "value.tpl"
|
2014-08-14 08:15:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (this *MainController) GetKeepAlive() {
|
|
|
|
if len(this.Ctx.Request.Header["KeepAlive"]) > 0 {
|
|
|
|
this.Data["Value"] = this.Ctx.Request.Header["KeepAlive"][0]
|
|
|
|
}
|
2016-11-15 07:08:59 +01:00
|
|
|
this.TplName = "value.tpl"
|
2014-08-14 08:15:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (this *MainController) GetAll() {
|
|
|
|
this.Data["Email"] = "missdeer@dfordsoft.com"
|
|
|
|
this.Data["UserAgent"] = this.Ctx.Request.UserAgent()
|
2014-12-23 02:19:11 +01:00
|
|
|
ip := this.Ctx.Input.IP()
|
|
|
|
names, err := net.LookupAddr(ip)
|
|
|
|
if err != nil || len(names) == 0 {
|
|
|
|
this.Data["Host"] = ""
|
|
|
|
} else {
|
|
|
|
var value string
|
|
|
|
for _, v := range names {
|
|
|
|
value += fmt.Sprintf("%s\n", v)
|
|
|
|
}
|
|
|
|
this.Data["Host"] = value
|
|
|
|
}
|
2014-08-14 08:15:52 +02:00
|
|
|
this.Data["IP"] = this.Ctx.Input.IP()
|
|
|
|
remote_addr := []byte(this.Ctx.Request.RemoteAddr)
|
|
|
|
pos := bytes.IndexByte(remote_addr, ':')
|
|
|
|
this.Data["Port"] = string(remote_addr[pos+1:])
|
|
|
|
this.Data["Method"] = this.Ctx.Request.Method
|
|
|
|
if len(this.Ctx.Request.Header["Accept-Encoding"]) > 0 {
|
|
|
|
this.Data["Encoding"] = this.Ctx.Request.Header["Accept-Encoding"][0]
|
|
|
|
}
|
|
|
|
if len(this.Ctx.Request.Header["Accept"]) > 0 {
|
|
|
|
this.Data["Mime"] = this.Ctx.Request.Header["Accept"][0]
|
|
|
|
}
|
|
|
|
if len(this.Ctx.Request.Header["Connection"]) > 0 {
|
|
|
|
this.Data["Connection"] = this.Ctx.Request.Header["Connection"][0]
|
|
|
|
}
|
|
|
|
if len(this.Ctx.Request.Header["Via"]) > 0 {
|
|
|
|
this.Data["Via"] = this.Ctx.Request.Header["Via"][0]
|
|
|
|
}
|
|
|
|
if len(this.Ctx.Request.Header["Charset"]) > 0 {
|
|
|
|
this.Data["Charset"] = this.Ctx.Request.Header["Charset"][0]
|
|
|
|
}
|
|
|
|
if len(this.Ctx.Request.Header["KeepAlive"]) > 0 {
|
|
|
|
this.Data["Keepalive"] = this.Ctx.Request.Header["KeepAlive"][0]
|
|
|
|
}
|
|
|
|
if len(this.Ctx.Request.Header["X-Forwarded-For"]) > 0 {
|
|
|
|
this.Data["Forwarded"] = this.Ctx.Request.Header["X-Forwarded-For"][0]
|
|
|
|
}
|
|
|
|
if len(this.Ctx.Request.Header["Accept-Language"]) > 0 {
|
|
|
|
this.Data["Lang"] = this.Ctx.Request.Header["Accept-Language"][0]
|
|
|
|
}
|
|
|
|
this.Data["Referer"] = this.Ctx.Input.Refer()
|
|
|
|
|
2016-11-15 07:08:59 +01:00
|
|
|
this.TplName = "all.tpl"
|
2014-08-14 08:15:52 +02:00
|
|
|
}
|
|
|
|
|
2014-08-14 09:16:09 +02:00
|
|
|
type ifconfig struct {
|
|
|
|
Email string
|
|
|
|
UserAgent string
|
|
|
|
Host string
|
|
|
|
IP string
|
|
|
|
Port string
|
|
|
|
Method string
|
|
|
|
Encoding string
|
|
|
|
Mime string
|
|
|
|
Connection string
|
|
|
|
Via string
|
|
|
|
Charset string
|
|
|
|
Keepalive string
|
|
|
|
Forwarded string
|
|
|
|
Lang string
|
|
|
|
Referer string
|
|
|
|
}
|
|
|
|
|
2014-08-14 08:15:52 +02:00
|
|
|
func (this *MainController) GetAllXML() {
|
2014-08-14 09:16:09 +02:00
|
|
|
thisData := ifconfig{}
|
|
|
|
thisData.Email = "missdeer@dfordsoft.com"
|
|
|
|
thisData.UserAgent = this.Ctx.Request.UserAgent()
|
2014-12-23 02:19:11 +01:00
|
|
|
|
|
|
|
ip := this.Ctx.Input.IP()
|
|
|
|
names, err := net.LookupAddr(ip)
|
|
|
|
if err != nil || len(names) == 0 {
|
|
|
|
thisData.Host = ""
|
|
|
|
} else {
|
|
|
|
var value string
|
|
|
|
for _, v := range names {
|
|
|
|
value += fmt.Sprintf("%s\n", v)
|
|
|
|
}
|
|
|
|
thisData.Host = value
|
|
|
|
}
|
|
|
|
|
2014-08-14 09:16:09 +02:00
|
|
|
thisData.IP = this.Ctx.Input.IP()
|
2014-08-14 08:15:52 +02:00
|
|
|
remote_addr := []byte(this.Ctx.Request.RemoteAddr)
|
|
|
|
pos := bytes.IndexByte(remote_addr, ':')
|
2014-08-14 09:16:09 +02:00
|
|
|
thisData.Port = string(remote_addr[pos+1:])
|
|
|
|
thisData.Method = this.Ctx.Request.Method
|
2014-08-14 08:15:52 +02:00
|
|
|
if len(this.Ctx.Request.Header["Accept-Encoding"]) > 0 {
|
2014-08-14 09:16:09 +02:00
|
|
|
thisData.Encoding = this.Ctx.Request.Header["Accept-Encoding"][0]
|
2014-08-14 08:15:52 +02:00
|
|
|
}
|
|
|
|
if len(this.Ctx.Request.Header["Accept"]) > 0 {
|
2014-08-14 09:16:09 +02:00
|
|
|
thisData.Mime = this.Ctx.Request.Header["Accept"][0]
|
2014-08-14 08:15:52 +02:00
|
|
|
}
|
|
|
|
if len(this.Ctx.Request.Header["Connection"]) > 0 {
|
2014-08-14 09:16:09 +02:00
|
|
|
thisData.Connection = this.Ctx.Request.Header["Connection"][0]
|
2014-08-14 08:15:52 +02:00
|
|
|
}
|
|
|
|
if len(this.Ctx.Request.Header["Via"]) > 0 {
|
2014-08-14 09:16:09 +02:00
|
|
|
thisData.Via = this.Ctx.Request.Header["Via"][0]
|
2014-08-14 08:15:52 +02:00
|
|
|
}
|
|
|
|
if len(this.Ctx.Request.Header["Charset"]) > 0 {
|
2014-08-14 09:16:09 +02:00
|
|
|
thisData.Charset = this.Ctx.Request.Header["Charset"][0]
|
2014-08-14 08:15:52 +02:00
|
|
|
}
|
|
|
|
if len(this.Ctx.Request.Header["KeepAlive"]) > 0 {
|
2014-08-14 09:16:09 +02:00
|
|
|
thisData.Keepalive = this.Ctx.Request.Header["KeepAlive"][0]
|
2014-08-14 08:15:52 +02:00
|
|
|
}
|
|
|
|
if len(this.Ctx.Request.Header["X-Forwarded-For"]) > 0 {
|
2014-08-14 09:16:09 +02:00
|
|
|
thisData.Forwarded = this.Ctx.Request.Header["X-Forwarded-For"][0]
|
2014-08-14 08:15:52 +02:00
|
|
|
}
|
|
|
|
if len(this.Ctx.Request.Header["Accept-Language"]) > 0 {
|
2014-08-14 09:16:09 +02:00
|
|
|
thisData.Lang = this.Ctx.Request.Header["Accept-Language"][0]
|
2014-08-14 08:15:52 +02:00
|
|
|
}
|
2014-08-14 09:16:09 +02:00
|
|
|
thisData.Referer = this.Ctx.Input.Refer()
|
2014-08-14 08:15:52 +02:00
|
|
|
|
|
|
|
this.Data["xml"] = thisData
|
2016-11-15 07:08:59 +01:00
|
|
|
this.ServeXML()
|
2014-08-14 08:15:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (this *MainController) GetAllJSON() {
|
|
|
|
thisData := make(map[string]interface{})
|
|
|
|
thisData["Email"] = "missdeer@dfordsoft.com"
|
|
|
|
thisData["UserAgent"] = this.Ctx.Request.UserAgent()
|
2014-12-23 02:19:11 +01:00
|
|
|
ip := this.Ctx.Input.IP()
|
|
|
|
names, err := net.LookupAddr(ip)
|
|
|
|
if err != nil || len(names) == 0 {
|
|
|
|
thisData["Host"] = ""
|
|
|
|
} else {
|
|
|
|
var value string
|
|
|
|
for _, v := range names {
|
|
|
|
value += fmt.Sprintf("%s\n", v)
|
|
|
|
}
|
|
|
|
thisData["Host"] = value
|
|
|
|
}
|
|
|
|
|
2014-08-14 08:15:52 +02:00
|
|
|
thisData["IP"] = this.Ctx.Input.IP()
|
|
|
|
remote_addr := []byte(this.Ctx.Request.RemoteAddr)
|
|
|
|
pos := bytes.IndexByte(remote_addr, ':')
|
|
|
|
thisData["Port"] = string(remote_addr[pos+1:])
|
|
|
|
thisData["Method"] = this.Ctx.Request.Method
|
|
|
|
if len(this.Ctx.Request.Header["Accept-Encoding"]) > 0 {
|
|
|
|
thisData["Encoding"] = this.Ctx.Request.Header["Accept-Encoding"][0]
|
|
|
|
}
|
|
|
|
if len(this.Ctx.Request.Header["Accept"]) > 0 {
|
|
|
|
thisData["Mime"] = this.Ctx.Request.Header["Accept"][0]
|
|
|
|
}
|
|
|
|
if len(this.Ctx.Request.Header["Connection"]) > 0 {
|
|
|
|
thisData["Connection"] = this.Ctx.Request.Header["Connection"][0]
|
|
|
|
}
|
|
|
|
if len(this.Ctx.Request.Header["Via"]) > 0 {
|
|
|
|
thisData["Via"] = this.Ctx.Request.Header["Via"][0]
|
|
|
|
}
|
|
|
|
if len(this.Ctx.Request.Header["Charset"]) > 0 {
|
|
|
|
thisData["Charset"] = this.Ctx.Request.Header["Charset"][0]
|
|
|
|
}
|
|
|
|
if len(this.Ctx.Request.Header["KeepAlive"]) > 0 {
|
|
|
|
thisData["Keepalive"] = this.Ctx.Request.Header["KeepAlive"][0]
|
|
|
|
}
|
|
|
|
if len(this.Ctx.Request.Header["X-Forwarded-For"]) > 0 {
|
|
|
|
thisData["Forwarded"] = this.Ctx.Request.Header["X-Forwarded-For"][0]
|
|
|
|
}
|
|
|
|
if len(this.Ctx.Request.Header["Accept-Language"]) > 0 {
|
|
|
|
thisData["Lang"] = this.Ctx.Request.Header["Accept-Language"][0]
|
|
|
|
}
|
|
|
|
thisData["Referer"] = this.Ctx.Input.Refer()
|
|
|
|
|
|
|
|
this.Data["json"] = thisData
|
2016-11-15 07:08:59 +01:00
|
|
|
this.ServeJSON()
|
2014-08-14 08:15:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (this *MainController) Get() {
|
2015-12-27 11:53:43 +01:00
|
|
|
if noweb := os.Getenv("NOWEB"); noweb == "1" {
|
2015-12-27 12:00:18 +01:00
|
|
|
this.Abort("404")
|
2015-12-27 11:53:43 +01:00
|
|
|
return
|
|
|
|
}
|
2014-08-14 08:15:52 +02:00
|
|
|
this.Data["Email"] = "missdeer@dfordsoft.com"
|
|
|
|
this.Data["UserAgent"] = this.Ctx.Request.UserAgent()
|
2014-12-23 02:19:11 +01:00
|
|
|
ip := this.Ctx.Input.IP()
|
|
|
|
names, err := net.LookupAddr(ip)
|
|
|
|
if err != nil || len(names) == 0 {
|
|
|
|
this.Data["Host"] = ""
|
|
|
|
} else {
|
|
|
|
var value string
|
|
|
|
for _, v := range names {
|
|
|
|
value += fmt.Sprintf("%s\n", v)
|
|
|
|
}
|
|
|
|
this.Data["Host"] = value
|
|
|
|
}
|
|
|
|
|
2014-08-14 08:15:52 +02:00
|
|
|
this.Data["IP"] = this.Ctx.Input.IP()
|
|
|
|
remote_addr := []byte(this.Ctx.Request.RemoteAddr)
|
|
|
|
pos := bytes.IndexByte(remote_addr, ':')
|
|
|
|
this.Data["Port"] = string(remote_addr[pos+1:])
|
|
|
|
this.Data["Method"] = this.Ctx.Request.Method
|
|
|
|
if len(this.Ctx.Request.Header["Accept-Encoding"]) > 0 {
|
|
|
|
this.Data["Encoding"] = this.Ctx.Request.Header["Accept-Encoding"][0]
|
|
|
|
}
|
|
|
|
if len(this.Ctx.Request.Header["Accept"]) > 0 {
|
|
|
|
this.Data["Mime"] = this.Ctx.Request.Header["Accept"][0]
|
|
|
|
}
|
|
|
|
if len(this.Ctx.Request.Header["Connection"]) > 0 {
|
|
|
|
this.Data["Connection"] = this.Ctx.Request.Header["Connection"][0]
|
|
|
|
}
|
|
|
|
if len(this.Ctx.Request.Header["Via"]) > 0 {
|
|
|
|
this.Data["Via"] = this.Ctx.Request.Header["Via"][0]
|
|
|
|
}
|
|
|
|
if len(this.Ctx.Request.Header["Charset"]) > 0 {
|
|
|
|
this.Data["Charset"] = this.Ctx.Request.Header["Charset"][0]
|
|
|
|
}
|
|
|
|
if len(this.Ctx.Request.Header["KeepAlive"]) > 0 {
|
|
|
|
this.Data["Keepalive"] = this.Ctx.Request.Header["KeepAlive"][0]
|
|
|
|
}
|
|
|
|
if len(this.Ctx.Request.Header["X-Forwarded-For"]) > 0 {
|
|
|
|
this.Data["Forwarded"] = this.Ctx.Request.Header["X-Forwarded-For"][0]
|
|
|
|
}
|
|
|
|
if len(this.Ctx.Request.Header["Accept-Language"]) > 0 {
|
|
|
|
this.Data["Lang"] = this.Ctx.Request.Header["Accept-Language"][0]
|
|
|
|
}
|
|
|
|
this.Data["Referer"] = this.Ctx.Input.Refer()
|
|
|
|
|
|
|
|
if strings.Contains(this.Ctx.Request.UserAgent(), "curl") {
|
2016-11-15 07:08:59 +01:00
|
|
|
this.TplName = "iponly.tpl"
|
2014-08-14 08:15:52 +02:00
|
|
|
} else {
|
2016-11-15 07:08:59 +01:00
|
|
|
this.TplName = "index.tpl"
|
2014-08-14 08:15:52 +02:00
|
|
|
}
|
|
|
|
}
|