Remove renamed Mute plugin
This commit is contained in:
parent
fc46bb65f8
commit
283231ac6e
10 changed files with 0 additions and 354 deletions
|
@ -1,160 +0,0 @@
|
|||
import time
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
|
||||
from Plugin import PluginManager
|
||||
from Translate import Translate
|
||||
from Config import config
|
||||
from util import helper
|
||||
|
||||
|
||||
if os.path.isfile("%s/mutes.json" % config.data_dir):
|
||||
try:
|
||||
data = json.load(open("%s/mutes.json" % config.data_dir))
|
||||
mutes = data.get("mutes", {})
|
||||
site_blacklist = data.get("site_blacklist", {})
|
||||
except Exception as err:
|
||||
mutes = {}
|
||||
site_blacklist = {}
|
||||
else:
|
||||
open("%s/mutes.json" % config.data_dir, "w").write('{"mutes": {}, "site_blacklist": {}}')
|
||||
mutes = {}
|
||||
site_blacklist = {}
|
||||
|
||||
if "_" not in locals():
|
||||
_ = Translate("plugins/Mute/languages/")
|
||||
|
||||
|
||||
@PluginManager.registerTo("UiWebsocket")
|
||||
class UiWebsocketPlugin(object):
|
||||
# Search and remove or readd files of an user
|
||||
def changeDb(self, auth_address, action):
|
||||
self.log.debug("Mute action %s on user %s" % (action, auth_address))
|
||||
res = self.site.content_manager.contents.db.execute(
|
||||
"SELECT * FROM content LEFT JOIN site USING (site_id) WHERE inner_path LIKE :inner_path",
|
||||
{"inner_path": "%%/%s/%%" % auth_address}
|
||||
)
|
||||
for row in res:
|
||||
site = self.server.sites.get(row["address"])
|
||||
if not site:
|
||||
continue
|
||||
dir_inner_path = helper.getDirname(row["inner_path"])
|
||||
for file_name in site.storage.walk(dir_inner_path):
|
||||
if action == "remove":
|
||||
site.storage.onUpdated(dir_inner_path + file_name, False)
|
||||
else:
|
||||
site.storage.onUpdated(dir_inner_path + file_name)
|
||||
site.onFileDone(dir_inner_path + file_name)
|
||||
|
||||
def cbMuteAdd(self, to, auth_address, cert_user_id, reason):
|
||||
mutes[auth_address] = {"cert_user_id": cert_user_id, "reason": reason, "source": self.site.address, "date_added": time.time()}
|
||||
self.saveMutes()
|
||||
self.changeDb(auth_address, "remove")
|
||||
self.response(to, "ok")
|
||||
|
||||
def actionMuteAdd(self, to, auth_address, cert_user_id, reason):
|
||||
if "ADMIN" in self.getPermissions(to):
|
||||
self.cbMuteAdd(to, auth_address, cert_user_id, reason)
|
||||
else:
|
||||
self.cmd(
|
||||
"confirm",
|
||||
[_["Hide all content from <b>%s</b>?"] % cert_user_id, _["Mute"]],
|
||||
lambda (res): self.cbMuteAdd(to, auth_address, cert_user_id, reason)
|
||||
)
|
||||
|
||||
def cbMuteRemove(self, to, auth_address):
|
||||
del mutes[auth_address]
|
||||
self.saveMutes()
|
||||
self.changeDb(auth_address, "load")
|
||||
self.response(to, "ok")
|
||||
|
||||
def actionMuteRemove(self, to, auth_address):
|
||||
if "ADMIN" in self.getPermissions(to):
|
||||
self.cbMuteRemove(to, auth_address)
|
||||
else:
|
||||
self.cmd(
|
||||
"confirm",
|
||||
[_["Unmute <b>%s</b>?"] % mutes[auth_address]["cert_user_id"], _["Unmute"]],
|
||||
lambda (res): self.cbMuteRemove(to, auth_address)
|
||||
)
|
||||
|
||||
def actionMuteList(self, to):
|
||||
if "ADMIN" in self.getPermissions(to):
|
||||
self.response(to, mutes)
|
||||
else:
|
||||
return self.response(to, {"error": "Only ADMIN sites can list mutes"})
|
||||
|
||||
# Blacklist
|
||||
def actionBlacklistAdd(self, to, site_address, reason=None):
|
||||
if "ADMIN" not in self.getPermissions(to):
|
||||
return self.response(to, {"error": "Forbidden, only admin sites can add to blacklist"})
|
||||
site_blacklist[site_address] = {"date_added": time.time(), "reason": reason}
|
||||
self.saveMutes()
|
||||
self.response(to, "ok")
|
||||
|
||||
def actionBlacklistRemove(self, to, site_address):
|
||||
if "ADMIN" not in self.getPermissions(to):
|
||||
return self.response(to, {"error": "Forbidden, only admin sites can remove from blacklist"})
|
||||
del site_blacklist[site_address]
|
||||
self.saveMutes()
|
||||
self.response(to, "ok")
|
||||
|
||||
def actionBlacklistList(self, to):
|
||||
if "ADMIN" in self.getPermissions(to):
|
||||
self.response(to, site_blacklist)
|
||||
else:
|
||||
return self.response(to, {"error": "Only ADMIN sites can list blacklists"})
|
||||
|
||||
# Write mutes and blacklist to json file
|
||||
def saveMutes(self):
|
||||
helper.atomicWrite("%s/mutes.json" % config.data_dir, json.dumps({"mutes": mutes, "site_blacklist": site_blacklist}, indent=2, sort_keys=True))
|
||||
|
||||
|
||||
@PluginManager.registerTo("SiteStorage")
|
||||
class SiteStoragePlugin(object):
|
||||
def updateDbFile(self, inner_path, file=None, cur=None):
|
||||
if file is not False: # File deletion always allowed
|
||||
# Find for bitcoin addresses in file path
|
||||
matches = re.findall("/(1[A-Za-z0-9]{26,35})/", inner_path)
|
||||
# Check if any of the adresses are in the mute list
|
||||
for auth_address in matches:
|
||||
if auth_address in mutes:
|
||||
self.log.debug("Mute match: %s, ignoring %s" % (auth_address, inner_path))
|
||||
return False
|
||||
|
||||
return super(SiteStoragePlugin, self).updateDbFile(inner_path, file=file, cur=cur)
|
||||
|
||||
|
||||
@PluginManager.registerTo("UiRequest")
|
||||
class UiRequestPlugin(object):
|
||||
def actionWrapper(self, path, extra_headers=None):
|
||||
match = re.match("/(?P<address>[A-Za-z0-9\._-]+)(?P<inner_path>/.*|$)", path)
|
||||
if not match:
|
||||
return False
|
||||
address = match.group("address")
|
||||
|
||||
if self.server.site_manager.get(address): # Site already exists
|
||||
return super(UiRequestPlugin, self).actionWrapper(path, extra_headers)
|
||||
|
||||
if self.server.site_manager.isDomain(address):
|
||||
address = self.server.site_manager.resolveDomain(address)
|
||||
|
||||
if address in site_blacklist:
|
||||
site = self.server.site_manager.get(config.homepage)
|
||||
if not extra_headers:
|
||||
extra_headers = {}
|
||||
self.sendHeader(extra_headers=extra_headers)
|
||||
return iter([super(UiRequestPlugin, self).renderWrapper(
|
||||
site, path, "uimedia/plugins/mute/blacklisted.html?address=" + address,
|
||||
"Blacklisted site", extra_headers, show_loadingscreen=False
|
||||
)])
|
||||
else:
|
||||
return super(UiRequestPlugin, self).actionWrapper(path, extra_headers)
|
||||
|
||||
def actionUiMedia(self, path, *args, **kwargs):
|
||||
if path.startswith("/uimedia/plugins/mute/"):
|
||||
file_path = path.replace("/uimedia/plugins/mute/", "plugins/Mute/media/")
|
||||
return self.actionFile(file_path)
|
||||
else:
|
||||
return super(UiRequestPlugin, self).actionUiMedia(path)
|
|
@ -1 +0,0 @@
|
|||
import MutePlugin
|
|
@ -1,6 +0,0 @@
|
|||
{
|
||||
"Hide all content from <b>%s</b>?": "Esconder todo el contenido de <b>%s</b>?",
|
||||
"Mute": "Silenciar",
|
||||
"Unmute <b>%s</b>?": "Mostrar todo el contenido de <b>%s</b>?",
|
||||
"Unmute": "Reactivar"
|
||||
}
|
|
@ -1,6 +0,0 @@
|
|||
{
|
||||
"Hide all content from <b>%s</b>?": "<b>%s</b> tartalmaniak elrejtése?",
|
||||
"Mute": "Elnémítás",
|
||||
"Unmute <b>%s</b>?": "<b>%s</b> tartalmaniak megjelenítése?",
|
||||
"Unmute": "Némítás visszavonása"
|
||||
}
|
|
@ -1,6 +0,0 @@
|
|||
{
|
||||
"Hide all content from <b>%s</b>?": "<b>%s</b> Vuoi nascondere i contenuti di questo utente ?",
|
||||
"Mute": "Attiva Silenzia",
|
||||
"Unmute <b>%s</b>?": "<b>%s</b> Vuoi mostrare i contenuti di questo utente ?",
|
||||
"Unmute": "Disattiva Silenzia"
|
||||
}
|
|
@ -1,6 +0,0 @@
|
|||
{
|
||||
"Hide all content from <b>%s</b>?": "Esconder todo conteúdo de <b>%s</b>?",
|
||||
"Mute": "Ativar mudo",
|
||||
"Unmute <b>%s</b>?": "Mostrar o contéudo de <b>%s</b>?",
|
||||
"Unmute": "Desativar mudo"
|
||||
}
|
|
@ -1,6 +0,0 @@
|
|||
{
|
||||
"Hide all content from <b>%s</b>?": "屏蔽 <b>%s</b> 的所有內容?",
|
||||
"Mute": "屏蔽",
|
||||
"Unmute <b>%s</b>?": "對 <b>%s</b> 解除屏蔽?",
|
||||
"Unmute": "解除屏蔽"
|
||||
}
|
|
@ -1,6 +0,0 @@
|
|||
{
|
||||
"Hide all content from <b>%s</b>?": "屏蔽 <b>%s</b> 的所有内容?",
|
||||
"Mute": "屏蔽",
|
||||
"Unmute <b>%s</b>?": "对 <b>%s</b> 解除屏蔽?",
|
||||
"Unmute": "解除屏蔽"
|
||||
}
|
|
@ -1,64 +0,0 @@
|
|||
<html>
|
||||
<body>
|
||||
|
||||
<style>
|
||||
.content { line-height: 24px; font-family: monospace; font-size: 14px; color: #636363; text-transform: uppercase; top: 38%; position: relative; text-align: center; perspective: 1000px }
|
||||
.content h1, .content h2 { font-weight: normal; letter-spacing: 1px; }
|
||||
.content h2 { font-size: 15px; }
|
||||
.content #details {
|
||||
text-align: left; display: inline-block; width: 350px; background-color: white; padding: 17px 27px; border-radius: 0px;
|
||||
box-shadow: 0px 2px 7px -1px #d8d8d8; text-transform: none; margin: 15px; transform: scale(0) rotateX(90deg); transition: all 0.6s cubic-bezier(0.785, 0.135, 0.15, 0.86);
|
||||
}
|
||||
.content #details #added { font-size: 12px; text-align: right; color: #a9a9a9; }
|
||||
|
||||
#button { transition: all 1s cubic-bezier(0.075, 0.82, 0.165, 1); opacity: 0; transform: translateY(50px); transition-delay: 0.5s }
|
||||
.button {
|
||||
padding: 8px 20px; background-color: #FFF85F; border-bottom: 2px solid #CDBD1E; border-radius: 2px;
|
||||
text-decoration: none; transition: all 0.5s; background-position: left center; display: inline-block; margin-top: 10px; color: black;
|
||||
}
|
||||
.button:hover { background-color: #FFF400; border-bottom: 2px solid #4D4D4C; transition: none; }
|
||||
.button:active { position: relative; top: 1px; }
|
||||
.button:focus { outline: none; }
|
||||
|
||||
</style>
|
||||
|
||||
<div class="content">
|
||||
<h1>Site blocked</h1>
|
||||
<h2>This site is on your blacklist:</h2>
|
||||
<div id="details">
|
||||
<div id="reason">Too much image</div>
|
||||
<div id="added">on 2015-01-25 12:32:11</div>
|
||||
</div>
|
||||
<div><a href="#Visit+Site" class="button button-submit" id="button">Remove from blacklist</a></div>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript" src="js/ZeroFrame.js"></script>
|
||||
|
||||
<script>
|
||||
class Page extends ZeroFrame {
|
||||
onOpenWebsocket () {
|
||||
this.cmd("wrapperSetTitle", "Blacklisted site - ZeroNet")
|
||||
this.cmd("siteInfo", {}, (site_info) => {
|
||||
this.site_info = site_info
|
||||
})
|
||||
this.cmd("blacklistList", {}, (blacklists) => {
|
||||
this.blacklists = blacklists
|
||||
var address = document.location.search.match(/address=(.*?)[&\?]/)[1]
|
||||
var reason = blacklists[address]["reason"]
|
||||
if (!reason) reason = "Unknown reason"
|
||||
var date = new Date(blacklists[address]["date_added"] * 1000)
|
||||
document.getElementById("reason").innerText = reason
|
||||
document.getElementById("added").innerText = "at " + date.toLocaleDateString() + " " + date.toLocaleTimeString()
|
||||
document.getElementById("details").style.transform = "scale(1) rotateX(0deg)"
|
||||
document.getElementById("button").style.transform = "translateY(0)"
|
||||
document.getElementById("button").style.opacity = "1"
|
||||
document.getElementById("button").onclick = () => {
|
||||
this.cmd("blacklistRemove", address, () => { this.cmd("wrapperReload") })
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
page = new Page()
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -1,93 +0,0 @@
|
|||
const CMD_INNER_READY = 'innerReady'
|
||||
const CMD_RESPONSE = 'response'
|
||||
const CMD_WRAPPER_READY = 'wrapperReady'
|
||||
const CMD_PING = 'ping'
|
||||
const CMD_PONG = 'pong'
|
||||
const CMD_WRAPPER_OPENED_WEBSOCKET = 'wrapperOpenedWebsocket'
|
||||
const CMD_WRAPPER_CLOSE_WEBSOCKET = 'wrapperClosedWebsocket'
|
||||
|
||||
class ZeroFrame {
|
||||
constructor(url) {
|
||||
this.url = url
|
||||
this.waiting_cb = {}
|
||||
this.wrapper_nonce = document.location.href.replace(/.*wrapper_nonce=([A-Za-z0-9]+).*/, "$1")
|
||||
this.connect()
|
||||
this.next_message_id = 1
|
||||
this.init()
|
||||
}
|
||||
|
||||
init() {
|
||||
return this
|
||||
}
|
||||
|
||||
connect() {
|
||||
this.target = window.parent
|
||||
window.addEventListener('message', e => this.onMessage(e), false)
|
||||
this.cmd(CMD_INNER_READY)
|
||||
}
|
||||
|
||||
onMessage(e) {
|
||||
let message = e.data
|
||||
let cmd = message.cmd
|
||||
if (cmd === CMD_RESPONSE) {
|
||||
if (this.waiting_cb[message.to] !== undefined) {
|
||||
this.waiting_cb[message.to](message.result)
|
||||
}
|
||||
else {
|
||||
this.log("Websocket callback not found:", message)
|
||||
}
|
||||
} else if (cmd === CMD_WRAPPER_READY) {
|
||||
this.cmd(CMD_INNER_READY)
|
||||
} else if (cmd === CMD_PING) {
|
||||
this.response(message.id, CMD_PONG)
|
||||
} else if (cmd === CMD_WRAPPER_OPENED_WEBSOCKET) {
|
||||
this.onOpenWebsocket()
|
||||
} else if (cmd === CMD_WRAPPER_CLOSE_WEBSOCKET) {
|
||||
this.onCloseWebsocket()
|
||||
} else {
|
||||
this.onRequest(cmd, message)
|
||||
}
|
||||
}
|
||||
|
||||
onRequest(cmd, message) {
|
||||
this.log("Unknown request", message)
|
||||
}
|
||||
|
||||
response(to, result) {
|
||||
this.send({
|
||||
cmd: CMD_RESPONSE,
|
||||
to: to,
|
||||
result: result
|
||||
})
|
||||
}
|
||||
|
||||
cmd(cmd, params={}, cb=null) {
|
||||
this.send({
|
||||
cmd: cmd,
|
||||
params: params
|
||||
}, cb)
|
||||
}
|
||||
|
||||
send(message, cb=null) {
|
||||
message.wrapper_nonce = this.wrapper_nonce
|
||||
message.id = this.next_message_id
|
||||
this.next_message_id++
|
||||
this.target.postMessage(message, '*')
|
||||
if (cb) {
|
||||
this.waiting_cb[message.id] = cb
|
||||
}
|
||||
}
|
||||
|
||||
log(...args) {
|
||||
console.log.apply(console, ['[ZeroFrame]'].concat(args))
|
||||
}
|
||||
|
||||
onOpenWebsocket() {
|
||||
this.log('Websocket open')
|
||||
}
|
||||
|
||||
onCloseWebsocket() {
|
||||
this.log('Websocket close')
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in a new issue