Skip to content

Commit

Permalink
Rev903, FeedQuery command only available for ADMIN sites, Show bad fi…
Browse files Browse the repository at this point in the history
…les in sidebar, Log unknown messages, Add and check inner_path and site address on sign/verify, Better peer cleanup limit, Log site load times, Testcase for address and inner_path verification, Re-sign testsite with new fields, Fix unnecessary loading screen display when browsing sub-folder with index.html, Fix safari notification width
  • Loading branch information
shortcutme committed Feb 18, 2016
1 parent 4885d2b commit 1dbc334
Show file tree
Hide file tree
Showing 20 changed files with 218 additions and 123 deletions.
3 changes: 3 additions & 0 deletions plugins/Newsfeed/NewsfeedPlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ def actionFeedListFollow(self, to):
self.response(to, feeds)

def actionFeedQuery(self, to):
if "ADMIN" not in self.site.settings["permissions"]:
return self.response(to, "FeedQuery not allowed")

from Site import SiteManager
rows = []
for address, site_data in self.user.sites.iteritems():
Expand Down
17 changes: 17 additions & 0 deletions plugins/Sidebar/SidebarPlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,21 @@ def sidebarRenderOptionalFileSettings(self, body, site):
</li>
""".format(**locals()))

def sidebarRenderBadFiles(self, body, site):
body.append("""
<li>
<label>Missing files:</label>
<ul class='filelist'>
""")

for bad_file in site.bad_files.keys():
body.append("<li class='color-red'>%s</li>" % bad_file)

body.append("""
</ul>
</li>
""")

def sidebarRenderDbOptions(self, body, site):
if not site.storage.db:
return False
Expand Down Expand Up @@ -352,6 +367,8 @@ def actionSidebarGetHtmlTag(self, to):
has_optional = self.sidebarRenderOptionalFileStats(body, site)
if has_optional:
self.sidebarRenderOptionalFileSettings(body, site)
if site.bad_files:
self.sidebarRenderBadFiles(body, site)
self.sidebarRenderDbOptions(body, site)
self.sidebarRenderIdentity(body, site)

Expand Down
3 changes: 3 additions & 0 deletions plugins/Sidebar/media/Sidebar.css
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@
.graph-legend b { text-align: right; display: inline-block; width: 50px; float: right; font-weight: normal; }
.graph-legend li:before { content: '\2022'; font-size: 23px; line-height: 0px; vertical-align: -3px; margin-right: 5px; }

.filelist { font-size: 12px; font-family: monospace; margin: 0px; padding: 0px; list-style-type: none; line-height: 1.5em; }
.filelist li:before { content: '\2022'; font-size: 11px; line-height: 0px; vertical-align: 0px; margin-right: 5px; color: #FFBE00; }

/* COLORS */

.back-green { background-color: #2ECC71 }
Expand Down
3 changes: 3 additions & 0 deletions plugins/Sidebar/media/all.css
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@
.graph-legend b { text-align: right; display: inline-block; width: 50px; float: right; font-weight: normal; }
.graph-legend li:before { content: '\2022'; font-size: 23px; line-height: 0px; vertical-align: -3px; margin-right: 5px; }

.filelist { font-size: 12px; font-family: monospace; margin: 0px; padding: 0px; list-style-type: none; line-height: 1.5em; }
.filelist li:before { content: '\2022'; font-size: 11px; line-height: 0px; vertical-align: 0px; margin-right: 5px; color: #FFBE00; }

/* COLORS */

.back-green { background-color: #2ECC71 }
Expand Down
2 changes: 1 addition & 1 deletion src/Config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Config(object):

def __init__(self, argv):
self.version = "0.3.6"
self.rev = 900
self.rev = 903
self.argv = argv
self.action = None
self.config_file = "zeronet.conf"
Expand Down
9 changes: 5 additions & 4 deletions src/Connection/Connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,10 +257,11 @@ def handleMessage(self, message):
self.server.handleRequest(self, message)
else: # Old style response, no req_id definied
if config.debug_socket:
self.log("Old style response, waiting: %s" % self.waiting_requests.keys())
last_req_id = min(self.waiting_requests.keys()) # Get the oldest waiting request and set it true
self.waiting_requests[last_req_id].set(message)
del self.waiting_requests[last_req_id] # Remove from waiting request
self.log("Unknown message: %s, waiting: %s" % (message, self.waiting_requests.keys()))
if self.waiting_requests:
last_req_id = min(self.waiting_requests.keys()) # Get the oldest waiting request and set it true
self.waiting_requests[last_req_id].set(message)
del self.waiting_requests[last_req_id] # Remove from waiting request

# Incoming handshake set request
def handleHandshake(self, message):
Expand Down
14 changes: 13 additions & 1 deletion src/Content/ContentManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,10 +379,12 @@ def sign(self, inner_path="content.json", privatekey=None, filewrite=True, updat

new_content["modified"] = time.time() # Add timestamp
if inner_path == "content.json":
new_content["address"] = self.site.address
new_content["zeronet_version"] = config.version
new_content["signs_required"] = content.get("signs_required", 1)

new_content["address"] = self.site.address
new_content["inner_path"] = inner_path

# Verify private key
from Crypt import CryptBitcoin
self.log.info("Verifying private key...")
Expand Down Expand Up @@ -484,6 +486,16 @@ def verifyContent(self, inner_path, content):

site_size_limit = self.site.getSizeLimit() * 1024 * 1024

# Check site address
if content.get("address") and content["address"] != self.site.address:
self.log.error("%s: Wrong site address: %s != %s" % (inner_path, content["address"], self.site.address))
return False

# Check file inner path
if content.get("inner_path") and content["inner_path"] != inner_path:
self.log.error("%s: Wrong inner_path: %s" % (inner_path, content["inner_path"]))
return False

# Check total site size limit
if site_size > site_size_limit:
self.log.error("%s: Site too large %s > %s, aborting task..." % (inner_path, site_size, site_size_limit))
Expand Down
2 changes: 1 addition & 1 deletion src/Site/Site.py
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,7 @@ def cleanupPeers(self):
if time.time() - peer.time_found > 60 * 60 * 4: # Not found on tracker or via pex in last 4 hour
peer.remove()
removed += 1
if removed > 5: # Don't remove too much at once
if removed > len(peers)*0.1: # Don't remove too much at once
break

if removed:
Expand Down
5 changes: 4 additions & 1 deletion src/Site/SiteManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import logging
import re
import os
import time

from Plugin import PluginManager
from Config import config
Expand All @@ -23,7 +24,9 @@ def load(self):
# Load new adresses
for address in json.load(open("%s/sites.json" % config.data_dir)):
if address not in self.sites and os.path.isfile("%s/%s/content.json" % (config.data_dir, address)):
s = time.time()
self.sites[address] = Site(address)
logging.debug("Loaded site %s in %.3fs" % (address, time.time()-s))
added += 1
address_found.append(address)

Expand Down Expand Up @@ -77,8 +80,8 @@ def delete(self, address):

# Lazy load sites
def list(self):
logging.debug("Loading sites...")
if self.sites is None: # Not loaded yet
logging.debug("Loading sites...")
self.load()
return self.sites

Expand Down
41 changes: 41 additions & 0 deletions src/Test/TestContent.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,44 @@ def testFileInfo(self, site):
file_info_optional = site.content_manager.getFileInfo("data/users/1CjfbrbwtP8Y2QjPy12vpTATkUT7oSiPQ9/peanut-butter-jelly-time.gif")
assert "sha512" in file_info_optional
assert file_info_optional["optional"] is True

def testVerify(self, site):
privatekey = "5KUh3PvNm5HUWoCfSUfcYvfQ2g3PrRNJWr6Q9eqdBGu23mtMntv"
inner_path = "data/test_include/content.json"
data_dict = site.content_manager.contents[inner_path]
data = StringIO(json.dumps(data_dict))

# Re-sign
data_dict["signs"] = {
"1TeSTvb4w2PWE81S2rEELgmX2GCCExQGT": CryptBitcoin.sign(json.dumps(data_dict, sort_keys=True), privatekey)
}
assert site.content_manager.verifyFile(inner_path, data, ignore_same=False)

# Wrong address
data_dict["address"] = "Othersite"
del data_dict["signs"]
data_dict["signs"] = {
"1TeSTvb4w2PWE81S2rEELgmX2GCCExQGT": CryptBitcoin.sign(json.dumps(data_dict, sort_keys=True), privatekey)
}
data = StringIO(json.dumps(data_dict))
assert not site.content_manager.verifyFile(inner_path, data, ignore_same=False)

# Wrong inner_path
data_dict["address"] = "1TeSTvb4w2PWE81S2rEELgmX2GCCExQGT"
data_dict["inner_path"] = "content.json"
del data_dict["signs"]
data_dict["signs"] = {
"1TeSTvb4w2PWE81S2rEELgmX2GCCExQGT": CryptBitcoin.sign(json.dumps(data_dict, sort_keys=True), privatekey)
}
data = StringIO(json.dumps(data_dict))
assert not site.content_manager.verifyFile(inner_path, data, ignore_same=False)

# Everything right again
data_dict["address"] = "1TeSTvb4w2PWE81S2rEELgmX2GCCExQGT"
data_dict["inner_path"] = inner_path
del data_dict["signs"]
data_dict["signs"] = {
"1TeSTvb4w2PWE81S2rEELgmX2GCCExQGT": CryptBitcoin.sign(json.dumps(data_dict, sort_keys=True), privatekey)
}
data = StringIO(json.dumps(data_dict))
assert site.content_manager.verifyFile(inner_path, data, ignore_same=False)
Loading

0 comments on commit 1dbc334

Please sign in to comment.