Different answer is given when server is requested with HTTP GET
This commit is contained in:
parent
d6eb5259d2
commit
181083eec7
@ -107,12 +107,14 @@ en = {
|
|||||||
"server-isolate-room-argument" : 'should rooms be isolated?',
|
"server-isolate-room-argument" : 'should rooms be isolated?',
|
||||||
"server-motd-argument": "path to file from which motd will be fetched",
|
"server-motd-argument": "path to file from which motd will be fetched",
|
||||||
"server-messed-up-motd": "Message of the Day has unescaped placeholders. All $ signs should be doubled ($$).",
|
"server-messed-up-motd": "Message of the Day has unescaped placeholders. All $ signs should be doubled ($$).",
|
||||||
|
"server-http-reply-argument": "path to file from which http reply will be fetched",
|
||||||
|
"server-default-http-reply": "This server should not be requested with your browser, but Syncplay software available from http://syncplay.pl",
|
||||||
|
|
||||||
#Server errors
|
#Server errors
|
||||||
"unknown-command-server-error" : "Unknown command\n%s", #message
|
"unknown-command-server-error" : "Unknown command {}", #message
|
||||||
"not-json-server-error" : "Not a json encoded string\n%s", #message
|
"not-json-server-error" : "Not a json encoded string {}", #message
|
||||||
"not-known-server-error" : "You must be known to server before sending this command",
|
"not-known-server-error" : "You must be known to server before sending this command",
|
||||||
"client-drop-server-error" : "Client drop: %s -- %s", #host, error
|
"client-drop-server-error" : "Client drop: {} -- {}", #host, error
|
||||||
"password-required-server-error" : "Password required",
|
"password-required-server-error" : "Password required",
|
||||||
"wrong-password-server-error" : "Wrong password supplied",
|
"wrong-password-server-error" : "Wrong password supplied",
|
||||||
"hello-server-error" : "Not enough Hello arguments",
|
"hello-server-error" : "Not enough Hello arguments",
|
||||||
|
|||||||
@ -39,7 +39,11 @@ class JSONCommandProtocol(LineReceiver):
|
|||||||
try:
|
try:
|
||||||
messages = json.loads(line)
|
messages = json.loads(line)
|
||||||
except:
|
except:
|
||||||
self.dropWithError(getMessage("en", "not-json-server-error").format(line))
|
if ("GET / HTTP/1." in line):
|
||||||
|
self.handleHttpRequest(line)
|
||||||
|
self.drop()
|
||||||
|
else:
|
||||||
|
self.dropWithError(getMessage("en", "not-json-server-error").format(line))
|
||||||
return
|
return
|
||||||
self.handleMessages(messages)
|
self.handleMessages(messages)
|
||||||
|
|
||||||
@ -190,6 +194,9 @@ class SyncClientProtocol(JSONCommandProtocol):
|
|||||||
position, paused, doSeek, stateChange = self._client.getLocalState()
|
position, paused, doSeek, stateChange = self._client.getLocalState()
|
||||||
self.sendState(position, paused, doSeek, latencyCalculation, stateChange)
|
self.sendState(position, paused, doSeek, latencyCalculation, stateChange)
|
||||||
|
|
||||||
|
def handleHttpRequest(self, request):
|
||||||
|
pass
|
||||||
|
|
||||||
def sendState(self, position, paused, doSeek, latencyCalculation, stateChange = False):
|
def sendState(self, position, paused, doSeek, latencyCalculation, stateChange = False):
|
||||||
state = {}
|
state = {}
|
||||||
positionAndPausedIsSet = position is not None and paused is not None
|
positionAndPausedIsSet = position is not None and paused is not None
|
||||||
@ -241,7 +248,7 @@ class SyncServerProtocol(JSONCommandProtocol):
|
|||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
def dropWithError(self, error):
|
def dropWithError(self, error):
|
||||||
print getMessage("en", "client-drop-server-error").format((self.transport.getPeer().host, error))
|
print getMessage("en", "client-drop-server-error").format(self.transport.getPeer().host, error)
|
||||||
self.sendError(error)
|
self.sendError(error)
|
||||||
self.drop()
|
self.drop()
|
||||||
|
|
||||||
@ -394,6 +401,9 @@ class SyncServerProtocol(JSONCommandProtocol):
|
|||||||
if(self.serverIgnoringOnTheFly == 0):
|
if(self.serverIgnoringOnTheFly == 0):
|
||||||
self._factory.updateWatcherState(self, position, paused, doSeek, latencyCalculation)
|
self._factory.updateWatcherState(self, position, paused, doSeek, latencyCalculation)
|
||||||
|
|
||||||
|
def handleHttpRequest(self, request):
|
||||||
|
self.sendLine(self._factory.gethttpRequestReply())
|
||||||
|
|
||||||
def handleError(self, error):
|
def handleError(self, error):
|
||||||
self.dropWithError(error["message"]) #TODO: more processing and fallbacking
|
self.dropWithError(error["message"]) #TODO: more processing and fallbacking
|
||||||
|
|
||||||
|
|||||||
@ -14,12 +14,13 @@ import os
|
|||||||
from string import Template
|
from string import Template
|
||||||
|
|
||||||
class SyncFactory(Factory):
|
class SyncFactory(Factory):
|
||||||
def __init__(self, password = '', motdFilePath = None):
|
def __init__(self, password = '', motdFilePath = None, httpReplyFilePath= None):
|
||||||
print getMessage("en", "welcome-server-notification").format(syncplay.version)
|
print getMessage("en", "welcome-server-notification").format(syncplay.version)
|
||||||
if(password):
|
if(password):
|
||||||
password = hashlib.md5(password).hexdigest()
|
password = hashlib.md5(password).hexdigest()
|
||||||
self.password = password
|
self.password = password
|
||||||
self._motdFilePath = motdFilePath
|
self._motdFilePath = motdFilePath
|
||||||
|
self._httpReplyFilePath = httpReplyFilePath
|
||||||
self._rooms = {}
|
self._rooms = {}
|
||||||
self._roomStates = {}
|
self._roomStates = {}
|
||||||
self._roomUpdate = threading.RLock()
|
self._roomUpdate = threading.RLock()
|
||||||
@ -99,6 +100,13 @@ class SyncFactory(Factory):
|
|||||||
else:
|
else:
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
|
def gethttpRequestReply(self):
|
||||||
|
if(self._httpReplyFilePath and os.path.isfile(self._httpReplyFilePath)):
|
||||||
|
tmpl = codecs.open(self._httpReplyFilePath, "r", "utf-8-sig").read()
|
||||||
|
return tmpl
|
||||||
|
else:
|
||||||
|
return getMessage("en", "server-default-http-reply")
|
||||||
|
|
||||||
def sendState(self, watcherProtocol, doSeek = False, senderLatency = 0, forcedUpdate = False):
|
def sendState(self, watcherProtocol, doSeek = False, senderLatency = 0, forcedUpdate = False):
|
||||||
watcher = self.getWatcher(watcherProtocol)
|
watcher = self.getWatcher(watcherProtocol)
|
||||||
if(not watcher):
|
if(not watcher):
|
||||||
|
|||||||
@ -206,4 +206,5 @@ class ServerConfigurationGetter(object):
|
|||||||
self._argparser.add_argument('--port', metavar='port', type=str, nargs='?', help=getMessage("en", "server-port-argument"))
|
self._argparser.add_argument('--port', metavar='port', type=str, nargs='?', help=getMessage("en", "server-port-argument"))
|
||||||
self._argparser.add_argument('--password', metavar='password', type=str, nargs='?', help=getMessage("en", "server-password-argument"))
|
self._argparser.add_argument('--password', metavar='password', type=str, nargs='?', help=getMessage("en", "server-password-argument"))
|
||||||
self._argparser.add_argument('--isolate-rooms', action='store_true', help=getMessage("en", "server-isolate-room-argument"))
|
self._argparser.add_argument('--isolate-rooms', action='store_true', help=getMessage("en", "server-isolate-room-argument"))
|
||||||
self._argparser.add_argument('--motd-file', metavar='motd', type=str, nargs='?', help=getMessage("en", "server-motd-argument"))
|
self._argparser.add_argument('--motd-file', metavar='file', type=str, nargs='?', help=getMessage("en", "server-motd-argument"))
|
||||||
|
self._argparser.add_argument('--http-reply-file', metavar='file', type=str, nargs='?', help=getMessage("en", "server-http-reply-argument"))
|
||||||
|
|||||||
@ -11,5 +11,5 @@ args = argsGetter.getConfiguration()
|
|||||||
if(not args.isolate_rooms):
|
if(not args.isolate_rooms):
|
||||||
reactor.listenTCP(int(args.port), SyncFactory(args.password, args.motd_file))
|
reactor.listenTCP(int(args.port), SyncFactory(args.password, args.motd_file))
|
||||||
else:
|
else:
|
||||||
reactor.listenTCP(int(args.port), SyncIsolatedFactory(args.password, args.motd_file))
|
reactor.listenTCP(int(args.port), SyncIsolatedFactory(args.password, args.motd_file, args.http_reply_file))
|
||||||
reactor.run()
|
reactor.run()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user