13 Commits

9 changed files with 57 additions and 53 deletions

View File

@@ -1,3 +1,5 @@
769fad81e3f8db8f7e5f5c164656a382a169d735 release-1.0.0
9ed95938d809a8226aca529e34b655e6d8c8c379 release-1.0.1
46fe533682419c8a519836ac95b5575053aa0fa8 release-1.0.2
a2c92b262f339f82eb01c8d92dda252a27432255 release-1.1.0
d14041daa7bbbd37ea2ff47aa978b9595af67ca3 release-1.1.1

View File

@@ -8,7 +8,6 @@ type Config struct {
Web struct {
Port int `json:"port"`
BindTo string `json:"bind_to"`
Extern string `json:"extern"`
Title string `json:"title"`
CustomFavicon bool `json:"custom_favicon"`

View File

@@ -8,10 +8,20 @@ Tags: nmdc
=UPGRADING FROM DCWEBUI2=
- The configuration file format is identical, but please now ensure it's valid json instead of just a .js file. This means no assignment, use double-quoted strings, and no comments.
- The configuration file content is identical between nmdc-webfrontend 1.0.0 and dcwebui2 1.3.0, but please now ensure it's valid JSON instead of arbitrary javascript. This means no assignment, use double-quoted strings, and no comments.
- Future changes to the configuration file since nmdc-webfrontend 1.0.0 are backward compatible (see the changelog for more details).
=CHANGELOG=
2017-02-06 1.1.2
- Autodetect 'extern', no need to include it in config files
- Enhancement: Remove redundant request, for a faster page load
- Display server version number in log file and in response headers
- Fix a cosmetic issue with spacing around user count in page title
2017-02-06 1.1.1
- Fix an issue with malformed content in minified build
2017-02-06 1.1.0
- Feature: Remember last username/password for login; remember last "show joins/parts" status
- Feature: Display user details on hover (description, email, client tag, share size)

View File

@@ -88,7 +88,7 @@ single_build() {
# GOARCH/GOOS supplied in function env
go build \
-a \
-ldflags '-s -w' \
-ldflags "-s -w -X main.VERSION=nmdc-webfrontend/${version}" \
-gcflags "-trimpath=${GOPATH}" \
-asmflags "-trimpath=${GOPATH}" \
-o "$(pathfix "${tmpdir}/${local_bin_name}")"

View File

@@ -5,6 +5,7 @@
var SENTINEL_PASSWORD = "************";
var CHAT_SCROLLBACK_LIMIT = 50; // Once over 2x $limit, the first $limit will be trimmed off the list
var EXTERN_ROOT = window.location.protocol + "//" + window.location.host + "/";
var $ = (document.querySelectorAll ?
function(s) {
@@ -155,7 +156,7 @@ var notify = function(title, body) {
case "granted": {
new Notification(title, {
body: body,
icon: DCWEBUI_CONF.extern + "/favicon.ico"
icon: EXTERN_ROOT + "/favicon.ico"
});
} break;
@@ -779,13 +780,13 @@ var updateTitle = function() {
prefix = "[NEW PM] "
}
document.title = prefix + hub_hubname + "("+userlist.count()+") "
document.title = prefix + hub_hubname + " ("+userlist.count()+")"
};
var sock = {};
var hub_state = 0; // [disconnected, sent-nick, connected]
var hub_last_nick = '';
var hub_hubname = DCWEBUI_CONF.title;
var hub_hubname = "Loading...";
var pm_tabs = {}; // nick => tabid
var next_tabid = 1;
@@ -917,7 +918,8 @@ var transition = function(new_state) {
$("#chatbox").disabled = true;
} break;
case STATE_ACTIVE: {
case STATE_ACTIVE: {
write("tab-main").system("Now talking on "+hub_hubname);
$("#chatbox").disabled = false;
$("#chatbox").spellcheck = true;
} break;
@@ -940,7 +942,7 @@ window.onload = function() {
show_joins = persistence_get("show_joins", false);
document.title = DCWEBUI_CONF.title;
document.title = hub_hubname; // "Loading...";
// HTML event handlers
@@ -1039,7 +1041,7 @@ window.onload = function() {
// Socket event handlers
sock = io.connect(DCWEBUI_CONF.extern);
sock = io.connect(EXTERN_ROOT);
sock.on('cls', function() {
transition(STATE_READY_FOR_LOGIN);
@@ -1062,7 +1064,6 @@ window.onload = function() {
}
});
sock.on('hubname', function(s) {
write("tab-main").system("Now talking on "+s);
hub_hubname = s;
updateTitle();
});

View File

@@ -53,7 +53,6 @@
</div>
<script type="text/javascript" src="/socket.io-1.7.2.js"></script>
<script type="text/javascript" src="/conf"></script>
<script type="text/javascript" src="/dcwebui.js"></script>
</body>
</html>

View File

@@ -30,21 +30,18 @@ if (is_dir('clientpack')) {
// Embed css into HTML file
$css_file = file_get_contents('clientpack/dcwebui.min.css');
$html_content = file_get_contents('clientpack/index.htm');
$html_content = preg_replace('~<link[^>]+dcwebui.css[^>]*>~', '<style type="text/css">'.$css_file.'</style>', $html_content);
$html_content = preg_replace_callback('~<link[^>]+dcwebui.css[^>]*>~', function() { return '<style type="text/css">'.file_get_contents('clientpack/dcwebui.min.css').'</style>'; }, $html_content);
// Embed JS into HTML file
$js_file = file_get_contents('clientpack/dcwebui.min.js');
$html_content = preg_replace('~<script[^>]+dcwebui.js[^>]*>~', '<script type="text/javascript">'.$js_file.'</script>', $html_content);
$html_content = preg_replace_callback('~<script[^>]+dcwebui.js[^>]*>~', function() { return '<script type="text/javascript">'.file_get_contents('clientpack/dcwebui.min.js').'</script>'; }, $html_content);
// Embed socketio into HTML file
$SIO_NAME = 'socket.io-1.7.2.js';
$sio_file = file_get_contents('clientpack/'.$SIO_NAME);
$html_content = preg_replace('~<script[^>]+'.$SIO_NAME.'[^>]*>~', '<script type="text/javascript">'.$sio_file.'</script>', $html_content);
define('SIO_NAME', 'socket.io-1.7.2.js');
$html_content = preg_replace_callback('~<script[^>]+'.SIO_NAME.'[^>]*>~', function() { return '<script type="text/javascript">'.file_get_contents('clientpack/'.SIO_NAME).'</script>'; }, $html_content);
// Minify the combined file
@@ -55,5 +52,5 @@ file_put_contents('clientpack/index.htm', $html_content);
// Clean up files
`rm clientpack/{index.htm,dcwebui{.min,}.js,dcwebui{.min,}.css}`;
unlink('clientpack/'.$SIO_NAME);
unlink('clientpack/'.SIO_NAME);
rename('clientpack/index.min.htm', 'clientpack/index.htm');

51
main.go
View File

@@ -12,6 +12,8 @@ import (
"github.com/googollee/go-socket.io"
)
var VERSION string = `nmdc-webfrontend/devel-unreleased`
type App struct {
cfg *Config
}
@@ -164,6 +166,7 @@ func (this *App) SocketIOServer(so socketio.Socket) {
log.Printf("[%s] Client connected", so.Id())
so.Emit("cls")
so.Emit("hubname", this.cfg.Web.Title)
so.Emit("raw", this.cfg.App.MotdHTML+"<br>")
so.Emit("sys", "Enter a name to connect as (or name:pass for a registered nick)")
@@ -185,24 +188,6 @@ func (this *App) customFaviconHandler(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, "favicon.ico")
}
func (this *App) ConfigRequestHandler(w http.ResponseWriter, r *http.Request) {
confStruct := struct {
Extern string `json:"extern"`
Title string `json:"title"`
}{
Extern: this.cfg.Web.Extern,
Title: this.cfg.Web.Title,
}
confBytes, _ := json.Marshal(confStruct)
//
w.Header().Set("Content-Type", "text/javascript")
w.WriteHeader(200)
fmt.Fprintf(w, "var DCWEBUI_CONF = %s;\n", string(confBytes))
}
func (this *App) StaticRequestHandler(w http.ResponseWriter, r *http.Request) {
fileName := r.URL.Path[1:]
if fileName == "" {
@@ -241,6 +226,9 @@ func (this *App) StaticRequestHandler(w http.ResponseWriter, r *http.Request) {
func (this *App) RunServer() {
// Inner mux {{
innerMux := http.NewServeMux()
// Socket.io handler
server, err := socketio.NewServer(nil)
if err != nil {
@@ -250,30 +238,39 @@ func (this *App) RunServer() {
server.On("error", func(so socketio.Socket, err error) {
log.Println("error:", err)
})
http.Handle("/socket.io/", server)
// Configuration handler
http.HandleFunc("/conf", this.ConfigRequestHandler)
innerMux.Handle("/socket.io/", server)
// Custom favicon handler
if this.cfg.Web.CustomFavicon {
http.HandleFunc("/favicon.ico", this.customFaviconHandler)
innerMux.HandleFunc("/favicon.ico", this.customFaviconHandler)
}
// Other files: asset handler
// Asset handler
if this.cfg.Web.ExternalWebroot {
http.Handle("/", http.FileServer(http.Dir("client")))
innerMux.Handle("/", http.FileServer(http.Dir("client")))
} else {
http.HandleFunc("/", this.StaticRequestHandler)
innerMux.HandleFunc("/", this.StaticRequestHandler)
}
// }}
// Wrapper mux {{
outerMux := http.NewServeMux()
outerMux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Server", VERSION)
innerMux.ServeHTTP(w, r)
})
// }}
// Listen and serve
bindAddr := fmt.Sprintf("%s:%d", this.cfg.Web.BindTo, this.cfg.Web.Port)
log.Printf("Serving at %s...", bindAddr)
log.Fatal(http.ListenAndServe(bindAddr, nil))
log.Fatal(http.ListenAndServe(bindAddr, outerMux))
}
func main() {
log.Println(VERSION)
a, err := NewApp("nmdc-webfrontend.conf")
if err != nil {
log.Fatal(err.Error())

View File

@@ -1,21 +1,20 @@
{
"app": {
"motd" : "Welcome!<br>"
"motd": "Welcome!<br>"
},
"web": {
"port" : 8082,
"port": 8082,
"bind_to": "127.0.0.1",
"extern" : "http://127.0.0.1:8082",
"title" : "DCWebUI",
"title": "NMDC Web Frontend",
"custom_favicon": false
},
"hub": {
"address": "127.0.0.1",
"port" : 411,
"tag" : "nmdc-webfrontend"
"port": 411,
"tag": "nmdc-webfrontend"
}
}