version 0.2.1, better browser open, site size limit, save number of peers to sites.json to faster warmup, silent wsgihandler error, siteSetLimit API comment, grant ADMIN permissions to wrapper, display site changetime from includes too, loading screen warning support

This commit is contained in:
HelloZeroNet 2015-02-14 14:05:00 +01:00
parent 882577968a
commit fa7164a0f0
14 changed files with 243 additions and 48 deletions

View file

@ -21,7 +21,10 @@ class UiWSGIHandler(WSGIHandler):
self.ws_handler.run_application()
else: # Standard HTTP request
#print self.application.__class__.__name__
return super(UiWSGIHandler, self).run_application()
try:
return super(UiWSGIHandler, self).run_application()
except Exception, err:
logging.debug("UiWSGIHandler error: %s" % err)
class UiServer:
@ -77,5 +80,13 @@ class UiServer:
self.log.info("Web interface: http://%s:%s/" % (config.ui_ip, config.ui_port))
self.log.info("--------------------------------------")
if config.open_browser:
logging.info("Opening browser: %s...", config.open_browser)
import webbrowser
if config.open_browser == "default_browser":
browser = webbrowser.get()
else:
browser = webbrowser.get(config.open_browser)
browser.open("http://%s:%s" % (config.ui_ip, config.ui_port), new=2)
WSGIServer((self.ip, self.port), handler, handler_class=UiWSGIHandler, log=self.log).serve_forever()

View file

@ -84,6 +84,9 @@ class UiWebsocket:
cmd = req.get("cmd")
params = req.get("params")
permissions = self.site.settings["permissions"]
if req["id"] >= 1000000: # Its a wrapper command, allow admin commands
permissions = permissions[:]
permissions.append("ADMIN")
if cmd == "response": # It's a response to a command
return self.actionResponse(req["to"], req["result"])
@ -114,6 +117,8 @@ class UiWebsocket:
func = self.actionSiteDelete
elif cmd == "siteList" and "ADMIN" in permissions:
func = self.actionSiteList
elif cmd == "siteSetLimit" and "ADMIN" in permissions:
func = self.actionSiteSetLimit
elif cmd == "channelJoinAllsite" and "ADMIN" in permissions:
func = self.actionChannelJoinAllsite
# Unknown command
@ -155,16 +160,21 @@ class UiWebsocket:
if "sign" in content: del(content["sign"])
if "signs" in content: del(content["signs"])
settings = site.settings.copy()
del settings["wrapper_key"] # Dont expose wrapper key
ret = {
"auth_key": self.site.settings["auth_key"], # Obsolete, will be removed
"auth_key_sha512": hashlib.sha512(self.site.settings["auth_key"]).hexdigest()[0:64], # Obsolete, will be removed
"auth_address": self.user.getAuthAddress(site.address),
"address": site.address,
"settings": site.settings,
"settings": settings,
"content_updated": site.content_updated,
"bad_files": len(site.bad_files),
"size_limit": site.getSizeLimit(),
"next_size_limit": site.getNextSizeLimit(),
"last_downloads": len(site.last_downloads),
"peers": len(site.peers),
"peers": site.settings["peers"],
"tasks": len([task["inner_path"] for task in site.worker_manager.tasks]),
"content": content
}
@ -344,3 +354,10 @@ class UiWebsocket:
site.updateWebsocket()
else:
self.response(to, {"error": "Unknown site: %s" % address})
def actionSiteSetLimit(self, to, size_limit):
self.site.settings["size_limit"] = size_limit
self.site.saveSettings()
self.response(to, "Site size limit changed to %sMB" % size_limit)
self.site.download()

View file

@ -34,7 +34,10 @@ class Loading
if not @screen_visible then return false
$(".loadingscreen .console .cursor").remove() # Remove previous cursor
if type == "error" then text = "<span class='console-error'>#{text}</span>" else text = text+"<span class='cursor'> </span>"
$(".loadingscreen .console").append("<div class='console-line'>#{text}</div>")
line = $("<div class='console-line'>#{text}</div>").appendTo(".loadingscreen .console")
if type == "warning" then line.addClass("console-warning")
return line

View file

@ -70,23 +70,28 @@ class Wrapper
else if cmd == "wrapperSetViewport" # Set the viewport
@actionSetViewport(message)
else # Send to websocket
@ws.send(message) # Pass message to websocket
if message.id < 1000000
@ws.send(message) # Pass message to websocket
else
@log "Invalid inner message id"
# - Actions -
actionWrapperConfirm: (message) ->
actionWrapperConfirm: (message, cb=false) ->
message.params = @toHtmlSafe(message.params) # Escape html
if message.params[1] then caption = message.params[1] else caption = "ok"
body = $("<span>"+message.params[0]+"</span>")
button = $("<a href='##{caption}' class='button button-#{caption}'>#{caption}</a>") # Add confirm button
button.on "click", => # Response on button click
@wrapperConfirm message.params[0], caption, =>
@sendInner {"cmd": "response", "to": message.id, "result": "boom"} # Response to confirm
return false
wrapperConfirm: (message, caption, cb) ->
body = $("<span>"+message+"</span>")
button = $("<a href='##{caption}' class='button button-#{caption}'>#{caption}</a>") # Add confirm button
button.on "click", cb
body.append(button)
@notifications.add("notification-#{message.id}", "ask", body)
@notifications.add("notification-#{caption}", "ask", body)
@ -151,7 +156,7 @@ class Wrapper
@ws_error = @notifications.add("connection", "error", "UiServer Websocket error, please reload the page.")
else if not @ws_error
@ws_error = @notifications.add("connection", "error", "Connection with <b>UiServer Websocket</b> was lost. Reconnecting...")
), 500
), 1000
# Iframe loaded
@ -163,7 +168,7 @@ class Wrapper
if window.location.hash then $("#inner-iframe")[0].src += window.location.hash # Hash tag
if @ws.ws.readyState == 1 and not @site_info # Ws opened
@reloadSiteInfo()
else if @site_info
else if @site_info and @site_info.content?.title?
window.document.title = @site_info.content.title+" - ZeroNet"
@log "Setting title to", window.document.title
@ -198,7 +203,18 @@ class Wrapper
# File failed downloading
else if site_info.event[0] == "file_failed"
@site_error = site_info.event[1]
@loading.printLine("#{site_info.event[1]} download failed", "error")
if site_info.settings.size > site_info.size_limit*1024*1024 # Site size too large and not displaying it yet
if $(".console .button-setlimit").length == 0 # Not displaying it yet
line = @loading.printLine("Site size: <b>#{parseInt(site_info.settings.size/1024/1024)}MB</b> is larger than default allowed #{parseInt(site_info.size_limit)}MB", "warning")
button = $("<a href='#Set+limit' class='button button-setlimit'>Open site and set size limit to #{site_info.next_size_limit}MB</a>")
button.on "click", (=> return @setSizeLimit(site_info.next_size_limit) )
line.after(button)
setTimeout (=>
@loading.printLine('Ready.')
), 100
else
@loading.printLine("#{site_info.event[1]} download failed", "error")
# New peers found
else if site_info.event[0] == "peers_added"
@loading.printLine("Peers found: #{site_info.peers}")
@ -209,6 +225,13 @@ class Wrapper
else
@site_error = "No peers found"
@loading.printLine "No peers found"
if not @site_info and $("#inner-iframe").attr("src").indexOf("?") == -1 # First site info and mainpage
if site_info.size_limit < site_info.next_size_limit # Need upgrade soon
@wrapperConfirm "Running out of size limit (#{(site_info.settings.size/1024/1024).toFixed(1)}MB/#{site_info.size_limit}MB)", "Set limit to #{site_info.next_size_limit}MB", =>
@ws.cmd "siteSetLimit", [site_info.next_size_limit], (res) =>
@notifications.add("size_limit", "done", res, 5000)
return false
@site_info = site_info
@ -221,6 +244,14 @@ class Wrapper
return values
setSizeLimit: (size_limit, reload=true) =>
@ws.cmd "siteSetLimit", [size_limit], (res) =>
@loading.printLine res
if reload
$("iframe").attr "src", $("iframe").attr("src") # Reload iframe
return false
log: (args...) ->
console.log "[Wrapper]", args...

View file

@ -14,6 +14,7 @@ a { color: black }
.button-Delete { background-color: #e74c3c; border-bottom-color: #c0392b; color: white }
.button-Delete:hover { background-color: #FF5442; border-bottom-color: #8E2B21 }
/* Fixbutton */
.fixbutton {
@ -76,6 +77,9 @@ a { color: black }
display: inline-block; width: 9px; height: 19px; vertical-align: -4px;
}
.console .console-error { color: #e74c3c; font-weight: bold; animation: pulse 2s infinite linear }
.console .console-warning { color: #8e44ad; }
.console .button { margin: 20px; display: inline-block; text-transform: none; padding: 10px 20px }
/* Flipper loading anim */
.flipper-container { width: 40px; height: 40px; position: absolute; top: 0%; left: 50%; transform: translate3d(-50%, -50%, 0); perspective: 1200; opacity: 0 }

View file

@ -19,6 +19,7 @@ a { color: black }
.button-Delete { background-color: #e74c3c; border-bottom-color: #c0392b; color: white }
.button-Delete:hover { background-color: #FF5442; border-bottom-color: #8E2B21 }
/* Fixbutton */
.fixbutton {
@ -81,6 +82,9 @@ a { color: black }
display: inline-block; width: 9px; height: 19px; vertical-align: -4px;
}
.console .console-error { color: #e74c3c; font-weight: bold; -webkit-animation: pulse 2s infinite linear ; -moz-animation: pulse 2s infinite linear ; -o-animation: pulse 2s infinite linear ; -ms-animation: pulse 2s infinite linear ; animation: pulse 2s infinite linear }
.console .console-warning { color: #8e44ad; }
.console .button { margin: 20px; display: inline-block; text-transform: none; padding: 10px 20px }
/* Flipper loading anim */
.flipper-container { width: 40px; height: 40px; position: absolute; top: 0%; left: 50%; -webkit-transform: translate3d(-50%, -50%, 0); -moz-transform: translate3d(-50%, -50%, 0); -o-transform: translate3d(-50%, -50%, 0); -ms-transform: translate3d(-50%, -50%, 0); transform: translate3d(-50%, -50%, 0) ; -webkit-perspective: 1200; -moz-perspective: 1200; -o-perspective: 1200; -ms-perspective: 1200; perspective: 1200 ; opacity: 0 }

View file

@ -502,6 +502,7 @@ jQuery.extend( jQuery.easing,
};
Loading.prototype.printLine = function(text, type) {
var line;
if (type == null) {
type = "normal";
}
@ -514,7 +515,11 @@ jQuery.extend( jQuery.easing,
} else {
text = text + "<span class='cursor'> </span>";
}
return $(".loadingscreen .console").append("<div class='console-line'>" + text + "</div>");
line = $("<div class='console-line'>" + text + "</div>").appendTo(".loadingscreen .console");
if (type === "warning") {
line.addClass("console-warning");
}
return line;
};
return Loading;
@ -720,6 +725,7 @@ jQuery.extend( jQuery.easing,
Wrapper = (function() {
function Wrapper(ws_url) {
this.setSizeLimit = __bind(this.setSizeLimit, this);
this.onLoad = __bind(this.onLoad, this);
this.onCloseWebsocket = __bind(this.onCloseWebsocket, this);
this.onOpenWebsocket = __bind(this.onOpenWebsocket, this);
@ -802,21 +808,26 @@ jQuery.extend( jQuery.easing,
} else if (cmd === "wrapperSetViewport") {
return this.actionSetViewport(message);
} else {
return this.ws.send(message);
if (message.id < 1000000) {
return this.ws.send(message);
} else {
return this.log("Invalid inner message id");
}
}
};
Wrapper.prototype.actionWrapperConfirm = function(message) {
var body, button, caption;
Wrapper.prototype.actionWrapperConfirm = function(message, cb) {
var caption;
if (cb == null) {
cb = false;
}
message.params = this.toHtmlSafe(message.params);
if (message.params[1]) {
caption = message.params[1];
} else {
caption = "ok";
}
body = $("<span>" + message.params[0] + "</span>");
button = $("<a href='#" + caption + "' class='button button-" + caption + "'>" + caption + "</a>");
button.on("click", (function(_this) {
return this.wrapperConfirm(message.params[0], caption, (function(_this) {
return function() {
_this.sendInner({
"cmd": "response",
@ -826,8 +837,15 @@ jQuery.extend( jQuery.easing,
return false;
};
})(this));
};
Wrapper.prototype.wrapperConfirm = function(message, caption, cb) {
var body, button;
body = $("<span>" + message + "</span>");
button = $("<a href='#" + caption + "' class='button button-" + caption + "'>" + caption + "</a>");
button.on("click", cb);
body.append(button);
return this.notifications.add("notification-" + message.id, "ask", body);
return this.notifications.add("notification-" + caption, "ask", body);
};
Wrapper.prototype.actionWrapperPrompt = function(message) {
@ -913,10 +931,11 @@ jQuery.extend( jQuery.easing,
return _this.ws_error = _this.notifications.add("connection", "error", "Connection with <b>UiServer Websocket</b> was lost. Reconnecting...");
}
};
})(this)), 500);
})(this)), 1000);
};
Wrapper.prototype.onLoad = function(e) {
var _ref;
this.log("onLoad");
this.inner_loaded = true;
if (!this.inner_ready) {
@ -932,7 +951,7 @@ jQuery.extend( jQuery.easing,
}
if (this.ws.ws.readyState === 1 && !this.site_info) {
return this.reloadSiteInfo();
} else if (this.site_info) {
} else if (this.site_info && (((_ref = this.site_info.content) != null ? _ref.title : void 0) != null)) {
window.document.title = this.site_info.content.title + " - ZeroNet";
return this.log("Setting title to", window.document.title);
}
@ -953,6 +972,7 @@ jQuery.extend( jQuery.easing,
};
Wrapper.prototype.setSiteInfo = function(site_info) {
var button, line;
if (site_info.event != null) {
if (site_info.event[0] === "file_added" && site_info.bad_files) {
this.loading.printLine(site_info.bad_files + " files needs to be downloaded");
@ -969,7 +989,25 @@ jQuery.extend( jQuery.easing,
}
} else if (site_info.event[0] === "file_failed") {
this.site_error = site_info.event[1];
this.loading.printLine(site_info.event[1] + " download failed", "error");
if (site_info.settings.size > site_info.size_limit * 1024 * 1024) {
if ($(".console .button-setlimit").length === 0) {
line = this.loading.printLine("Site size: <b>" + (parseInt(site_info.settings.size / 1024 / 1024)) + "MB</b> is larger than default allowed " + (parseInt(site_info.size_limit)) + "MB", "warning");
button = $("<a href='#Set+limit' class='button button-setlimit'>Open site and set size limit to " + site_info.next_size_limit + "MB</a>");
button.on("click", ((function(_this) {
return function() {
return _this.setSizeLimit(site_info.next_size_limit);
};
})(this)));
line.after(button);
setTimeout(((function(_this) {
return function() {
return _this.loading.printLine('Ready.');
};
})(this)), 100);
}
} else {
this.loading.printLine(site_info.event[1] + " download failed", "error");
}
} else if (site_info.event[0] === "peers_added") {
this.loading.printLine("Peers found: " + site_info.peers);
}
@ -982,6 +1020,18 @@ jQuery.extend( jQuery.easing,
this.loading.printLine("No peers found");
}
}
if (!this.site_info && $("#inner-iframe").attr("src").indexOf("?") === -1) {
if (site_info.size_limit < site_info.next_size_limit) {
this.wrapperConfirm("Running out of size limit (" + ((site_info.settings.size / 1024 / 1024).toFixed(1)) + "MB/" + site_info.size_limit + "MB)", "Set limit to " + site_info.next_size_limit + "MB", (function(_this) {
return function() {
_this.ws.cmd("siteSetLimit", [site_info.next_size_limit], function(res) {
return _this.notifications.add("size_limit", "done", res, 5000);
});
return false;
};
})(this));
}
}
return this.site_info = site_info;
};
@ -999,6 +1049,21 @@ jQuery.extend( jQuery.easing,
return values;
};
Wrapper.prototype.setSizeLimit = function(size_limit, reload) {
if (reload == null) {
reload = true;
}
this.ws.cmd("siteSetLimit", [size_limit], (function(_this) {
return function(res) {
_this.loading.printLine(res);
if (reload) {
return $("iframe").attr("src", $("iframe").attr("src"));
}
};
})(this));
return false;
};
Wrapper.prototype.log = function() {
var args;
args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];