Removed web interface as it is unfinshed
This commit is contained in:
parent
683a5e9719
commit
03cb8a9ab5
4
Makefile
4
Makefile
|
@ -1,6 +1,6 @@
|
|||
all: mumbledj
|
||||
|
||||
mumbledj: main.go commands.go parseconfig.go strings.go service.go service_youtube.go songqueue.go cache.go web.go
|
||||
mumbledj: main.go commands.go parseconfig.go strings.go service.go youtube_dl.go service_youtube.go service_soundcloud.go songqueue.go cache.go
|
||||
if [ ! -f $(GOPATH)/bin/goop ]; then go get github.com/nitrous-io/goop; fi;
|
||||
rm -rf Goopfile.lock
|
||||
goop install
|
||||
|
@ -12,10 +12,8 @@ clean:
|
|||
install:
|
||||
mkdir -p ~/.mumbledj/config
|
||||
mkdir -p ~/.mumbledj/songs
|
||||
mkdir -p ~/.mumbledj/web
|
||||
if [ -f ~/.mumbledj/config/mumbledj.gcfg ]; then mv ~/.mumbledj/config/mumbledj.gcfg ~/.mumbledj/config/mumbledj_backup.gcfg; fi;
|
||||
cp -u config.gcfg ~/.mumbledj/config/mumbledj.gcfg
|
||||
cp -u index.html ~/.mumbledj/web/index.html
|
||||
if [ -d ~/bin ]; then cp -f mumbledj* ~/bin/mumbledj; else sudo cp -f mumbledj* /usr/local/bin/mumbledj; fi;
|
||||
|
||||
build:
|
||||
|
|
|
@ -82,13 +82,6 @@ func parseCommand(user *gumble.User, username, command string) {
|
|||
} else {
|
||||
dj.SendPrivateMessage(user, NO_PERMISSION_MSG)
|
||||
}
|
||||
// Web command
|
||||
case dj.conf.Aliases.WebAlias:
|
||||
if dj.HasPermission(username, dj.conf.Permissions.AdminWeb) {
|
||||
web.GetWebAddress(user)
|
||||
} else {
|
||||
dj.SendPrivateMessage(user, NO_PERMISSION_MSG)
|
||||
}
|
||||
// Move command
|
||||
case dj.conf.Aliases.MoveAlias:
|
||||
if dj.HasPermission(username, dj.conf.Permissions.AdminMove) {
|
||||
|
|
|
@ -86,10 +86,6 @@ HelpAlias = "help"
|
|||
# DEFAULT VALUE: "volume"
|
||||
VolumeAlias = "volume"
|
||||
|
||||
# Alias used for web address command
|
||||
# DEFAULT VALUE: "web"
|
||||
WebAlias = "web"
|
||||
|
||||
# Alias used for move command
|
||||
# DEFAULT VALUE: "move"
|
||||
MoveAlias = "move"
|
||||
|
@ -166,10 +162,6 @@ AdminHelp = false
|
|||
# DEFAULT VALUE: false
|
||||
AdminVolume = false
|
||||
|
||||
# Make web an admin command?
|
||||
# DEFAULT VALUE: false
|
||||
AdminWeb = false
|
||||
|
||||
# Make move an admin command?
|
||||
# DEFAULT VALUE: true
|
||||
AdminMove = true
|
||||
|
|
49
index.html
49
index.html
|
@ -1,49 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="ISO-8859-1">
|
||||
<title>{{.User}} - mumbledj</title>
|
||||
<script
|
||||
src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
|
||||
<script type="text/javascript">
|
||||
function onLoad() {
|
||||
window.setInterval(function() {
|
||||
// Get the song queue
|
||||
}, 6000);
|
||||
}
|
||||
|
||||
function setAPI(type, val) {
|
||||
$.ajax({
|
||||
url : "http://{{.Site}}/api/" + type + "?token={{.Token}}"
|
||||
+ "&value=" + val,
|
||||
complete : apiComplete,
|
||||
cache : false
|
||||
});
|
||||
}
|
||||
|
||||
function apiComplete(jqXHR, textStatus) {
|
||||
alert(textStatus);
|
||||
}
|
||||
|
||||
function txtBox(type) {
|
||||
var txt = $("#textbox");
|
||||
api(type, txt.attr("value"));
|
||||
txt.attr("value", "");
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body onload="onLoad();" bgcolor="#FFFFFF">
|
||||
<h1>Add Song Form</h1>
|
||||
<input id="textbox" type="text" />
|
||||
<input id="add" type="button" value="Add Song"
|
||||
onclick="setAPI('add', $('#textbox').attr('value'))" />
|
||||
<input id="volume" type="button" value="Set Volume"
|
||||
onclick="setAPI('volume', $('#textbox').attr('value'))" />
|
||||
<input id="skipSong" type="button" value="Skip Current Song"
|
||||
onclick="setAPI('skip', false)" />
|
||||
<input id="skipPlaylist" type="button" value="Skip Current Playlist"
|
||||
onclick="setAPI('skip', true)" />
|
||||
<br />
|
||||
<textarea id="status" rows="10" cols="30"></textarea>
|
||||
</body>
|
||||
</html>
|
3
main.go
3
main.go
|
@ -252,9 +252,6 @@ func main() {
|
|||
Test(password, address, port, strings.Split(accesstokens, " "))
|
||||
}
|
||||
|
||||
web = NewWebServer(9563)
|
||||
web.makeWeb()
|
||||
|
||||
if isNil(web) {
|
||||
Verbose("WEB IS NIL")
|
||||
}
|
||||
|
|
|
@ -51,7 +51,6 @@ type DjConfig struct {
|
|||
NumCachedAlias string
|
||||
CacheSizeAlias string
|
||||
KillAlias string
|
||||
WebAlias string
|
||||
}
|
||||
Permissions struct {
|
||||
AdminsEnabled bool
|
||||
|
@ -71,7 +70,6 @@ type DjConfig struct {
|
|||
AdminNumCached bool
|
||||
AdminCacheSize bool
|
||||
AdminKill bool
|
||||
AdminWeb bool
|
||||
}
|
||||
}
|
||||
|
||||
|
|
197
web.go
197
web.go
|
@ -1,197 +0,0 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
//"encoding/json"
|
||||
"fmt"
|
||||
"html"
|
||||
"html/template"
|
||||
"io/ioutil"
|
||||
"math/rand"
|
||||
"net/http"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/layeh/gumble/gumble"
|
||||
)
|
||||
|
||||
type WebServer struct {
|
||||
port int
|
||||
client_token map[*gumble.User]string
|
||||
token_client map[string]*gumble.User
|
||||
}
|
||||
|
||||
type Page struct {
|
||||
Site string
|
||||
Token string
|
||||
User string
|
||||
}
|
||||
|
||||
type Status struct {
|
||||
Error bool
|
||||
ErrorMsg string
|
||||
Queue []SongInfo
|
||||
}
|
||||
type SongInfo struct {
|
||||
TitleID string
|
||||
PlaylistID string
|
||||
Title string
|
||||
Playlist string
|
||||
Submitter string
|
||||
Duration string
|
||||
Thumbnail string
|
||||
}
|
||||
|
||||
var external_ip = ""
|
||||
|
||||
func NewWebServer(port int) *WebServer {
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
return &WebServer{
|
||||
port: port,
|
||||
client_token: make(map[*gumble.User]string),
|
||||
token_client: make(map[string]*gumble.User),
|
||||
}
|
||||
}
|
||||
|
||||
func (web *WebServer) makeWeb() {
|
||||
http.HandleFunc("/", web.homepage)
|
||||
http.HandleFunc("/api/add", web.add)
|
||||
http.HandleFunc("/api/volume", web.volume)
|
||||
http.HandleFunc("/api/skip", web.skip)
|
||||
//http.HandleFunc("/api/status", web.status)
|
||||
http.ListenAndServe(":"+strconv.Itoa(web.port), nil)
|
||||
}
|
||||
|
||||
func (web *WebServer) homepage(w http.ResponseWriter, r *http.Request) {
|
||||
var uname = web.token_client[r.URL.Path[1:]]
|
||||
if uname == nil {
|
||||
fmt.Fprintf(w, "Invalid Token")
|
||||
} else {
|
||||
var webpage = uname.Name
|
||||
|
||||
// Check to see if user has a custom webpage
|
||||
if _, err := os.Stat(fmt.Sprintf("%s/.mumbledj/web/%s.html", dj.homeDir, uname.Name)); os.IsNotExist(err) {
|
||||
webpage = "index"
|
||||
}
|
||||
|
||||
t, err := template.ParseFiles(fmt.Sprintf("%s/.mumbledj/web/%s.html", dj.homeDir, webpage))
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
err = t.Execute(w, Page{getIP() + ":" + strconv.Itoa(web.port), r.URL.Path[1:], uname.Name})
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (web *WebServer) add(w http.ResponseWriter, r *http.Request) {
|
||||
var uname = web.token_client[r.FormValue("token")]
|
||||
if uname == nil {
|
||||
fmt.Fprintf(w, "Invalid Token")
|
||||
} else {
|
||||
add(uname, html.UnescapeString(r.FormValue("value")))
|
||||
fmt.Fprintf(w, "Success")
|
||||
}
|
||||
}
|
||||
|
||||
func (web *WebServer) volume(w http.ResponseWriter, r *http.Request) {
|
||||
var uname = web.token_client[r.FormValue("token")]
|
||||
if uname == nil {
|
||||
fmt.Fprintf(w, "Invalid Token")
|
||||
} else {
|
||||
var vol = html.UnescapeString(r.FormValue("value"))
|
||||
volume(uname, vol)
|
||||
fmt.Fprintf(w, "Success")
|
||||
}
|
||||
}
|
||||
|
||||
func (web *WebServer) skip(w http.ResponseWriter, r *http.Request) {
|
||||
var uname = web.token_client[r.FormValue("token")]
|
||||
if uname == nil {
|
||||
fmt.Fprintf(w, "Invalid Token")
|
||||
} else {
|
||||
value := html.UnescapeString(r.FormValue("value"))
|
||||
playlist, err := strconv.ParseBool(value)
|
||||
if err == nil {
|
||||
skip(uname, false, playlist)
|
||||
fmt.Fprintf(w, "Success")
|
||||
} else {
|
||||
fmt.Fprintf(w, "Invalid Value")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//func (web *WebServer) status(w http.ResponseWriter, r *http.Request) {
|
||||
// var uname = web.token_client[r.FormValue("token")]
|
||||
// if uname == nil {
|
||||
// str, ok := json.Marshal(&Status{true, "Invalid Token"}).(string)
|
||||
// fmt.Fprintf(w, str)
|
||||
// } else {
|
||||
// // Generate song queue
|
||||
// queueLength := dj.queue.Len()
|
||||
// var songsInQueue [queueLength]SongInfo
|
||||
// for i := 0; i < dj.queue.Len(); i++ {
|
||||
// songItem := dj.queue.Get(i)
|
||||
// songsInQueue[i] = &SongInfo{
|
||||
// TitleID: songItem.ID(),
|
||||
// Title: songItem.Title(),
|
||||
// Submitter: songItem.Submitter(),
|
||||
// Duration: songItem.Duration(),
|
||||
// Thumbnail: songItem.Thumbnail(),
|
||||
// }
|
||||
// if !isNil(songItem.Playlist()) {
|
||||
// songsInQueue[i].PlaylistID = songItem.Playlist().ID()
|
||||
// songsInQueue[i].Playlist = songItem.Playlist().Title()
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// // Output status
|
||||
// fmt.Fprintf(w, string(json.MarshalIndent(&Status{false, "", songsInQueue})))
|
||||
// }
|
||||
//}
|
||||
|
||||
func (website *WebServer) GetWebAddress(user *gumble.User) {
|
||||
Verbose("Port number: " + strconv.Itoa(web.port))
|
||||
if web.client_token[user] != "" {
|
||||
web.token_client[web.client_token[user]] = nil
|
||||
}
|
||||
// dealing with collisions
|
||||
var firstLoop = true
|
||||
for firstLoop || web.token_client[web.client_token[user]] != nil || web.client_token[user] == "api" {
|
||||
web.client_token[user] = randSeq(10)
|
||||
firstLoop = false
|
||||
}
|
||||
web.token_client[web.client_token[user]] = user
|
||||
dj.SendPrivateMessage(user, fmt.Sprintf(WEB_ADDRESS, getIP(), web.client_token[user], getIP(), web.client_token[user]))
|
||||
}
|
||||
|
||||
// Gets the external ip address for the server
|
||||
func getIP() string {
|
||||
if external_ip != "" {
|
||||
return external_ip
|
||||
} else {
|
||||
if response, err := http.Get("http://myexternalip.com/raw"); err == nil {
|
||||
defer response.Body.Close()
|
||||
if response.StatusCode == 200 {
|
||||
if body, err := ioutil.ReadAll(response.Body); err == nil {
|
||||
external_ip = strings.TrimSpace(string(body))
|
||||
}
|
||||
}
|
||||
}
|
||||
return external_ip
|
||||
}
|
||||
}
|
||||
|
||||
// Generates a pseudorandom string of characters
|
||||
func randSeq(n int) string {
|
||||
var letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
|
||||
b := make([]rune, n)
|
||||
for i := range b {
|
||||
b[i] = letters[rand.Intn(len(letters))]
|
||||
}
|
||||
return string(b)
|
||||
}
|
Reference in a new issue