2015-07-12 20:36:46 +02:00
|
|
|
import json
|
|
|
|
import time
|
|
|
|
import sys
|
|
|
|
import hashlib
|
Version 0.3.6, Rev879, Fix sidebar error on description missing, New trayicon, New favicon, Disable some functions on MultiUser proxies, New homepage, Replace only the last ? in SQL queries, Alwaays grant ADMIN permission to homepage site, Announce before publish if no peers, configSet, serverShutdown, ADMIN WebsocketAPI command, Stop Tor client before updating, Ignore peer ip packing error, Ignore db files from git, Fix safari ajax error when UiPassword enabled
2016-02-02 11:40:45 +01:00
|
|
|
import os
|
2016-04-09 19:43:44 +02:00
|
|
|
import shutil
|
2016-09-04 18:05:17 +02:00
|
|
|
import re
|
2015-07-12 20:36:46 +02:00
|
|
|
|
|
|
|
import gevent
|
|
|
|
|
2015-01-12 02:03:45 +01:00
|
|
|
from Config import config
|
|
|
|
from Site import SiteManager
|
2015-01-17 18:50:56 +01:00
|
|
|
from Debug import Debug
|
2015-04-24 02:36:00 +02:00
|
|
|
from util import QueryJson, RateLimit
|
version 0.2.7, plugin system, multiuser plugin for zeroproxies, reworked imports, cookie parse, stats moved to plugin, usermanager class, dont generate site auth on listing, multiline notifications, allow server side prompt from user, update script keep plugins disabled status
2015-03-24 01:33:09 +01:00
|
|
|
from Plugin import PluginManager
|
2016-11-18 20:09:51 +01:00
|
|
|
from Translate import translate as _
|
version 0.2.0, new lib for bitcoin ecc, dont display or track notify errors, dont reload again within 1 sec, null peer ip fix, signingmoved to ContentManager, content.json include support, content.json multisig ready, content.json proper bitcoincore compatible signing, content.json include permissions, multithreaded publish, publish timeout 60s, no exception on invalid bitcoin address, testcase for new lib, bip32 based persite privatekey generation, multiuser ready, simple json database query command, websocket api fileGet, wrapper loading title stuck bugfix
2015-02-09 02:09:02 +01:00
|
|
|
|
2015-07-12 20:36:46 +02:00
|
|
|
|
version 0.2.7, plugin system, multiuser plugin for zeroproxies, reworked imports, cookie parse, stats moved to plugin, usermanager class, dont generate site auth on listing, multiline notifications, allow server side prompt from user, update script keep plugins disabled status
2015-03-24 01:33:09 +01:00
|
|
|
@PluginManager.acceptPlugins
|
|
|
|
class UiWebsocket(object):
|
2015-02-20 01:37:12 +01:00
|
|
|
|
2015-07-17 00:28:43 +02:00
|
|
|
def __init__(self, ws, site, server, user, request):
|
2015-07-12 20:36:46 +02:00
|
|
|
self.ws = ws
|
|
|
|
self.site = site
|
|
|
|
self.user = user
|
|
|
|
self.log = site.log
|
2015-07-17 00:28:43 +02:00
|
|
|
self.request = request
|
Version 0.3.6, Rev879, Fix sidebar error on description missing, New trayicon, New favicon, Disable some functions on MultiUser proxies, New homepage, Replace only the last ? in SQL queries, Alwaays grant ADMIN permission to homepage site, Announce before publish if no peers, configSet, serverShutdown, ADMIN WebsocketAPI command, Stop Tor client before updating, Ignore peer ip packing error, Ignore db files from git, Fix safari ajax error when UiPassword enabled
2016-02-02 11:40:45 +01:00
|
|
|
self.permissions = []
|
2015-07-12 20:36:46 +02:00
|
|
|
self.server = server
|
|
|
|
self.next_message_id = 1
|
|
|
|
self.waiting_cb = {} # Waiting for callback. Key: message_id, Value: function pointer
|
|
|
|
self.channels = [] # Channels joined to
|
|
|
|
self.sending = False # Currently sending to client
|
|
|
|
self.send_queue = [] # Messages to send to client
|
2017-01-22 11:08:41 +01:00
|
|
|
self.admin_commands = (
|
|
|
|
"sitePause", "siteResume", "siteDelete", "siteList", "siteSetLimit", "siteClone",
|
2017-07-27 16:29:39 +02:00
|
|
|
"channelJoinAllsite", "serverUpdate", "serverPortcheck", "serverShutdown", "serverShowdirectory",
|
|
|
|
"certSet", "configSet", "permissionAdd", "permissionRemove"
|
2017-01-22 11:08:41 +01:00
|
|
|
)
|
2017-02-25 05:47:38 +01:00
|
|
|
self.async_commands = ("fileGet", "fileList", "dirList")
|
2015-07-12 20:36:46 +02:00
|
|
|
|
|
|
|
# Start listener loop
|
|
|
|
def start(self):
|
|
|
|
ws = self.ws
|
|
|
|
if self.site.address == config.homepage and not self.site.page_requested:
|
|
|
|
# Add open fileserver port message or closed port error to homepage at first request after start
|
Version 0.3.5, Rev830, Full Tor mode support with hidden services, Onion stats in Sidebar, GeoDB download fix using Tor, Gray out disabled sites in Stats page, Tor hidden service status in stat page, Benchmark sha256, Skyts tracker out expodie in, 2 new tracker using ZeroNet protocol, Keep SSL cert option between restarts, SSL Certificate pinning support for connections, Site lock support for connections, Certificate pinned connections using implicit SSL, Flood protection whitelist support, Foreign keys support for DB layer, Not support for SQL query helper, 0 length file get bugfix, Pex onion address support, Faster port testing, Faster uPnP port opening, Need connections more often on owned sites, Delay ZeroHello startup message if port check or Tor manager not ready yet, Use lockfiles to avoid double start, Save original socket on proxy monkey patching to get ability to connect localhost directly, Handle atomic write errors, Broken gevent https workaround helper, Rsa crypt functions, Plugin to Bootstrap using ZeroNet protocol
2016-01-05 00:20:52 +01:00
|
|
|
self.site.page_requested = True # Dont add connection notification anymore
|
|
|
|
file_server = sys.modules["main"].file_server
|
|
|
|
if file_server.port_opened is None or file_server.tor_manager.start_onions is None:
|
|
|
|
self.site.page_requested = False # Not ready yet, check next time
|
|
|
|
else:
|
2017-05-22 11:13:45 +02:00
|
|
|
try:
|
|
|
|
self.addHomepageNotifications()
|
|
|
|
except Exception, err:
|
|
|
|
self.log.error("Uncaught Exception: " + Debug.formatException(err))
|
Version 0.3.5, Rev830, Full Tor mode support with hidden services, Onion stats in Sidebar, GeoDB download fix using Tor, Gray out disabled sites in Stats page, Tor hidden service status in stat page, Benchmark sha256, Skyts tracker out expodie in, 2 new tracker using ZeroNet protocol, Keep SSL cert option between restarts, SSL Certificate pinning support for connections, Site lock support for connections, Certificate pinned connections using implicit SSL, Flood protection whitelist support, Foreign keys support for DB layer, Not support for SQL query helper, 0 length file get bugfix, Pex onion address support, Faster port testing, Faster uPnP port opening, Need connections more often on owned sites, Delay ZeroHello startup message if port check or Tor manager not ready yet, Use lockfiles to avoid double start, Save original socket on proxy monkey patching to get ability to connect localhost directly, Handle atomic write errors, Broken gevent https workaround helper, Rsa crypt functions, Plugin to Bootstrap using ZeroNet protocol
2016-01-05 00:20:52 +01:00
|
|
|
|
2015-07-12 20:36:46 +02:00
|
|
|
for notification in self.site.notifications: # Send pending notification messages
|
2017-05-22 11:13:45 +02:00
|
|
|
# send via WebSocket
|
2015-07-12 20:36:46 +02:00
|
|
|
self.cmd("notification", notification)
|
2017-05-22 11:13:45 +02:00
|
|
|
# just in case, log them to terminal
|
|
|
|
if notification[0] == "error":
|
|
|
|
self.log.error("\n*** %s\n" % self.dedent(notification[1]))
|
|
|
|
|
2015-07-12 20:36:46 +02:00
|
|
|
self.site.notifications = []
|
2017-05-22 11:13:45 +02:00
|
|
|
|
2015-07-12 20:36:46 +02:00
|
|
|
while True:
|
|
|
|
try:
|
2017-05-22 11:34:16 +02:00
|
|
|
if ws.closed:
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
message = ws.receive()
|
2015-07-12 20:36:46 +02:00
|
|
|
except Exception, err:
|
2017-05-22 11:34:16 +02:00
|
|
|
self.log.error("WebSocket receive error: %s" % Debug.formatException(err))
|
|
|
|
break
|
2015-08-16 11:51:00 +02:00
|
|
|
|
|
|
|
if message:
|
|
|
|
try:
|
|
|
|
self.handleRequest(message)
|
|
|
|
except Exception, err:
|
2015-07-12 20:36:46 +02:00
|
|
|
if config.debug: # Allow websocket errors to appear on /Debug
|
|
|
|
sys.modules["main"].DebugHook.handleError()
|
2017-04-21 11:26:17 +02:00
|
|
|
self.log.error("WebSocket handleRequest error: %s \n %s" % (Debug.formatException(err), message))
|
2017-05-22 11:13:45 +02:00
|
|
|
if not self.hasPlugin("Multiuser"):
|
|
|
|
self.cmd("error", "Internal error: %s" % Debug.formatException(err, "html"))
|
|
|
|
|
|
|
|
def dedent(self, text):
|
|
|
|
return re.sub("[\\r\\n\\x20\\t]+", " ", text.strip().replace("<br>", " "))
|
|
|
|
|
|
|
|
def addHomepageNotifications(self):
|
|
|
|
if not(self.hasPlugin("Multiuser")) and not(self.hasPlugin("UiPassword")):
|
|
|
|
bind_ip = getattr(config, "ui_ip", "")
|
|
|
|
whitelist = getattr(config, "ui_restrict", [])
|
|
|
|
# binds to the Internet, no IP whitelist, no UiPassword, no Multiuser
|
|
|
|
if ("0.0.0.0" == bind_ip or "*" == bind_ip) and (not whitelist):
|
|
|
|
self.site.notifications.append([
|
|
|
|
"error",
|
|
|
|
_(u"You are not going to set up a public gateway. However, <b>your Web UI is<br>" + \
|
|
|
|
"open to the whole Internet.</b> " + \
|
|
|
|
"Please check your configuration.")
|
|
|
|
])
|
|
|
|
|
|
|
|
file_server = sys.modules["main"].file_server
|
|
|
|
if file_server.port_opened is True:
|
|
|
|
self.site.notifications.append([
|
|
|
|
"done",
|
|
|
|
_["Congratulation, your port <b>{0}</b> is opened.<br>You are full member of ZeroNet network!"].format(config.fileserver_port),
|
|
|
|
10000
|
|
|
|
])
|
|
|
|
elif config.tor == "always" and file_server.tor_manager.start_onions:
|
|
|
|
self.site.notifications.append([
|
|
|
|
"done",
|
|
|
|
_(u"""
|
|
|
|
{_[Tor mode active, every connection using Onion route.]}<br>
|
|
|
|
{_[Successfully started Tor onion hidden services.]}
|
|
|
|
"""),
|
|
|
|
10000
|
|
|
|
])
|
|
|
|
elif config.tor == "always" and file_server.tor_manager.start_onions is not False:
|
|
|
|
self.site.notifications.append([
|
|
|
|
"error",
|
|
|
|
_(u"""
|
|
|
|
{_[Tor mode active, every connection using Onion route.]}<br>
|
|
|
|
{_[Unable to start hidden services, please check your config.]}
|
|
|
|
"""),
|
|
|
|
0
|
|
|
|
])
|
|
|
|
elif file_server.port_opened is False and file_server.tor_manager.start_onions:
|
|
|
|
self.site.notifications.append([
|
|
|
|
"done",
|
|
|
|
_(u"""
|
|
|
|
{_[Successfully started Tor onion hidden services.]}<br>
|
|
|
|
{_[For faster connections open <b>{0}</b> port on your router.]}
|
|
|
|
""").format(config.fileserver_port),
|
|
|
|
10000
|
|
|
|
])
|
|
|
|
else:
|
|
|
|
self.site.notifications.append([
|
|
|
|
"error",
|
|
|
|
_(u"""
|
|
|
|
{_[Your connection is restricted. Please, open <b>{0}</b> port on your router]}<br>
|
|
|
|
{_[or configure Tor to become full member of ZeroNet network.]}
|
|
|
|
""").format(config.fileserver_port),
|
|
|
|
0
|
|
|
|
])
|
|
|
|
|
|
|
|
def hasPlugin(self, name):
|
|
|
|
return name in PluginManager.plugin_manager.plugin_names
|
2015-07-12 20:36:46 +02:00
|
|
|
|
2017-02-11 18:20:46 +01:00
|
|
|
# Has permission to run the command
|
|
|
|
def hasCmdPermission(self, cmd):
|
|
|
|
cmd = cmd[0].lower() + cmd[1:]
|
|
|
|
|
|
|
|
if cmd in self.admin_commands and "ADMIN" not in self.permissions:
|
|
|
|
return False
|
|
|
|
else:
|
|
|
|
return True
|
|
|
|
|
|
|
|
# Has permission to access a site
|
2016-11-07 22:55:09 +01:00
|
|
|
def hasSitePermission(self, address):
|
|
|
|
if address != self.site.address and "ADMIN" not in self.site.settings["permissions"]:
|
|
|
|
return False
|
|
|
|
else:
|
|
|
|
return True
|
|
|
|
|
2015-07-12 20:36:46 +02:00
|
|
|
# Event in a channel
|
|
|
|
def event(self, channel, *params):
|
|
|
|
if channel in self.channels: # We are joined to channel
|
|
|
|
if channel == "siteChanged":
|
|
|
|
site = params[0] # Triggerer site
|
|
|
|
site_info = self.formatSiteInfo(site)
|
|
|
|
if len(params) > 1 and params[1]: # Extra data
|
|
|
|
site_info.update(params[1])
|
|
|
|
self.cmd("setSiteInfo", site_info)
|
|
|
|
|
|
|
|
# Send response to client (to = message.id)
|
|
|
|
def response(self, to, result):
|
|
|
|
self.send({"cmd": "response", "to": to, "result": result})
|
|
|
|
|
|
|
|
# Send a command
|
|
|
|
def cmd(self, cmd, params={}, cb=None):
|
|
|
|
self.send({"cmd": cmd, "params": params}, cb)
|
|
|
|
|
|
|
|
# Encode to json and send message
|
|
|
|
def send(self, message, cb=None):
|
|
|
|
message["id"] = self.next_message_id # Add message id to allow response
|
|
|
|
self.next_message_id += 1
|
2016-04-09 19:49:23 +02:00
|
|
|
if cb: # Callback after client responded
|
2015-07-12 20:36:46 +02:00
|
|
|
self.waiting_cb[message["id"]] = cb
|
|
|
|
if self.sending:
|
|
|
|
return # Already sending
|
|
|
|
self.send_queue.append(message)
|
|
|
|
try:
|
|
|
|
while self.send_queue:
|
|
|
|
self.sending = True
|
|
|
|
message = self.send_queue.pop(0)
|
|
|
|
self.ws.send(json.dumps(message))
|
|
|
|
self.sending = False
|
|
|
|
except Exception, err:
|
|
|
|
self.log.debug("Websocket send error: %s" % Debug.formatException(err))
|
|
|
|
|
2015-07-17 00:28:43 +02:00
|
|
|
def getPermissions(self, req_id):
|
|
|
|
permissions = self.site.settings["permissions"]
|
|
|
|
if req_id >= 1000000: # Its a wrapper command, allow admin commands
|
|
|
|
permissions = permissions[:]
|
|
|
|
permissions.append("ADMIN")
|
|
|
|
return permissions
|
|
|
|
|
2017-01-22 11:09:26 +01:00
|
|
|
def asyncWrapper(self, func):
|
2017-02-09 01:53:02 +01:00
|
|
|
def asyncErrorWatcher(func, *args, **kwargs):
|
|
|
|
try:
|
|
|
|
func(*args, **kwargs)
|
|
|
|
except Exception, err:
|
|
|
|
if config.debug: # Allow websocket errors to appear on /Debug
|
|
|
|
sys.modules["main"].DebugHook.handleError()
|
|
|
|
self.log.error("WebSocket handleRequest error: %s" % Debug.formatException(err))
|
|
|
|
self.cmd("error", "Internal error: %s" % Debug.formatException(err, "html"))
|
|
|
|
|
2017-01-22 11:09:26 +01:00
|
|
|
def wrapper(*args, **kwargs):
|
2017-02-09 01:53:02 +01:00
|
|
|
gevent.spawn(asyncErrorWatcher, func, *args, **kwargs)
|
2017-01-22 11:09:26 +01:00
|
|
|
return wrapper
|
|
|
|
|
2015-07-12 20:36:46 +02:00
|
|
|
# Handle incoming messages
|
|
|
|
def handleRequest(self, data):
|
|
|
|
req = json.loads(data)
|
|
|
|
|
|
|
|
cmd = req.get("cmd")
|
|
|
|
params = req.get("params")
|
Version 0.3.6, Rev879, Fix sidebar error on description missing, New trayicon, New favicon, Disable some functions on MultiUser proxies, New homepage, Replace only the last ? in SQL queries, Alwaays grant ADMIN permission to homepage site, Announce before publish if no peers, configSet, serverShutdown, ADMIN WebsocketAPI command, Stop Tor client before updating, Ignore peer ip packing error, Ignore db files from git, Fix safari ajax error when UiPassword enabled
2016-02-02 11:40:45 +01:00
|
|
|
self.permissions = self.getPermissions(req["id"])
|
2015-07-12 20:36:46 +02:00
|
|
|
|
|
|
|
if cmd == "response": # It's a response to a command
|
|
|
|
return self.actionResponse(req["to"], req["result"])
|
2017-02-11 18:20:46 +01:00
|
|
|
elif not self.hasCmdPermission(cmd): # Admin commands
|
2016-12-08 17:14:30 +01:00
|
|
|
return self.response(req["id"], {"error": "You don't have permission to run %s" % cmd})
|
2015-07-12 20:36:46 +02:00
|
|
|
else: # Normal command
|
|
|
|
func_name = "action" + cmd[0].upper() + cmd[1:]
|
|
|
|
func = getattr(self, func_name, None)
|
|
|
|
if not func: # Unknown command
|
Version 0.3.4, Rev656, CryptMessage plugin for AES and ECIES encryption, Added pyelliptic lib for OpenSSSL based encryption methods, Test CryptMessage plugin, Force reload content.json before signing and after write, Escaped Sql IN queries support, Test Sql parameter escaping, ui_websocket Test fixture, Plugin testing support, Always return websocket errors as dict, Wait for file on weboscket fileGet command if its already in bad_files queue, PushState and ReplaceState url manipulation support in wrapper API, Per auth-address localstorage, Longer timeout for udp tracker query
2015-12-10 21:36:20 +01:00
|
|
|
self.response(req["id"], {"error": "Unknown command: %s" % cmd})
|
2015-07-12 20:36:46 +02:00
|
|
|
return
|
|
|
|
|
2017-01-22 11:09:26 +01:00
|
|
|
# Execute in parallel
|
|
|
|
if cmd in self.async_commands:
|
|
|
|
func = self.asyncWrapper(func)
|
|
|
|
|
2016-04-09 19:49:23 +02:00
|
|
|
# Support calling as named, unnamed parameters and raw first argument too
|
2015-07-12 20:36:46 +02:00
|
|
|
if type(params) is dict:
|
|
|
|
func(req["id"], **params)
|
|
|
|
elif type(params) is list:
|
|
|
|
func(req["id"], *params)
|
2015-08-16 11:51:00 +02:00
|
|
|
elif params:
|
2015-07-12 20:36:46 +02:00
|
|
|
func(req["id"], params)
|
2015-08-16 11:51:00 +02:00
|
|
|
else:
|
|
|
|
func(req["id"])
|
2015-07-12 20:36:46 +02:00
|
|
|
|
|
|
|
# Format site info
|
|
|
|
def formatSiteInfo(self, site, create_user=True):
|
|
|
|
content = site.content_manager.contents.get("content.json")
|
|
|
|
if content: # Remove unnecessary data transfer
|
|
|
|
content = content.copy()
|
|
|
|
content["files"] = len(content.get("files", {}))
|
Rev571, Optional file sizes to sidebar, Download all optional files option in sidebar, Optional file number in peer stats, Delete removed or changed optional files, Auto download optional files if autodownloadoptional checked, SiteReload command, Peer use global file server if no site defined, Allow browser cache video files, Allow more keepalive connections, Gevent 1.1 ranged request bugfix, Dont sent optional files details on websocket, Remove files from workermanager tasks if no longer in bad_files, Notify local client about changes on external siteSign
2015-11-09 00:44:03 +01:00
|
|
|
content["files_optional"] = len(content.get("files_optional", {}))
|
2015-07-12 20:36:46 +02:00
|
|
|
content["includes"] = len(content.get("includes", {}))
|
|
|
|
if "sign" in content:
|
|
|
|
del(content["sign"])
|
|
|
|
if "signs" in content:
|
|
|
|
del(content["signs"])
|
|
|
|
if "signers_sign" in content:
|
|
|
|
del(content["signers_sign"])
|
|
|
|
|
|
|
|
settings = site.settings.copy()
|
|
|
|
del settings["wrapper_key"] # Dont expose wrapper key
|
|
|
|
del settings["auth_key"] # Dont send auth key twice
|
|
|
|
|
|
|
|
ret = {
|
|
|
|
"auth_key": self.site.settings["auth_key"], # Obsolete, will be removed
|
|
|
|
"auth_address": self.user.getAuthAddress(site.address, create=create_user),
|
|
|
|
"cert_user_id": self.user.getCertUserId(site.address),
|
|
|
|
"address": site.address,
|
|
|
|
"settings": settings,
|
|
|
|
"content_updated": site.content_updated,
|
|
|
|
"bad_files": len(site.bad_files),
|
|
|
|
"size_limit": site.getSizeLimit(),
|
|
|
|
"next_size_limit": site.getNextSizeLimit(),
|
2015-08-16 11:51:00 +02:00
|
|
|
"peers": max(site.settings.get("peers", 0), len(site.peers)),
|
2015-07-12 20:36:46 +02:00
|
|
|
"started_task_num": site.worker_manager.started_task_num,
|
|
|
|
"tasks": len(site.worker_manager.tasks),
|
|
|
|
"workers": len(site.worker_manager.workers),
|
|
|
|
"content": content
|
|
|
|
}
|
|
|
|
if site.settings["own"]:
|
|
|
|
ret["privatekey"] = bool(self.user.getSiteData(site.address, create=create_user).get("privatekey"))
|
|
|
|
if site.settings["serving"] and content:
|
|
|
|
ret["peers"] += 1 # Add myself if serving
|
|
|
|
return ret
|
|
|
|
|
|
|
|
def formatServerInfo(self):
|
|
|
|
return {
|
Rev900, Sidebar filestats bar width round fix, Sidebar WebGL not supported error, Sidebar optimalizations, Trayicon gray shadow, Trim end of line whitespace from json files, Fix testweb testcase, Implement experimental postMessage nonce security, Return None when testing external ip, Window opener security check and message, Increase timeout for large files
2016-02-10 02:30:04 +01:00
|
|
|
"ip_external": sys.modules["main"].file_server.port_opened,
|
2015-07-12 20:36:46 +02:00
|
|
|
"platform": sys.platform,
|
|
|
|
"fileserver_ip": config.fileserver_ip,
|
|
|
|
"fileserver_port": config.fileserver_port,
|
Version 0.3.5, Rev830, Full Tor mode support with hidden services, Onion stats in Sidebar, GeoDB download fix using Tor, Gray out disabled sites in Stats page, Tor hidden service status in stat page, Benchmark sha256, Skyts tracker out expodie in, 2 new tracker using ZeroNet protocol, Keep SSL cert option between restarts, SSL Certificate pinning support for connections, Site lock support for connections, Certificate pinned connections using implicit SSL, Flood protection whitelist support, Foreign keys support for DB layer, Not support for SQL query helper, 0 length file get bugfix, Pex onion address support, Faster port testing, Faster uPnP port opening, Need connections more often on owned sites, Delay ZeroHello startup message if port check or Tor manager not ready yet, Use lockfiles to avoid double start, Save original socket on proxy monkey patching to get ability to connect localhost directly, Handle atomic write errors, Broken gevent https workaround helper, Rsa crypt functions, Plugin to Bootstrap using ZeroNet protocol
2016-01-05 00:20:52 +01:00
|
|
|
"tor_enabled": sys.modules["main"].file_server.tor_manager.enabled,
|
|
|
|
"tor_status": sys.modules["main"].file_server.tor_manager.status,
|
2015-07-12 20:36:46 +02:00
|
|
|
"ui_ip": config.ui_ip,
|
|
|
|
"ui_port": config.ui_port,
|
|
|
|
"version": config.version,
|
|
|
|
"rev": config.rev,
|
2016-11-18 20:11:11 +01:00
|
|
|
"language": config.language,
|
2015-07-12 20:36:46 +02:00
|
|
|
"debug": config.debug,
|
|
|
|
"plugins": PluginManager.plugin_manager.plugin_names
|
|
|
|
}
|
|
|
|
|
|
|
|
# - Actions -
|
|
|
|
|
|
|
|
# Do callback on response {"cmd": "response", "to": message_id, "result": result}
|
|
|
|
def actionResponse(self, to, result):
|
|
|
|
if to in self.waiting_cb:
|
|
|
|
self.waiting_cb[to](result) # Call callback function
|
|
|
|
else:
|
|
|
|
self.log.error("Websocket callback not found: %s, %s" % (to, result))
|
|
|
|
|
|
|
|
# Send a simple pong answer
|
|
|
|
def actionPing(self, to):
|
|
|
|
self.response(to, "pong")
|
|
|
|
|
|
|
|
# Send site details
|
|
|
|
def actionSiteInfo(self, to, file_status=None):
|
|
|
|
ret = self.formatSiteInfo(self.site)
|
|
|
|
if file_status: # Client queries file status
|
2016-04-09 19:49:23 +02:00
|
|
|
if self.site.storage.isFile(file_status): # File exist, add event done
|
2015-07-12 20:36:46 +02:00
|
|
|
ret["event"] = ("file_done", file_status)
|
|
|
|
self.response(to, ret)
|
|
|
|
|
|
|
|
# Join to an event channel
|
|
|
|
def actionChannelJoin(self, to, channel):
|
|
|
|
if channel not in self.channels:
|
|
|
|
self.channels.append(channel)
|
|
|
|
|
|
|
|
# Server variables
|
|
|
|
def actionServerInfo(self, to):
|
|
|
|
ret = self.formatServerInfo()
|
|
|
|
self.response(to, ret)
|
|
|
|
|
|
|
|
# Sign content.json
|
2017-01-27 12:02:14 +01:00
|
|
|
def actionSiteSign(self, to, privatekey=None, inner_path="content.json", response_ok=True, update_changed_files=False, remove_missing_optional=False):
|
2016-03-18 19:15:38 +01:00
|
|
|
self.log.debug("Signing: %s" % inner_path)
|
2015-07-12 20:36:46 +02:00
|
|
|
site = self.site
|
|
|
|
extend = {} # Extended info for signing
|
2016-08-10 12:21:34 +02:00
|
|
|
|
|
|
|
# Change to the file's content.json
|
|
|
|
file_info = site.content_manager.getFileInfo(inner_path)
|
|
|
|
if not inner_path.endswith("content.json"):
|
|
|
|
if not file_info:
|
|
|
|
raise Exception("Invalid content.json file: %s" % inner_path)
|
2015-07-12 20:36:46 +02:00
|
|
|
inner_path = file_info["content_inner_path"]
|
2016-08-10 12:21:34 +02:00
|
|
|
|
|
|
|
# Add certificate to user files
|
|
|
|
if file_info and "cert_signers" in file_info and privatekey is None:
|
|
|
|
cert = self.user.getCert(self.site.address)
|
|
|
|
extend["cert_auth_type"] = cert["auth_type"]
|
|
|
|
extend["cert_user_id"] = self.user.getCertUserId(site.address)
|
|
|
|
extend["cert_sign"] = cert["cert_sign"]
|
2015-07-12 20:36:46 +02:00
|
|
|
|
|
|
|
if (
|
|
|
|
not site.settings["own"] and
|
|
|
|
self.user.getAuthAddress(self.site.address) not in self.site.content_manager.getValidSigners(inner_path)
|
|
|
|
):
|
2017-03-03 03:42:20 +01:00
|
|
|
self.log.error("SiteSign error: you don't own this site & site owner doesn't allow you to do so.")
|
Version 0.3.4, Rev656, CryptMessage plugin for AES and ECIES encryption, Added pyelliptic lib for OpenSSSL based encryption methods, Test CryptMessage plugin, Force reload content.json before signing and after write, Escaped Sql IN queries support, Test Sql parameter escaping, ui_websocket Test fixture, Plugin testing support, Always return websocket errors as dict, Wait for file on weboscket fileGet command if its already in bad_files queue, PushState and ReplaceState url manipulation support in wrapper API, Per auth-address localstorage, Longer timeout for udp tracker query
2015-12-10 21:36:20 +01:00
|
|
|
return self.response(to, {"error": "Forbidden, you can only modify your own sites"})
|
2017-03-03 03:42:20 +01:00
|
|
|
|
2016-08-10 12:21:34 +02:00
|
|
|
if privatekey == "stored": # Get privatekey from sites.json
|
2015-07-12 20:36:46 +02:00
|
|
|
privatekey = self.user.getSiteData(self.site.address).get("privatekey")
|
|
|
|
if not privatekey: # Get privatekey from users.json auth_address
|
|
|
|
privatekey = self.user.getAuthPrivatekey(self.site.address)
|
|
|
|
|
|
|
|
# Signing
|
2016-05-16 22:26:40 +02:00
|
|
|
# Reload content.json, ignore errors to make it up-to-date
|
|
|
|
site.content_manager.loadContent(inner_path, add_bad_files=False, force=True)
|
|
|
|
# Sign using private key sent by user
|
2017-06-19 16:11:47 +02:00
|
|
|
try:
|
|
|
|
signed = site.content_manager.sign(inner_path, privatekey, extend=extend, update_changed_files=update_changed_files, remove_missing_optional=remove_missing_optional)
|
|
|
|
except Exception, err:
|
|
|
|
self.cmd("notification", ["error", _["Content signing failed"] + "<br><small>%s</small>" % err])
|
|
|
|
self.response(to, {"error": "Site sign failed: %s" % err})
|
2015-07-12 20:36:46 +02:00
|
|
|
return
|
|
|
|
|
2016-03-16 21:08:19 +01:00
|
|
|
site.content_manager.loadContent(inner_path, add_bad_files=False) # Load new content.json, ignore errors
|
2016-04-25 02:26:13 +02:00
|
|
|
|
2016-05-16 22:26:40 +02:00
|
|
|
if update_changed_files:
|
|
|
|
self.site.updateWebsocket(file_done=inner_path)
|
|
|
|
|
Version 0.3.4, Rev656, CryptMessage plugin for AES and ECIES encryption, Added pyelliptic lib for OpenSSSL based encryption methods, Test CryptMessage plugin, Force reload content.json before signing and after write, Escaped Sql IN queries support, Test Sql parameter escaping, ui_websocket Test fixture, Plugin testing support, Always return websocket errors as dict, Wait for file on weboscket fileGet command if its already in bad_files queue, PushState and ReplaceState url manipulation support in wrapper API, Per auth-address localstorage, Longer timeout for udp tracker query
2015-12-10 21:36:20 +01:00
|
|
|
if response_ok:
|
|
|
|
self.response(to, "ok")
|
2015-07-12 20:36:46 +02:00
|
|
|
|
|
|
|
return inner_path
|
|
|
|
|
|
|
|
# Sign and publish content.json
|
|
|
|
def actionSitePublish(self, to, privatekey=None, inner_path="content.json", sign=True):
|
|
|
|
if sign:
|
Version 0.3.4, Rev656, CryptMessage plugin for AES and ECIES encryption, Added pyelliptic lib for OpenSSSL based encryption methods, Test CryptMessage plugin, Force reload content.json before signing and after write, Escaped Sql IN queries support, Test Sql parameter escaping, ui_websocket Test fixture, Plugin testing support, Always return websocket errors as dict, Wait for file on weboscket fileGet command if its already in bad_files queue, PushState and ReplaceState url manipulation support in wrapper API, Per auth-address localstorage, Longer timeout for udp tracker query
2015-12-10 21:36:20 +01:00
|
|
|
inner_path = self.actionSiteSign(to, privatekey, inner_path, response_ok=False)
|
2015-07-12 20:36:46 +02:00
|
|
|
if not inner_path:
|
|
|
|
return
|
|
|
|
# Publishing
|
|
|
|
if not self.site.settings["serving"]: # Enable site if paused
|
|
|
|
self.site.settings["serving"] = True
|
|
|
|
self.site.saveSettings()
|
|
|
|
self.site.announce()
|
|
|
|
|
2017-06-19 15:38:05 +02:00
|
|
|
if not inner_path in self.site.content_manager.contents:
|
|
|
|
return self.response(to, {"error": "File %s not found" % inner_path})
|
|
|
|
|
2015-07-12 20:36:46 +02:00
|
|
|
event_name = "publish %s %s" % (self.site.address, inner_path)
|
2016-03-30 23:15:18 +02:00
|
|
|
called_instantly = RateLimit.isAllowed(event_name, 30)
|
2016-08-10 12:22:27 +02:00
|
|
|
thread = RateLimit.callAsync(event_name, 30, self.doSitePublish, self.site, inner_path) # Only publish once in 30 seconds
|
2015-07-12 20:36:46 +02:00
|
|
|
notification = "linked" not in dir(thread) # Only display notification on first callback
|
|
|
|
thread.linked = True
|
2016-03-30 23:15:18 +02:00
|
|
|
if called_instantly: # Allowed to call instantly
|
|
|
|
# At the end callback with request id and thread
|
2017-01-16 13:41:57 +01:00
|
|
|
self.cmd("progress", ["publish", _["Content published to {0}/{1} peers."].format(0, 5), 0])
|
2016-08-10 12:22:27 +02:00
|
|
|
thread.link(lambda thread: self.cbSitePublish(to, self.site, thread, notification, callback=notification))
|
2016-03-30 23:15:18 +02:00
|
|
|
else:
|
|
|
|
self.cmd(
|
|
|
|
"notification",
|
2016-11-18 20:09:51 +01:00
|
|
|
["info", _["Content publish queued for {0:.0f} seconds."].format(RateLimit.delayLeft(event_name, 30)), 5000]
|
2016-03-30 23:15:18 +02:00
|
|
|
)
|
|
|
|
self.response(to, "ok")
|
|
|
|
# At the end display notification
|
2016-08-10 12:22:27 +02:00
|
|
|
thread.link(lambda thread: self.cbSitePublish(to, self.site, thread, notification, callback=False))
|
2016-03-30 23:15:18 +02:00
|
|
|
|
2016-08-10 12:22:27 +02:00
|
|
|
def doSitePublish(self, site, inner_path):
|
2017-01-16 13:41:57 +01:00
|
|
|
def cbProgress(published, limit):
|
|
|
|
progress = int(float(published) / limit * 100)
|
|
|
|
self.cmd("progress", [
|
|
|
|
"publish",
|
|
|
|
_["Content published to {0}/{1} peers."].format(published, limit),
|
|
|
|
progress
|
|
|
|
])
|
2016-08-10 12:22:27 +02:00
|
|
|
diffs = site.content_manager.getDiffs(inner_path)
|
2017-01-16 13:41:57 +01:00
|
|
|
back = site.publish(limit=5, inner_path=inner_path, diffs=diffs, cb_progress=cbProgress)
|
|
|
|
if back == 0: # Failed to publish to anyone
|
|
|
|
self.cmd("progress", ["publish", _["Content publish failed."], -100])
|
|
|
|
else:
|
|
|
|
cbProgress(back, back)
|
|
|
|
return back
|
2015-07-12 20:36:46 +02:00
|
|
|
|
|
|
|
# Callback of site publish
|
2016-08-10 12:22:27 +02:00
|
|
|
def cbSitePublish(self, to, site, thread, notification=True, callback=True):
|
2015-07-12 20:36:46 +02:00
|
|
|
published = thread.value
|
2016-04-09 19:49:23 +02:00
|
|
|
if published > 0: # Successfully published
|
2015-07-12 20:36:46 +02:00
|
|
|
if notification:
|
2017-01-16 13:41:57 +01:00
|
|
|
# self.cmd("notification", ["done", _["Content published to {0} peers."].format(published), 5000])
|
2015-07-12 20:36:46 +02:00
|
|
|
site.updateWebsocket() # Send updated site data to local websocket clients
|
2016-03-30 23:15:18 +02:00
|
|
|
if callback:
|
|
|
|
self.response(to, "ok")
|
2015-07-12 20:36:46 +02:00
|
|
|
else:
|
|
|
|
if len(site.peers) == 0:
|
Version 0.3.6, Rev879, Fix sidebar error on description missing, New trayicon, New favicon, Disable some functions on MultiUser proxies, New homepage, Replace only the last ? in SQL queries, Alwaays grant ADMIN permission to homepage site, Announce before publish if no peers, configSet, serverShutdown, ADMIN WebsocketAPI command, Stop Tor client before updating, Ignore peer ip packing error, Ignore db files from git, Fix safari ajax error when UiPassword enabled
2016-02-02 11:40:45 +01:00
|
|
|
if sys.modules["main"].file_server.port_opened or sys.modules["main"].file_server.tor_manager.start_onions:
|
2015-07-12 20:36:46 +02:00
|
|
|
if notification:
|
2017-03-18 11:11:01 +01:00
|
|
|
self.cmd("notification", ["info", _["No peers found, but your content is ready to access."]])
|
2016-03-30 23:15:18 +02:00
|
|
|
if callback:
|
Version 0.3.4, Rev656, CryptMessage plugin for AES and ECIES encryption, Added pyelliptic lib for OpenSSSL based encryption methods, Test CryptMessage plugin, Force reload content.json before signing and after write, Escaped Sql IN queries support, Test Sql parameter escaping, ui_websocket Test fixture, Plugin testing support, Always return websocket errors as dict, Wait for file on weboscket fileGet command if its already in bad_files queue, PushState and ReplaceState url manipulation support in wrapper API, Per auth-address localstorage, Longer timeout for udp tracker query
2015-12-10 21:36:20 +01:00
|
|
|
self.response(to, "ok")
|
2015-07-12 20:36:46 +02:00
|
|
|
else:
|
|
|
|
if notification:
|
|
|
|
self.cmd("notification", [
|
|
|
|
"info",
|
2017-03-18 11:11:01 +01:00
|
|
|
_(u"""{_[Your network connection is restricted. Please, open <b>{0}</b> port]}<br>
|
2016-11-18 20:09:51 +01:00
|
|
|
{_[on your router to make your site accessible for everyone.]}""").format(config.fileserver_port)
|
2015-07-12 20:36:46 +02:00
|
|
|
])
|
2016-03-30 23:15:18 +02:00
|
|
|
if callback:
|
Version 0.3.4, Rev656, CryptMessage plugin for AES and ECIES encryption, Added pyelliptic lib for OpenSSSL based encryption methods, Test CryptMessage plugin, Force reload content.json before signing and after write, Escaped Sql IN queries support, Test Sql parameter escaping, ui_websocket Test fixture, Plugin testing support, Always return websocket errors as dict, Wait for file on weboscket fileGet command if its already in bad_files queue, PushState and ReplaceState url manipulation support in wrapper API, Per auth-address localstorage, Longer timeout for udp tracker query
2015-12-10 21:36:20 +01:00
|
|
|
self.response(to, {"error": "Port not opened."})
|
2015-07-12 20:36:46 +02:00
|
|
|
|
|
|
|
else:
|
|
|
|
if notification:
|
Version 0.3.4, Rev656, CryptMessage plugin for AES and ECIES encryption, Added pyelliptic lib for OpenSSSL based encryption methods, Test CryptMessage plugin, Force reload content.json before signing and after write, Escaped Sql IN queries support, Test Sql parameter escaping, ui_websocket Test fixture, Plugin testing support, Always return websocket errors as dict, Wait for file on weboscket fileGet command if its already in bad_files queue, PushState and ReplaceState url manipulation support in wrapper API, Per auth-address localstorage, Longer timeout for udp tracker query
2015-12-10 21:36:20 +01:00
|
|
|
self.response(to, {"error": "Content publish failed."})
|
2015-07-12 20:36:46 +02:00
|
|
|
|
|
|
|
# Write a file to disk
|
2016-09-04 18:05:17 +02:00
|
|
|
def actionFileWrite(self, to, inner_path, content_base64, ignore_bad_files=False):
|
2016-08-10 12:23:01 +02:00
|
|
|
valid_signers = self.site.content_manager.getValidSigners(inner_path)
|
|
|
|
auth_address = self.user.getAuthAddress(self.site.address)
|
|
|
|
if not self.site.settings["own"] and auth_address not in valid_signers:
|
2017-03-03 03:42:20 +01:00
|
|
|
self.log.error("FileWrite forbidden %s not in valid_signers %s" % (auth_address, valid_signers))
|
Version 0.3.4, Rev656, CryptMessage plugin for AES and ECIES encryption, Added pyelliptic lib for OpenSSSL based encryption methods, Test CryptMessage plugin, Force reload content.json before signing and after write, Escaped Sql IN queries support, Test Sql parameter escaping, ui_websocket Test fixture, Plugin testing support, Always return websocket errors as dict, Wait for file on weboscket fileGet command if its already in bad_files queue, PushState and ReplaceState url manipulation support in wrapper API, Per auth-address localstorage, Longer timeout for udp tracker query
2015-12-10 21:36:20 +01:00
|
|
|
return self.response(to, {"error": "Forbidden, you can only modify your own files"})
|
2015-07-12 20:36:46 +02:00
|
|
|
|
2016-09-04 18:05:17 +02:00
|
|
|
# Try not to overwrite files currently in sync
|
|
|
|
content_inner_path = re.sub("^(.*)/.*?$", "\\1/content.json", inner_path) # Also check the content.json from same directory
|
|
|
|
if (self.site.bad_files.get(inner_path) or self.site.bad_files.get(content_inner_path)) and not ignore_bad_files:
|
|
|
|
found = self.site.needFile(inner_path, update=True, priority=10)
|
|
|
|
if not found:
|
|
|
|
self.cmd(
|
2016-09-14 18:28:48 +02:00
|
|
|
"confirm",
|
2016-11-18 20:09:51 +01:00
|
|
|
[_["This file still in sync, if you write it now, then the previous content may be lost."], _["Write content anyway"]],
|
2016-09-14 18:41:28 +02:00
|
|
|
lambda (res): self.actionFileWrite(to, inner_path, content_base64, ignore_bad_files=True)
|
2016-09-04 18:05:17 +02:00
|
|
|
)
|
|
|
|
return False
|
|
|
|
|
2015-07-12 20:36:46 +02:00
|
|
|
try:
|
|
|
|
import base64
|
|
|
|
content = base64.b64decode(content_base64)
|
2016-04-06 13:56:32 +02:00
|
|
|
# Save old file to generate patch later
|
2016-04-25 02:26:13 +02:00
|
|
|
if (
|
|
|
|
inner_path.endswith(".json") and not inner_path.endswith("content.json") and
|
|
|
|
self.site.storage.isFile(inner_path) and not self.site.storage.isFile(inner_path + "-old")
|
|
|
|
):
|
2016-04-09 19:43:44 +02:00
|
|
|
try:
|
|
|
|
self.site.storage.rename(inner_path, inner_path + "-old")
|
|
|
|
except Exception:
|
|
|
|
# Rename failed, fall back to standard file write
|
|
|
|
f_old = self.site.storage.open(inner_path, "rb")
|
|
|
|
f_new = self.site.storage.open(inner_path + "-old", "wb")
|
|
|
|
shutil.copyfileobj(f_old, f_new)
|
2016-04-06 13:56:32 +02:00
|
|
|
|
2015-07-12 20:36:46 +02:00
|
|
|
self.site.storage.write(inner_path, content)
|
|
|
|
except Exception, err:
|
2017-03-03 03:42:20 +01:00
|
|
|
self.log.error("File write error: %s" % Debug.formatException(err))
|
2016-04-07 10:35:02 +02:00
|
|
|
return self.response(to, {"error": "Write error: %s" % Debug.formatException(err)})
|
2015-07-12 20:36:46 +02:00
|
|
|
|
|
|
|
if inner_path.endswith("content.json"):
|
Version 0.3.4, Rev656, CryptMessage plugin for AES and ECIES encryption, Added pyelliptic lib for OpenSSSL based encryption methods, Test CryptMessage plugin, Force reload content.json before signing and after write, Escaped Sql IN queries support, Test Sql parameter escaping, ui_websocket Test fixture, Plugin testing support, Always return websocket errors as dict, Wait for file on weboscket fileGet command if its already in bad_files queue, PushState and ReplaceState url manipulation support in wrapper API, Per auth-address localstorage, Longer timeout for udp tracker query
2015-12-10 21:36:20 +01:00
|
|
|
self.site.content_manager.loadContent(inner_path, add_bad_files=False, force=True)
|
2015-07-12 20:36:46 +02:00
|
|
|
|
|
|
|
self.response(to, "ok")
|
|
|
|
|
|
|
|
# Send sitechanged to other local users
|
|
|
|
for ws in self.site.websockets:
|
|
|
|
if ws != self:
|
|
|
|
ws.event("siteChanged", self.site, {"event": ["file_done", inner_path]})
|
|
|
|
|
2015-09-16 00:01:23 +02:00
|
|
|
def actionFileDelete(self, to, inner_path):
|
|
|
|
if (
|
|
|
|
not self.site.settings["own"] and
|
|
|
|
self.user.getAuthAddress(self.site.address) not in self.site.content_manager.getValidSigners(inner_path)
|
|
|
|
):
|
2017-03-03 03:42:20 +01:00
|
|
|
self.log.error("File delete error: you don't own this site & you are not approved by the owner.")
|
Version 0.3.4, Rev656, CryptMessage plugin for AES and ECIES encryption, Added pyelliptic lib for OpenSSSL based encryption methods, Test CryptMessage plugin, Force reload content.json before signing and after write, Escaped Sql IN queries support, Test Sql parameter escaping, ui_websocket Test fixture, Plugin testing support, Always return websocket errors as dict, Wait for file on weboscket fileGet command if its already in bad_files queue, PushState and ReplaceState url manipulation support in wrapper API, Per auth-address localstorage, Longer timeout for udp tracker query
2015-12-10 21:36:20 +01:00
|
|
|
return self.response(to, {"error": "Forbidden, you can only modify your own files"})
|
2015-09-16 00:01:23 +02:00
|
|
|
|
2017-01-27 12:02:14 +01:00
|
|
|
file_info = self.site.content_manager.getFileInfo(inner_path)
|
2017-06-27 18:08:28 +02:00
|
|
|
if file_info and file_info.get("optional"):
|
2017-01-27 14:01:55 +01:00
|
|
|
self.log.debug("Deleting optional file: %s" % inner_path)
|
|
|
|
relative_path = file_info["relative_path"]
|
|
|
|
content_json = self.site.storage.loadJson(file_info["content_inner_path"])
|
|
|
|
if relative_path in content_json.get("files_optional", {}):
|
|
|
|
del content_json["files_optional"][relative_path]
|
|
|
|
self.site.storage.writeJson(file_info["content_inner_path"], content_json)
|
|
|
|
self.site.content_manager.loadContent(file_info["content_inner_path"], add_bad_files=False, force=True)
|
2017-01-27 12:02:14 +01:00
|
|
|
|
2015-09-16 00:01:23 +02:00
|
|
|
try:
|
|
|
|
self.site.storage.delete(inner_path)
|
|
|
|
except Exception, err:
|
2017-03-03 03:42:20 +01:00
|
|
|
self.log.error("File delete error: Exception - %s" % err)
|
Version 0.3.4, Rev656, CryptMessage plugin for AES and ECIES encryption, Added pyelliptic lib for OpenSSSL based encryption methods, Test CryptMessage plugin, Force reload content.json before signing and after write, Escaped Sql IN queries support, Test Sql parameter escaping, ui_websocket Test fixture, Plugin testing support, Always return websocket errors as dict, Wait for file on weboscket fileGet command if its already in bad_files queue, PushState and ReplaceState url manipulation support in wrapper API, Per auth-address localstorage, Longer timeout for udp tracker query
2015-12-10 21:36:20 +01:00
|
|
|
return self.response(to, {"error": "Delete error: %s" % err})
|
2015-09-16 00:01:23 +02:00
|
|
|
|
|
|
|
self.response(to, "ok")
|
|
|
|
|
|
|
|
# Send sitechanged to other local users
|
|
|
|
for ws in self.site.websockets:
|
|
|
|
if ws != self:
|
|
|
|
ws.event("siteChanged", self.site, {"event": ["file_deleted", inner_path]})
|
|
|
|
|
2015-07-12 20:36:46 +02:00
|
|
|
# Find data in json files
|
2017-04-21 11:26:17 +02:00
|
|
|
def actionFileQuery(self, to, dir_inner_path, query=None):
|
2015-07-12 20:36:46 +02:00
|
|
|
# s = time.time()
|
|
|
|
dir_path = self.site.storage.getPath(dir_inner_path)
|
2017-04-21 11:26:17 +02:00
|
|
|
rows = list(QueryJson.query(dir_path, query or ""))
|
2015-07-12 20:36:46 +02:00
|
|
|
# self.log.debug("FileQuery %s %s done in %s" % (dir_inner_path, query, time.time()-s))
|
|
|
|
return self.response(to, rows)
|
|
|
|
|
2017-01-05 02:26:58 +01:00
|
|
|
# List files in directory
|
|
|
|
def actionFileList(self, to, inner_path):
|
2017-02-25 05:47:38 +01:00
|
|
|
return self.response(to, list(self.site.storage.walk(inner_path)))
|
|
|
|
|
|
|
|
# List directories in a directory
|
|
|
|
def actionDirList(self, to, inner_path):
|
2017-01-05 02:26:58 +01:00
|
|
|
return self.response(to, list(self.site.storage.list(inner_path)))
|
|
|
|
|
2015-07-12 20:36:46 +02:00
|
|
|
# Sql query
|
|
|
|
def actionDbQuery(self, to, query, params=None, wait_for=None):
|
2017-03-15 13:13:21 +01:00
|
|
|
if config.debug or config.verbose:
|
2016-09-04 18:05:31 +02:00
|
|
|
s = time.time()
|
2015-07-12 20:36:46 +02:00
|
|
|
rows = []
|
|
|
|
try:
|
2016-11-18 20:11:03 +01:00
|
|
|
if not query.strip().upper().startswith("SELECT"):
|
|
|
|
raise Exception("Only SELECT query supported")
|
2015-07-12 20:36:46 +02:00
|
|
|
res = self.site.storage.query(query, params)
|
|
|
|
except Exception, err: # Response the error to client
|
2017-03-06 15:30:31 +01:00
|
|
|
self.log.error("DbQuery error: %s" % err)
|
2015-07-12 20:36:46 +02:00
|
|
|
return self.response(to, {"error": str(err)})
|
|
|
|
# Convert result to dict
|
|
|
|
for row in res:
|
|
|
|
rows.append(dict(row))
|
2016-09-04 18:05:31 +02:00
|
|
|
if config.verbose and time.time() - s > 0.1: # Log slow query
|
|
|
|
self.log.debug("Slow query: %s (%.3fs)" % (query, time.time() - s))
|
2015-07-12 20:36:46 +02:00
|
|
|
return self.response(to, rows)
|
|
|
|
|
|
|
|
# Return file content
|
2017-01-22 11:09:45 +01:00
|
|
|
def actionFileGet(self, to, inner_path, required=True, format="text", timeout=300):
|
2015-07-12 20:36:46 +02:00
|
|
|
try:
|
Version 0.3.4, Rev656, CryptMessage plugin for AES and ECIES encryption, Added pyelliptic lib for OpenSSSL based encryption methods, Test CryptMessage plugin, Force reload content.json before signing and after write, Escaped Sql IN queries support, Test Sql parameter escaping, ui_websocket Test fixture, Plugin testing support, Always return websocket errors as dict, Wait for file on weboscket fileGet command if its already in bad_files queue, PushState and ReplaceState url manipulation support in wrapper API, Per auth-address localstorage, Longer timeout for udp tracker query
2015-12-10 21:36:20 +01:00
|
|
|
if required or inner_path in self.site.bad_files:
|
2017-01-22 11:09:45 +01:00
|
|
|
with gevent.Timeout(timeout):
|
|
|
|
self.site.needFile(inner_path, priority=6)
|
2015-07-12 20:36:46 +02:00
|
|
|
body = self.site.storage.read(inner_path)
|
Version 0.3.4, Rev656, CryptMessage plugin for AES and ECIES encryption, Added pyelliptic lib for OpenSSSL based encryption methods, Test CryptMessage plugin, Force reload content.json before signing and after write, Escaped Sql IN queries support, Test Sql parameter escaping, ui_websocket Test fixture, Plugin testing support, Always return websocket errors as dict, Wait for file on weboscket fileGet command if its already in bad_files queue, PushState and ReplaceState url manipulation support in wrapper API, Per auth-address localstorage, Longer timeout for udp tracker query
2015-12-10 21:36:20 +01:00
|
|
|
except Exception, err:
|
2017-03-03 03:42:20 +01:00
|
|
|
self.log.error("%s fileGet error: %s" % (inner_path, err))
|
2015-07-12 20:36:46 +02:00
|
|
|
body = None
|
2017-01-22 11:09:45 +01:00
|
|
|
if body and format == "base64":
|
|
|
|
import base64
|
|
|
|
body = base64.b64encode(body)
|
2015-07-12 20:36:46 +02:00
|
|
|
return self.response(to, body)
|
|
|
|
|
|
|
|
def actionFileRules(self, to, inner_path):
|
|
|
|
rules = self.site.content_manager.getRules(inner_path)
|
2016-08-10 12:15:16 +02:00
|
|
|
if inner_path.endswith("content.json") and rules:
|
2015-07-12 20:36:46 +02:00
|
|
|
content = self.site.content_manager.contents.get(inner_path)
|
|
|
|
if content:
|
|
|
|
rules["current_size"] = len(json.dumps(content)) + sum([file["size"] for file in content["files"].values()])
|
|
|
|
else:
|
|
|
|
rules["current_size"] = 0
|
|
|
|
return self.response(to, rules)
|
|
|
|
|
|
|
|
# Add certificate to user
|
|
|
|
def actionCertAdd(self, to, domain, auth_type, auth_user_name, cert):
|
|
|
|
try:
|
|
|
|
res = self.user.addCert(self.user.getAuthAddress(self.site.address), domain, auth_type, auth_user_name, cert)
|
|
|
|
if res is True:
|
|
|
|
self.cmd(
|
|
|
|
"notification",
|
2017-01-07 01:09:05 +01:00
|
|
|
["done", _("{_[New certificate added]:} <b>{auth_type}/{auth_user_name}@{domain}</b>.")]
|
2015-07-12 20:36:46 +02:00
|
|
|
)
|
2017-04-12 00:32:19 +02:00
|
|
|
self.user.setCert(self.site.address, domain)
|
|
|
|
self.site.updateWebsocket(cert_changed=domain)
|
2015-07-12 20:36:46 +02:00
|
|
|
self.response(to, "ok")
|
2016-04-09 19:49:12 +02:00
|
|
|
elif res is False:
|
|
|
|
# Display confirmation of change
|
|
|
|
cert_current = self.user.certs[domain]
|
2017-01-07 01:09:05 +01:00
|
|
|
body = _("{_[Your current certificate]:} <b>{cert_current[auth_type]}/{cert_current[auth_user_name]}@{domain}</b>")
|
2016-05-16 22:26:40 +02:00
|
|
|
self.cmd(
|
|
|
|
"confirm",
|
2016-11-18 20:09:51 +01:00
|
|
|
[body, _("Change it to {auth_type}/{auth_user_name}@{domain}")],
|
2016-04-09 19:49:12 +02:00
|
|
|
lambda (res): self.cbCertAddConfirm(to, domain, auth_type, auth_user_name, cert)
|
|
|
|
)
|
2015-07-12 20:36:46 +02:00
|
|
|
else:
|
|
|
|
self.response(to, "Not changed")
|
|
|
|
except Exception, err:
|
2017-03-03 03:42:20 +01:00
|
|
|
self.log.error("CertAdd error: Exception - %s" % err.message)
|
2015-07-12 20:36:46 +02:00
|
|
|
self.response(to, {"error": err.message})
|
|
|
|
|
2016-04-09 19:49:12 +02:00
|
|
|
def cbCertAddConfirm(self, to, domain, auth_type, auth_user_name, cert):
|
|
|
|
self.user.deleteCert(domain)
|
|
|
|
self.user.addCert(self.user.getAuthAddress(self.site.address), domain, auth_type, auth_user_name, cert)
|
|
|
|
self.cmd(
|
|
|
|
"notification",
|
2016-11-18 20:09:51 +01:00
|
|
|
["done", _("Certificate changed to: <b>{auth_type}/{auth_user_name}@{domain}</b>.")]
|
2016-04-09 19:49:12 +02:00
|
|
|
)
|
2017-04-12 00:32:19 +02:00
|
|
|
self.user.setCert(self.site.address, domain)
|
|
|
|
self.site.updateWebsocket(cert_changed=domain)
|
2016-04-09 19:49:12 +02:00
|
|
|
self.response(to, "ok")
|
|
|
|
|
2015-07-12 20:36:46 +02:00
|
|
|
# Select certificate for site
|
2016-08-10 12:18:22 +02:00
|
|
|
def actionCertSelect(self, to, accepted_domains=[], accept_any=False):
|
2015-07-12 20:36:46 +02:00
|
|
|
accounts = []
|
2016-11-18 20:09:51 +01:00
|
|
|
accounts.append(["", _["Unique to site"], ""]) # Default option
|
2015-07-12 20:36:46 +02:00
|
|
|
active = "" # Make it active if no other option found
|
|
|
|
|
|
|
|
# Add my certs
|
|
|
|
auth_address = self.user.getAuthAddress(self.site.address) # Current auth address
|
2017-04-12 00:45:48 +02:00
|
|
|
site_data = self.user.getSiteData(self.site.address) # Current auth address
|
2015-07-12 20:36:46 +02:00
|
|
|
for domain, cert in self.user.certs.items():
|
2017-04-12 00:45:48 +02:00
|
|
|
if auth_address == cert["auth_address"] and domain == site_data.get("cert"):
|
2015-07-12 20:36:46 +02:00
|
|
|
active = domain
|
|
|
|
title = cert["auth_user_name"] + "@" + domain
|
2016-08-10 12:18:22 +02:00
|
|
|
if domain in accepted_domains or not accepted_domains or accept_any:
|
2015-07-12 20:36:46 +02:00
|
|
|
accounts.append([domain, title, ""])
|
|
|
|
else:
|
|
|
|
accounts.append([domain, title, "disabled"])
|
|
|
|
|
|
|
|
# Render the html
|
2016-11-18 20:09:51 +01:00
|
|
|
body = "<span style='padding-bottom: 5px; display: inline-block'>" + _["Select account you want to use in this site:"] + "</span>"
|
2015-07-12 20:36:46 +02:00
|
|
|
# Accounts
|
|
|
|
for domain, account, css_class in accounts:
|
|
|
|
if domain == active:
|
|
|
|
css_class += " active" # Currently selected option
|
2016-11-18 20:09:51 +01:00
|
|
|
title = _(u"<b>%s</b> <small>({_[currently selected]})</small>") % account
|
2015-07-12 20:36:46 +02:00
|
|
|
else:
|
|
|
|
title = "<b>%s</b>" % account
|
|
|
|
body += "<a href='#Select+account' class='select select-close cert %s' title='%s'>%s</a>" % (css_class, domain, title)
|
2016-04-09 19:49:23 +02:00
|
|
|
# More available providers
|
|
|
|
more_domains = [domain for domain in accepted_domains if domain not in self.user.certs] # Domains we not displayed yet
|
2015-07-12 20:36:46 +02:00
|
|
|
if more_domains:
|
|
|
|
# body+= "<small style='margin-top: 10px; display: block'>Accepted authorization providers by the site:</small>"
|
|
|
|
body += "<div style='background-color: #F7F7F7; margin-right: -30px'>"
|
|
|
|
for domain in more_domains:
|
2016-11-18 20:09:51 +01:00
|
|
|
body += _(u"""
|
|
|
|
<a href='/{domain}' onclick='wrapper.gotoSite(this)' class='select'>
|
|
|
|
<small style='float: right; margin-right: 40px; margin-top: -1px'>{_[Register]} »</small>{domain}
|
2015-07-12 20:36:46 +02:00
|
|
|
</a>
|
2016-11-18 20:09:51 +01:00
|
|
|
""")
|
2015-07-12 20:36:46 +02:00
|
|
|
body += "</div>"
|
|
|
|
|
|
|
|
body += """
|
|
|
|
<script>
|
|
|
|
$(".notification .select.cert").on("click", function() {
|
|
|
|
$(".notification .select").removeClass('active')
|
2017-06-03 00:53:40 +02:00
|
|
|
wrapper.ws.cmd('certSet', [this.title], function() {
|
|
|
|
wrapper.sendInner({"cmd": "response", "to": %s, "result": this.title})
|
|
|
|
})
|
2015-07-12 20:36:46 +02:00
|
|
|
return false
|
|
|
|
})
|
|
|
|
</script>
|
2017-06-03 00:53:40 +02:00
|
|
|
""" % to
|
2015-07-12 20:36:46 +02:00
|
|
|
|
|
|
|
# Send the notification
|
|
|
|
self.cmd("notification", ["ask", body])
|
|
|
|
|
2016-04-09 19:49:23 +02:00
|
|
|
# - Admin actions -
|
|
|
|
|
2016-08-10 12:12:47 +02:00
|
|
|
def actionPermissionAdd(self, to, permission):
|
|
|
|
if permission not in self.site.settings["permissions"]:
|
|
|
|
self.site.settings["permissions"].append(permission)
|
|
|
|
self.site.saveSettings()
|
2016-12-30 18:55:11 +01:00
|
|
|
self.site.updateWebsocket(permission_added=permission)
|
2016-08-10 12:12:47 +02:00
|
|
|
self.response(to, "ok")
|
|
|
|
|
|
|
|
def actionPermissionRemove(self, to, permission):
|
|
|
|
self.site.settings["permissions"].remove(permission)
|
|
|
|
self.site.saveSettings()
|
2016-12-30 18:55:11 +01:00
|
|
|
self.site.updateWebsocket(permission_removed=permission)
|
2016-08-10 12:12:47 +02:00
|
|
|
self.response(to, "ok")
|
|
|
|
|
2015-07-12 20:36:46 +02:00
|
|
|
# Set certificate that used for authenticate user for site
|
|
|
|
def actionCertSet(self, to, domain):
|
|
|
|
self.user.setCert(self.site.address, domain)
|
|
|
|
self.site.updateWebsocket(cert_changed=domain)
|
2017-06-03 00:53:40 +02:00
|
|
|
self.response(to, "ok")
|
2015-07-12 20:36:46 +02:00
|
|
|
|
|
|
|
# List all site info
|
|
|
|
def actionSiteList(self, to):
|
|
|
|
ret = []
|
|
|
|
SiteManager.site_manager.load() # Reload sites
|
|
|
|
for site in self.server.sites.values():
|
|
|
|
if not site.content_manager.contents.get("content.json"):
|
|
|
|
continue # Broken site
|
|
|
|
ret.append(self.formatSiteInfo(site, create_user=False)) # Dont generate the auth_address on listing
|
|
|
|
self.response(to, ret)
|
|
|
|
|
|
|
|
# Join to an event channel on all sites
|
|
|
|
def actionChannelJoinAllsite(self, to, channel):
|
|
|
|
if channel not in self.channels: # Add channel to channels
|
|
|
|
self.channels.append(channel)
|
|
|
|
|
|
|
|
for site in self.server.sites.values(): # Add websocket to every channel
|
|
|
|
if self not in site.websockets:
|
|
|
|
site.websockets.append(self)
|
|
|
|
|
|
|
|
# Update site content.json
|
2017-01-29 19:02:08 +01:00
|
|
|
def actionSiteUpdate(self, to, address, check_files=False, since=None):
|
Rev957, Sidebar displays onion peers in graph, Sidebar display bad file retry number, Sidebar site Update/Pause/Delete, Ratelimit sidebar update, Encoded typo, Fix onion findHashId, More retry for bad files, Log file path errors, Testcase for self findhashIds, Testcase for Tor findHashId, Better Tor version parse, UiWebsocket callback on update/pause/resume/delete, Skip invalid postMessage messages
2016-03-09 00:48:57 +01:00
|
|
|
def updateThread():
|
2017-01-29 19:02:08 +01:00
|
|
|
site.update(check_files=check_files, since=since)
|
Rev957, Sidebar displays onion peers in graph, Sidebar display bad file retry number, Sidebar site Update/Pause/Delete, Ratelimit sidebar update, Encoded typo, Fix onion findHashId, More retry for bad files, Log file path errors, Testcase for self findhashIds, Testcase for Tor findHashId, Better Tor version parse, UiWebsocket callback on update/pause/resume/delete, Skip invalid postMessage messages
2016-03-09 00:48:57 +01:00
|
|
|
self.response(to, "Updated")
|
|
|
|
|
2015-07-12 20:36:46 +02:00
|
|
|
site = self.server.sites.get(address)
|
2016-08-10 12:18:22 +02:00
|
|
|
if not site.settings["serving"]:
|
|
|
|
site.settings["serving"] = True
|
|
|
|
site.saveSettings()
|
2015-07-12 20:36:46 +02:00
|
|
|
if site and (site.address == self.site.address or "ADMIN" in self.site.settings["permissions"]):
|
Rev957, Sidebar displays onion peers in graph, Sidebar display bad file retry number, Sidebar site Update/Pause/Delete, Ratelimit sidebar update, Encoded typo, Fix onion findHashId, More retry for bad files, Log file path errors, Testcase for self findhashIds, Testcase for Tor findHashId, Better Tor version parse, UiWebsocket callback on update/pause/resume/delete, Skip invalid postMessage messages
2016-03-09 00:48:57 +01:00
|
|
|
gevent.spawn(updateThread)
|
2015-07-12 20:36:46 +02:00
|
|
|
else:
|
|
|
|
self.response(to, {"error": "Unknown site: %s" % address})
|
|
|
|
|
|
|
|
# Pause site serving
|
|
|
|
def actionSitePause(self, to, address):
|
|
|
|
site = self.server.sites.get(address)
|
|
|
|
if site:
|
|
|
|
site.settings["serving"] = False
|
|
|
|
site.saveSettings()
|
|
|
|
site.updateWebsocket()
|
|
|
|
site.worker_manager.stopWorkers()
|
Rev957, Sidebar displays onion peers in graph, Sidebar display bad file retry number, Sidebar site Update/Pause/Delete, Ratelimit sidebar update, Encoded typo, Fix onion findHashId, More retry for bad files, Log file path errors, Testcase for self findhashIds, Testcase for Tor findHashId, Better Tor version parse, UiWebsocket callback on update/pause/resume/delete, Skip invalid postMessage messages
2016-03-09 00:48:57 +01:00
|
|
|
self.response(to, "Paused")
|
2015-07-12 20:36:46 +02:00
|
|
|
else:
|
|
|
|
self.response(to, {"error": "Unknown site: %s" % address})
|
|
|
|
|
|
|
|
# Resume site serving
|
|
|
|
def actionSiteResume(self, to, address):
|
|
|
|
site = self.server.sites.get(address)
|
|
|
|
if site:
|
|
|
|
site.settings["serving"] = True
|
|
|
|
site.saveSettings()
|
|
|
|
gevent.spawn(site.update, announce=True)
|
|
|
|
time.sleep(0.001) # Wait for update thread starting
|
|
|
|
site.updateWebsocket()
|
Rev957, Sidebar displays onion peers in graph, Sidebar display bad file retry number, Sidebar site Update/Pause/Delete, Ratelimit sidebar update, Encoded typo, Fix onion findHashId, More retry for bad files, Log file path errors, Testcase for self findhashIds, Testcase for Tor findHashId, Better Tor version parse, UiWebsocket callback on update/pause/resume/delete, Skip invalid postMessage messages
2016-03-09 00:48:57 +01:00
|
|
|
self.response(to, "Resumed")
|
2015-07-12 20:36:46 +02:00
|
|
|
else:
|
|
|
|
self.response(to, {"error": "Unknown site: %s" % address})
|
|
|
|
|
|
|
|
def actionSiteDelete(self, to, address):
|
|
|
|
site = self.server.sites.get(address)
|
|
|
|
if site:
|
2016-09-05 13:55:51 +02:00
|
|
|
site.delete()
|
2015-09-11 02:25:37 +02:00
|
|
|
self.user.deleteSiteData(address)
|
Rev957, Sidebar displays onion peers in graph, Sidebar display bad file retry number, Sidebar site Update/Pause/Delete, Ratelimit sidebar update, Encoded typo, Fix onion findHashId, More retry for bad files, Log file path errors, Testcase for self findhashIds, Testcase for Tor findHashId, Better Tor version parse, UiWebsocket callback on update/pause/resume/delete, Skip invalid postMessage messages
2016-03-09 00:48:57 +01:00
|
|
|
self.response(to, "Deleted")
|
2016-09-04 18:05:55 +02:00
|
|
|
import gc
|
|
|
|
gc.collect(2)
|
2015-07-12 20:36:46 +02:00
|
|
|
else:
|
|
|
|
self.response(to, {"error": "Unknown site: %s" % address})
|
|
|
|
|
2017-05-18 03:07:32 +02:00
|
|
|
def actionSiteClone(self, to, address, root_inner_path="", target_address=None):
|
2017-01-27 23:27:45 +01:00
|
|
|
self.cmd("notification", ["info", _["Cloning site..."]])
|
2015-07-12 20:36:46 +02:00
|
|
|
site = self.server.sites.get(address)
|
2017-05-18 03:07:32 +02:00
|
|
|
if target_address:
|
|
|
|
target_site = self.server.sites.get(target_address)
|
|
|
|
privatekey = self.user.getSiteData(target_site.address).get("privatekey")
|
|
|
|
site.clone(target_address, privatekey, root_inner_path=root_inner_path)
|
|
|
|
self.cmd("notification", ["done", _["Site source code upgraded!"]])
|
|
|
|
site.publish()
|
|
|
|
else:
|
|
|
|
# Generate a new site from user's bip32 seed
|
|
|
|
new_address, new_address_index, new_site_data = self.user.getNewSiteData()
|
|
|
|
new_site = site.clone(new_address, new_site_data["privatekey"], address_index=new_address_index, root_inner_path=root_inner_path)
|
|
|
|
new_site.settings["own"] = True
|
|
|
|
new_site.saveSettings()
|
|
|
|
self.cmd("notification", ["done", _["Site cloned"] + "<script>window.top.location = '/%s'</script>" % new_address])
|
|
|
|
gevent.spawn(new_site.announce)
|
|
|
|
|
2015-07-12 20:36:46 +02:00
|
|
|
def actionSiteSetLimit(self, to, size_limit):
|
2015-08-16 11:51:00 +02:00
|
|
|
self.site.settings["size_limit"] = int(size_limit)
|
2015-07-12 20:36:46 +02:00
|
|
|
self.site.saveSettings()
|
2017-04-12 17:36:50 +02:00
|
|
|
self.response(to, "ok")
|
2015-08-06 00:51:25 +02:00
|
|
|
self.site.download(blind_includes=True)
|
2015-07-12 20:36:46 +02:00
|
|
|
|
2017-07-10 02:41:01 +02:00
|
|
|
def actionUserGetSettings(self, to):
|
|
|
|
settings = self.user.sites[self.site.address].get("settings", {})
|
|
|
|
self.response(to, settings)
|
|
|
|
|
|
|
|
def actionUserSetSettings(self, to, settings):
|
|
|
|
self.user.setSettings(self.site.address, settings)
|
|
|
|
self.response(to, "ok")
|
|
|
|
|
2015-07-12 20:36:46 +02:00
|
|
|
def actionServerUpdate(self, to):
|
|
|
|
self.cmd("updating")
|
|
|
|
sys.modules["main"].update_after_shutdown = True
|
2016-12-04 18:55:03 +01:00
|
|
|
SiteManager.site_manager.save()
|
2015-07-12 20:36:46 +02:00
|
|
|
sys.modules["main"].file_server.stop()
|
|
|
|
sys.modules["main"].ui_server.stop()
|
2015-11-17 12:48:03 +01:00
|
|
|
|
|
|
|
def actionServerPortcheck(self, to):
|
|
|
|
sys.modules["main"].file_server.port_opened = None
|
|
|
|
res = sys.modules["main"].file_server.openport()
|
|
|
|
self.response(to, res)
|
Version 0.3.6, Rev879, Fix sidebar error on description missing, New trayicon, New favicon, Disable some functions on MultiUser proxies, New homepage, Replace only the last ? in SQL queries, Alwaays grant ADMIN permission to homepage site, Announce before publish if no peers, configSet, serverShutdown, ADMIN WebsocketAPI command, Stop Tor client before updating, Ignore peer ip packing error, Ignore db files from git, Fix safari ajax error when UiPassword enabled
2016-02-02 11:40:45 +01:00
|
|
|
|
|
|
|
def actionServerShutdown(self, to):
|
|
|
|
sys.modules["main"].file_server.stop()
|
|
|
|
sys.modules["main"].ui_server.stop()
|
|
|
|
|
2017-07-27 16:29:39 +02:00
|
|
|
def actionServerShowdirectory(self, to, directory="backup"):
|
|
|
|
import webbrowser
|
|
|
|
webbrowser.open('file://' + os.path.abspath(config.data_dir))
|
|
|
|
|
Version 0.3.6, Rev879, Fix sidebar error on description missing, New trayicon, New favicon, Disable some functions on MultiUser proxies, New homepage, Replace only the last ? in SQL queries, Alwaays grant ADMIN permission to homepage site, Announce before publish if no peers, configSet, serverShutdown, ADMIN WebsocketAPI command, Stop Tor client before updating, Ignore peer ip packing error, Ignore db files from git, Fix safari ajax error when UiPassword enabled
2016-02-02 11:40:45 +01:00
|
|
|
def actionConfigSet(self, to, key, value):
|
2016-11-18 20:10:24 +01:00
|
|
|
if key not in ["tor", "language"]:
|
2016-11-07 22:55:09 +01:00
|
|
|
self.response(to, {"error": "Forbidden"})
|
2016-02-20 11:19:28 +01:00
|
|
|
return
|
|
|
|
|
2016-11-07 22:51:43 +01:00
|
|
|
config.saveValue(key, value)
|
2016-11-18 20:10:24 +01:00
|
|
|
|
|
|
|
if key == "language":
|
|
|
|
import Translate
|
|
|
|
for translate in Translate.translates:
|
|
|
|
translate.setLanguage(value)
|
|
|
|
self.cmd("notification", ["done",
|
|
|
|
_["You have successfully changed the web interface's language!"] + "<br>" +
|
|
|
|
_["Due to the browser's caching, the full transformation could take some minute."]
|
|
|
|
, 10000])
|
|
|
|
config.language = value
|
|
|
|
|
Version 0.3.6, Rev879, Fix sidebar error on description missing, New trayicon, New favicon, Disable some functions on MultiUser proxies, New homepage, Replace only the last ? in SQL queries, Alwaays grant ADMIN permission to homepage site, Announce before publish if no peers, configSet, serverShutdown, ADMIN WebsocketAPI command, Stop Tor client before updating, Ignore peer ip packing error, Ignore db files from git, Fix safari ajax error when UiPassword enabled
2016-02-02 11:40:45 +01:00
|
|
|
self.response(to, "ok")
|