クッキーは無効にされたらも、アクセス出来る様に

このコミットが含まれているのは:
守矢諏訪子 2023-05-12 09:31:27 +09:00
コミット 9ae3b011fb
4個のファイルの変更20行の追加18行の削除

ファイルの表示

@ -1,7 +1,8 @@
# 2.0.2(未リリース)
# 2.0.2
* Makefileでの「make install」部分を修正
* manページで「オプションなし」部分を追加
* 「短熟」→「短縮」を修正
* クッキーは無効にする又はクッキーが未対応のブラウザ対応の修正
# 2.0.1
* 送信ページの無英訳を修正

ファイルの表示

@ -1,5 +1,5 @@
NAME=urloli
VERSION=2.0.2p
VERSION=2.0.2
# Linux、Cruxの場合は必須。他のディストリビューションはどうでも良い
PREFIX=/usr
# FreeBSDとOpenBSD

ファイルの表示

@ -6,7 +6,7 @@ import (
"strconv"
)
var version = "2.0.2p"
var version = "2.0.2"
func help () {
fmt.Println("使い方:");

31
srv.go
ファイルの表示

@ -19,18 +19,18 @@ func serv (cnf Config, port int) {
http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("static"))))
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
data := &Page{Tit: "トップ", Ver: version}
cookie, err := r.Cookie("lang")
if err != nil {
http.SetCookie(w, &http.Cookie {Name: "lang", Value: "ja", MaxAge: 31536000, Path: "/"})
http.Redirect(w, r, "/", http.StatusSeeOther)
return
data.Lan = "ja"
} else {
data.Lan = cookie.Value
}
uri := r.URL.Path
query := r.URL.Query()
qnewurl := query.Get("newurl")
data := &Page{Tit: "トップ", Lan: cookie.Value, Ver: version}
if cookie.Value == "en" {
if data.Lan == "en" {
data.Tit = "Top"
}
tmpl := template.Must(template.ParseFiles(cnf.webpath + "/view/index.html", cnf.webpath + "/view/header.html", cnf.webpath + "/view/footer.html"))
@ -44,7 +44,7 @@ func serv (cnf Config, port int) {
chkprx := checkprefix(addurl)
chklim := checkcharlim(addurl)
if !chkprx {
if cookie.Value == "ja" {
if data.Lan == "ja" {
data.Tit = "不正なURL"
data.Err = "URLは「http://」又は「https://」で始めます。"
} else {
@ -54,7 +54,7 @@ func serv (cnf Config, port int) {
tmpl = template.Must(template.ParseFiles(cnf.webpath + "/view/404.html", cnf.webpath + "/view/header.html", cnf.webpath + "/view/footer.html"))
}
if !chklim {
if cookie.Value == "ja" {
if data.Lan == "ja" {
data.Tit = "不正なURL"
data.Err = "URLは500文字以内です。"
} else {
@ -73,7 +73,7 @@ func serv (cnf Config, port int) {
res := insertjson(addurl, cnf.linkpath)
data.Url = res
data.Dom = cnf.domain
if cookie.Value == "ja" {
if data.Lan == "ja" {
data.Tit = "短縮済み"
} else {
data.Tit = "Shortened"
@ -82,7 +82,7 @@ func serv (cnf Config, port int) {
}
}
} else {
if cookie.Value == "ja" {
if data.Lan == "ja" {
data.Tit = "未検出"
data.Err = "URLをご入力下さい。"
} else {
@ -92,10 +92,11 @@ func serv (cnf Config, port int) {
tmpl = template.Must(template.ParseFiles(cnf.webpath + "/view/404.html", cnf.webpath + "/view/header.html", cnf.webpath + "/view/footer.html"))
}
} else if r.PostForm.Get("langchange") != "" {
if cookie.Value == "ja" {
http.SetCookie(w, &http.Cookie {Name: "lang", Value: "en"})
cookie, err := r.Cookie("lang")
if err != nil || cookie.Value == "ja" {
http.SetCookie(w, &http.Cookie {Name: "lang", Value: "en", MaxAge: 31536000, Path: "/"})
} else {
http.SetCookie(w, &http.Cookie {Name: "lang", Value: "ja"})
http.SetCookie(w, &http.Cookie {Name: "lang", Value: "ja", MaxAge: 31536000, Path: "/"})
}
http.Redirect(w, r, "/", http.StatusSeeOther)
return
@ -109,7 +110,7 @@ func serv (cnf Config, port int) {
http.Redirect(w, r, red, http.StatusSeeOther)
return
} else {
if cookie.Value == "ja" {
if data.Lan == "ja" {
data.Tit = "未検出"
data.Err = "このURLを見つけられませんでした。"
} else {
@ -121,14 +122,14 @@ func serv (cnf Config, port int) {
} else if uri == "/" && qnewurl != "" {
data.Url = qnewurl
data.Dom = cnf.domain
if cookie.Value == "ja" {
if data.Lan == "ja" {
data.Tit = "短縮済み"
} else {
data.Tit = "Shortened"
}
tmpl = template.Must(template.ParseFiles(cnf.webpath + "/view/submitted.html", cnf.webpath + "/view/header.html", cnf.webpath + "/view/footer.html"))
} else {
if cookie.Value == "ja" {
if data.Lan == "ja" {
data.Tit = "未検出"
data.Err = "このURLを見つけられませんでした。"
} else {