1
0
mirror of https://git.envs.net/envs/ifconfig synced 2024-11-26 06:33:46 +01:00
ifconfig/controllers/default.go

329 lines
9.5 KiB
Go
Raw Normal View History

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]
}
this.TplNames = "value.tpl"
}
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
}
2014-08-14 08:15:52 +02:00
this.TplNames = "value.tpl"
}
func (this *MainController) GetIP() {
this.Data["Value"] = this.Ctx.Input.IP()
this.TplNames = "value.tpl"
}
func (this *MainController) GetPort() {
remote_addr := []byte(this.Ctx.Request.RemoteAddr)
pos := bytes.IndexByte(remote_addr, ':')
this.Data["Value"] = string(remote_addr[pos+1:])
this.TplNames = "value.tpl"
}
func (this *MainController) GetVia() {
if len(this.Ctx.Request.Header["Via"]) > 0 {
this.Data["Value"] = this.Ctx.Request.Header["Via"][0]
}
this.TplNames = "value.tpl"
}
func (this *MainController) GetMime() {
if len(this.Ctx.Request.Header["Accept"]) > 0 {
this.Data["Value"] = this.Ctx.Request.Header["Accept"][0]
}
this.TplNames = "value.tpl"
}
func (this *MainController) GetLang() {
if len(this.Ctx.Request.Header["Accept-Language"]) > 0 {
this.Data["Value"] = this.Ctx.Request.Header["Accept-Language"][0]
}
this.TplNames = "value.tpl"
}
func (this *MainController) GetCharset() {
if len(this.Ctx.Request.Header["Charset"]) > 0 {
this.Data["Value"] = this.Ctx.Request.Header["Charset"][0]
}
this.TplNames = "value.tpl"
}
func (this *MainController) GetEncoding() {
if len(this.Ctx.Request.Header["Accept-Encoding"]) > 0 {
this.Data["Value"] = this.Ctx.Request.Header["Accept-Encoding"][0]
}
this.TplNames = "value.tpl"
}
func (this *MainController) GetUserAgent() {
this.Data["Value"] = this.Ctx.Request.UserAgent()
this.TplNames = "value.tpl"
}
func (this *MainController) GetConnection() {
if len(this.Ctx.Request.Header["Connection"]) > 0 {
this.Data["Value"] = this.Ctx.Request.Header["Connection"][0]
}
this.TplNames = "value.tpl"
}
func (this *MainController) GetKeepAlive() {
if len(this.Ctx.Request.Header["KeepAlive"]) > 0 {
this.Data["Value"] = this.Ctx.Request.Header["KeepAlive"][0]
}
this.TplNames = "value.tpl"
}
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()
this.TplNames = "all.tpl"
}
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
this.ServeXml()
}
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
this.ServeJson()
}
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") {
this.TplNames = "iponly.tpl"
} else {
this.TplNames = "index.tpl"
}
}