summaryrefslogtreecommitdiff
path: root/d1pkgweb-query.go
diff options
context:
space:
mode:
authorKatolaZ <katolaz@freaknet.org>2019-03-30 11:31:51 +0000
committerKatolaZ <katolaz@freaknet.org>2019-03-30 11:31:51 +0000
commit427bdcb381f0d447a8d69553ceb8534b09340d22 (patch)
tree6775274b911d8f0223268c6ad04b091069c5fc60 /d1pkgweb-query.go
parent37c29b825dbf422e2c1a8ce534296a71ced98272 (diff)
first gopher versiongopher
Diffstat (limited to 'd1pkgweb-query.go')
-rw-r--r--d1pkgweb-query.go148
1 files changed, 23 insertions, 125 deletions
diff --git a/d1pkgweb-query.go b/d1pkgweb-query.go
index 72e5ab3..6b2f4b0 100644
--- a/d1pkgweb-query.go
+++ b/d1pkgweb-query.go
@@ -4,8 +4,8 @@ import (
"bufio"
"fmt"
"html/template"
- "net/http"
- "net/http/cgi"
+ //"net/http"
+ // "net/http/cgi"
"os"
"os/exec"
"strings"
@@ -28,105 +28,19 @@ type ResultPage struct {
}
var resTempl = `
-<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
-<html>
-<head>
-<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
-<link rel="stylesheet" type="text/css" href="/search.css" />
-<title>Devuan Package information</title>
-<style type="text/css">
-code {font-weight: normal;
- margin: 0 0px;
- padding: 0px 0px;
- border: 1px solid #ffffff;
- font-size: 95%; }
-</style>
-
-<body>
-
- <div class="nav">
- <div class="leftfl">
- <a href="https://pkginfo.devuan.org" title="Devuan Package Information">
- <span>Home</span></a>
- <span class="separator">|</span>
- <a href="https://devuan.org" title="Devuan website">
- <span>Devuan</span></a>
- <span class="separator">|</span>
- <a href="https://git.devuan.org" title="Devuan gitlab">
- <span>Git</span></a>
- <span class="separator">|</span>
- <a href="https://devuan.org" title="Devuan BTS">
- <span>BTS</span></a>
- <span class="separator">|</span>
- <a href="https://dev1galaxy.org" title="dev1galaxy forum">
- <span>Forum</span></a>
- <span class="separator">|</span>
- <a href="https://popcon.devuan.org" title="Popularity Context">
- <span>Popcon</span></a>
- </div>
-
- <div class="rightfl-do">
- <a title="Please support Devuan development" class="button-do" href="https://devuan.org/os/donate">donate now!</a>
- </div>
-
- <div class="rightfl-dl">
- <a title="Download Devuan" class="button-dl" href="https://files.devuan.org/">download</a>
- </div>
-
- </div>
-
-
-<div class="wrap">
-
-<h1>Devuan Package information</h1>
-
-
-<form method="GET" action="/cgi-bin/d1pkgweb-query">
-Search Devuan Packages for: <input type="text" name="search"/> in release
-<select name="release">
-<option value="jessie">Jessie 1.0.0 (oldstable)</option>
-<option value="ascii" selected>Ascii 2.0.0 (stable) </option>
-<option value="beowulf" >Beowulf (testing)</option>
-<option value="ceres" >Ceres (unstable)</option>
-<option value="experimental" >Experimental</option>
-<option value="any" >Any</option>
-</select>
-<input type="submit" value="Go!"/>
-</form>
-
-
-<h1>{{.NumResults}} results for <b>"{{.Query}}"</b> in {{.Release}} (in {{.Time}}) </h1>
-
-<ul class="res_list">
-{{range .Results}}
-<li class="res_item">
- <a href="{{.URL}}">[{{.Suite}}] {{.Name}}-{{.Version}}</a>
-</li>
+i | _) _| Err pkginfo.devuan.org 70
+i __ \ | / _' | | __ \ | _ \ Err pkginfo.devuan.org 70
+i | | < ( | | | | __| ( | Err pkginfo.devuan.org 70
+i .__/ _|\_\ \__, | _| _| _| _| \___/ Err pkginfo.devuan.org 70
+i _| |___/ Err pkginfo.devuan.org 70
+i Err pkginfo.devuan.org 70
+i Devuan Package information Err pkginfo.devuan.org 70
+i Err pkginfo.devuan.org 70
+i {{.NumResults}} results for "{{.Query}}" (in {{.Time}}) Err pkginfo.devuan.org 70
+i -------------------------- Err pkginfo.devuan.org 70
+{{range .Results}}
+1 {{.Suite}}] {{.Name}}-{{.Version}} {{URL}} pkginfo.devuan.org 70
{{end}}
-</div>
-
-</div>
-
- <p style="margin-top:0px; margin-bottom:20px ; text-align: center;"> This site is a cookie-free zone</p>
- <div class="foot">
- <p id="copyright" style="white-space: nowrap;">
- Copyright (c) 2014-2018 <a href="https://www.dyne.org" data-rel="fiscal sponsor"
- title="Learn about our fiscal sponsor">Dyne.org foundation</a>
- <span></span>
- <a rel="license" href="https://creativecommons.org/licenses/by-sa/4.0/"
- title="This work is licensed under a Creative Commons Attribution-ShareAlike
- 4.0 International License.">CC-BY-SA 4.0 international</a></p>
-
- <p class="trademarks">
- Devuan is a registered trademark of the Dyne.org foundation.</p>
- <p class="trademarks" style="margin-top: -15px;">
- Debian is a registered trademark of Software in the Public Interest, Inc. Linux is a registered trademark of Linus Torvalds.</p>
- </div>
-
-
-</body>
-</html>
-
`
var releaseMap = map[string]string{
@@ -180,29 +94,20 @@ func pipeComands(commands []*exec.Cmd) ([]byte, error) {
}
-func getResults(req http.Request) (ResultPage, error) {
+func getResults() (ResultPage, error) {
var res ResultPage
var release string
- req.ParseForm()
-
- searchQuery := req.Form["search"]
+ searchQuery := os.Getenv("X_GOPHER_SEARCH")
if len(searchQuery) < 1 {
- printError(503, fmt.Sprintf("Something went wrong in parsing query...\r\n%s\r\n", req.Form))
+ printError(503, fmt.Sprintf("Something went wrong in parsing query...\r\n"))
os.Exit(0)
}
- res.Query = searchQuery[0]
+ res.Query = searchQuery
QueryTerms := strings.Split(res.Query, " ")
- selectedRelease := req.Form["release"]
- if len(selectedRelease) < 1 {
- release = "any"
- } else {
- release = selectedRelease[0]
- }
-
- res.Release = release
+ res.Release = "any"
fmt.Printf("QueryTerms: %s\n", QueryTerms)
startTime := time.Now()
@@ -222,7 +127,7 @@ func getResults(req http.Request) (ResultPage, error) {
//if cmdOut, err := exec.Command(cmd, args...).Output(); err != nil {
if cmdOut, err := pipeComands(commands); err != nil {
- fmt.Printf("error executing command: %s", err)
+ fmt.Printf("error executing command: %s %s", commands, err)
res.Time = fmt.Sprintf("%s", time.Since(startTime))
return res, nil
} else {
@@ -241,22 +146,15 @@ func printResults(results ResultPage) {
return
}
- fmt.Printf("Status: 200 OK\r\n")
- fmt.Printf("Content-Type: text/html\r\n")
+ //fmt.Printf("Status: 200 OK\r\n")
+ //fmt.Printf("Content-Type: text/html\r\n")
t.Execute(os.Stdout, results)
}
func main() {
- var req *http.Request
var err error
- req, err = cgi.Request()
- if err != nil {
- printError(500, "cannot get requested resource"+err.Error())
- return
- }
-
- res, err := getResults(*req)
+ res, err := getResults()
if err != nil {
printError(404, fmt.Sprintf("%s", err))
} else {