Пример #1
0
/**设置nginx路径**/
func (c *MainController) Addconfdir() {
	var (
		option models.Option
	)
	//optionerr := option.Query().Filter("name", "confdir").One(&option)
	confdir := c.GetString("confdir")
	_, err := option.Query().Filter("name", "confdir").Update(orm.Params{"value": confdir})
	if err != nil {
		c.Ctx.WriteString("设置失败,错误:" + err.Error())
	}
	c.Ctx.WriteString("设置成功,请返回刷新列表")
}
Пример #2
0
/**虚拟主机列表**/
func (c *MainController) Domain() {
	var (
		domian  models.Domain
		domians []models.Domain
		option  models.Option
		//options []models.Option
	)
	optionerr := option.Query().Filter("name", "confdir").One(&option)
	domian.Query().All(&domians)

	if optionerr == nil {
		c.Data["option"] = option
	} else {

	}

	if len(domians) > 0 {
		c.Data["domians"] = domians
	} else {

	}
	c.TplNames = "domain.tpl"
}
Пример #3
0
/**虚拟主机列表**/
func (c *MainController) Create() {
	var (
		domian models.Domain
		//tmpdomian models.Domain
		//domians []models.Domain
		option  models.Option
		id      int64
		confdir string
	)

	if id, _ = strconv.ParseInt(c.Ctx.Input.Param(":id"), 10, 64); id < 1 {
		c.Ctx.WriteString("错误的id")
		//this.RenderString()
		return
	}

	optionerr := option.Query().Filter("name", "confdir").One(&option)
	if optionerr == nil {
		confdir = option.Value
	} else {
		confdir = ""
	}

	domian.Query().Filter("id", id).One(&domian)
	// domian.Access_log
	// domian.Expires
	// domian.Port
	// domian.Proxy_pass
	// domian.Root
	// domian.Server_name
	paththis, _ := os.Getwd()
	d := string(os.PathSeparator)
	fmt.Println(paththis)
	//path = paththis + d + "static" + d + "upload" + d + path + d + h.Filename
	pathdir := paththis + d + "views" + d + "domainconf.tpl"

	s1, tmperr := template.ParseFiles(pathdir)
	if tmperr != nil {
		fmt.Println(tmperr.Error())
	}
	fmt.Println(confdir)
	/**********test write********* /
	file, err := os.Create(confdir + d + domian.Server_name + ".conf")
	if err != nil {
		fmt.Println("writer", err)
		c.Ctx.WriteString("not Create ok")
		return
	}
	defer file.Close()
	//writer := bufio.NewWriter(file)
	/**********test write end********* /
	//s1.Execute(c.Ctx.ResponseWriter, domian)//这个也可以使用
	//domiant := models.Domain{Id: 1, Server_name: "", Port: 80, Proxy_pass: "", Access_log: "", Expires: "", Root: ""}
	exeuteerr := s1.Execute(file, domian)
	if exeuteerr != nil {
		fmt.Println(exeuteerr.Error())
	}

	/****test writer to string****/
	r, w := io.Pipe()
	var tmp string
	tmp = ""
	//data := make([]byte, 2048)
	//r.Read(data)

	data := make([]byte, 1024)

	go func() {
		for n, err := r.Read(data); err == nil; n, err = r.Read(data) {
			fmt.Printf("%s", data[:n])
			tmp = tmp + string(data[:n])
		}
		// for {
		// 	r.Read(data)
		// 	tmp = tmp + string(data)
		// 	//fmt.Println(string(b[0:])) //hello widuu
		// }
	}()

	//var b [128]byte
	// go func() {
	// 	for {
	// 		r.Read(b[0:])
	// 		tmp = tmp + string(b[0:])
	// 		//fmt.Println(string(b[0:])) //hello widuu
	// 	}

	// }()

	s1.Execute(w, domian)
	fmt.Println(tmp)
	//fmt.Println("read number", n)

	/********/

	csh := sh.Command("/etc/init.d/nginx", "reload")
	csh.Start()
	csh.Run()
	msgcsh, _ := csh.Output()
	fmt.Println(msgcsh)

	msg, _ := sh.Command("/etc/init.d/nginx", "reload").Output()

	c.Ctx.WriteString(string(msg))

	c.Ctx.WriteString("ok")
	//writer.Flush()

	//this.RenderString()
	return
	//c.TplNames = "domain.tpl"
}