Skip to content

Commit

Permalink
initial github release
Browse files Browse the repository at this point in the history
  • Loading branch information
schnoddelbotz committed Apr 13, 2017
0 parents commit 61fb26a
Show file tree
Hide file tree
Showing 35 changed files with 4,994 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.DS_Store
amtgo.db
key.pem
cert.pem
amtc/
amt-cmd/
*.out
dependencies
amtpassword.txt
19 changes: 19 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright (c) 2016-2017 Jan Hacker https://github.com/schnoddelbotz

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
79 changes: 79 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
PLATFORMS= freebsd/amd64 linux/amd64 linux/arm-6 linux/arm-7 linux/arm64 windows/386 windows/amd64 darwin/amd64
AMTC_CHECKOUT=amtc
AMTCWEB_CHECKOUT=$(AMTC_CHECKOUT)/amtc-web

VERSION=$(shell git describe --tags | cut -dv -f2)
LDFLAGS:=-X main.AppVersion=$(VERSION) -w
GOBIN ?= $(CWD)
BIN=$(shell echo amtgo-`uname -s`-`uname -m`)
SOURCES=$(shell echo main.go ./*/*.go)

$(BIN): $(SOURCES) dependencies
go build -v -ldflags "$(LDFLAGS) -s" -o "$(BIN)" main.go

zip: $(BIN) $(BIN)_v$(VERSION).zip

$(BIN)_v$(VERSION).zip:
zip $(BIN)_v$(VERSION).zip $(BIN)

dependencies:
go get -v
touch dependencies

release: xgo dependencies
xgo -go 1.8 -ldflags "$(LDFLAGS)" -targets "$(PLATFORMS)" .

ziprelease: release
for bin in amtgo-*; do zip $${bin}_v$(VERSION).zip $$bin; done

xgo:
go get github.com/karalabe/xgo

lint:
golint ./...

test: dependencies
go test -v -coverprofile=webserver.out ./webserver
go test -v -coverprofile=database.out ./database
go vet ./...

coverage: test
# https://github.com/golang/go/issues/6909
go tool cover -html=webserver.out
go tool cover -html=database.out

# targets below only required to rebuild assets

go-bindata:
go get github.com/jteeuwen/go-bindata/...

$(AMTC_CHECKOUT):
git clone https://github.com/schnoddelbotz/amtc.git
# patch only bit in amtc-web: initial setup dialogue
cp webserver/setup.hbs.html amtc/amtc-web/templates/
perl -pi -e "s@localhost@@" amtc/amtc-web/js/app/app.js
perl -pi -e "s@mysqlUser: 'amtcweb'@mysqlUser: ''@" amtc/amtc-web/js/app/app.js
perl -pi -e "s@Uptime, load average@amtgo uptime@" amtc/amtc-web/templates/systemhealth.hbs.html
perl -pi -e "s@Disk free@amtgo memory usage@" amtc/amtc-web/templates/systemhealth.hbs.html
perl -pi -e "s@Active amtc processes@Active go routines@" amtc/amtc-web/templates/systemhealth.hbs.html
perl -pi -e "s@PHP@Go@" amtc/amtc-web/templates/systemhealth.hbs.html
perl -pi -e "s@amtc binary@amtgo binary@" amtc/amtc-web/templates/systemhealth.hbs.html
perl -pi -e "s@\(notyet\)@@" amtc/amtc-web/templates/systemhealth.hbs.html
cd amtc/amtc-web ; make -j 8

assets: go-bindata $(AMTC_CHECKOUT)
mkdir -p web-assets/{js,fonts,css,page} amt-cmd
cp $(AMTCWEB_CHECKOUT)/{index.html.gz,amtc-favicon.png} web-assets
cp $(AMTCWEB_CHECKOUT)/css/styles.css.gz web-assets/css
cp $(AMTCWEB_CHECKOUT)/js/jslibs.js.gz web-assets/js
cp $(AMTCWEB_CHECKOUT)/page/*.md web-assets/page
cp $(AMTCWEB_CHECKOUT)/fonts/fontawesome-webfont.woff* web-assets/fonts
cp $(shell ls -1 $(AMTC_CHECKOUT)/src/wsman_* | grep -v '\.h$$' | xargs) amt-cmd
go-bindata -pkg webserver -prefix "`pwd`/web-assets" -nocompress -nomemcopy -o webserver/assets.go web-assets/...
go-bindata -pkg amt -prefix "`pwd`/amt-cmd" -nocompress -nomemcopy -o amt/commands.go amt-cmd/...

clean:
rm -f $(BIN) $(BIN).zip *.out dependencies

realclean: clean
rm -rf amtc amt-cmd amtgo-*
115 changes: 115 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
# amtgo

A [golang](https://golang.org/) implementation of
[amtc](https://github.com/schnoddelbotz/amtc) and its amtc-web GUI.
Like amtc -- for mass remote power management and monitoring [Intel AMT](http://en.wikipedia.org/wiki/Intel_Active_Management_Technology) hosts.

Features over amtc / amtc-web:

- [x] includes amtc-web application webserver in a single binary
- [x] instant, parallel execution of GUI-submitted tasks
- [x] includes cron functionality for monitoring and scheduled tasks
- [x] it finally has a command/context-sensitive `-h(elp)` command line switch
- [x] windows binaries are available on [releases](./../../releases) page, too

amtgo still supports SQLite and MySQL as database back-ends.
amtc-web GUI is included 1:1 from amtc repository.

## binary installation

Download the latest [release](./../../releases) for your OS.
Unzip the download -- the zip file contains the amtgo binary.
Move the binary to a location of your choice, e.g. `/usr/local/bin`.
That's all needed to run amtgo from CLI like amtc.
You should be able to run `amtgo -h` for help.

`amtgo server` should be started up via systemd or the like.
Find first run instructions below.

### ... when using SQLite

- In a terminal / CMD session, `cd` to the directory where
amtgo is supposed to store its SQLite database and
AMT password files.
- Put your AMT password into a file, e.g. `echo 'mY$ecurePassw0rd' > amtpassword.txt`
- Type/Run `amtgo server`. Visit http://localhost:8080 to create initial
web site user account and log in

### ... when using MySQL

- Install MySQL, start it and create a database and a user for amtgo purposes.
- Proceed like with SQLite above
- Starting amtgo server using MySQL requires MySQL connection details.
They should be passed as environment variables, but can also be passed
as command line arguments for testing. Output excerpt from `amtgo server -h`:

```
OPTIONS:
--dbdriver value, -d value Database driver: sqlite3 or mysql (default: "sqlite3") [$DB_DRIVER]
--dbfile value, -F value SQLite database file (default: "amtgo.db") [$DB_FILE]
--dbName value, -D value MySQL database name (default: "amtgo") [$DB_NAME]
--dbHost value, -H value MySQL database host (default: "localhost") [$DB_HOST]
--dbUser value, -U value MySQL database user name (default: "amtgo") [$DB_USER]
--dbPassword value, -P value MySQL database password [$DB_PASSWORD]
--dbPort value, -p value MySQL database port (default: "3306") [$DB_PORT]
```

For example, to run amtgo server using mysql database `foo` on localhost as user `joe`
using password `1234`, run: `amtgo server -d mysql -D foo -U joe -P 1234`.

For testing purposes, you may want to run a ephemeral MySQL instance using Docker:

```bash
docker run --rm --name amtgo-mysql \
-e MYSQL_RANDOM_ROOT_PASSWORD=yes \
-e MYSQL_DATABASE=amtgo \
-e MYSQL_USER=amtgo \
-e MYSQL_PASSWORD=1234 \
-p 3306:3306 \
-d mysql/mysql-server
```

## building amtgo from source

```bash
# if using Go < 1.8
export GOPATH=/home/you/go

# fetch and build amtgo
go get -v github.com/schnoddelbotz/amtgo
```

To run tests, git clone the repository and run `make test` or `make coverage`.
Note that the repository contains a pre-built amtc-web; to rebuild amtc-web
from source, run `make assets`, then `make` to build amtgo itself.

## status & open issues

amtgo is a fun project for me to get into golang -- I never was too
happy with amtc-web's requirement for Apache, PHP and cron...
Like amtc, amtgo works for me (tm), but I lack long-term usage experience.
Note that amtgo, in contrast to amtc, does not support EOI protocol but
only WS-MAN. For AMT versions <6, you might want to stay with amtc.

Please report any [issues](./../../issues/) you encounter.
I'm also thankful for any hints for improvement.

## license

amtgo is published under [MIT license](LICENSE.txt).

Besides golang's standard library, amtgo relies on:

- [urfave/cli](https://github.com/urfave/cli) for CLI parsing
- [mattn/go-sqlite3](https://github.com/mattn/go-sqlite3) as SQLite driver
- [go-sql-driver/mysql](https://github.com/go-sql-driver/mysql) as MySQL driver
- [gorilla](https://github.com/gorilla) handlers, mux, securecookie & sessions for amtc-web
- [xinsnake/go-http-digest-auth-client](https://github.com/xinsnake/go-http-digest-auth-client),
[tweaked](tree/master/amt/digest_auth_client) to support TLS, timeouts and certificate
verification for AMT.

Assets (i.e. amtc-web static content and AMT commands) are included
using [go-bindata](https://github.com/jteeuwen/go-bindata).
Releases for all platforms are built using [xgo](https://github.com/karalabe/xgo).

Please check [amtc-web 3rd party components](https://github.com/schnoddelbotz/amtc/blob/master/amtc-web/LICENSES-3rd-party.txt), too.
Loading

0 comments on commit 61fb26a

Please sign in to comment.