8c1905a287
Signed-off-by: kim (grufwub) <grufwub@gmail.com>
56 lines
1.8 KiB
Go
56 lines
1.8 KiB
Go
package gopher
|
|
|
|
import "gophi/core"
|
|
|
|
// We make heavy-use of string concat here instead of StringBuilder
|
|
// as this is performed during the setup phase of the server and therefore
|
|
// doesn't impact run-time performance.
|
|
|
|
// generatePolicyHeader generates a commented-out header for a policy file of supplied name
|
|
func generatePolicyHeader(name string) string {
|
|
text := "# This is an automatically generated" + "\r\n"
|
|
text += "# server policy file: " + name + "\r\n"
|
|
text += "#" + "\r\n"
|
|
text += "# BlackLivesMatter" + "\r\n"
|
|
return text
|
|
}
|
|
|
|
// generateCapsTxt generates a byte slice of what would be a 'caps.txt' policy file
|
|
func generateCapsTxt(desc, admin, geo string) []byte {
|
|
text := "CAPS" + "\r\n"
|
|
text += "\r\n"
|
|
text += generatePolicyHeader("caps.txt")
|
|
text += "\r\n"
|
|
text += "CapsVersion=1" + "\r\n"
|
|
text += "ExpireCapsAfter=1800" + "\r\n"
|
|
text += "\r\n"
|
|
text += "PathDelimeter=/" + "\r\n"
|
|
text += "PathIdentity=." + "\r\n"
|
|
text += "PathParent=.." + "\r\n"
|
|
text += "PathParentDouble=FALSE" + "\r\n"
|
|
text += "PathEscapeCharacter=\\" + "\r\n"
|
|
text += "PathKeepPreDelimeter=FALSE" + "\r\n"
|
|
text += "\r\n"
|
|
text += "ServerSoftware=Gophi" + "\r\n"
|
|
text += "ServerSoftwareVersion=" + core.Version + "\r\n"
|
|
text += "ServerDescription=" + desc + "\r\n"
|
|
text += "ServerGeolocationString=" + geo + "\r\n"
|
|
text += "ServerDefaultEncoding=utf-8" + "\r\n"
|
|
text += "\r\n"
|
|
text += "ServerAdmin=" + admin + "\r\n"
|
|
return []byte(text)
|
|
}
|
|
|
|
// generateRobotsTxt generates a byte slice of what would be a 'robots.txt' policy file
|
|
func generateRobotsTxt() []byte {
|
|
text := generatePolicyHeader("robots.txt")
|
|
text += "\r\n"
|
|
text += "Usage-agent: *" + "\r\n"
|
|
text += "Disallow: *" + "\r\n"
|
|
text += "\r\n"
|
|
text += "Crawl-delay: 99999" + "\r\n"
|
|
text += "\r\n"
|
|
text += "# This server does not support scraping" + "\r\n"
|
|
return []byte(text)
|
|
}
|