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)
}
}

87
install
View File

@ -17,64 +17,75 @@ older () {
html () {
target=$DESTDIR/${1%mdwn}html
if older $target $1 tmpl/*; then
echo "HTML $1"
mkdir -p $(dirname $target)
./tmpl/mdwntohtml < $1 > $target
fi
target=$DESTDIR/${1%mdwn}html
if older $target $1 tmpl/*; then
echo "HTML $1"
mkdir -p $(dirname $target)
./tmpl/mdwntohtml < $1 > $target
fi
}
copy () {
target=$DESTDIR/$1
if older $target $1; then
echo "COPY $1"
mkdir -p $(dirname $target)
cp $1 $target
fi
target=$DESTDIR/$1
if older $target $1; then
echo "COPY $1"
mkdir -p $(dirname $target)
cp $1 $target
fi
}
cc () {
target=$DESTDIR/${1%.c}
if older $target $1; then
echo "CC $1"
gcc -o $target $1
fi
target=$DESTDIR/${1%.c}
if older $target $1; then
echo "CC $1"
gcc -o $target $1
fi
}
gc () {
target=$DESTDIR/${1%.go}
if older $target $1; then
echo "GO $1"
go build -o $target $1
fi
target=$DESTDIR/${1%.go}
if older $target $1; then
echo "GO $1"
go build -o $target $1
fi
}
setuid () {
target=$DESTDIR/${1%.*}
echo "SETUID $target"
chmod u+s $target
}
install () {
fd=$(dirname $fn)
echo "SUBINSTALL $fd"
(cd $fd && ./install $DESTDIR/$fd)
fd=$(dirname $fn)
echo "SUBINSTALL $fd"
(cd $fd && ./install $DESTDIR/$fd)
}
git ls-files | while read fn; do
case "$fn" in
case "$fn" in
.*|*/.*|*~|install)
;;
true # Skip
;;
*/install)
install $fn
;;
install $fn
;;
car.cgi.go)
gc $fn
setuid $fn
;;
*.mdwn)
html $fn
;;
html $fn
;;
*.cgi.c)
cc $fn
;;
cc $fn
;;
*.cgi.go)
gc $fn
;;
gc $fn
;;
*)
copy $fn
;;
esac
copy $fn
;;
esac
done

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="ffffff,000000,000000">Light</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,ffffff,ffff55">Spring</option>
<option class="item-select-option" value="000000,ff55ff,ffffff">Dusk</option>
<option class="item-select-option" value="000000,ffff55,ffffff">Spring</option>
<option class="item-select-option" value="000000,ffaa55,ffffff">Fall</option>
</select>
</label>

View File

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

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
git repository:
git clone http://woozle.org/~neale/projects/xss
git clone http://woozle.org/~neale/projects/x11/xss
History