2015-06-17 23:27:56 +02:00
|
|
|
# Included modules
|
|
|
|
import os
|
|
|
|
import sys
|
2016-05-26 16:00:14 +02:00
|
|
|
import stat
|
2015-06-17 23:27:56 +02:00
|
|
|
import time
|
2015-06-18 02:53:01 +02:00
|
|
|
import logging
|
2015-06-17 23:27:56 +02:00
|
|
|
|
|
|
|
# Third party modules
|
|
|
|
import gevent
|
2016-03-11 12:39:39 +01:00
|
|
|
|
2015-06-17 23:27:56 +02:00
|
|
|
from gevent import monkey
|
2016-01-05 20:18:17 +01:00
|
|
|
if "patch_subprocess" in dir(monkey): # New gevent
|
2015-10-24 13:57:46 +02:00
|
|
|
monkey.patch_all(thread=False, subprocess=False)
|
2016-01-05 20:18:17 +01:00
|
|
|
else: # Old gevent
|
|
|
|
import ssl
|
|
|
|
# Fix PROTOCOL_SSLv3 not defined
|
|
|
|
if "PROTOCOL_SSLv3" not in dir(ssl):
|
|
|
|
ssl.PROTOCOL_SSLv3 = ssl.PROTOCOL_SSLv23
|
2015-10-24 13:57:46 +02:00
|
|
|
monkey.patch_all(thread=False)
|
|
|
|
# Not thread: pyfilesystem and systray icon, Not subprocess: Gevent 1.1+
|
2015-06-17 23:27:56 +02:00
|
|
|
|
|
|
|
update_after_shutdown = False # If set True then update and restart zeronet after main loop ended
|
2015-01-12 02:03:45 +01:00
|
|
|
|
|
|
|
# Load config
|
|
|
|
from Config import config
|
2015-07-17 00:28:43 +02:00
|
|
|
config.parse(silent=True) # Plugins need to access the configuration
|
2015-09-10 23:25:09 +02:00
|
|
|
if not config.arguments: # Config parse failed, show the help screen and exit
|
|
|
|
config.parse()
|
2015-01-12 02:03:45 +01:00
|
|
|
|
2015-05-31 15:52:21 +02:00
|
|
|
# Create necessary files and dirs
|
2015-07-12 20:36:46 +02:00
|
|
|
if not os.path.isdir(config.log_dir):
|
|
|
|
os.mkdir(config.log_dir)
|
|
|
|
if not os.path.isdir(config.data_dir):
|
|
|
|
os.mkdir(config.data_dir)
|
2015-06-17 23:27:56 +02:00
|
|
|
if not os.path.isfile("%s/sites.json" % config.data_dir):
|
|
|
|
open("%s/sites.json" % config.data_dir, "w").write("{}")
|
2016-05-26 16:00:14 +02:00
|
|
|
os.chmod("%s/sites.json" % config.data_dir, stat.S_IRUSR | stat.S_IWUSR)
|
2015-06-17 23:27:56 +02:00
|
|
|
if not os.path.isfile("%s/users.json" % config.data_dir):
|
|
|
|
open("%s/users.json" % config.data_dir, "w").write("{}")
|
2016-05-26 16:00:14 +02:00
|
|
|
os.chmod("%s/users.json" % config.data_dir, stat.S_IRUSR | stat.S_IWUSR)
|
2015-05-31 15:52:21 +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
|
|
|
# Setup logging
|
2015-01-12 02:03:45 +01:00
|
|
|
if config.action == "main":
|
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
|
|
|
from util import helper
|
|
|
|
log_file_path = "%s/debug.log" % config.log_dir
|
|
|
|
try:
|
|
|
|
helper.openLocked(log_file_path, "a")
|
|
|
|
except IOError as err:
|
|
|
|
print "Can't lock %s file, your ZeroNet client is probably already running, exiting... (%s)" % (log_file_path, err)
|
|
|
|
sys.exit()
|
|
|
|
|
2015-06-17 23:27:56 +02:00
|
|
|
if os.path.isfile("%s/debug.log" % config.log_dir): # Simple logrotate
|
|
|
|
if os.path.isfile("%s/debug-last.log" % config.log_dir):
|
|
|
|
os.unlink("%s/debug-last.log" % config.log_dir)
|
|
|
|
os.rename("%s/debug.log" % config.log_dir, "%s/debug-last.log" % config.log_dir)
|
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
|
|
|
logging.basicConfig(
|
|
|
|
format='[%(asctime)s] %(levelname)-8s %(name)s %(message)s',
|
|
|
|
level=logging.DEBUG, stream=helper.openLocked(log_file_path, "a")
|
|
|
|
)
|
2015-01-12 02:03:45 +01:00
|
|
|
else:
|
2016-03-19 18:11:37 +01:00
|
|
|
log_file_path = "%s/cmd.log" % config.log_dir
|
|
|
|
logging.basicConfig(
|
|
|
|
format='[%(asctime)s] %(levelname)-8s %(name)s %(message)s',
|
|
|
|
level=logging.DEBUG, stream=open(log_file_path, "w")
|
|
|
|
)
|
2015-01-12 02:03:45 +01:00
|
|
|
|
2015-01-17 18:50:56 +01:00
|
|
|
# Console logger
|
2015-01-12 02:03:45 +01:00
|
|
|
console_log = logging.StreamHandler()
|
2015-06-17 23:27:56 +02:00
|
|
|
if config.action == "main": # Add time if main action
|
|
|
|
console_log.setFormatter(logging.Formatter('[%(asctime)s] %(name)s %(message)s', "%H:%M:%S"))
|
2015-01-17 18:50:56 +01:00
|
|
|
else:
|
2015-06-17 23:27:56 +02:00
|
|
|
console_log.setFormatter(logging.Formatter('%(name)s %(message)s', "%H:%M:%S"))
|
2015-01-17 18:50:56 +01:00
|
|
|
|
2015-06-17 23:27:56 +02:00
|
|
|
logging.getLogger('').addHandler(console_log) # Add console logger
|
|
|
|
logging.getLogger('').name = "-" # Remove root prefix
|
2015-01-12 02:03:45 +01:00
|
|
|
|
|
|
|
# Debug dependent configuration
|
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
|
|
|
from Debug import DebugHook
|
2015-01-12 02:03:45 +01:00
|
|
|
if config.debug:
|
2015-07-12 20:36:46 +02:00
|
|
|
console_log.setLevel(logging.DEBUG) # Display everything to console
|
2015-01-12 02:03:45 +01:00
|
|
|
else:
|
2015-07-12 20:36:46 +02:00
|
|
|
console_log.setLevel(logging.INFO) # Display only important info to console
|
2015-06-17 23:27:56 +02:00
|
|
|
|
2015-07-17 00:28:43 +02:00
|
|
|
# Load plugins
|
|
|
|
from Plugin import PluginManager
|
|
|
|
PluginManager.plugin_manager.loadPlugins()
|
|
|
|
config.loadPlugins()
|
|
|
|
config.parse() # Parse again to add plugin configuration options
|
2015-01-12 02:03:45 +01: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
|
|
|
# Log current config
|
2015-03-19 21:19:14 +01:00
|
|
|
logging.debug("Config: %s" % config)
|
2015-01-12 02:03:45 +01:00
|
|
|
|
2015-08-06 00:51:25 +02:00
|
|
|
# Use pure-python implementation of msgpack to save CPU
|
|
|
|
if config.msgpack_purepython:
|
|
|
|
os.environ["MSGPACK_PUREPYTHON"] = "True"
|
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
|
|
|
|
2015-04-12 23:59:22 +02:00
|
|
|
# Socks Proxy monkey patch
|
|
|
|
if config.proxy:
|
2015-06-17 23:27:56 +02:00
|
|
|
from util import SocksProxy
|
2015-06-18 02:53:01 +02:00
|
|
|
import urllib2
|
2015-06-17 23:27:56 +02:00
|
|
|
logging.info("Patching sockets to socks proxy: %s" % config.proxy)
|
2015-07-12 20:36:46 +02:00
|
|
|
config.fileserver_ip = '127.0.0.1' # Do not accept connections anywhere but localhost
|
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
|
|
|
SocksProxy.monkeyPatch(*config.proxy.split(":"))
|
|
|
|
elif config.tor == "always":
|
|
|
|
from util import SocksProxy
|
|
|
|
import urllib2
|
|
|
|
logging.info("Patching sockets to tor socks proxy: %s" % config.tor_proxy)
|
|
|
|
config.fileserver_ip = '127.0.0.1' # Do not accept connections anywhere but localhost
|
|
|
|
SocksProxy.monkeyPatch(*config.tor_proxy.split(":"))
|
|
|
|
config.disable_udp = True
|
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
|
|
|
# -- Actions --
|
|
|
|
|
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-04-15 02:54:10 +02:00
|
|
|
@PluginManager.acceptPlugins
|
2015-06-17 23:27:56 +02:00
|
|
|
class Actions(object):
|
2015-07-17 00:28:43 +02:00
|
|
|
def call(self, function_name, kwargs):
|
2016-09-07 17:41:09 +02:00
|
|
|
logging.info("Version: %s r%s, Python %s, Gevent: %s" % (config.version, config.rev, sys.version, gevent.__version__))
|
|
|
|
|
2015-07-17 00:28:43 +02:00
|
|
|
func = getattr(self, function_name, None)
|
|
|
|
func(**kwargs)
|
2015-07-12 20:36:46 +02:00
|
|
|
|
2015-07-17 00:28:43 +02:00
|
|
|
# Default action: Start serving UiServer and FileServer
|
2015-06-17 23:27:56 +02:00
|
|
|
def main(self):
|
|
|
|
global ui_server, file_server
|
|
|
|
from File import FileServer
|
|
|
|
from Ui import UiServer
|
2015-09-24 22:08:08 +02:00
|
|
|
logging.info("Creating FileServer....")
|
|
|
|
file_server = FileServer()
|
2015-06-17 23:27:56 +02:00
|
|
|
logging.info("Creating UiServer....")
|
|
|
|
ui_server = UiServer()
|
|
|
|
|
|
|
|
logging.info("Removing old SSL certs...")
|
|
|
|
from Crypt import CryptConnection
|
|
|
|
CryptConnection.manager.removeCerts()
|
|
|
|
|
|
|
|
logging.info("Starting servers....")
|
|
|
|
gevent.joinall([gevent.spawn(ui_server.start), gevent.spawn(file_server.start)])
|
|
|
|
|
|
|
|
# Site commands
|
|
|
|
|
|
|
|
def siteCreate(self):
|
|
|
|
logging.info("Generating new privatekey...")
|
|
|
|
from Crypt import CryptBitcoin
|
|
|
|
privatekey = CryptBitcoin.newPrivatekey()
|
|
|
|
logging.info("----------------------------------------------------------------------")
|
|
|
|
logging.info("Site private key: %s" % privatekey)
|
|
|
|
logging.info(" !!! ^ Save it now, required to modify the site ^ !!!")
|
|
|
|
address = CryptBitcoin.privatekeyToAddress(privatekey)
|
|
|
|
logging.info("Site address: %s" % address)
|
|
|
|
logging.info("----------------------------------------------------------------------")
|
|
|
|
|
2015-09-02 19:15:55 +02:00
|
|
|
while True and not config.batch:
|
2015-07-12 20:36:46 +02:00
|
|
|
if raw_input("? Have you secured your private key? (yes, no) > ").lower() == "yes":
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
logging.info("Please, secure it now, you going to need it to modify your site!")
|
2015-06-17 23:27:56 +02:00
|
|
|
|
|
|
|
logging.info("Creating directory structure...")
|
|
|
|
from Site import Site
|
|
|
|
os.mkdir("%s/%s" % (config.data_dir, address))
|
|
|
|
open("%s/%s/index.html" % (config.data_dir, address), "w").write("Hello %s!" % address)
|
|
|
|
|
|
|
|
logging.info("Creating content.json...")
|
|
|
|
site = Site(address)
|
2016-02-21 11:44:10 +01:00
|
|
|
site.content_manager.sign(privatekey=privatekey, extend={"postmessage_nonce_security": True})
|
2015-06-17 23:27:56 +02:00
|
|
|
site.settings["own"] = True
|
|
|
|
site.saveSettings()
|
|
|
|
|
|
|
|
logging.info("Site created!")
|
|
|
|
|
|
|
|
def siteSign(self, address, privatekey=None, inner_path="content.json", publish=False):
|
|
|
|
from Site import Site
|
|
|
|
logging.info("Signing site: %s..." % address)
|
2015-07-12 20:36:46 +02:00
|
|
|
site = Site(address, allow_create=False)
|
2015-06-17 23:27:56 +02:00
|
|
|
|
2016-03-21 09:43:53 +01:00
|
|
|
if not privatekey: # If no privatekey defined
|
2015-11-08 12:33:13 +01:00
|
|
|
from User import UserManager
|
|
|
|
user = UserManager.user_manager.get()
|
2015-11-28 18:04:59 +01:00
|
|
|
if user:
|
|
|
|
site_data = user.getSiteData(address)
|
|
|
|
privatekey = site_data.get("privatekey")
|
|
|
|
else:
|
|
|
|
privatekey = None
|
2015-11-08 12:33:13 +01:00
|
|
|
if not privatekey:
|
|
|
|
# Not found in users.json, ask from console
|
|
|
|
import getpass
|
|
|
|
privatekey = getpass.getpass("Private key (input hidden):")
|
2016-04-06 13:58:43 +02:00
|
|
|
diffs = site.content_manager.getDiffs(inner_path)
|
2015-06-17 23:27:56 +02:00
|
|
|
succ = site.content_manager.sign(inner_path=inner_path, privatekey=privatekey, update_changed_files=True)
|
|
|
|
if succ and publish:
|
2016-04-06 13:58:43 +02:00
|
|
|
self.sitePublish(address, inner_path=inner_path, diffs=diffs)
|
2015-06-17 23:27:56 +02:00
|
|
|
|
|
|
|
def siteVerify(self, address):
|
|
|
|
import time
|
|
|
|
from Site import Site
|
|
|
|
s = time.time()
|
|
|
|
logging.info("Verifing site: %s..." % address)
|
|
|
|
site = Site(address)
|
|
|
|
bad_files = []
|
|
|
|
|
|
|
|
for content_inner_path in site.content_manager.contents:
|
2016-03-18 19:19:34 +01:00
|
|
|
s = time.time()
|
2015-06-17 23:27:56 +02:00
|
|
|
logging.info("Verifing %s signature..." % content_inner_path)
|
2015-07-12 20:36:46 +02:00
|
|
|
file_correct = site.content_manager.verifyFile(
|
|
|
|
content_inner_path, site.storage.open(content_inner_path, "rb"), ignore_same=False
|
|
|
|
)
|
|
|
|
if file_correct is True:
|
2016-03-19 18:11:12 +01:00
|
|
|
logging.info("[OK] %s (Done in %.3fs)" % (content_inner_path, time.time() - s))
|
2015-06-17 23:27:56 +02:00
|
|
|
else:
|
|
|
|
logging.error("[ERROR] %s: invalid file!" % content_inner_path)
|
2016-08-29 11:17:36 +02:00
|
|
|
raw_input("Continue?")
|
2015-06-17 23:27:56 +02:00
|
|
|
bad_files += content_inner_path
|
|
|
|
|
|
|
|
logging.info("Verifying site files...")
|
|
|
|
bad_files += site.storage.verifyFiles()
|
|
|
|
if not bad_files:
|
2015-07-12 20:36:46 +02:00
|
|
|
logging.info("[OK] All file sha512sum matches! (%.3fs)" % (time.time() - s))
|
2015-06-17 23:27:56 +02:00
|
|
|
else:
|
|
|
|
logging.error("[ERROR] Error during verifying site files!")
|
|
|
|
|
|
|
|
def dbRebuild(self, address):
|
|
|
|
from Site import Site
|
2016-08-10 12:44:17 +02:00
|
|
|
from Site import SiteManager
|
|
|
|
SiteManager.site_manager.load()
|
2015-06-17 23:27:56 +02:00
|
|
|
logging.info("Rebuilding site sql cache: %s..." % address)
|
2016-08-10 12:44:17 +02:00
|
|
|
site = SiteManager.site_manager.get(address)
|
2015-06-17 23:27:56 +02:00
|
|
|
s = time.time()
|
|
|
|
site.storage.rebuildDb()
|
2015-07-12 20:36:46 +02:00
|
|
|
logging.info("Done in %.3fs" % (time.time() - s))
|
2015-06-17 23:27:56 +02:00
|
|
|
|
|
|
|
def dbQuery(self, address, query):
|
|
|
|
from Site import Site
|
|
|
|
import json
|
|
|
|
site = Site(address)
|
|
|
|
result = []
|
|
|
|
for row in site.storage.query(query):
|
|
|
|
result.append(dict(row))
|
|
|
|
print json.dumps(result, indent=4)
|
|
|
|
|
|
|
|
def siteAnnounce(self, address):
|
|
|
|
from Site.Site import Site
|
|
|
|
logging.info("Announcing site %s to tracker..." % address)
|
|
|
|
site = Site(address)
|
|
|
|
|
|
|
|
s = time.time()
|
|
|
|
site.announce()
|
2015-07-12 20:36:46 +02:00
|
|
|
print "Response time: %.3fs" % (time.time() - s)
|
2015-06-17 23:27:56 +02:00
|
|
|
print site.peers
|
|
|
|
|
2016-03-19 18:11:12 +01:00
|
|
|
def siteDownload(self, address):
|
|
|
|
from Site import Site
|
|
|
|
|
|
|
|
logging.info("Opening a simple connection server")
|
|
|
|
global file_server
|
|
|
|
from Connection import ConnectionServer
|
|
|
|
file_server = ConnectionServer("127.0.0.1", 1234)
|
|
|
|
|
|
|
|
site = Site(address)
|
|
|
|
|
|
|
|
on_completed = gevent.event.AsyncResult()
|
|
|
|
|
|
|
|
def onComplete(evt):
|
|
|
|
evt.set(True)
|
|
|
|
|
|
|
|
site.onComplete.once(lambda: onComplete(on_completed))
|
|
|
|
print "Announcing..."
|
|
|
|
site.announce()
|
|
|
|
|
|
|
|
s = time.time()
|
|
|
|
print "Downloading..."
|
|
|
|
site.downloadContent("content.json", check_modifications=True)
|
|
|
|
|
|
|
|
print on_completed.get()
|
|
|
|
print "Downloaded in %.3fs" % (time.time()-s)
|
|
|
|
|
|
|
|
|
2015-06-17 23:27:56 +02:00
|
|
|
def siteNeedFile(self, address, inner_path):
|
|
|
|
from Site import Site
|
2016-03-19 18:11:12 +01:00
|
|
|
|
2016-01-19 20:42:00 +01:00
|
|
|
def checker():
|
|
|
|
while 1:
|
|
|
|
s = time.time()
|
|
|
|
time.sleep(1)
|
2016-03-19 18:11:12 +01:00
|
|
|
print "Switch time:", time.time() - s
|
2016-01-19 20:42:00 +01:00
|
|
|
gevent.spawn(checker)
|
|
|
|
|
|
|
|
logging.info("Opening a simple connection server")
|
|
|
|
global file_server
|
|
|
|
from Connection import ConnectionServer
|
|
|
|
file_server = ConnectionServer("127.0.0.1", 1234)
|
|
|
|
|
2015-06-17 23:27:56 +02:00
|
|
|
site = Site(address)
|
|
|
|
site.announce()
|
|
|
|
print site.needFile(inner_path, update=True)
|
|
|
|
|
2016-04-06 13:58:43 +02:00
|
|
|
def sitePublish(self, address, peer_ip=None, peer_port=15441, inner_path="content.json", diffs={}):
|
2015-06-17 23:27:56 +02:00
|
|
|
global file_server
|
2016-09-28 20:36:02 +02:00
|
|
|
from Site import Site
|
2015-07-12 20:36:46 +02:00
|
|
|
from File import FileServer # We need fileserver to handle incoming file requests
|
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
|
|
|
from Peer import Peer
|
2015-06-17 23:27:56 +02:00
|
|
|
|
2015-12-12 16:39:22 +01:00
|
|
|
logging.info("Loading site...")
|
2016-09-28 20:36:02 +02:00
|
|
|
site = Site(address, allow_create=False)
|
2015-07-12 20:36:46 +02:00
|
|
|
site.settings["serving"] = True # Serving the site even if its disabled
|
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
|
|
|
|
2015-12-12 16:39:22 +01:00
|
|
|
logging.info("Creating FileServer....")
|
|
|
|
file_server = FileServer()
|
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
|
|
|
site.connection_server = file_server
|
2015-12-12 16:39:22 +01:00
|
|
|
file_server_thread = gevent.spawn(file_server.start, check_sites=False) # Dont check every site integrity
|
2016-03-16 00:34:57 +01:00
|
|
|
time.sleep(0.001)
|
2015-12-12 16:39:22 +01:00
|
|
|
|
|
|
|
if not file_server_thread.ready():
|
|
|
|
# Started fileserver
|
|
|
|
file_server.openport()
|
|
|
|
if peer_ip: # Announce ip specificed
|
|
|
|
site.addPeer(peer_ip, peer_port)
|
|
|
|
else: # Just ask the tracker
|
|
|
|
logging.info("Gathering peers from tracker")
|
|
|
|
site.announce() # Gather peers
|
2016-04-25 02:24:30 +02:00
|
|
|
published = site.publish(5, inner_path, diffs=diffs) # Push to peers
|
2015-12-12 16:39:22 +01:00
|
|
|
if published > 0:
|
|
|
|
time.sleep(3)
|
|
|
|
logging.info("Serving files (max 60s)...")
|
|
|
|
gevent.joinall([file_server_thread], timeout=60)
|
|
|
|
logging.info("Done.")
|
|
|
|
else:
|
|
|
|
logging.info("No peers found, sitePublish command only works if you already have visitors serving your site")
|
|
|
|
else:
|
2016-04-25 02:24:30 +02:00
|
|
|
# Already running, notify local client on new content
|
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
|
|
|
logging.info("Sending siteReload")
|
2015-12-12 16:39:22 +01:00
|
|
|
my_peer = Peer("127.0.0.1", config.fileserver_port)
|
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
|
|
|
logging.info(my_peer.request("siteReload", {"site": site.address, "inner_path": inner_path}))
|
2015-12-12 16:39:22 +01:00
|
|
|
logging.info("Sending sitePublish")
|
2016-04-06 13:58:43 +02:00
|
|
|
logging.info(my_peer.request("sitePublish", {"site": site.address, "inner_path": inner_path, "diffs": diffs}))
|
2015-06-17 23:27:56 +02:00
|
|
|
logging.info("Done.")
|
2015-12-12 16:39:22 +01:00
|
|
|
|
2015-06-17 23:27:56 +02:00
|
|
|
# Crypto commands
|
|
|
|
def cryptPrivatekeyToAddress(self, privatekey=None):
|
|
|
|
from Crypt import CryptBitcoin
|
2015-07-12 20:36:46 +02:00
|
|
|
if not privatekey: # If no privatekey in args then ask it now
|
2015-06-17 23:27:56 +02:00
|
|
|
import getpass
|
|
|
|
privatekey = getpass.getpass("Private key (input hidden):")
|
|
|
|
|
|
|
|
print CryptBitcoin.privatekeyToAddress(privatekey)
|
|
|
|
|
|
|
|
def cryptSign(self, message, privatekey):
|
|
|
|
from Crypt import CryptBitcoin
|
|
|
|
print CryptBitcoin.sign(message, privatekey)
|
|
|
|
|
|
|
|
# Peer
|
|
|
|
def peerPing(self, peer_ip, peer_port=None):
|
|
|
|
if not peer_port:
|
|
|
|
peer_port = config.fileserver_port
|
|
|
|
logging.info("Opening a simple connection server")
|
|
|
|
global file_server
|
|
|
|
from Connection import ConnectionServer
|
|
|
|
file_server = ConnectionServer("127.0.0.1", 1234)
|
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
|
|
|
from Crypt import CryptConnection
|
|
|
|
CryptConnection.manager.loadCerts()
|
2015-06-17 23:27:56 +02:00
|
|
|
|
|
|
|
from Peer import Peer
|
|
|
|
logging.info("Pinging 5 times peer: %s:%s..." % (peer_ip, int(peer_port)))
|
|
|
|
peer = Peer(peer_ip, peer_port)
|
|
|
|
for i in range(5):
|
2016-03-01 23:16:31 +01:00
|
|
|
print "Response time: %.3fs (crypt: %s)" % (peer.ping(), peer.connection.crypt)
|
2015-06-17 23:27:56 +02:00
|
|
|
time.sleep(1)
|
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
|
|
|
peer.remove()
|
|
|
|
print "Reconnect test..."
|
|
|
|
peer = Peer(peer_ip, peer_port)
|
|
|
|
for i in range(5):
|
2016-03-01 23:16:31 +01:00
|
|
|
print "Response time: %.3fs (crypt: %s)" % (peer.ping(), peer.connection.crypt)
|
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
|
|
|
time.sleep(1)
|
2015-06-17 23:27:56 +02:00
|
|
|
|
2015-07-25 13:38:58 +02:00
|
|
|
def peerGetFile(self, peer_ip, peer_port, site, filename, benchmark=False):
|
2015-06-17 23:27:56 +02:00
|
|
|
logging.info("Opening a simple connection server")
|
|
|
|
global file_server
|
|
|
|
from Connection import ConnectionServer
|
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
|
|
|
file_server = ConnectionServer("127.0.0.1", 1234)
|
|
|
|
from Crypt import CryptConnection
|
|
|
|
CryptConnection.manager.loadCerts()
|
2015-06-17 23:27:56 +02:00
|
|
|
|
|
|
|
from Peer import Peer
|
|
|
|
logging.info("Getting %s/%s from peer: %s:%s..." % (site, filename, peer_ip, peer_port))
|
|
|
|
peer = Peer(peer_ip, peer_port)
|
|
|
|
s = time.time()
|
2015-07-25 13:38:58 +02:00
|
|
|
if benchmark:
|
|
|
|
for i in range(10):
|
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
|
|
|
peer.getFile(site, filename),
|
2015-07-25 13:38:58 +02:00
|
|
|
print "Response time: %.3fs" % (time.time() - s)
|
|
|
|
raw_input("Check memory")
|
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
|
|
|
else:
|
|
|
|
print peer.getFile(site, filename).read()
|
2015-07-25 13:38:58 +02:00
|
|
|
|
2015-06-17 23:27:56 +02:00
|
|
|
def peerCmd(self, peer_ip, peer_port, cmd, parameters):
|
|
|
|
logging.info("Opening a simple connection server")
|
|
|
|
global file_server
|
|
|
|
from Connection import ConnectionServer
|
|
|
|
file_server = ConnectionServer()
|
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
|
|
|
from Crypt import CryptConnection
|
|
|
|
CryptConnection.manager.loadCerts()
|
|
|
|
|
2015-06-17 23:27:56 +02:00
|
|
|
from Peer import Peer
|
|
|
|
peer = Peer(peer_ip, peer_port)
|
|
|
|
|
|
|
|
import json
|
|
|
|
if parameters:
|
|
|
|
parameters = json.loads(parameters.replace("'", '"'))
|
|
|
|
else:
|
|
|
|
parameters = {}
|
|
|
|
logging.info("Response: %s" % peer.request(cmd, parameters))
|
rev125, Class statistics, OpenSSL disabled on OSX by default because of possible segfault, --disable_openssl command line parameter, Save memory on Connection, Peer and FileRequest objects using slots, Dont store modification time from the far future, Able to query modified files from peer, Allow reannounce in 30secs, Use with command in SiteStorage, Always create dir before write file, PeerCmd shell command to query specific command from peer
2015-04-29 23:12:45 +02:00
|
|
|
|
|
|
|
|
2015-04-15 02:54:10 +02:00
|
|
|
actions = Actions()
|
|
|
|
# Starts here when running zeronet.py
|
2015-07-12 20:36:46 +02:00
|
|
|
|
|
|
|
|
2015-04-15 02:54:10 +02:00
|
|
|
def start():
|
2015-06-17 23:27:56 +02:00
|
|
|
# Call function
|
|
|
|
action_kwargs = config.getActionArguments()
|
2015-07-17 00:28:43 +02:00
|
|
|
actions.call(config.action, action_kwargs)
|