Exemple #1
0
func backend(w http.ResponseWriter, r *http.Request, m map[string]interface{}) {

	w.Header().Set("Content-type", "text/html; charset=utf-8")
	w.WriteHeader(http.StatusOK)

	if ok, _, msg := login.CheckForAdminUser(r); !ok {
		w.Write([]byte(msg))
		return
	}

	b1 := new(bytes.Buffer)
	b1.WriteString(tplx.ExecTplHelper(tplx.Head, map[string]interface{}{"HtmlTitle": "Backend V1"}))

	htmlfrag.Wb(b1, "Debug pprof", "/debug/pprof")

	htmlfrag.Wb(b1, "Diverse", "nobr")
	htmlfrag.Wb(b1, "Schreib-Methoden", "/write-methods")
	htmlfrag.Wb(b1, "Letzte Email", "/email-view")
	htmlfrag.Wb(b1, "Blob List", "/blob2")

	htmlfrag.Wb(b1, "fetch via proxy", routes.ProxifyURI)
	htmlfrag.Wb(b1, "Instance Info", "/instance-info/view")

	htmlfrag.Wb(b1, "Fulltext put", "/fulltext-search/put")
	htmlfrag.Wb(b1, "Fulltext get", "/fulltext-search/get")

	htmlfrag.Wb(b1, "datastore object view quoted printabe", "/dsu/show")

	htmlfrag.Wb(b1, "Statistics", "/_ah/stats")

	htmlfrag.Wb(b1, "Request Images ", "")
	htmlfrag.Wb(b1, "WrapBlob from Datastore", "/image/img-from-datastore?p=chart1")
	htmlfrag.Wb(b1, "base64 from Datastore", "/image/base64-from-datastore?p=chart1")
	htmlfrag.Wb(b1, "base64 from Variable", "/image/base64-from-var?p=1")
	htmlfrag.Wb(b1, "base64 from File", "/image/base64-from-file?p=static/pberg1.png")
	htmlfrag.Wb(b1, "Drawing a static chart", "/image/draw-lines-example")

	htmlfrag.Wb(b1, "Big Query ...", "")
	htmlfrag.Wb(b1, "Get real data", "/big-query/query-into-datastore")
	htmlfrag.Wb(b1, "Get mocked data", "/big-query/mock-data-into-datastore")
	htmlfrag.Wb(b1, "        ... with Chart", "")
	htmlfrag.Wb(b1, "Process Data 1 (mock=1)", "/big-query/regroup-data-01?mock=0")
	htmlfrag.Wb(b1, "Process Data 2", "/big-query/regroup-data-02?f=table")
	htmlfrag.Wb(b1, "Show as Table", "/big-query/show-table")
	htmlfrag.Wb(b1, "Show as Chart", "/big-query/show-chart")
	htmlfrag.Wb(b1, "As HTML", "/big-query/html")

	htmlfrag.Wb(b1, "Namespaces + Task Queues", "")
	htmlfrag.Wb(b1, "Increment", "/namespaced-counters/increment")
	htmlfrag.Wb(b1, "Read", "/namespaced-counters/read")
	htmlfrag.Wb(b1, "Push to task-queue", "/namespaced-counters/queue-push")

	htmlfrag.Wb(b1, "URLs with/without ancestors", "nobr")
	htmlfrag.Wb(b1, "Backend", "/save-url/backend")

	htmlfrag.Wb(b1, "Guest Book", "")
	htmlfrag.Wb(b1, "Eintrag hinzufügen", "/guest-entry")
	htmlfrag.Wb(b1, "Einträge auflisten", "/guest-view")
	htmlfrag.Wb(b1, "Einträge auflisten - paged - serialized cursor", "/guest-view-cursor")

	b1.WriteString("<hr>\n")

	uiDsFs := webapi.BackendUIRendered()
	b1.Write(uiDsFs.Bytes())

	b1.WriteString("<hr>\n")

	b1.Write(upload.BackendUIRendered().Bytes())

	b1.Write(repo.BackendUIRendered().Bytes())

	b1.Write(dedup.BackendUIRendered().Bytes())

	b1.Write(coinbase.BackendUIRendered().Bytes())

	b1.Write(tplx.BackendUIRendered().Bytes())

	b1.Write(login.BackendUIRendered().Bytes())

	b1.WriteString("<br>\n")
	b1.WriteString("<hr>\n")

	urlLocalAdmin := fmt.Sprintf("http://localhost:%v/mail", routes.DevAdminPort())
	ancLocalAdmin := fmt.Sprintf(" &nbsp; &nbsp; <a target='_gae' href='%v' >local app console</a><br>\n", urlLocalAdmin)
	b1.WriteString(ancLocalAdmin)

	urlConsole := fmt.Sprintf("https://console.developers.google.com/project/%v", routes.AppID())
	ancConsole := fmt.Sprintf("<a target='_gae' href='%v' ><b>global</b> developer console</a>\n", urlConsole)
	b1.WriteString(ancConsole)

	urlOldAdmin := fmt.Sprintf("https://appengine.google.com/settings?&app_id=s~%v", routes.AppID())
	ancOldAdmin := fmt.Sprintf(" &nbsp; &nbsp; <a target='_gae' href='%v' >old admin UI</a><br>\n ", urlOldAdmin)
	b1.WriteString(ancOldAdmin)

	b1.WriteString(` &nbsp; &nbsp; <a target='_gae' 
			href='http://go-lint.appspot.com/github.com/pbberlin/tools/dsu' 
			>lint a package</a><br>`)

	dir := m["dir"].(string)
	base := m["base"].(string)
	b1.WriteString("<br>\n")
	b1.WriteString("Dir: --" + dir + "-- &nbsp; &nbsp; &nbsp; &nbsp;   Base: --" + base + "-- <br>\n")

	b1.WriteString("<br>\n")
	s := fmt.Sprintf("IntegerSequenes a, b: %v %v %v<br>\n", util.MyIntSeq01(), util.MyIntSeq01(), util.MyIntSeq02())
	b1.WriteString(s)

	// b1.WriteString("<br>\n")
	// b1.WriteString(fmt.Sprintf("Temp dir is %s<br>\n", os.TempDir()))

	b1.WriteString("<br>\n")

	io.WriteString(b1, "Date: "+util.TimeMarker()+"  - ")
	b1.WriteString(fmt.Sprintf("Last Month %q - 24 Months ago is %q<br>\n", util.MonthsBack(0),
		util.MonthsBack(24)))

	b1.WriteString("<br>\n")
	x1 := " z" + stringspb.IncrementString("--z")
	x2 := " Z" + stringspb.IncrementString("--Z")
	x3 := " 9" + stringspb.IncrementString("--9")
	x4 := stringspb.IncrementString(" --Peter")
	sEnc := "Łódź <  " + stringspb.IncrementString("Łódź") + x1 + x2 + x3 + x4
	b1.WriteString(fmt.Sprint(string([]byte(sEnc)), "<br>"))

	b1.WriteString(tplx.Foot)

	w.Write(b1.Bytes())

}
Exemple #2
0
// working differently as in Python
//		//blob2s := blobstore.BlobInfo.gql("ORDER BY creation DESC")
func blobList(w http.ResponseWriter, r *http.Request, m map[string]interface{}) {

	c := appengine.NewContext(r)

	b1 := new(bytes.Buffer)
	defer func() {
		w.Header().Set("Content-type", "text/html; charset=utf-8")
		b1.WriteString(closeHTML)
		w.Write(b1.Bytes())
	}()

	errFormParse := r.ParseForm()
	if errFormParse != nil {
		b1.WriteString(fmt.Sprintf("Form parse Error %v", errFormParse))
		return
	}

	s1 := ""
	b1.WriteString(openHTML)
	b1.WriteString(restrictForm)

	nameFilter := r.PostFormValue("nameFilter")
	nameFilter = strings.TrimSpace(nameFilter)

	if nameFilter == "" {
		return
	} else {
		tn := time.Now()
		f := "2006-01-02 15:04:05"
		f = "January 02"
		prefix := tn.Format(f)
		// nameFilter = fmt.Sprintf("%v %s", prefix,nameFilter )
		if !strings.HasPrefix(nameFilter, prefix) || len(nameFilter) == len(prefix) {
			b1.WriteString(fmt.Sprintf("cannot filter by %v", nameFilter))
			return
		} else {
			nameFilter = nameFilter[len(prefix):]
		}
	}

	u := user.Current(c)
	if u != nil {
		b1.WriteString(fmt.Sprintf("%v %v %v<br>\n", u.ID, u.Email, u.FederatedIdentity))
	} else {
		b1.WriteString("nobody calling on the phone<br>")
	}

	// c := appengine.NewContext(r)
	q := datastore.NewQuery("__BlobInfo__")
	if nameFilter != "" {

		// nameFilter = strings.ToLower(nameFilter)
		b1.WriteString(fmt.Sprintf("Filtering by %v-%v<br>", nameFilter, stringspb.IncrementString(nameFilter)))

		q = datastore.NewQuery("__BlobInfo__").Filter("filename >=", nameFilter)
		q = q.Filter("filename <", stringspb.IncrementString(nameFilter))

	}
	for t := q.Run(c); ; {
		var bi BlobInfo
		dsKey, err := t.Next(&bi)

		if err == datastore.Done {
			// aelog.Infof(c,"   No Results (any more) blob-list %v", err)
			break
		}
		// other err
		if err != nil {
			loghttp.E(w, r, err, false)
			return
		}

		//s1 = fmt.Sprintf("key %v %v %v %v %v %v<br>\n", dsKey.AppID(),dsKey.Namespace() , dsKey.Parent(), dsKey.Kind(), dsKey.StringID(), dsKey.IntID())
		//b1.WriteString( s1 )

		//s1 = fmt.Sprintf("blobinfo: %v %v<br>\n", bi.Filename, bi.Size)
		//b1.WriteString( s1 )

		ext := path.Ext(bi.Filename)
		base := path.Base(bi.Filename)
		base = base[:len(base)-len(ext)]

		//b1.WriteString( fmt.Sprintf("-%v-  -%v-",base, ext) )

		base = strings.Replace(base, "_", " ", -1)
		base = strings.Title(base)
		ext = strings.ToLower(ext)

		titledFilename := base + ext
		if strings.HasPrefix(titledFilename, "Backup") {
			showBackup := r.FormValue("backup")
			if len(showBackup) < 1 {
				continue
			}
		}

		s1 = fmt.Sprintf("<a class='ib' style='width:280px;margin-right:20px' target='_view' href='/blob2/serve-full?blobkey=%v'>%v</a> &nbsp; &nbsp; \n", dsKey.StringID(), titledFilename)
		b1.WriteString(s1)

		if bi.ContentType == "image/png" || bi.ContentType == "image/jpeg" {
			s1 = fmt.Sprintf("<img class='ib' style='width:40px;' src='/_ah/img/%v%v' />\n",
				dsKey.StringID(), "=s200-c")
			b1.WriteString(s1)

			s1 = fmt.Sprintf("<a class='ib' target='_view' href='/_ah/img/%v%v'>Thumb</a>\n",
				dsKey.StringID(), "=s200-c")
			b1.WriteString(s1)

		} else {
			s1 = fmt.Sprintf("<span class='ib' style='width:145px;'> &nbsp; no thb</span>")
			b1.WriteString(s1)
		}

		s1 = fmt.Sprintf("<a class='ib' target='_rename_delete' href='/blob2/rename-delete?action=delete&blobkey=%v'>Delete</a>\n",
			dsKey.StringID())
		b1.WriteString(s1)

		s1 = fmt.Sprintf(`
			<span class='ib' style='width:450px; border: 1px solid #aaa'>
				<form target='_rename_delete' action='/blob2/rename-delete' >
					<input name='blobkey'  value='%v'     type='hidden'/>
					<input name='action'   value='rename' type='hidden'/>
					<input name='filename' value='%v' size='42'/>
					<input type='submit'   value='Rename' />
				</form>
			</span>
			`, dsKey.StringID(), bi.Filename)
		b1.WriteString(s1)

		b1.WriteString("<br><br>\n\n")

	}

	b1.WriteString("<a accesskey='u' href='/blob2/upload' ><b>U</b>pload</a><br>")
	b1.WriteString(`<a  href='https://appengine.google.com/blobstore/explorer?&app_id=s~libertarian-islands' 
		>Delete via Console</a><br>`)

}