2013-10-02 22:06:06 +00:00
import HydrusConstants as HC
import HydrusExceptions
import HydrusFileHandling
import HydrusImageHandling
2017-03-02 02:14:56 +00:00
import HydrusNetwork
2015-11-04 22:30:28 +00:00
import HydrusPaths
2015-09-02 23:16:09 +00:00
import HydrusSerialisable
2013-10-02 22:06:06 +00:00
import os
2014-07-16 20:50:18 +00:00
import time
2013-10-02 22:06:06 +00:00
import traceback
from twisted . internet import reactor , defer
from twisted . internet . threads import deferToThread
2015-04-29 19:20:35 +00:00
from twisted . web . server import NOT_DONE_YET
2013-10-02 22:06:06 +00:00
from twisted . web . resource import Resource
from twisted . web . static import File as FileResource , NoRangeStaticProducer
2015-03-25 22:04:19 +00:00
import HydrusData
2017-05-10 21:33:58 +00:00
import HydrusGlobals as HG
2013-10-02 22:06:06 +00:00
2017-03-02 02:14:56 +00:00
def GenerateEris ( service , domain ) :
name = service . GetName ( )
service_type = service . GetServiceType ( )
welcome_text_1 = ' This is <b> ' + name + ' </b>, '
welcome_text_2 = ' a ' + HC . service_string_lookup [ service_type ] + ' . '
welcome_text_3 = ' Software version ' + str ( HC . SOFTWARE_VERSION )
welcome_text_4 = ' Network version ' + str ( HC . NETWORK_VERSION )
if domain . IsLocal ( ) :
welcome_text_5 = ' It only responds to requests from localhost. '
else :
welcome_text_5 = ' It responds to requests from any host. '
return ''' <html><head><title> ''' + name + ''' </title></head><body><pre>
< font color = " red " > 8888 8888888 < / font >
< font color = " red " > 888888888888888888888888 < / font >
< font color = " red " > 8888 < / font > : : : < font color = " red " > 8888888888888888888888888 < / font >
< font color = " red " > 8888 < / font > : : : : : : < font color = " red " > 8888888888888888888888888888 < / font >
< font color = " red " > 88 < / font > : : : : : : : : < font color = " red " > 888 < / font > : : : < font color = " red " > 8888888888888888888888888 < / font >
< font color = " red " > 88888888 < / font > : : : : < font color = " red " > 8 < / font > : : : : : : : : : : : < font color = " red " > 88888888888888888888 < / font >
< font color = " red " > 888 8 < / font > : : < font color = " red " > 888888 < / font > : : : : : : : : : : : : : : : : : : < font color = " red " > 88888888888 888 < / font >
< font color = " red " > 88 < / font > : : : : < font color = " red " > 88888888 < / font > : : : : < font color = " gray " > m < / font > : : : : : : : : : : < font color = " red " > 88888888888 8 < / font >
< font color = " red " > 888888888888888888 < / font > : < font color = " gray " > M < / font > : : : : : : : : : : : < font color = " red " > 8888888888888 < / font >
< font color = " red " > 88888888888888888888 < / font > : : : : : : : : : : : : < font color = " gray " > M < / font > < font color = " red " > 88888888888888 < / font >
< font color = " red " > 8888888888888888888888 < / font > : : : : : : : : : < font color = " gray " > M < / font > < font color = " red " > 8888888888888888 < / font >
< font color = " red " > 8888888888888888888888 < / font > : : : : : : : < font color = " gray " > M < / font > < font color = " red " > 888888888888888888 < / font >
< font color = " red " > 8888888888888888 < / font > : : < font color = " red " > 88888 < / font > : : : : : : < font color = " gray " > M < / font > < font color = " red " > 88888888888888888888 < / font >
< font color = " red " > 88888888888888888 < / font > : : : < font color = " red " > 88888 < / font > : : : : : < font color = " gray " > M < / font > < font color = " red " > 888888888888888 8888 < / font >
< font color = " red " > 88888888888888888 < / font > : : : < font color = " red " > 88888 < / font > : : : : < font color = " gray " > M < / font > : : < font color = " black " > ; o < / font > < font color = " maroon " > * < / font > < font color = " green " > M < / font > < font color = " maroon " > * < / font > < font color = " black " > o ; < / font > < font color = " red " > 888888888 88 < / font >
< font color = " red " > 88888888888888888 < / font > : : : < font color = " red " > 8888 < / font > : : : : : < font color = " gray " > M < / font > : : : : : : : : : : : < font color = " red " > 88888888 8 < / font >
< font color = " red " > 88888888888888888 < / font > : : : : < font color = " red " > 88 < / font > : : : : : : < font color = " gray " > M < / font > : < font color = " gray " > ; < / font > : : : : : : : : : : : < font color = " red " > 888888888 < / font >
< font color = " red " > 8888888888888888888 < / font > : : : < font color = " red " > 8 < / font > : : : : : : < font color = " gray " > M < / font > : : < font color = " gray " > aAa < / font > : : : : : : : : < font color = " gray " > M < / font > < font color = " red " > 8888888888 8 < / font >
< font color = " red " > 88 8888888888 < / font > : : < font color = " red " > 88 < / font > : : : : < font color = " red " > 8 < / font > : : : : < font color = " gray " > M < / font > : : : : : : : : : : : : : < font color = " red " > 888888888888888 8888 < / font >
< font color = " red " > 88 88888888888 < / font > : : : < font color = " red " > 8 < / font > : : : : : : : : : < font color = " gray " > M < / font > : : : : : : : : : : ; : : < font color = " red " > 88 < / font > < font color = " black " > : < / font > < font color = " red " > 88888888888888888 < / font >
< font color = " red " > 8 8888888888888 < / font > : : : : : : : : : : : < font color = " gray " > M < / font > : : < font color = " violet " > & quot ; @ @ @ @ @ @ @ & quot ; < / font > : : : : < font color = " red " > 8 < / font > < font color = " gray " > w < / font > < font color = " red " > 8888888888888888 < / font >
< font color = " red " > 88888888888 < / font > : < font color = " red " > 888 < / font > : : : : : : : : : : < font color = " gray " > M < / font > : : : : : < font color = " violet " > & quot ; @a @ & quot ; < / font > : : : : : < font color = " gray " > M < / font > < font color = " red " > 8 < / font > < font color = " gray " > i < / font > < font color = " red " > 888888888888888 < / font >
< font color = " red " > 8888888888 < / font > : : : : < font color = " red " > 88 < / font > : : : : : : : : : < font color = " gray " > M < / font > < font color = " red " > 88 < / font > : : : : : : : : : : : : : < font color = " gray " > M < / font > < font color = " red " > 88 < / font > < font color = " gray " > z < / font > < font color = " red " > 88888888888888888 < / font >
< font color = " red " > 8888888888 < / font > : : : : : < font color = " red " > 8 < / font > : : : : : : : : : < font color = " gray " > M < / font > < font color = " red " > 88888 < / font > : : : : : : : : : < font color = " gray " > MM < / font > < font color = " red " > 888 < / font > < font color = " gray " > ! < / font > < font color = " red " > 888888888888888888 < / font >
< font color = " red " > 888888888 < / font > : : : : : < font color = " red " > 8 < / font > : : : : : : : : : < font color = " gray " > M < / font > < font color = " red " > 8888888 < / font > < font color = " gray " > MAmmmAMVMM < / font > < font color = " red " > 888 < / font > < font color = " gray " > * < / font > < font color = " red " > 88888888 88888888 < / font >
< font color = " red " > 888888 < / font > < font color = " gray " > M < / font > : : : : : : : : : : : : : : : < font color = " gray " > M < / font > < font color = " red " > 888888888 < / font > : : : : : : : < font color = " gray " > MM < / font > < font color = " red " > 88888888888888 8888888 < / font >
< font color = " red " > 8888 < / font > < font color = " gray " > M < / font > : : : : : : : : : : : : : : < font color = " gray " > M < / font > < font color = " red " > 88888888888 < / font > : : : : : : < font color = " gray " > MM < / font > < font color = " red " > 888888888888888 88888 < / font >
< font color = " red " > 888 < / font > < font color = " gray " > M < / font > : : : : : : : : : : : : : < font color = " gray " > M < / font > < font color = " red " > 8888888888888 < / font > < font color = " gray " > M < / font > : : : : : < font color = " gray " > mM < / font > < font color = " red " > 888888888888888 8888 < / font >
< font color = " red " > 888 < / font > < font color = " gray " > M < / font > : : : : : : : : : : : : < font color = " gray " > M < / font > < font color = " red " > 8888 < / font > : < font color = " red " > 888888888888 < / font > : : : : < font color = " gray " > m < / font > : : < font color = " gray " > Mm < / font > < font color = " red " > 88888 888888 8888 < / font >
< font color = " red " > 88 < / font > < font color = " gray " > M < / font > : : : : : : : : : : : : < font color = " red " > 8888 < / font > : < font color = " red " > 88888888888888888 < / font > : : : : : : < font color = " gray " > Mm < / font > < font color = " red " > 8 88888 888 < / font >
< font color = " red " > 88 < / font > < font color = " gray " > M < / font > : : : : : : : : : : < font color = " red " > 8888 < / font > < font color = " gray " > M < / font > : : < font color = " red " > 88888 < / font > : : < font color = " red " > 888888888888 < / font > : : : : : : : < font color = " gray " > Mm < / font > < font color = " red " > 88888 88 < / font >
< font color = " red " > 8 < / font > < font color = " gray " > MM < / font > : : : : : : : : < font color = " red " > 8888 < / font > < font color = " gray " > M < / font > : : : < font color = " red " > 8888 < / font > : : : : : < font color = " red " > 888888888888 < / font > : : : : : : : : < font color = " gray " > Mm < / font > < font color = " red " > 8 4 < / font > ''' + welcome_text_1 + '''
< font color = " red " > 8 < / font > < font color = " gray " > M < / font > : : : : : : : < font color = " red " > 8888 < / font > < font color = " gray " > M < / font > : : : : : < font color = " red " > 888 < / font > : : : : : : : < font color = " red " > 88 < / font > : : : < font color = " red " > 8888888 < / font > : : : : : : : : < font color = " gray " > Mm < / font > < font color = " red " > 2 < / font > ''' + welcome_text_2 + '''
< font color = " red " > 88 < / font > < font color = " gray " > MM < / font > : : : : : < font color = " red " > 8888 < / font > < font color = " gray " > M < / font > : : : : : : : < font color = " red " > 88 < / font > : : : : : : : : < font color = " red " > 8 < / font > : : : : : < font color = " red " > 888888 < / font > : : : < font color = " gray " > M < / font > : : : : : < font color = " gray " > M < / font >
< font color = " red " > 8888 < / font > < font color = " gray " > M < / font > : : : : : < font color = " red " > 888 < / font > < font color = " gray " > MM < / font > : : : : : : : : < font color = " red " > 8 < / font > : : : : : : : : : : : < font color = " gray " > M < / font > : : : : < font color = " red " > 8888 < / font > : : : : < font color = " gray " > M < / font > : : : : < font color = " gray " > M < / font > ''' + welcome_text_3 + '''
< font color = " red " > 88888 < / font > < font color = " gray " > M < / font > : : : : : < font color = " red " > 88 < / font > : < font color = " gray " > M < / font > : : : : : : : : : : < font color = " red " > 8 < / font > : : : : : : : : : : : < font color = " gray " > M < / font > : : : < font color = " red " > 8888 < / font > : : : : : : < font color = " gray " > M < / font > : : < font color = " gray " > M < / font > ''' + welcome_text_4 + '''
< font color = " red " > 88 888 < / font > < font color = " gray " > MM < / font > : : : < font color = " red " > 888 < / font > : < font color = " gray " > M < / font > : : : : : : : : : : : : : : : : : : : : : : : < font color = " gray " > M < / font > : < font color = " red " > 8888 < / font > : : : : : : : : : < font color = " gray " > M < / font > :
< font color = " red " > 8 88888 < / font > < font color = " gray " > M < / font > : : : < font color = " red " > 88 < / font > : : < font color = " gray " > M < / font > : : : : : : : : : : : : : : : : : : : : : : : < font color = " gray " > MM < / font > : < font color = " red " > 88 < / font > : : : : : : : : : : : : < font color = " gray " > M < / font > ''' + welcome_text_5 + '''
< font color = " red " > 88888 < / font > < font color = " gray " > M < / font > : : : < font color = " red " > 88 < / font > : : < font color = " gray " > M < / font > : : : : : : : : : : < font color = " thistle " > * 88 * < / font > : : : : : : : : : : < font color = " gray " > M < / font > : < font color = " red " > 88 < / font > : : : : : : : : : : : : : : < font color = " gray " > M < / font >
< font color = " red " > 888888 < / font > < font color = " gray " > M < / font > : : : < font color = " red " > 88 < / font > : : < font color = " gray " > M < / font > : : : : : : : : : < font color = " thistle " > 88 @ @ 88 < / font > : : : : : : : : : < font color = " gray " > M < / font > : : < font color = " red " > 88 < / font > : : : : : : : : : : : : : : < font color = " gray " > M < / font >
< font color = " red " > 888888 < / font > < font color = " gray " > MM < / font > : : < font color = " red " > 88 < / font > : : < font color = " gray " > MM < / font > : : : : : : : : < font color = " thistle " > 88 @ @ 88 < / font > : : : : : : : : : < font color = " gray " > M < / font > : : : < font color = " red " > 8 < / font > : : : : : : : : : : : : : : < font color = " thistle " > * 8 < / font >
< font color = " red " > 88888 < / font > < font color = " gray " > M < / font > : : : < font color = " red " > 8 < / font > : : < font color = " gray " > MM < / font > : : : : : : : : : < font color = " thistle " > * 88 * < / font > : : : : : : : : : : < font color = " gray " > M < / font > : : : : : : : : : : : : : : : : : < font color = " thistle " > 88 @ @ < / font >
< font color = " red " > 8888 < / font > < font color = " gray " > MM < / font > : : : : : : < font color = " gray " > MM < / font > : : : : : : : : : : : : : : : : : : : : : < font color = " gray " > MM < / font > : : : : : : : : : : : : : : : : : < font color = " thistle " > 88 @ @ < / font >
< font color = " red " > 888 < / font > < font color = " gray " > M < / font > : : : : : : : < font color = " gray " > MM < / font > : : : : : : : : : : : : : : : : : : : < font color = " gray " > MM < / font > : : < font color = " gray " > M < / font > : : : : : : : : : : : : : : : : < font color = " thistle " > * 8 < / font >
< font color = " red " > 888 < / font > < font color = " gray " > MM < / font > : : : : : : : < font color = " gray " > MMM < / font > : : : : : : : : : : : : : : : : < font color = " gray " > MM < / font > : : : < font color = " gray " > MM < / font > : : : : : : : : : : : : : : : < font color = " gray " > M < / font >
< font color = " red " > 88 < / font > < font color = " gray " > M < / font > : : : : : : : : < font color = " gray " > MMMM < / font > : : : : : : : : : : : < font color = " gray " > MMMM < / font > : : : : : < font color = " gray " > MM < / font > : : : : : : : : : : : : < font color = " gray " > MM < / font >
< font color = " red " > 88 < / font > < font color = " gray " > MM < / font > : : : : : : : : : < font color = " gray " > MMMMMMMMMMMMMMM < / font > : : : : : : : : < font color = " gray " > MMM < / font > : : : : : : : : < font color = " gray " > MMM < / font >
< font color = " red " > 88 < / font > < font color = " gray " > MM < / font > : : : : : : : : : : : : < font color = " gray " > MMMMMMM < / font > : : : : : : : : : : : : : : < font color = " gray " > MMMMMMMMMM < / font >
< font color = " red " > 88 8 < / font > < font color = " gray " > MM < / font > : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : < font color = " gray " > MMMMMM < / font >
< font color = " red " > 8 88 < / font > < font color = " gray " > MM < / font > : : : : : : : : : : : : : : : : : : : : : : < font color = " gray " > M < / font > : : : < font color = " gray " > M < / font > : : : : : : : : < font color = " gray " > MM < / font >
< font color = " red " > 888 < / font > < font color = " gray " > MM < / font > : : : : : : : : : : : : : : : : : : < font color = " gray " > MM < / font > : : : : : : < font color = " gray " > MM < / font > : : : : : : < font color = " gray " > MM < / font >
< font color = " red " > 88888 < / font > < font color = " gray " > MM < / font > : : : : : : : : : : : : : : : < font color = " gray " > MMM < / font > : : : : : : : < font color = " gray " > mM < / font > : : : : : < font color = " gray " > MM < / font >
< font color = " red " > 888888 < / font > < font color = " gray " > MM < / font > : : : : : : : : : : : : : < font color = " gray " > MMM < / font > : : : : : : : : : < font color = " gray " > MMM < / font > : : : < font color = " gray " > M < / font >
< font color = " red " > 88888888 < / font > < font color = " gray " > MM < / font > : : : : : : : : : : : < font color = " gray " > MMM < / font > : : : : : : : : : : : < font color = " gray " > MM < / font > : : : < font color = " gray " > M < / font >
< font color = " red " > 88 8888888 < / font > < font color = " gray " > M < / font > : : : : : : : : : < font color = " gray " > MMM < / font > : : : : : : : : : : : : : : < font color = " gray " > M < / font > : : : < font color = " gray " > M < / font >
< font color = " red " > 8 888888 < / font > < font color = " gray " > M < / font > : : : : : : : < font color = " gray " > MM < / font > : : : : : : : : : : : : : : : : : < font color = " gray " > M < / font > : : : < font color = " gray " > M < / font > :
< font color = " red " > 888888 < / font > < font color = " gray " > M < / font > : : : : : : < font color = " gray " > M < / font > : : : : : : : : : : : : : : : : : : : < font color = " gray " > M < / font > : : : < font color = " gray " > MM < / font >
< font color = " red " > 888888 < / font > < font color = " gray " > M < / font > : : : : : < font color = " gray " > M < / font > : : : : : : : : : : : : : : : : : : : : : : : : < font color = " gray " > M < / font > : < font color = " gray " > M < / font >
< font color = " red " > 888888 < / font > < font color = " gray " > M < / font > : : : : : < font color = " gray " > M < / font > : : : : : : : : : < font color = " gray " > @ < / font > : : : : : : : : : : : : : : < font color = " gray " > M < / font > : : < font color = " gray " > M < / font >
< font color = " red " > 88888 < / font > < font color = " gray " > M < / font > : : : : : : : : : : : : : : < font color = " gray " > @ @ < / font > : : : : : : : : : : : : : : : < font color = " gray " > M < / font > : : < font color = " gray " > M < / font >
< font color = " red " > 88888 < / font > < font color = " gray " > M < / font > : : : : : : : : : : : : : : < font color = " gray " > @ @ @ < / font > : : : : : : : : : : : : : : : : < font color = " gray " > M < / font > : : < font color = " gray " > M < / font >
< font color = " red " > 88888 < / font > < font color = " gray " > M < / font > : : : : : : : : : : : : : : : < font color = " gray " > @ @ < / font > : : : : : : : : : : : : : : : : : : < font color = " gray " > M < / font > : : < font color = " gray " > M < / font >
< font color = " red " > 88888 < / font > < font color = " gray " > M < / font > : : : : : < font color = " gray " > m < / font > : : : : : : : : : : < font color = " gray " > @ < / font > : : : : : : : : : : < font color = " gray " > Mm < / font > : : : : : : : < font color = " gray " > M < / font > : : : < font color = " gray " > M < / font >
< font color = " red " > 8888 < / font > < font color = " gray " > M < / font > : : : : : < font color = " gray " > M < / font > : : : : : : : : : : : : : : : : : : : : : : : < font color = " gray " > MM < / font > : : : : : : : < font color = " gray " > M < / font > : : : < font color = " gray " > M < / font >
< font color = " red " > 8888 < / font > < font color = " gray " > M < / font > : : : : : < font color = " gray " > M < / font > : : : : : : : : : : : : : : : : : : : : : : : < font color = " gray " > MMM < / font > : : : : : : : : < font color = " gray " > M < / font > : : : < font color = " gray " > M < / font >
< font color = " red " > 888 < / font > < font color = " gray " > M < / font > : : : : : < font color = " gray " > Mm < / font > : : : : : : : : : : : : : : : : : : : : : : < font color = " gray " > MMM < / font > : : : : : : : : : < font color = " gray " > M < / font > : : : : < font color = " gray " > M < / font >
< font color = " red " > 8888 < / font > < font color = " gray " > MM < / font > : : : : < font color = " gray " > Mm < / font > : : : : : : : : : : : : : : : : : : : : : < font color = " gray " > MMMM < / font > : : : : : : : : : < font color = " gray " > m < / font > : : < font color = " gray " > m < / font > : : : < font color = " gray " > M < / font >
< font color = " red " > 888 < / font > < font color = " gray " > M < / font > : : : : : < font color = " gray " > M < / font > : : : : : : : : : : : : : : : : : : : : < font color = " gray " > MMM < / font > : : : : : : : : : : : : < font color = " gray " > M < / font > : : < font color = " gray " > mm < / font > : : : < font color = " gray " > M < / font >
< font color = " red " > 8888 < / font > < font color = " gray " > MM < / font > : : : : : : : : : : : : : : : : : : : : : : : : : < font color = " gray " > MM < / font > : : : : : : : : : : : : : < font color = " gray " > mM < / font > : : < font color = " gray " > MM < / font > : : : < font color = " gray " > M < / font > :
< font color = " gray " > M < / font > : : : : : : : : : : : : : : : : : : : : : : : : : < font color = " gray " > M < / font > : : : : : : : : : : : : : : : < font color = " gray " > mM < / font > : : < font color = " gray " > MM < / font > : : : < font color = " gray " > Mm < / font >
< font color = " gray " > MM < / font > : : : : : : < font color = " gray " > m < / font > : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : < font color = " gray " > M < / font > : : < font color = " gray " > MM < / font > : : : < font color = " gray " > MM < / font >
< font color = " gray " > M < / font > : : : : : : : : < font color = " gray " > M < / font > : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : < font color = " gray " > M < / font > : : < font color = " gray " > M < / font > : : : < font color = " gray " > MM < / font >
< font color = " gray " > MM < / font > : : : : : : : : : < font color = " gray " > M < / font > : : : : : : : : : : : : : < font color = " gray " > M < / font > : : : : : : : : : : : : : : : : : : : : : < font color = " gray " > M < / font > : < font color = " gray " > M < / font > : : : < font color = " gray " > MM < / font >
< font color = " gray " > M < / font > : : : : : : : : : : : < font color = " gray " > M < / font > < font color = " maroon " > 88 < / font > : : : : : : : : : < font color = " gray " > M < / font > : : : : : : : : : : : : : : : : : : : : : : : < font color = " gray " > MM < / font > : : < font color = " gray " > MMM < / font >
< font color = " gray " > M < / font > : : : : : : : : : : : : < font color = " maroon " > 8888888888 < / font > < font color = " gray " > M < / font > : : : : : : : : : : : : : : : : : : : : : : : : < font color = " gray " > MM < / font > : : < font color = " gray " > MM < / font >
< font color = " gray " > M < / font > : : : : : : : : : : : : : < font color = " maroon " > 88888888 < / font > < font color = " gray " > M < / font > : : : : : : : : : : : : : : : : : : : : : : : : : < font color = " gray " > M < / font > : : < font color = " gray " > MM < / font >
< font color = " gray " > M < / font > : : : : : : : : : : : : : : < font color = " maroon " > 888888 < / font > < font color = " gray " > M < / font > : : : : : : : : : : : : : : : : : : : : : : : : : < font color = " gray " > M < / font > : : < font color = " gray " > MM < / font >
< font color = " gray " > M < / font > : : : : : : : : : : : : : : : < font color = " maroon " > 88888 < / font > < font color = " gray " > M < / font > : : : : : : : : : : : : : : : : : : : : : : : : : < font color = " gray " > M < / font > : < font color = " gray " > MM < / font >
< font color = " gray " > M < / font > : : : : : : : : : : : : : : : : : < font color = " maroon " > 88 < / font > < font color = " gray " > M < / font > : : : : : : : : : : : : : : : : : : : : : : : : : : < font color = " gray " > MMM < / font >
< font color = " gray " > M < / font > : : : : : : : : : : : : : : : : : : : < font color = " gray " > M < / font > : : : : : : : : : : : : : : : : : : : : : : : : : : < font color = " gray " > MMM < / font >
< font color = " gray " > MM < / font > : : : : : : : : : : : : : : : : : < font color = " gray " > M < / font > : : : : : : : : : : : : : : : : : : : : : : : : : : < font color = " gray " > MMM < / font >
< font color = " gray " > M < / font > : : : : : : : : : : : : : : : : : < font color = " gray " > M < / font > : : : : : : : : : : : : : : : : : : : : : : : : : : < font color = " gray " > MMM < / font >
< font color = " gray " > MM < / font > : : : : : : : : : : : : : : : < font color = " gray " > M < / font > : : : : : : : : : : : : : : : : : : : : : : : : : : < font color = " gray " > MMM < / font >
< font color = " gray " > M < / font > : : : : : : : : : : : : : : : < font color = " gray " > M < / font > : : : : : : : : : : : : : : : : : : : : : : : : : < font color = " gray " > MMM < / font >
< font color = " gray " > MM < / font > : : : : : : : : : : : : : < font color = " gray " > M < / font > : : : : : : : : : : : : : : : : : : : : : : : : : < font color = " gray " > MMM < / font >
< font color = " gray " > M < / font > : : : : : : : : : : : : : < font color = " gray " > M < / font > : : : : : : : : : : : : : : : : : : : : : : : : < font color = " gray " > MMM < / font >
< font color = " gray " > MM < / font > : : : : : : : : : : : < font color = " gray " > M < / font > : : : : : : : : : : : : : : : : : : : : : : : : < font color = " gray " > MMM < / font >
< font color = " gray " > M < / font > : : : : : : : : : : : < font color = " gray " > M < / font > : : : : : : : : : : : : : : : : : : : : : : : < font color = " gray " > MMM < / font >
< font color = " gray " > MM < / font > : : : : : : : : : < font color = " gray " > M < / font > : : : : : : : : : : : : : : : : : : : : : : : < font color = " gray " > MMM < / font >
< font color = " gray " > M < / font > : : : : : : : : : < font color = " gray " > M < / font > : : : : : : : : : : : : : : : : : : : : : : < font color = " gray " > MMM < / font >
< font color = " gray " > MM < / font > : : : : : : : < font color = " gray " > M < / font > : : : : : : : : : : : : : : : : : : : : : : < font color = " gray " > MMM < / font >
< font color = " gray " > MM < / font > : : : : : : < font color = " gray " > M < / font > : : : : : : : : : : : : : : : : : : : : : < font color = " gray " > MMM < / font >
< font color = " gray " > MM < / font > : : : : : < font color = " gray " > M < / font > : : : : : : : : : : : : : : : : : : : : : < font color = " gray " > MMM < / font >
< font color = " gray " > MM < / font > : : : : < font color = " gray " > M < / font > : : : : : : : : : : : : : : : : : : : : < font color = " gray " > MMM < / font >
< font color = " gray " > MM < / font > : : : < font color = " gray " > M < / font > : : : : : : : : : : : : : : : : : : : : < font color = " gray " > MMM < / font >
< font color = " gray " > MM < / font > : : < font color = " gray " > M < / font > : : : : : : : : : : : : : : : : : : : < font color = " gray " > MMM < / font >
< font color = " gray " > MM < / font > : < font color = " gray " > M < / font > : : : : : : : : : : : : : : : : : : : < font color = " gray " > MMM < / font >
< font color = " gray " > MMM < / font > : : : : : : : : : : : : : : : : : : < font color = " gray " > MMM < / font >
< font color = " gray " > MM < / font > : : : : : : : : : : : : : : : : : : < font color = " gray " > MMM < / font >
< font color = " gray " > M < / font > : : : : : : : : : : : : : : : : : < font color = " gray " > MMM < / font >
< font color = " gray " > MM < / font > : : : : : : : : : : : : : : : : < font color = " gray " > MMM < / font >
< font color = " gray " > MM < / font > : : : : : : : : : : : : : : : < font color = " gray " > MMM < / font >
< font color = " gray " > MM < / font > : : : : < font color = " gray " > M < / font > : : : : : : : : : < font color = " gray " > MMM < / font > :
< font color = " gray " > mMM < / font > : : : : < font color = " gray " > MM < / font > : : : : : : : < font color = " gray " > MMMM < / font >
< font color = " gray " > MMM < / font > : : : : : : : : : : : < font color = " gray " > MMM < / font > : < font color = " gray " > M < / font >
< font color = " gray " > mMM < / font > : : : < font color = " gray " > M < / font > : : : : : : : < font color = " gray " > M < / font > : < font color = " gray " > M < / font > : < font color = " gray " > M < / font >
< font color = " gray " > MM < / font > : : < font color = " gray " > MMMM < / font > : : : : : : : < font color = " gray " > M < / font > : < font color = " gray " > M < / font >
< font color = " gray " > MM < / font > : : < font color = " gray " > MMM < / font > : : : : : : : : < font color = " gray " > M < / font > : < font color = " gray " > M < / font >
< font color = " gray " > mMM < / font > : : < font color = " gray " > MM < / font > : : : : : : : : < font color = " gray " > M < / font > : < font color = " gray " > M < / font >
< font color = " gray " > MM < / font > : : < font color = " gray " > MM < / font > : : : : : : : : : < font color = " gray " > M < / font > : < font color = " gray " > M < / font >
< font color = " gray " > MM < / font > : : < font color = " gray " > MM < / font > : : : : : : : : : : < font color = " gray " > M < / font > : < font color = " gray " > m < / font >
< font color = " gray " > MM < / font > : : : < font color = " gray " > M < / font > : : : : : : : : : : : < font color = " gray " > MM < / font >
< font color = " gray " > MMM < / font > : : : : : : : : : : : : : : : < font color = " gray " > M < / font > :
< font color = " gray " > MMM < / font > : : : : : : : : : : : : : : : < font color = " gray " > M < / font > :
< font color = " gray " > MMM < / font > : : : : : : : : : : : : : : : : < font color = " gray " > M < / font >
< font color = " gray " > MMM < / font > : : : : : : : : : : : : : : : : < font color = " gray " > M < / font >
< font color = " gray " > MMM < / font > : : : : : : : : : : : : : : : : < font color = " gray " > Mm < / font >
< font color = " gray " > MM < / font > : : : : : : : : : : : : : : : : < font color = " gray " > MM < / font >
< font color = " gray " > MMM < / font > : : : : : : : : : : : : : : : < font color = " gray " > MM < / font >
< font color = " gray " > MMM < / font > : : : : : : : : : : : : : : : < font color = " gray " > MM < / font >
< font color = " gray " > MMM < / font > : : : : : : : : : : : : : : : < font color = " gray " > MM < / font >
< font color = " gray " > MMM < / font > : : : : : : : : : : : : : : : < font color = " gray " > MM < / font >
< font color = " gray " > MM < / font > : : : : : : : : : : : : : : < font color = " gray " > MMM < / font >
< font color = " gray " > MMM < / font > : : : : : : : : : : : : : < font color = " gray " > MM < / font >
< font color = " gray " > MMM < / font > : : : : : : : : : : : : : < font color = " gray " > MM < / font >
< font color = " gray " > MMM < / font > : : : : : : : : : : : : < font color = " gray " > MM < / font >
< font color = " gray " > MM < / font > : : : : : : : : : : : : < font color = " gray " > MM < / font >
< font color = " gray " > MM < / font > : : : : : : : : : : : : < font color = " gray " > MM < / font >
< font color = " gray " > MM < / font > : : : : : : : : : : : < font color = " gray " > MM < / font >
< font color = " gray " > MMM < / font > : : : : : : : : : : < font color = " gray " > MM < / font >
< font color = " gray " > MMM < / font > : : : : : : : : : : < font color = " gray " > MM < / font >
< font color = " gray " > MM < / font > : : : : : : : : : < font color = " gray " > MM < / font >
< font color = " gray " > MMM < / font > : : : : : : : : < font color = " gray " > MM < / font >
< font color = " gray " > MMM < / font > : : : : : : : : < font color = " gray " > MM < / font >
< font color = " gray " > MM < / font > : : : : : : : : < font color = " gray " > MM < / font >
< font color = " gray " > MMM < / font > : : : : : : < font color = " gray " > MM < / font >
< font color = " gray " > MMM < / font > : : : : : : < font color = " gray " > MM < / font >
< font color = " gray " > MM < / font > : : : : : : < font color = " gray " > MM < / font >
< font color = " gray " > MM < / font > : : : : : : < font color = " gray " > MM < / font >
< font color = " gray " > MM < / font > : : : : : < font color = " gray " > MM < / font >
< font color = " gray " > MM < / font > : : : : : < font color = " gray " > MM < / font > :
< font color = " gray " > MM < / font > : : : : : < font color = " gray " > M < / font > : < font color = " gray " > M < / font >
< font color = " gray " > MM < / font > : : : : : < font color = " gray " > M < / font > : < font color = " gray " > M < / font >
: < font color = " gray " > M < / font > : : : : : : < font color = " gray " > M < / font > :
< font color = " gray " > M < / font > : < font color = " gray " > M < / font > : : : : : : : < font color = " gray " > M < / font >
< font color = " gray " > M < / font > : : : < font color = " gray " > M < / font > : : : : : : < font color = " gray " > M < / font >
< font color = " gray " > M < / font > : : : : < font color = " gray " > M < / font > : : : : : : < font color = " gray " > M < / font >
< font color = " gray " > M < / font > : : : : : < font color = " gray " > M < / font > : : : : : : : < font color = " gray " > M < / font >
< font color = " gray " > M < / font > : : : : : : < font color = " gray " > MM < / font > : : : : : : : < font color = " gray " > M < / font >
< font color = " gray " > M < / font > : : : : : : : < font color = " gray " > M < / font > : : : : : : : : < font color = " gray " > M < / font >
< font color = " gray " > M ; < / font > : < font color = " gray " > ; < / font > : : : : < font color = " gray " > M < / font > : : : : : : : : : < font color = " gray " > M < / font >
< font color = " gray " > M < / font > : < font color = " gray " > m < / font > : < font color = " gray " > ; < / font > : : : < font color = " gray " > M < / font > : : : : : : : : : : < font color = " gray " > M < / font >
< font color = " gray " > MM < / font > : < font color = " gray " > m < / font > : < font color = " gray " > m < / font > : : < font color = " gray " > M < / font > : : : : : : : : < font color = " gray " > ; < / font > : < font color = " gray " > M < / font >
< font color = " gray " > MM < / font > : < font color = " gray " > m < / font > : : < font color = " gray " > MM < / font > : : : : : : : < font color = " gray " > ; < / font > : < font color = " gray " > ; M < / font >
< font color = " gray " > MM < / font > : : < font color = " gray " > MMM < / font > : : : : : : < font color = " gray " > ; < / font > : < font color = " gray " > m < / font > : < font color = " gray " > M < / font >
< font color = " gray " > MMMM MM < / font > : : : : < font color = " gray " > m < / font > : < font color = " gray " > m < / font > : < font color = " gray " > MM < / font >
< font color = " gray " > MM < / font > : : : : < font color = " gray " > m < / font > : < font color = " gray " > MM < / font >
< font color = " gray " > MM < / font > : : : : < font color = " gray " > MM < / font >
< font color = " gray " > MM < / font > : : < font color = " gray " > MM < / font >
< font color = " gray " > MMMM < / font >
< / pre > < / body > < / html > '''
2013-10-02 22:06:06 +00:00
def ParseFileArguments ( path ) :
HydrusImageHandling . ConvertToPngIfBmp ( path )
hash = HydrusFileHandling . GetHashFromPath ( path )
2015-03-04 22:44:32 +00:00
try :
( size , mime , width , height , duration , num_frames , num_words ) = HydrusFileHandling . GetFileInfo ( path )
except HydrusExceptions . SizeException :
raise HydrusExceptions . ForbiddenException ( ' File is of zero length! ' )
except HydrusExceptions . MimeException :
raise HydrusExceptions . ForbiddenException ( ' Filetype is not permitted! ' )
except Exception as e :
2015-11-04 22:30:28 +00:00
raise HydrusExceptions . ForbiddenException ( HydrusData . ToUnicode ( e ) )
2015-03-04 22:44:32 +00:00
2013-10-02 22:06:06 +00:00
args = { }
args [ ' path ' ] = path
args [ ' hash ' ] = hash
args [ ' size ' ] = size
args [ ' mime ' ] = mime
if width is not None : args [ ' width ' ] = width
if height is not None : args [ ' height ' ] = height
if duration is not None : args [ ' duration ' ] = duration
if num_frames is not None : args [ ' num_frames ' ] = num_frames
if num_words is not None : args [ ' num_words ' ] = num_words
2015-11-25 22:00:57 +00:00
if mime in HC . MIMES_WITH_THUMBNAILS :
2013-10-02 22:06:06 +00:00
2016-04-27 19:20:37 +00:00
try :
thumbnail = HydrusFileHandling . GenerateThumbnail ( path )
except Exception as e :
tb = traceback . format_exc ( )
raise HydrusExceptions . ForbiddenException ( ' Could not generate thumbnail from that file: ' + os . linesep + tb )
2013-10-02 22:06:06 +00:00
args [ ' thumbnail ' ] = thumbnail
return args
2015-11-04 22:30:28 +00:00
hydrus_favicon = FileResource ( os . path . join ( HC . STATIC_DIR , ' hydrus.ico ' ) , defaultType = ' image/x-icon ' )
2013-10-02 22:06:06 +00:00
2014-07-09 22:15:14 +00:00
class HydrusDomain ( object ) :
def __init__ ( self , local_only ) :
self . _local_only = local_only
def CheckValid ( self , client_ip ) :
2017-03-02 02:14:56 +00:00
if self . _local_only and client_ip != ' 127.0.0.1 ' :
raise HydrusExceptions . ForbiddenException ( ' Only local access allowed! ' )
2014-07-09 22:15:14 +00:00
2017-03-02 02:14:56 +00:00
def IsLocal ( self ) :
return self . _local_only
class HydrusResource ( Resource ) :
2013-10-02 22:06:06 +00:00
2017-03-02 02:14:56 +00:00
def __init__ ( self , service , domain ) :
2013-10-02 22:06:06 +00:00
Resource . __init__ ( self )
2017-03-02 02:14:56 +00:00
self . _service = service
self . _service_key = self . _service . GetServiceKey ( )
self . _domain = domain
2013-10-02 22:06:06 +00:00
2017-03-02 02:14:56 +00:00
service_type = self . _service . GetServiceType ( )
2013-10-02 22:06:06 +00:00
2014-01-01 20:01:00 +00:00
self . _server_version_string = HC . service_string_lookup [ service_type ] + ' / ' + str ( HC . NETWORK_VERSION )
2015-07-22 19:40:39 +00:00
2017-03-02 02:14:56 +00:00
def _callbackCheckRestrictions ( self , request ) :
2014-01-01 20:01:00 +00:00
2017-03-02 02:14:56 +00:00
self . _domain . CheckValid ( request . getClientIP ( ) )
2014-01-01 20:01:00 +00:00
2017-03-02 02:14:56 +00:00
self . _checkService ( request )
2013-10-02 22:06:06 +00:00
2017-03-02 02:14:56 +00:00
self . _checkUserAgent ( request )
2014-07-09 22:15:14 +00:00
2017-03-02 02:14:56 +00:00
return request
2013-10-02 22:06:06 +00:00
2017-03-02 02:14:56 +00:00
def _checkService ( self , request ) :
2015-07-22 19:40:39 +00:00
2017-05-10 21:33:58 +00:00
if HG . server_busy :
2015-07-22 19:40:39 +00:00
raise HydrusExceptions . ServerBusyException ( ' This server is busy, please try again later. ' )
2013-10-02 22:06:06 +00:00
return request
2017-03-02 02:14:56 +00:00
def _checkUserAgent ( self , request ) :
2013-10-02 22:06:06 +00:00
2017-03-02 02:14:56 +00:00
request . is_hydrus_user_agent = False
2013-10-02 22:06:06 +00:00
2017-03-02 02:14:56 +00:00
if request . requestHeaders . hasHeader ( ' User-Agent ' ) :
2013-10-02 22:06:06 +00:00
2017-03-02 02:14:56 +00:00
user_agent_texts = request . requestHeaders . getRawHeaders ( ' User-Agent ' )
2013-10-02 22:06:06 +00:00
2017-03-02 02:14:56 +00:00
user_agent_text = user_agent_texts [ 0 ]
2013-10-02 22:06:06 +00:00
2017-03-02 02:14:56 +00:00
try :
2013-10-02 22:06:06 +00:00
2017-03-02 02:14:56 +00:00
user_agents = user_agent_text . split ( ' ' )
2013-10-02 22:06:06 +00:00
2017-03-02 02:14:56 +00:00
except : return # crazy user agent string, so just assume not a hydrus client
2013-10-02 22:06:06 +00:00
2017-03-02 02:14:56 +00:00
for user_agent in user_agents :
2015-10-14 21:02:25 +00:00
2017-03-02 02:14:56 +00:00
if ' / ' in user_agent :
( client , network_version ) = user_agent . split ( ' / ' , 1 )
if client == ' hydrus ' :
request . is_hydrus_user_agent = True
network_version = int ( network_version )
if network_version == HC . NETWORK_VERSION : return
else :
if network_version < HC . NETWORK_VERSION : message = ' Your client is out of date; please download the latest release. '
else : message = ' This server is out of date; please ask its admin to update to the latest release. '
raise HydrusExceptions . NetworkVersionException ( ' Network version mismatch! This server \' s network version is ' + str ( HC . NETWORK_VERSION ) + ' , whereas your client \' s is ' + str ( network_version ) + ' ! ' + message )
2015-10-14 21:02:25 +00:00
2017-03-02 02:14:56 +00:00
def _callbackParseGETArgs ( self , request ) :
hydrus_args = HydrusNetwork . ParseGETArgs ( request . args )
2013-10-02 22:06:06 +00:00
request . hydrus_args = hydrus_args
return request
def _callbackParsePOSTArgs ( self , request ) :
request . content . seek ( 0 )
2015-09-16 18:11:00 +00:00
if not request . requestHeaders . hasHeader ( ' Content-Type ' ) :
2013-10-02 22:06:06 +00:00
2015-09-16 18:11:00 +00:00
hydrus_args = { }
2013-10-02 22:06:06 +00:00
else :
2015-09-16 18:11:00 +00:00
content_types = request . requestHeaders . getRawHeaders ( ' Content-Type ' )
2015-03-25 22:04:19 +00:00
2015-09-16 18:11:00 +00:00
content_type = content_types [ 0 ]
2015-03-25 22:04:19 +00:00
2017-03-02 02:14:56 +00:00
try :
2013-10-02 22:06:06 +00:00
2017-03-02 02:14:56 +00:00
mime = HC . mime_enum_lookup [ content_type ]
2015-09-16 18:11:00 +00:00
2017-03-02 02:14:56 +00:00
except :
2015-09-16 18:11:00 +00:00
2017-03-02 02:14:56 +00:00
raise HydrusExceptions . ForbiddenException ( ' Did not recognise Content-Type header! ' )
2015-09-16 18:11:00 +00:00
2017-03-02 02:14:56 +00:00
2017-06-21 21:15:59 +00:00
total_bytes_read = 0
2017-03-02 02:14:56 +00:00
if mime == HC . APPLICATION_JSON :
2015-10-14 21:02:25 +00:00
json_string = request . content . read ( )
2017-06-21 21:15:59 +00:00
total_bytes_read + = len ( json_string )
2015-10-14 21:02:25 +00:00
2017-03-02 02:14:56 +00:00
hydrus_args = HydrusNetwork . ParseBodyString ( json_string )
2015-10-14 21:02:25 +00:00
2015-09-16 18:11:00 +00:00
else :
2015-11-04 22:30:28 +00:00
( os_file_handle , temp_path ) = HydrusPaths . GetTempPath ( )
2015-09-16 18:11:00 +00:00
request . temp_file_info = ( os_file_handle , temp_path )
with open ( temp_path , ' wb ' ) as f :
2013-10-02 22:06:06 +00:00
2015-11-04 22:30:28 +00:00
for block in HydrusPaths . ReadFileLikeAsBlocks ( request . content ) :
2015-09-16 18:11:00 +00:00
f . write ( block )
2017-06-21 21:15:59 +00:00
total_bytes_read + = len ( block )
2015-09-16 18:11:00 +00:00
2013-10-02 22:06:06 +00:00
2015-09-16 18:11:00 +00:00
hydrus_args = ParseFileArguments ( temp_path )
2013-10-02 22:06:06 +00:00
2017-06-21 21:15:59 +00:00
self . _reportDataUsed ( request , total_bytes_read )
2013-10-02 22:06:06 +00:00
request . hydrus_args = hydrus_args
return request
def _callbackRenderResponseContext ( self , request ) :
2015-03-25 22:04:19 +00:00
self . _CleanUpTempFile ( request )
2013-10-02 22:06:06 +00:00
response_context = request . hydrus_response_context
status_code = response_context . GetStatusCode ( )
request . setResponseCode ( status_code )
2017-03-02 02:14:56 +00:00
for ( k , v , kwargs ) in response_context . GetCookies ( ) :
request . addCookie ( k , v , * * kwargs )
2013-10-02 22:06:06 +00:00
do_finish = True
2017-03-02 02:14:56 +00:00
if response_context . HasPath ( ) :
2013-10-02 22:06:06 +00:00
path = response_context . GetPath ( )
2016-04-14 01:54:29 +00:00
size = os . path . getsize ( path )
2013-10-02 22:06:06 +00:00
2017-03-02 02:14:56 +00:00
mime = response_context . GetMime ( )
if mime == HC . APPLICATION_UNKNOWN :
2013-10-02 22:06:06 +00:00
mime = HydrusFileHandling . GetMime ( path )
2017-03-02 02:14:56 +00:00
content_type = HC . mime_string_lookup [ mime ]
2013-10-02 22:06:06 +00:00
content_length = size
2017-03-02 02:14:56 +00:00
( base , filename ) = os . path . split ( path )
content_disposition = ' inline; filename= " ' + filename + ' " '
2015-11-04 22:30:28 +00:00
# can't be unicode!
request . setHeader ( ' Content-Type ' , str ( content_type ) )
2013-10-02 22:06:06 +00:00
request . setHeader ( ' Content-Length ' , str ( content_length ) )
2016-08-03 22:15:54 +00:00
request . setHeader ( ' Content-Disposition ' , str ( content_disposition ) )
2013-10-02 22:06:06 +00:00
2014-07-16 20:50:18 +00:00
request . setHeader ( ' Expires ' , time . strftime ( ' %a , %d % b % Y % H: % M: % S GMT ' , time . gmtime ( time . time ( ) + 86400 * 365 ) ) )
2017-03-02 02:14:56 +00:00
request . setHeader ( ' Cache-Control ' , str ( 86400 * 365 ) )
2014-07-16 20:50:18 +00:00
2013-10-02 22:06:06 +00:00
fileObject = open ( path , ' rb ' )
producer = NoRangeStaticProducer ( request , fileObject )
producer . start ( )
do_finish = False
2017-03-02 02:14:56 +00:00
elif response_context . HasBody ( ) :
mime = response_context . GetMime ( )
body = response_context . GetBody ( )
content_type = HC . mime_string_lookup [ mime ]
content_length = len ( body )
content_disposition = ' inline '
request . setHeader ( ' Content-Type ' , content_type )
request . setHeader ( ' Content-Length ' , str ( content_length ) )
request . setHeader ( ' Content-Disposition ' , content_disposition )
request . write ( HydrusData . ToByteString ( body ) )
2013-10-02 22:06:06 +00:00
else :
content_length = 0
request . setHeader ( ' Content-Length ' , str ( content_length ) )
2017-06-21 21:15:59 +00:00
self . _reportDataUsed ( request , content_length )
self . _reportRequestUsed ( request )
2013-10-02 22:06:06 +00:00
2015-11-18 22:44:07 +00:00
if do_finish :
request . finish ( )
2013-10-02 22:06:06 +00:00
def _callbackDoGETJob ( self , request ) :
def wrap_thread_result ( response_context ) :
request . hydrus_response_context = response_context
return request
d = deferToThread ( self . _threadDoGETJob , request )
d . addCallback ( wrap_thread_result )
return d
def _callbackDoPOSTJob ( self , request ) :
def wrap_thread_result ( response_context ) :
request . hydrus_response_context = response_context
return request
d = deferToThread ( self . _threadDoPOSTJob , request )
d . addCallback ( wrap_thread_result )
return d
2015-11-25 22:00:57 +00:00
def _errbackDisconnected ( self , failure , request_deferred ) :
request_deferred . cancel ( )
2013-10-02 22:06:06 +00:00
def _errbackHandleEmergencyError ( self , failure , request ) :
2015-08-12 20:35:24 +00:00
try : self . _CleanUpTempFile ( request )
except : pass
2015-03-25 22:04:19 +00:00
2015-11-18 22:44:07 +00:00
try : HydrusData . DebugPrint ( failure . getTraceback ( ) )
2015-08-12 20:35:24 +00:00
except : pass
2013-10-02 22:06:06 +00:00
try : request . write ( failure . getTraceback ( ) )
except : pass
2015-11-25 22:00:57 +00:00
try : request . finish ( )
except : pass
2013-10-02 22:06:06 +00:00
def _errbackHandleProcessingError ( self , failure , request ) :
2015-03-25 22:04:19 +00:00
self . _CleanUpTempFile ( request )
2017-03-02 02:14:56 +00:00
default_mime = HC . TEXT_HTML
default_encoding = HydrusData . ToByteString
2014-01-01 20:01:00 +00:00
2017-03-02 02:14:56 +00:00
if failure . type == KeyError :
2014-01-01 20:01:00 +00:00
2017-05-31 21:50:53 +00:00
response_context = ResponseContext ( 400 , mime = default_mime , body = default_encoding ( ' It appears one or more parameters required for that request were missing: ' + os . linesep + failure . getTraceback ( ) ) )
2014-01-01 20:01:00 +00:00
2017-03-02 02:14:56 +00:00
elif failure . type == HydrusExceptions . BandwidthException :
2013-10-02 22:06:06 +00:00
2017-03-02 02:14:56 +00:00
response_context = ResponseContext ( 509 , mime = default_mime , body = default_encoding ( failure . value ) )
2013-10-02 22:06:06 +00:00
2017-03-02 02:14:56 +00:00
elif failure . type == HydrusExceptions . PermissionException :
2013-10-02 22:06:06 +00:00
2017-03-02 02:14:56 +00:00
response_context = ResponseContext ( 401 , mime = default_mime , body = default_encoding ( failure . value ) )
elif failure . type == HydrusExceptions . ForbiddenException :
response_context = ResponseContext ( 403 , mime = default_mime , body = default_encoding ( failure . value ) )
elif failure . type in ( HydrusExceptions . NotFoundException , HydrusExceptions . DataMissing ) :
response_context = ResponseContext ( 404 , mime = default_mime , body = default_encoding ( failure . value ) )
elif failure . type == HydrusExceptions . NetworkVersionException :
response_context = ResponseContext ( 426 , mime = default_mime , body = default_encoding ( failure . value ) )
elif failure . type == HydrusExceptions . ServerBusyException :
response_context = ResponseContext ( 503 , mime = default_mime , body = default_encoding ( failure . value ) )
elif failure . type == HydrusExceptions . SessionException :
response_context = ResponseContext ( 419 , mime = default_mime , body = default_encoding ( failure . value ) )
2013-10-02 22:06:06 +00:00
else :
2015-11-18 22:44:07 +00:00
HydrusData . DebugPrint ( failure . getTraceback ( ) )
2013-10-02 22:06:06 +00:00
2015-03-25 22:04:19 +00:00
response_context = ResponseContext ( 500 , mime = default_mime , body = default_encoding ( ' The repository encountered an error it could not handle! Here is a dump of what happened, which will also be written to your client.log file. If it persists, please forward it to hydrus.admin@gmail.com: ' + os . linesep * 2 + failure . getTraceback ( ) ) )
2013-10-02 22:06:06 +00:00
request . hydrus_response_context = response_context
return request
def _parseAccessKey ( self , request ) :
2017-03-02 02:14:56 +00:00
if not request . requestHeaders . hasHeader ( ' Hydrus-Key ' ) :
raise HydrusExceptions . PermissionException ( ' No hydrus key header found! ' )
2013-10-02 22:06:06 +00:00
hex_keys = request . requestHeaders . getRawHeaders ( ' Hydrus-Key ' )
hex_key = hex_keys [ 0 ]
2017-03-02 02:14:56 +00:00
try :
access_key = hex_key . decode ( ' hex ' )
except :
raise HydrusExceptions . ForbiddenException ( ' Could not parse the hydrus key! ' )
2013-10-02 22:06:06 +00:00
return access_key
2017-06-21 21:15:59 +00:00
def _reportDataUsed ( self , request , num_bytes ) :
2017-03-02 02:14:56 +00:00
2017-06-21 21:15:59 +00:00
self . _service . ReportDataUsed ( num_bytes )
HG . controller . ReportDataUsed ( num_bytes )
def _reportRequestUsed ( self , request ) :
2017-03-02 02:14:56 +00:00
2017-06-21 21:15:59 +00:00
self . _service . ReportRequestUsed ( )
2017-03-02 02:14:56 +00:00
2017-06-21 21:15:59 +00:00
HG . controller . ReportRequestUsed ( )
2017-03-02 02:14:56 +00:00
2013-10-02 22:06:06 +00:00
2017-05-31 21:50:53 +00:00
def _threadDoGETJob ( self , request ) :
raise HydrusExceptions . NotFoundException ( ' This service does not support that request! ' )
2013-10-02 22:06:06 +00:00
2017-05-31 21:50:53 +00:00
def _threadDoPOSTJob ( self , request ) :
raise HydrusExceptions . NotFoundException ( ' This service does not support that request! ' )
2013-10-02 22:06:06 +00:00
2015-03-25 22:04:19 +00:00
def _CleanUpTempFile ( self , request ) :
if hasattr ( request , ' temp_file_info ' ) :
( os_file_handle , temp_path ) = request . temp_file_info
2015-11-04 22:30:28 +00:00
HydrusPaths . CleanUpTempPath ( os_file_handle , temp_path )
2015-03-25 22:04:19 +00:00
2015-08-12 20:35:24 +00:00
del request . temp_file_info
2015-03-25 22:04:19 +00:00
2013-10-02 22:06:06 +00:00
def render_GET ( self , request ) :
request . setHeader ( ' Server ' , self . _server_version_string )
d = defer . Deferred ( )
d . addCallback ( self . _callbackCheckRestrictions )
d . addCallback ( self . _callbackParseGETArgs )
d . addCallback ( self . _callbackDoGETJob )
d . addErrback ( self . _errbackHandleProcessingError , request )
d . addCallback ( self . _callbackRenderResponseContext )
d . addErrback ( self . _errbackHandleEmergencyError , request )
reactor . callLater ( 0 , d . callback , request )
2015-11-25 22:00:57 +00:00
request . notifyFinish ( ) . addErrback ( self . _errbackDisconnected , d )
2013-10-02 22:06:06 +00:00
return NOT_DONE_YET
def render_POST ( self , request ) :
request . setHeader ( ' Server ' , self . _server_version_string )
d = defer . Deferred ( )
d . addCallback ( self . _callbackCheckRestrictions )
d . addCallback ( self . _callbackParsePOSTArgs )
d . addCallback ( self . _callbackDoPOSTJob )
d . addErrback ( self . _errbackHandleProcessingError , request )
d . addCallback ( self . _callbackRenderResponseContext )
d . addErrback ( self . _errbackHandleEmergencyError , request )
reactor . callLater ( 0 , d . callback , request )
2015-11-25 22:00:57 +00:00
request . notifyFinish ( ) . addErrback ( self . _errbackDisconnected , d )
2013-10-02 22:06:06 +00:00
return NOT_DONE_YET
2017-05-31 21:50:53 +00:00
class HydrusResourceRobotsTXT ( HydrusResource ) :
def _threadDoGETJob ( self , request ) :
body = ''' User-agent: *
Disallow : / '''
response_context = ResponseContext ( 200 , mime = HC . TEXT_PLAIN , body = body )
return response_context
2017-03-02 02:14:56 +00:00
class HydrusResourceWelcome ( HydrusResource ) :
def _threadDoGETJob ( self , request ) :
body = GenerateEris ( self . _service , self . _domain )
response_context = ResponseContext ( 200 , mime = HC . TEXT_HTML , body = body )
return response_context
2015-03-25 22:04:19 +00:00
class ResponseContext ( object ) :
2017-03-02 02:14:56 +00:00
def __init__ ( self , status_code , mime = HC . APPLICATION_JSON , body = None , path = None , cookies = None ) :
if isinstance ( body , HydrusSerialisable . SerialisableBase ) :
body = body . DumpToNetworkString ( )
2015-03-25 22:04:19 +00:00
2017-03-02 02:14:56 +00:00
if cookies is None :
cookies = [ ]
2015-03-25 22:04:19 +00:00
self . _status_code = status_code
self . _mime = mime
self . _body = body
self . _path = path
self . _cookies = cookies
2017-03-02 02:14:56 +00:00
def GetBody ( self ) :
return self . _body
2015-03-25 22:04:19 +00:00
def GetCookies ( self ) : return self . _cookies
def GetLength ( self ) : return len ( self . _body )
2017-03-02 02:14:56 +00:00
def GetMime ( self ) : return self . _mime
2015-03-25 22:04:19 +00:00
def GetPath ( self ) : return self . _path
def GetStatusCode ( self ) : return self . _status_code
def HasBody ( self ) : return self . _body is not None
def HasPath ( self ) : return self . _path is not None