mirror of
https://github.com/Eggbertx/gochan.git
synced 2025-08-05 04:36:24 -07:00
fixed remote cookies not being set to the site domain
This commit is contained in:
parent
eb27a7e2e8
commit
112156f139
4 changed files with 18 additions and 8 deletions
|
@ -143,7 +143,8 @@ func createSession(key string,username string, password string, request *http.Re
|
||||||
return 1
|
return 1
|
||||||
} else {
|
} else {
|
||||||
// successful login
|
// successful login
|
||||||
cookie := &http.Cookie{Name: "sessiondata", Value: key, Path: "/", Domain: config.Domain, RawExpires: getSpecificSQLDateTime(time.Now().Add(time.Duration(time.Hour*2))),MaxAge: 7200}
|
cookie := &http.Cookie{Name: "sessiondata", Value: key, Path: "/", Domain: config.SiteDomain, RawExpires: getSpecificSQLDateTime(time.Now().Add(time.Duration(time.Hour*2))),MaxAge: 7200}
|
||||||
|
// cookie := &http.Cookie{Name: "sessiondata", Value: key, Path: "/", Domain: config.Domain, RawExpires: getSpecificSQLDateTime(time.Now().Add(time.Duration(time.Hour*2))),MaxAge: 7200}
|
||||||
http.SetCookie(*writer, cookie)
|
http.SetCookie(*writer, cookie)
|
||||||
_,err := db.Exec("INSERT INTO `"+config.DBprefix+"sessions` (`key`, `data`, `expires`) VALUES('"+key+"','"+username+"', '"+getSpecificSQLDateTime(time.Now().Add(time.Duration(time.Hour*2)))+"');")
|
_,err := db.Exec("INSERT INTO `"+config.DBprefix+"sessions` (`key`, `data`, `expires`) VALUES('"+key+"','"+username+"', '"+getSpecificSQLDateTime(time.Now().Add(time.Duration(time.Hour*2)))+"');")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -255,7 +256,8 @@ var manage_functions = map[string]ManageFunction{
|
||||||
if cookie != nil {
|
if cookie != nil {
|
||||||
key = cookie.Value
|
key = cookie.Value
|
||||||
new_expire := time.Now().AddDate(0,0,-1)
|
new_expire := time.Now().AddDate(0,0,-1)
|
||||||
new_cookie := &http.Cookie{Name: "sessiondata",Value: cookie.Value,Path: "/",Domain: config.Domain,Expires: new_expire,RawExpires: new_expire.Format(time.UnixDate),MaxAge: -1,Secure: true,HttpOnly: true,Raw: "sessiondata="+key}
|
new_cookie := &http.Cookie{Name: "sessiondata",Value: cookie.Value,Path: "/",Domain: config.SiteDomain,Expires: new_expire,RawExpires: new_expire.Format(time.UnixDate),MaxAge: -1,Secure: true,HttpOnly: true,Raw: "sessiondata="+key}
|
||||||
|
// new_cookie := &http.Cookie{Name: "sessiondata",Value: cookie.Value,Path: "/",Domain: config.Domain,Expires: new_expire,RawExpires: new_expire.Format(time.UnixDate),MaxAge: -1,Secure: true,HttpOnly: true,Raw: "sessiondata="+key}
|
||||||
http.SetCookie(writer, new_cookie)
|
http.SetCookie(writer, new_cookie)
|
||||||
return "Logged out successfully"
|
return "Logged out successfully"
|
||||||
}
|
}
|
||||||
|
|
|
@ -420,21 +420,27 @@ func makePost(w http.ResponseWriter, r *http.Request) {
|
||||||
post.Password = md5_sum(request.FormValue("postpassword"))
|
post.Password = md5_sum(request.FormValue("postpassword"))
|
||||||
post_name_cookie := strings.Replace(url.QueryEscape(post_name),"+", "%20", -1)
|
post_name_cookie := strings.Replace(url.QueryEscape(post_name),"+", "%20", -1)
|
||||||
url.QueryEscape(post_name_cookie)
|
url.QueryEscape(post_name_cookie)
|
||||||
http.SetCookie(writer, &http.Cookie{Name: "name", Value: post_name_cookie, Path: "/", Domain: config.Domain, RawExpires: getSpecificSQLDateTime(time.Now().Add(time.Duration(31536000))),MaxAge: 31536000})
|
http.SetCookie(writer, &http.Cookie{Name: "name", Value: post_name_cookie, Path: "/", Domain: config.SiteDomain, RawExpires: getSpecificSQLDateTime(time.Now().Add(time.Duration(31536000))),MaxAge: 31536000})
|
||||||
|
// http.SetCookie(writer, &http.Cookie{Name: "name", Value: post_name_cookie, Path: "/", Domain: config.Domain, RawExpires: getSpecificSQLDateTime(time.Now().Add(time.Duration(31536000))),MaxAge: 31536000})
|
||||||
if email_command == "" {
|
if email_command == "" {
|
||||||
http.SetCookie(writer, &http.Cookie{Name: "email", Value: post.Email, Path: "/", Domain: config.Domain, RawExpires: getSpecificSQLDateTime(time.Now().Add(time.Duration(31536000))),MaxAge: 31536000})
|
http.SetCookie(writer, &http.Cookie{Name: "email", Value: post.Email, Path: "/", Domain: config.SiteDomain, RawExpires: getSpecificSQLDateTime(time.Now().Add(time.Duration(31536000))),MaxAge: 31536000})
|
||||||
|
// http.SetCookie(writer, &http.Cookie{Name: "email", Value: post.Email, Path: "/", Domain: config.Domain, RawExpires: getSpecificSQLDateTime(time.Now().Add(time.Duration(31536000))),MaxAge: 31536000})
|
||||||
} else {
|
} else {
|
||||||
if email_command == "noko" {
|
if email_command == "noko" {
|
||||||
if post.Email == "" {
|
if post.Email == "" {
|
||||||
http.SetCookie(writer, &http.Cookie{Name: "email", Value:"noko", Path: "/", Domain: config.Domain, RawExpires: getSpecificSQLDateTime(time.Now().Add(time.Duration(31536000))),MaxAge: 31536000})
|
http.SetCookie(writer, &http.Cookie{Name: "email", Value:"noko", Path: "/", Domain: config.SiteDomain, RawExpires: getSpecificSQLDateTime(time.Now().Add(time.Duration(31536000))),MaxAge: 31536000})
|
||||||
|
// http.SetCookie(writer, &http.Cookie{Name: "email", Value:"noko", Path: "/", Domain: config.Domain, RawExpires: getSpecificSQLDateTime(time.Now().Add(time.Duration(31536000))),MaxAge: 31536000})
|
||||||
} else {
|
} else {
|
||||||
http.SetCookie(writer, &http.Cookie{Name: "email", Value: post.Email + "#noko", Path: "/", Domain: config.Domain, RawExpires: getSpecificSQLDateTime(time.Now().Add(time.Duration(31536000))),MaxAge: 31536000})
|
http.SetCookie(writer, &http.Cookie{Name: "email", Value: post.Email + "#noko", Path: "/", Domain: config.SiteDomain, RawExpires: getSpecificSQLDateTime(time.Now().Add(time.Duration(31536000))),MaxAge: 31536000})
|
||||||
|
//http.SetCookie(writer, &http.Cookie{Name: "email", Value: post.Email + "#noko", Path: "/", Domain: config.Domain, RawExpires: getSpecificSQLDateTime(time.Now().Add(time.Duration(31536000))),MaxAge: 31536000})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
http.SetCookie(writer, &http.Cookie{Name: "password", Value: request.FormValue("postpassword"), Path: "/", Domain: config.Domain, RawExpires: getSpecificSQLDateTime(time.Now().Add(time.Duration(31536000))),MaxAge: 31536000})
|
http.SetCookie(writer, &http.Cookie{Name: "password", Value: request.FormValue("postpassword"), Path: "/", Domain: config.SiteDomain, RawExpires: getSpecificSQLDateTime(time.Now().Add(time.Duration(31536000))),MaxAge: 31536000})
|
||||||
|
//http.SetCookie(writer, &http.Cookie{Name: "password", Value: request.FormValue("postpassword"), Path: "/", Domain: config.Domain, RawExpires: getSpecificSQLDateTime(time.Now().Add(time.Duration(31536000))),MaxAge: 31536000})
|
||||||
|
|
||||||
post.IP = request.RemoteAddr
|
post.IP = request.RemoteAddr
|
||||||
post.Timestamp = time.Now()
|
post.Timestamp = time.Now()
|
||||||
post.PosterAuthority = getStaffRank()
|
post.PosterAuthority = getStaffRank()
|
||||||
|
|
|
@ -226,7 +226,8 @@ func error404() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func validReferrer(request http.Request) (valid bool) {
|
func validReferrer(request http.Request) (valid bool) {
|
||||||
if request.Referer() == "" || request.Referer()[7:len(config.Domain)+7] != config.Domain {
|
if request.Referer() == "" || request.Referer()[7:len(config.SiteDomain)+7] != config.SiteDomain {
|
||||||
|
// if request.Referer() == "" || request.Referer()[7:len(config.Domain)+7] != config.Domain {
|
||||||
valid = false
|
valid = false
|
||||||
} else {
|
} else {
|
||||||
valid = true
|
valid = true
|
||||||
|
|
|
@ -281,6 +281,7 @@ type GochanConfig struct {
|
||||||
SiteSlogan string
|
SiteSlogan string
|
||||||
SiteHeaderURL string
|
SiteHeaderURL string
|
||||||
SiteWebfolder string
|
SiteWebfolder string
|
||||||
|
SiteDomain string
|
||||||
|
|
||||||
Styles_img []string
|
Styles_img []string
|
||||||
DefaultStyle_img string
|
DefaultStyle_img string
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue