保存したページの表示(未完了)

このコミットが含まれているのは:
守矢諏訪子 2023-05-12 13:50:25 +09:00
コミット 1c96ba9be9
3個のファイルの変更84行の追加29行の削除

10
prep.go
ファイルの表示

@ -84,14 +84,14 @@ func scanpage (path string, domain string, thisdomain string) {
/* 削除 */
var script = regexp.MustCompile(`(<script.*</script>)`).ReplaceAllString(string(fn), "")
var noscript = regexp.MustCompile(`(<noscript.*</noscript>)`).ReplaceAllString(string(script), "")
var audio = regexp.MustCompile(`(<script.*</script>)`).ReplaceAllString(string(noscript), "")
var video = regexp.MustCompile(`(<script.*</script>)`).ReplaceAllString(string(audio), "")
var iframe = regexp.MustCompile(`(<script.*</script>)`).ReplaceAllString(string(video), "")
var audio = regexp.MustCompile(`(<audio.*</audio>)`).ReplaceAllString(string(noscript), "")
var video = regexp.MustCompile(`(<video.*</video>)`).ReplaceAllString(string(audio), "")
var iframe = regexp.MustCompile(`(<iframe.*</iframe>)`).ReplaceAllString(string(video), "")
/* 追加ダウンロード+ローカル化 */
var ass = regexp.MustCompile(`(<img.*src="|<link.*href=")(.*\.)(png|webm|jpg|jpeg|gif|css)`)
var ass = regexp.MustCompile(`(<img.*src="|<meta.*content="|<link.*href=")(.*\.)(png|webm|jpg|jpeg|gif|css)`)
for _, cssx := range ass.FindAllString(iframe, -1) {
s := regexp.MustCompile(`(.*src="|.*href=")`).Split(cssx, -1)
s := regexp.MustCompile(`(.*src="|.*content="|.*href=")`).Split(cssx, -1)
ss := regexp.MustCompile(`(".*)`).Split(s[1], -1)
if strings.HasPrefix(ss[0], "http://") || strings.HasPrefix(ss[0], "https://") {
// TODO

69
srv.go
ファイルの表示

@ -4,6 +4,8 @@ import (
"text/template"
"fmt"
"net/http"
"strings"
"os"
)
type Page struct {
@ -13,6 +15,7 @@ type Page struct {
Ver string
Ext []string // 既に存在する場合
Url string // 確認ページ用
Body string // 保存したページ用
}
func serv (cnf Config, port int) {
@ -46,36 +49,54 @@ func serv (cnf Config, port int) {
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"))
ftmpl[0] = cnf.webpath + "/view/index.html"
tmpl := template.Must(template.ParseFiles(ftmpl[0], ftmpl[1], ftmpl[2]))
if r.Method == "POST" {
err := r.ParseForm()
if err != nil { fmt.Println(err) }
// クッキー
if r.PostForm.Get("langchange") != "" {
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", MaxAge: 31536000, Path: "/"})
}
http.Redirect(w, r, "/", http.StatusSeeOther)
if strings.HasPrefix(r.URL.Path, "/archive") {
pth := r.URL.Path
if !strings.HasSuffix(pth, "/") && !strings.HasSuffix(pth, "index.html") {
pth += "/index.html"
} else if strings.HasSuffix(pth, "/") && !strings.HasSuffix(pth, "index.html") {
pth += "index.html"
}
bdy, err := os.ReadFile(cnf.datapath + pth)
if err != nil {
http.Redirect(w, r, "/404", http.StatusSeeOther)
return
}
if r.PostForm.Get("hozonsite") != "" {
url := r.PostForm.Get("hozonsite")
// HTTPかHTTPSじゃない場合
if !checkprefix(url) {
if data.Lan == "ja" {
data.Err = "URLは「http://」又は「https://」で始めます。"
data.Body = string(bdy)
tmpl = template.Must(template.ParseFiles(cnf.webpath + "/view/archive.html"))
} else {
if r.Method == "POST" {
err := r.ParseForm()
if err != nil { fmt.Println(err) }
// クッキー
if r.PostForm.Get("langchange") != "" {
cookie, err := r.Cookie("lang")
if err != nil || cookie.Value == "ja" {
http.SetCookie(w, &http.Cookie {Name: "lang", Value: "en", MaxAge: 31536000, Path: "/"})
} else {
data.Err = "The URL should start with \"http://\" or \"https://\"."
http.SetCookie(w, &http.Cookie {Name: "lang", Value: "ja", MaxAge: 31536000, Path: "/"})
}
http.Redirect(w, r, "/", http.StatusSeeOther)
return
}
if r.PostForm.Get("hozonsite") != "" {
url := r.PostForm.Get("hozonsite")
// HTTPかHTTPSじゃない場合
if !checkprefix(url) {
if data.Lan == "ja" {
data.Err = "URLは「http://」又は「https://」で始めます。"
} else {
data.Err = "The URL should start with \"http://\" or \"https://\"."
}
ftmpl[0] = cnf.webpath + "/view/404.html"
tmpl = template.Must(template.ParseFiles(ftmpl[0], ftmpl[1], ftmpl[2]))
} else {
//if r.PostForm.Get("sosin") != "" {}
}
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("sosin") != "" {}
}
}
}

34
view/archive.html ノーマルファイル
ファイルの表示

@ -0,0 +1,34 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<style>
.archhead {
background-color: #320202 !important;
display: block !important;
border: 4px #ff3b3b groove !important;
color: #ea8181 !important;
padding: 10px !important;
z-index: 999999 !important;
position: fixed !important;
left: 0 !important;
top: 0 !important;
font-size: 14px !important;
font-family: unset !important;
width: 100% !important;
}
.archbody {
padding-top: 74px !important;
}
</style>
</head>
<body>
<div class="archhead">
{{if eq .Lan "ja"}}保存サイトでアーカイブしました。{{else}}Archived with Hozon Site.{{end}} hozonsite-{{ .Ver }}<br />
<a style="color: #ffeb3b !important;" href="/">{{if eq .Lan "ja"}}トップページへ{{else}}To toppage{{end}}</a>
</div>
<div class="archbody">
{{ .Body }}
</div>
</body>
</html>