Add car cgi

This commit is contained in:
Neale Pickett 2017-04-29 19:13:10 +00:00
parent 88c1d0d626
commit 27adf8569d
7 changed files with 132 additions and 43 deletions

66
car.cgi.go Normal file
View File

@ -0,0 +1,66 @@
package main
import (
"fmt"
"log"
"net/http"
"net/http/cgi"
"os"
"github.com/jsgoecke/tesla"
"github.com/coduno/netrc"
)
const authtok = "~!Jf5!uYFxhK"
const clientId = "81527cff06843c8634fdc09e8ac0abefb46ac849f38fe1e431c2ef2106796384"
const clientSec = "c7257eb71a564034f9419ee651c7d0e5f7aa6bfbd18bafb5c5c033b093bb2fa3"
type Handler struct {
cgi.Handler
}
func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if r.FormValue("auth") != authtok {
w.Header().Set("Content-Type", "text/plain")
fmt.Fprintln(w, "NO: Invalid authtok")
return
}
os.Setenv("HOME", "/home/neale")
n, _ := netrc.Parse()
secrets := n["gitlab.com"] // Requiring a password is such bullshit.
auth := tesla.Auth{
ClientID: clientId,
ClientSecret: clientSec,
Email: secrets.Login,
Password: secrets.Password,
}
cli, err := tesla.NewClient(&auth)
if err != nil {
w.Header().Set("Content-Type", "text/plain")
fmt.Fprintln(w, err)
return
}
vehicles, err := cli.Vehicles()
if err != nil {
w.Header().Set("Content-Type", "text/plain")
fmt.Fprintln(w, err)
return
}
vehicle := vehicles[0]
w.Header().Set("Content-Type", "text/plain")
fmt.Fprintln(w, "OK")
fmt.Fprintln(w, vehicle.StartAirConditioning())
}
func main() {
log.SetOutput(os.Stdout)
log.SetFlags(0)
log.SetPrefix("Status: 500 CGI Go Boom\nContent-type: text/plain\n\nERROR: ")
h := Handler{}
if err := cgi.Serve(h); err != nil {
log.Fatal(err)
}
}

11
install
View File

@ -50,6 +50,12 @@ gc () {
fi fi
} }
setuid () {
target=$DESTDIR/${1%.*}
echo "SETUID $target"
chmod u+s $target
}
install () { install () {
fd=$(dirname $fn) fd=$(dirname $fn)
echo "SUBINSTALL $fd" echo "SUBINSTALL $fd"
@ -60,10 +66,15 @@ install () {
git ls-files | while read fn; do git ls-files | while read fn; do
case "$fn" in case "$fn" in
.*|*/.*|*~|install) .*|*/.*|*~|install)
true # Skip
;; ;;
*/install) */install)
install $fn install $fn
;; ;;
car.cgi.go)
gc $fn
setuid $fn
;;
*.mdwn) *.mdwn)
html $fn html $fn
;; ;;

View File

@ -0,0 +1,11 @@
Title: I Also Enjoy Wearing Kilts
*This was published as a [letter to the Editor of the Daily Post](http://www.ladailypost.com/content/letter-editor-i-also-enjoy-wearing-kilts)*
September 28, 2016
I enjoyed seeing the article "Los Alamos County Council Candidate Models Kilts" - click [here](http://www.ladailypost.com/content/los-alamos-county-council-candidate-models-kilts).
I've been wearing kilts to work several days a week since August, and find them practical and comfortable. I get positive comments every time I wear one!
Congratulations to Jaret McDonald on getting the modeling gig!

View File

@ -20,8 +20,9 @@
<option class="item-select-option" value="000000,ffffff,ffffff">Dark</option> <option class="item-select-option" value="000000,ffffff,ffffff">Dark</option>
<option class="item-select-option" value="ffffff,000000,000000">Light</option> <option class="item-select-option" value="ffffff,000000,000000">Light</option>
<option class="item-select-option" value="000000,ffffff,aaaaaa">Gray</option> <option class="item-select-option" value="000000,ffffff,aaaaaa">Gray</option>
<option class="item-select-option" value="000000,ffffff,aa55ff">Dusk</option> <option class="item-select-option" value="000000,ff55ff,ffffff">Dusk</option>
<option class="item-select-option" value="000000,ffffff,ffff55">Spring</option> <option class="item-select-option" value="000000,ffff55,ffffff">Spring</option>
<option class="item-select-option" value="000000,ffaa55,ffffff">Fall</option>
</select> </select>
</label> </label>

View File

@ -30,7 +30,7 @@ function submit() {
} else if (t == "text") { } else if (t == "text") {
v = Number(input.value); v = Number(input.value);
} else if (t == "select-one") { } else if (t == "select-one") {
v = Number(input.value); v = input.value;
} else { } else {
console.log("Unknown type: " + t); console.log("Unknown type: " + t);
continue; continue;

View File

@ -94,7 +94,7 @@ action send to the list and the list only, and provides a "reply to
author" action that will always send to the message's author whether author" action that will always send to the message's author whether
it's a list or not. "Reply to author" honors the `Reply-To` field. it's a list or not. "Reply to author" honors the `Reply-To` field.
This is exactly the convenient behavior Simon claims to want in his This is exactly the convenient behavior Simon claims to want in his
essay, and it can all be done using standard behavior. "considered useful" essay, and it can all be done using standard behavior.
Getting two copies of the same email Getting two copies of the same email

View File

@ -91,7 +91,7 @@ download a [tarball of the latest
commit](http://woozle.org/neale/g.cgi/x11/xss/snapshot/xss-master.tar.gz), or clone the commit](http://woozle.org/neale/g.cgi/x11/xss/snapshot/xss-master.tar.gz), or clone the
git repository: git repository:
git clone http://woozle.org/~neale/projects/xss git clone http://woozle.org/~neale/projects/x11/xss
History History