Exemple #1
0
    def run_local(self, url):
        log.last_url = None
        log.last_url_fetched = None

        log.ThugLogging.set_url(url)
        log.ThugOpts.local = True

        log.HTTPSession = HTTPSession()

        content = open(url, 'r', encoding="utf-8").read()
        extension = os.path.splitext(url)

        if len(extension) > 1 and extension[1].lower() in (
                '.js',
                '.jse',
        ):
            if not content.lstrip().startswith('<script'):
                html = tostring(E.HTML(E.HEAD(), E.BODY(E.SCRIPT(content))))
            else:
                soup = bs4.BeautifulSoup(content, "html.parser")

                try:
                    soup.html.unwrap()
                except AttributeError:
                    pass

                try:
                    soup.head.unwrap()
                except AttributeError:
                    pass

                try:
                    soup.body.unwrap()
                except AttributeError:
                    pass

                code = soup.script.get_text(types=(NavigableString, CData,
                                                   Script))
                html = tostring(E.HTML(E.HEAD(), E.BODY(E.SCRIPT(code))))
        else:
            html = content

        if log.ThugOpts.features_logging:
            log.ThugLogging.Features.add_characters_count(len(html))

            whitespaces_count = len([
                a for a in html
                if isinstance(a, six.string_types) and a.isspace()
            ])
            log.ThugLogging.Features.add_whitespaces_count(whitespaces_count)

        doc = w3c.parseString(html)
        window = Window('about:blank', doc, personality=log.ThugOpts.useragent)
        window.open()
        self.__run(window)
Exemple #2
0
    def run_local(self, url):
        log.last_url = None
        log.last_url_fetched = None

        log.ThugLogging.set_url(url)
        log.ThugOpts.local = True

        log.HTTPSession = HTTPSession()

        content = open(url, 'r').read()
        extension = os.path.splitext(url)
        encoding = cchardet.detect(content)

        if len(extension) > 1 and extension[1].lower() in (
                '.js',
                '.jse',
        ):
            if not content.lstrip().startswith('<script'):
                html = tostring(
                    E.HTML(
                        E.HEAD(),
                        E.BODY(E.SCRIPT(content.decode(
                            encoding['encoding'])))))
            else:
                soup = BeautifulSoup(content, "html.parser")

                try:
                    soup.html.unwrap()
                except AttributeError:
                    pass

                try:
                    soup.head.unwrap()
                except AttributeError:
                    pass

                try:
                    soup.body.unwrap()
                except AttributeError:
                    pass

                html = tostring(
                    E.HTML(E.HEAD(), E.BODY(E.SCRIPT(soup.script.get_text()))))
        else:
            html = content

        if log.ThugOpts.features_logging:
            log.ThugLogging.Features.add_characters_count(len(html))
            log.ThugLogging.Features.add_whitespaces_count(
                len([a for a in html if a.isspace()]))

        doc = w3c.parseString(html)
        window = Window('about:blank', doc, personality=log.ThugOpts.useragent)
        window.open()
        self.__run(window)
Exemple #3
0
def html_page_return(board, thread, default_style):
    html = E.HTML(
        E.HEAD(
            E.META(**{'http-equiv':"Default-Style", 'content':default_style, 'id':'stylemetatag'}),
            E.TITLE("/"+board+"/ - №"+str(thread)), #title
            E.SCRIPT(type = 'text/javascript', src = '/mainscript.js'), #js
            *initiate.style_cache
            ),
        E.BODY(
            E.P(E.CLASS("board"), board, id = 'board'),
            E.P(E.CLASS("thread"), str(thread), id = 'thread'),
            E.TABLE(
                E.CLASS("maintable"),
                E.THEAD(E.TR(E.TD(
                    E.TABLE(E.TR(E.TD(E.CLASS('left'), copy.copy(initiate.board_cache_navigation)),
                                 E.TD(E.CLASS('right'), utilfunctions.generate_right_up_corner_menu()),
                                 ),
                            id='headblock'),
                    E.HR(E.CLASS("delimeter")),
                    )), id = 'header'),
                E.TBODY(E.TR(E.TD(
                    E.H2(E.CLASS("boardname"),
                         E.A('/' + board + '/ - '+ initiate.board_cache[board].name, href = '/' + board),
                         ),
                    E.HR(E.CLASS("delimeter")),
                    initiate.board_cache[board].post_form, #need to make it depending on post_form_type
                    E.SCRIPT('function open_form() {document.getElementById("postform").style.display = "block"; document.getElementById("closeform").style.display = "block"; document.getElementById("threadcreate").style.display = "none";}'),
                    E.SCRIPT('function close_form() {document.getElementById("postform").style.display = "none"; document.getElementById("closeform").style.display = "none"; document.getElementById("threadcreate").style.display = "block";}'),
                    E.H3(E.A('Ответить в тред', href = "javascript:open_form();"), id = 'threadcreate'),
                    E.H4(E.A('Скрыть форму', href = "javascript:close_form();"), id = 'closeform'),
                    E.HR(E.CLASS("delimeter")),
                    EM('main', '', id = 'mainframe'),
                    E.DIV('', id = 'optionsdiv'),
                    )), id = 'mainpart'),
                E.TFOOT(E.TR(E.TD(
                       E.DIV(
                           E.HR(E.CLASS("delimeter"), id = 'end')
                           ),
                       initiate.board_cache_navigation,
                       E.DIV('powered by ',
                             E.A('Farlight Imageboard Engine',
                                 href='https://github.com/Alpherie/farlight_board_engine',
                                 target='_blank',
                                 ),
                             id='credentials'),
                    )), id = 'footer'),#we make it a footer
                ),
            onload = 'threadfunc()'
            )
        )
    return lxml.html.tostring(html)
Exemple #4
0
 def footer():
     """put non-essential javascript in the footer"""
     return E.E.footer(
         # zepto is the one resource we don't embed.
         # It's (relatively) big, and non-essential.
         E.SCRIPT(
             src=('http://cdnjs.cloudflare.com'
                  '/ajax/libs/zepto/1.1.3/zepto.js'),
             type='text/javascript',
         ),
         E.SCRIPT(
             file_contents('script.js'),
             type='text/javascript',
         ),
     )
Exemple #5
0
def gen_posts(p_list):
    index = builder.HTML(
        builder.HEAD(*make_head()),
        builder.BODY(make_menu(),
                     builder.DIV(
                         builder.H1("Posts", builder.CLASS("section-title")),
                         *make_short_posts(p_list), builder.CLASS("section")),
                     style="background-color:#f7f7f7"))
    print(html.etree.tostring(index, pretty_print=True,
                              method='html').decode("utf-8"),
          file=open(os.path.join(base_path, "posts.html"), "w"))

    for post in p_list:
        html_content = builder.DIV(
            builder.H1(post.title, builder.CLASS("full-post-title")),
            builder.DIV(post.date.strftime("%d %B %Y, %H:%M"),
                        builder.CLASS("full-post-date")),
            builder.DIV(html.fromstring(post.content),
                        builder.CLASS("full-post-content")),
            builder.CLASS("full-post-container"))

        page = builder.HTML(
            builder.HEAD(
                *make_head(),
                builder.SCRIPT("", src=base_url + "js/table.js"),
            ), builder.BODY(make_menu(), html_content))
        print(html.etree.tostring(page, pretty_print=True,
                                  method='html').decode("utf-8"),
              file=open(
                  os.path.join(base_path, "posts", post.id, "index.html"),
                  "w"))
Exemple #6
0
    def transform(self, result, encoding):
        css = u''
        javascript = u''
        for parent in parents(self.published.context, iface=IFlowFolder):
            css = parent._v_css = getattr(  # noqa: P001
                parent,
                '_v_css',
                Scss().compile(parent.css or u''),
            )
            javascript =\
                (parent.javascript or u'').strip().replace(u'\r\n', u'\n')
            break

        root = result.tree.getroot()
        if css:
            head = root.find('head')
            # trick LXML to render styles with //<!CDATA[[
            style = builder.STYLE(u'\n/*', type='text/css')
            style.append(builder.S(CDATA(u'*/\n' + css + u'\n/*')))
            style.getchildren()[0].tail = u'*/\n'
            head.append(style)
            # head.append(builder.STYLE(
            #     css,
            #     type='text/css',
            # ))

        if javascript:
            body = root.find('body')
            # trick LXML to render script with //<!CDATA[[
            script = builder.SCRIPT(u'\n//', type='application/javascript')
            script.append(builder.S(CDATA(u'\n' + javascript + u'\n//')))
            script.getchildren()[0].tail = u'\n'
            body.append(script)

        return result
Exemple #7
0
    def inject(self, req, req_body, res, res_body):
        #print ("subtype")
        #print(res.headers.get_content_subtype() )
        #print ("status")
        #print(res.status)
        #print ("Content-Encoding")
        #print(res.getheader)
        #print("res")
        #print(bytes(self.getFakePlugins(),'utf-8') + decompress(res_body))
        scripts       = ScriptsInjection.getAll()
        subtype       = res.headers.get_content_subtype()
        status        = res.status
        contentEncode = res.getheader('Content-Encoding')

        # various checks to make sure we're only injecting the script on appropriate responses
        # we check that the content type is HTML, that the status code is 200, and that the encoding is gzip
        if subtype == "javascript" and self.hasInjectedJS==False:
            self.hasInjectedJS=True
            return compress(bytes(scripts,'utf-8') + decompress(res_body))
        elif subtype == "html":
            script_elem_to_inject = builder.SCRIPT(scripts)
            if status != 200 or contentEncode != 'gzip':
                return None
            try:
                parsed_html = html.fromstring(decompress(res_body))
            except ParserError:
                return None
            try:
                parsed_html.head.insert(0, script_elem_to_inject)
            except IndexError: # no head element
                return None
            self.hasInjectedJS=True
            return compress(html.tostring(parsed_html))
def template(name, contents):

    cpu_class = 'active' if name == 'cpu' else ''
    wc_class = 'active' if name == 'wc' else ''
    help_class = 'active' if name == 'help' else ''

    return E.HTML(
        E.HEAD(
            E.LINK(rel='stylesheet',
                   type='text/css',
                   href='bootstrap/css/bootstrap.css'),
            E.LINK(rel='stylesheet', type='text/css', href='profile.css'),
            E.SCRIPT(src='bootstrap/js/bootstrap.min.js'),
            E.TITLE('RUM Job Profile')),
        E.BODY(
            E.DIV(E.DIV(E.DIV(E.A(E.SPAN(CLASS='icon-bar'),
                                  E.SPAN(CLASS='icon-bar'),
                                  E.SPAN(CLASS='icon-bar'),
                                  CLASS='btn btn-navbar'),
                              E.A('RUM Profile', CLASS='brand', href='#'),
                              E.DIV(E.UL(E.LI(E.A('CPU time', href='cpu.html'),
                                              CLASS=cpu_class),
                                         E.LI(E.A('Wallclock time',
                                                  href='wc.html'),
                                              CLASS=wc_class),
                                         E.LI(E.A('Help', href='help.html'),
                                              CLASS=help_class),
                                         CLASS='nav'),
                                    CLASS='nav-collapse collapse'),
                              CLASS='container'),
                        CLASS='navbar-inner'),
                  CLASS='navbar navbar-inverse navbar-fixed-top'), E.BR(),
            E.BR(), E.BR(), E.DIV(contents, CLASS='container')))
Exemple #9
0
def list_bans_menu(ban_list, purpose):
    """need to put bans and boards table creating to a joint function in future"""
    tablerows = [E.TR(E.TD(str(b.id)),
                      E.TD(b.ip),
                      E.TD(b.initiator),
                      E.TD(time.strftime('%d/%m/%Y %H:%M', time.localtime(b.date))),
                      E.TD(str(b.level)),
                      E.TD(E.BUTTON('Снять', type = 'button', onclick = 'remove_ban(this);'))
                      )for b in ban_list]
    #purpose will be applyed later
    html = E.HTML(
        E.HEAD(
            E.LINK(rel="stylesheet", href="/css/deeplight.css", type="text/css"), 
            E.TITLE("Creating board"),
            E.SCRIPT(type = 'text/javascript', src = '/adminscript.js') #js
            ),
        E.BODY(
            E.DIV(E.CLASS('adminupdiv'),
                E.DIV(E.CLASS('logout'), E.A('Logout', href='/admin/logout')),
                E.H2(E.CLASS("heading"), "Listing bans"),
                ),
            E.TABLE(
                E.CLASS("boardstable"),
                E.TR(E.TH('ID'),
                     E.TH('IP'),
                     E.TH('Забанивший'),
                     E.TH('Дата'),
                     E.TH('Уровень'),
                     E.TH('')
                     ),
                *tablerows
                )
            )
        )
    return lxml.html.tostring(html)
Exemple #10
0
def _add_popcorn_plugins(document_tree, config):
    """Adds the popcorn plugins from the template config"""
    if not config:
        return document_tree
    static_tag = "{{baseDir}}"
    script_text = '<script type="text/javascript" src="%s"></script>'
    fix_url = lambda x: x.replace(' ','').replace(static_tag,
                                                  settings.STATIC_URL)
    head = document_tree.xpath('//head')[0]
    popcorn = E.SCRIPT(src=settings.STATIC_URL+'dist/buttered-popcorn.min.js',
                       type="text/javascript")
    head.append(popcorn)
    for plugin in config['plugin']['plugins']:
        src = fix_url(plugin['path'])
        script_tag = E.SCRIPT(type="text/javascript", src=src)
        head.append(script_tag)
    return document_tree
Exemple #11
0
def _add_popcorn_metadata(document_tree, metadata):
    """Transform the metadata into Popcorn instructions"""
    if not metadata:
        return document_tree
    data = json.loads(metadata)
    popcorn = prepare_popcorn_string_from_project_data(data)
    body = document_tree.xpath('//body')[0]
    script = E.SCRIPT(popcorn, type="text/javascript")
    body.append(script)
    return document_tree
Exemple #12
0
def make_head():
    head = [
        #builder.BASE(href="https://dakovalev1.github.io/my_site/"),
        #builder.BASE(href="http://localhost/my_site/docs/"), # ONLY FOR DEBUG!!!
        #builder.BASE(href=sys.argv[1]),
        builder.META(charset="utf-8"),
        builder.TITLE("Dmitry Kovalev"),
        builder.META(name="viewport",
                     content="width=device-width, initial-scale=1"),
        builder.SCRIPT(
            "",
            type="text/javascript",
            src=
            "https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.4/MathJax.js",
            async="async"),
        builder.SCRIPT(open("src/js/mathjax.js").read(),
                       type="text/x-mathjax-config"),
        builder.SCRIPT(
            "",
            src=
            "https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"
        ),
        #builder.SCRIPT("", src="js/jquery.waypoints.min.js"),
        #builder.SCRIPT("", src="js/jquery.scrollTo.min.js"),
        builder.LINK(
            rel="stylesheet",
            href="https://use.fontawesome.com/releases/v5.8.1/css/all.css",
            integrity=
            "sha384-50oBUHEmvpQ+1lW4y57PTFmhCaXp0ML5d60M1M7uH2+nqUivzIebhndOJK28anvf",
            crossorigin="anonymous"),
        builder.LINK(
            rel="stylesheet",
            href=
            "https://cdn.rawgit.com/jpswalsh/academicons/master/css/academicons.min.css"
        ),
        builder.LINK(rel="stylesheet", href=base_url + "css/menu.css"),
        builder.LINK(rel="stylesheet", href=base_url + "css/common.css"),
        builder.SCRIPT("", src=base_url + "js/menu.js"),
        builder.SCRIPT("", src=base_url + "js/scroll.js"),
    ]

    return head
Exemple #13
0
    def run_local(self, url):
        log.ThugLogging.set_url(url)
        log.ThugOpts.local = True

        log.HTTPSession = HTTPSession()

        content = open(url, 'r').read()
        extension = os.path.splitext(url)

        if len(extension) > 1 and extension[1].lower() in (
                '.js',
                '.jse',
        ):
            if not content.lstrip().startswith('<script'):
                html = tostring(E.HTML(E.HEAD(), E.BODY(E.SCRIPT(content))))
            else:
                soup = BeautifulSoup(content, "html.parser")

                try:
                    soup.html.unwrap()
                except AttributeError:
                    pass

                try:
                    soup.head.unwrap()
                except AttributeError:
                    pass

                try:
                    soup.body.unwrap()
                except AttributeError:
                    pass

                html = tostring(
                    E.HTML(E.HEAD(), E.BODY(E.SCRIPT(soup.script.get_text()))))
        else:
            html = content

        doc = w3c.parseString(html)
        window = Window('about:blank', doc, personality=log.ThugOpts.useragent)
        window.open()
        self.__run(window)
Exemple #14
0
def list_boards_menu(board_list, purpose):
    """need to put boards table creating to a separate function in future"""
    posts_num_cell = E.DIV(E.SPAN('????', style = 'display:inline-block; width:4em; text-align:center;'),
                           E.INPUT(type='number', size='6', min='0', value='1', style = 'width: 6em;'),
                           E.SELECT(E.OPTION('Секунды', value='1'),
                                    E.OPTION('Минуты', value='60'),
                                    E.OPTION('Часы', value='3600'),
                                    E.OPTION('Дни', value='86400', selected='')
                                    ),
                           E.BUTTON('GET', onclick='get_posts_num_from_time(this)', type = 'button'))
    tablerows = [E.TR(E.TD(E.A(b.address, href = '/'+b.address)),
                      E.TD(b.tablename),
                      E.TD(str(b.name)),
                      E.TD(str(b.fullname)),
                      E.TD(str(b.description)),
                      E.TD(str(b.category)),
                      E.TD(str(b.pictures)),
                      E.TD(str(b.bumplimit)),
                      E.TD(str(b.maxthreads)),
                      E.TD(copy.copy(posts_num_cell))
                      )for b in board_list]
    #purpose will be applyed later
    html = E.HTML(
        E.HEAD(
            E.LINK(rel="stylesheet", href="/css/deeplight.css", type="text/css"), 
            E.TITLE("Creating board"),
            E.SCRIPT(type = 'text/javascript', src = '/adminscript.js') #js
            ),
        E.BODY(
            E.DIV(E.CLASS('adminupdiv'),
                E.DIV(E.CLASS('logout'), E.A('Logout', href='/admin/logout')),
                E.H2(E.CLASS("heading"), "Listing boards"),
                ),
            E.TABLE(
                E.CLASS("boardstable"),
                E.TR(E.TH('Адрес'),
                     E.TH('Таблица'),
                     E.TH('Название'),
                     E.TH('Полное название'),
                     E.TH('Описание'),
                     E.TH('Категория'),
                     E.TH('Максимум картинок'),
                     E.TH('Бамплимит'),
                     E.TH('Максимум тредов'),
                     E.TH('Постов за последнее время')
                     ),
                *tablerows
                )
            )
        )
    return lxml.html.tostring(html)
Exemple #15
0
def main_page_gen(default_style):
    html = E.HTML(
        E.HEAD(
            E.META(**{'http-equiv':"Default-Style", 'content':default_style, 'id':'stylemetatag'}),
            E.TITLE("U2ch - Main Page"),
            E.SCRIPT(type = 'text/javascript', src = '/mainscript.js'), #js
	    *initiate.style_cache
            ),
        E.BODY(
            E.UL(initiate.stats_cache,
                 style = "display: none;",
                 id = "mblstatscache"),
	    E.TABLE(
                E.CLASS("maintable"),
                E.THEAD(E.TR(E.TD(E.DIV(E.CLASS("mainslogandiv"),
                                        E.SPAN("U2CH"),
                                        E.SPAN("",
                                               style="display: inline-block; width: 5em;"),
                                        E.SPAN("Viewing above imageboards"),
                                        ),
                                  E.DIV(E.CLASS("mainimagediv"),
                                        E.IMG(src="u-2.jpg", style="width:496px;height:334px;"),
                                        ),
                                  )), id = 'header'),
                E.TBODY(E.TR(E.TD(
                    E.HR(E.CLASS("delimeter")),
                    E.DIV(E.CLASS("mblcontainer"),
                          E.DIV(E.CLASS("mblcentering"),
                                initiate.board_cache_main_page,
                                ),
                          ),
                    E.HR(E.CLASS("delimeter")),
                    )), id = 'mainpart'),
                E.TFOOT(E.TR(E.TD(
                    E.DIV('powered by ',
                        E.A('Farlight Imageboard Engine',
                            href='https://github.com/Alpherie/farlight_board_engine',
                            target='_blank',
                            ),
                        id='credentials'),
                    )), id = 'footer'),
                ),
            onload = 'mainpagefunc()'
            )
        )
    return lxml.html.tostring(html)
 def head(self):
     """The HEAD of the html document"""
     head = E.HEAD(
         E.META({
             'http-equiv': 'Content-Type',
             'content': 'text/html; charset=utf-8'
         }),
         E.TITLE('%s -- GCC Python Plugin' % self.data['filename']),
     )
     head.extend(
         E.LINK(rel='stylesheet', href=css + '.css', type='text/css')
         for css in ('extlib/reset-20110126', 'pygments_c', 'style'))
     head.extend(
         E.SCRIPT(src=js + '.js')
         for js in ('extlib/prefixfree-1.0.4.min',
                    'extlib/jquery-1.7.1.min', 'script'))
     return head
Exemple #17
0
    def run_local(self, url):
        log.ThugLogging.set_url(url)
        log.ThugOpts.local = True

        log.HTTPSession = HTTPSession()

        content = open(url, 'r').read()
        extension = os.path.splitext(url)

        if len(extension) > 1 and extension[1].lower() in ('.js'):
            html = tostring(E.HTML(E.BODY(E.SCRIPT(content))))
        else:
            html = content

        doc = w3c.parseString(html)
        window = Window('about:blank', doc, personality=log.ThugOpts.useragent)
        window.open()
        self.run(window)
Exemple #18
0
def send(self, varBody = None):
    msg = "send"
    if varBody:
        msg = "%s('%s')" % (msg, str(varBody), )

    log.ThugLogging.add_behavior_warn("[Microsoft XMLHTTP ActiveX] %s" % (msg, ))
    log.ThugLogging.add_behavior_warn("[Microsoft XMLHTTP ActiveX] Fetching from URL %s (method: %s)" % (self.bstrUrl,
                                                                                                         self.bstrMethod, ))
    log.ThugLogging.log_exploit_event(self._window.url,
                                      "Microsoft XMLHTTP ActiveX",
                                      "Send",
                                      forward = False,
                                      data = {
                                                "method" : self.bstrMethod,
                                                "url"    : str(self.bstrUrl)
                                             }
                                     )

    response = None

    self.dispatchEvent("loadstart")

    try:
        response = self._window._navigator.fetch(self.bstrUrl,
                                                 method        = self.bstrMethod,
                                                 headers       = self.requestHeaders,
                                                 body          = varBody,
                                                 redirect_type = "Microsoft XMLHTTP")
    except Exception:
        log.ThugLogging.add_behavior_warn('[Microsoft XMLHTTP ActiveX] Fetch failed')
        self.dispatchEvent("timeout")
        self.dispatchEvent("error")

    if response is None:
        return 0

    self.status          = response.status_code
    self.responseHeaders = response.headers
    self.responseBody    = response.content
    self.responseText    = response.text
    self.readyState      = 4

    if getattr(log, 'XMLHTTP', None) is None:
        log.XMLHTTP = dict()

    log.XMLHTTP['status']          = self.status
    log.XMLHTTP['responseHeaders'] = self.responseHeaders
    log.XMLHTTP['responseBody']    = self.responseBody
    log.XMLHTTP['responseText']    = self.responseText
    log.XMLHTTP['readyState']      = self.readyState

    last_bstrUrl    = log.XMLHTTP.get('last_bstrUrl', None)
    last_bstrMethod = log.XMLHTTP.get('last_bstrMethod', None)

    if last_bstrUrl in (self.bstrUrl, ) and last_bstrMethod in (self.bstrMethod, ): # pragma: no cover
        return 0

    log.XMLHTTP['last_bstrUrl']    = str(self.bstrUrl)
    log.XMLHTTP['last_bstrMethod'] = str(self.bstrMethod)

    if self.mimeType:
        contenttype = self.mimeType
    else:
        contenttype = self.responseHeaders.get('content-type', None)

    if contenttype is None: # pragma: no cover
        return 0

    self.dispatchEvent("load")
    self.dispatchEvent("readystatechange")

    if 'javascript' in contenttype:
        html = tostring(E.HTML(E.HEAD(), E.BODY(E.SCRIPT(response.text))))

        doc = DOM.W3C.w3c.parseString(html)
        window = DOM.Window.Window(self.bstrUrl, doc, personality = log.ThugOpts.useragent)

        dft = DOM.DFT.DFT(window)
        dft.run()
        return 0

    if 'text/html' in contenttype:
        tags = ('<html', '<body', '<head', '<script')

        if not any(tag in response.text.lower() for tag in tags):
            html = tostring(E.HTML(E.HEAD(), E.BODY(E.SCRIPT(response.text)))) # pragma: no cover
        else:
            html = response.text

        doc = DOM.W3C.w3c.parseString(html)
        window = DOM.Window.Window(self.bstrUrl, doc, personality = log.ThugOpts.useragent)
        dft = DOM.DFT.DFT(window)
        dft.run()
        return 0

    handler = log.MIMEHandler.get_handler(contenttype)
    if handler:
        handler(self.bstrUrl, self.responseBody)

    return 0
Exemple #19
0
def process_robot_output(robot_output):
    root = etree.parse(robot_output).getroot()
    print("one time")
    for suite in root.xpath("//suite[@source]"):
        suite_id = suite.get("id", "")
        suite_container = E.DIV(E.CLASS("suite span12"), id=suite_id)
        suite_container.append(E.H3(E.CLASS("span12"), suite.get("name", "")))

        tests = suite.xpath(".//test")
        for i, test in enumerate(tests):
            test_id = "{0}".format(test.get("id", ""))

            test_container = E.DIV(E.CLASS("span6"))
            test_name = test.get("name", "")

            test_container.append(E.H4(test_name))

            doc = "".join([
                doc.text for doc in test.xpath("./doc") if doc.text is not None
            ])
            test_container.append(E.P(doc))

            status_tags = test.xpath("./status")
            status = ""
            if status_tags != []:
                status = status_tags[0].get("status")
                if status == "PASS":
                    btn_class = "btn-success"
                    text_class = "text-success"
                elif status == "FAIL":
                    btn_class = "btn-danger"
                    text_class = "text-error"

            btn_id = test_id + "-btn"
            test_container.append(
                E.BUTTON(status,
                         E.CLASS("btn " + btn_class),
                         type="button",
                         id=btn_id))

            btn = test_container.get_element_by_id(btn_id)
            btn.set("data-target", "#" + test_id)
            btn.set("data-toggle", "collapse")

            messages = E.DIV(E.CLASS("collapse " + text_class), id=test_id)
            for kw in test.xpath("./kw"):
                for msg in kw.xpath(".//msg"):
                    messages.append(format_msg(msg, status=status))
                if kw.get(
                        "name") == "Selenium2Library.Wait Until Page Contains":
                    text_check = [
                        "text" in doc.text for doc in kw.xpath(".//doc")
                    ]
                    if text_check:
                        text_match = " ".join(
                            [arg.text for arg in kw.xpath(".//arg")])
                    messages.append(
                        E.P("Checking the page contains: " + text_match))
            test_container.append(messages)

            # Two columns per row
            if i % 2 == 0 or i == len(tests):
                row = E.DIV(E.CLASS("row"), test_container)
                suite_container.append(row)
            else:
                row.append(test_container)

        content_area.append(E.DIV(E.CLASS("row"), suite_container))

    # ScrollSpy might be nice
    # report.body.set("data-spy","scroll")
    # report.body.set("data-target", ".suite")
    report.append(E.SCRIPT(src="http://code.jquery.com/jquery-1.9.1.min.js"))

    report.append(
        E.SCRIPT(
            src=
            "http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/js/bootstrap.min.js"  # noqa: E501
        ))
Exemple #20
0
    def generate(self):
        Logger.info("Generating Chart by id {0}".format(self._cid))
        self._data = {"columns": []}

        if isinstance(self.chart_type, dict):
            self._data["types"] = {
                key: get_raw_type(value)
                for key, value in self.chart_type.items()
            }
            self.raw_type = "MultipleType_{0}".format("_".join(
                list(self._data["types"].values())))
        elif isinstance(self.chart_type, str):
            self._data["type"] = get_raw_type(self.chart_type)
            self.raw_type = "SingleType_{0}".format(self._data["type"])
        else:
            raise ChartTypeError("invalid type format: {0}".format(
                self.chart_type))

        if "x" in self.options.keys():
            self._data["x"] = self.options["x"]
            self.options.pop("x", None)

        try:
            if self.stack:
                self._data["groups"] = [self.dataframe.columns.tolist()]
        except:
            pass

        for col in self.dataframe.columns:
            self._data["columns"].append([col] +
                                         self.dataframe[col].values.tolist())

        self._root = lxhtml.DIV(lxhtml.DIV(id=self._id),
                                lxhtml.CLASS("billboard-{0}".format(
                                    self.raw_type)),
                                style="padding: 10px;")

        script_text = ""
        if self.include_res:
            self._root.append(
                lxhtml.SCRIPT(get_config("billboard-js"),
                              id="{0}-js".format(self._id)))
            self._root.append(
                lxhtml.STYLE(get_config("billboard-css"),
                             id="{0}-css".format(self._id)))

            script_text += """
if (document.getElementById("billboard-js") == null && document.getElementById("billboard-css") == null) {
    var billboard_js = document.createElement("script"), billboard_css = document.createElement("style");
    billboard_js.id = "billboard-js", billboard_css.id = "billboard-css";

    billboard_js.appendChild(document.createTextNode(document.getElementById("%(js_id)s").text));
    billboard_css.appendChild(document.createTextNode(document.getElementById("%(css_id)s").innerText));

    document.head.appendChild(billboard_js);
    document.head.appendChild(billboard_css);
}

document.getElementById("%(js_id)s").remove();
document.getElementById("%(css_id)s").remove();
""" % {
                "js_id": "{0}-js".format(self._id),
                "css_id": "{0}-css".format(self._id)
            }

        script_text += """
bb.generate({
    bindto: "#%s",
    data: %s,
    %s
});
""" % (self._id, self._data, ",\n".join([
            "'{0}': {1}".format(key, value)
            for key, value in self.options.items()
        ]))

        self._root.append(
            lxhtml.SCRIPT(script_text,
                          type="text/javascript",
                          id="{0}-script".format(self._id),
                          onload="eval(this.text);"))

        Logger.info("Generated Chart {0}".format(self.raw_type))
Exemple #21
0
def build(input_file, configs):
    # Making build folder
    build_name = os.path.normpath(configs["buildPath"] + configs["timeStamp"])
    base_dir = os.path.abspath(os.path.dirname(input_file))
    build_dir = os.path.join(base_dir, build_name)
    os.makedirs(build_dir, exist_ok=True)

    # Getting list of excluded files:
    excludes = get_files(base_dir, configs["exclude"])
    
    # Merging requested files in config-file:
    merged_objects = merge(configs["merge"], base_dir, build_dir, excludes, configs["obfuscate"])
    merged_files = [f for mo in merged_objects for f in mo.merging_files]

    # Traverse directory of the given html file recursively and process unmerged remaining files:
    for root, dirs, files in os.walk(base_dir):

        if build_name in dirs:
            dirs.remove(build_name)

        if files:
            # remove config file from files list:
            if configs["file"] in files:
                files.remove(configs["file"])

        dest = os.path.join(build_dir, os.path.relpath(root, base_dir))
        for file in files:
            file_path = os.path.join(root, file)
            # If file was already part of a merge process:
            if file_path in merged_files or file_path in excludes:
                continue

            if is_min_file_exists(file, file_path):
                continue

            os.makedirs(dest, exist_ok=True)

            ext = os.path.splitext(file)[1][1:]
            if ext in configs["minify"] and not is_min_file(file):
                # Processing(minifying) js/css file:
                print("minifying %s" % file_path)
                min_file_path = os.path.join(dest, os.path.splitext(os.path.basename(file))[0] + ".min." + ext)
                if ext == "js":
                    data = slimit.minify(open(file_path, "r", encoding="utf-8").read(), mangle=configs["obfuscate"], mangle_toplevel=False)
                else:
                    data = csscompressor.compress(open(file_path, "r", encoding="utf-8").read())
                
                with open(min_file_path, "w", encoding="utf-8") as min_file:
                    min_file.write(data)

            else:
                # just copy the file.
                print("copying %s" % file_path)
                shutil.copy2(file_path, dest)


    # Now editing given html file <script> and <link> tags:
    print("Updating html file...")
    tree = None
    with open(os.path.join(build_dir, os.path.basename(input_file)), "r", encoding="utf-8") as html_file:
        tree = html.parse(html_file)

        # Updating javascript tags:
        for tag in tree.findall("//script[@src]"):
            if tag.attrib["src"].startswith("http"):
                continue
            # Get the complete path of source file:
            src_file = os.path.normpath(os.path.join(base_dir, tag.attrib["src"]))
            if src_file in merged_files:
                # Source file is part of a merge:
                mo = get_merge_object(merged_objects, src_file)
                if mo is not None and not mo.added:
                    # Replacing new merged file tag with old one:
                    new_tag = E.SCRIPT(type="text/javascript", src=mo.into)
                    tag.getparent().replace(tag, new_tag)
                    mo.added = True
                else:
                    # Merged file tag was already added.
                    tag.getparent().remove(tag)
            elif not src_file.endswith(".min.js"):
                # replacing source file with minified one:
                tag.attrib["src"] = os.path.relpath(src_file, base_dir)[:-2] + "min.js"

        # Updating stylesheet link tags:
        for tag in tree.xpath('//*[@rel="stylesheet" or @media="all" or @media="screen"]'):
            if tag.attrib["href"].startswith("http"):
                continue
            # Get the complete path of source file:
            href_file = os.path.normpath(os.path.join(base_dir, tag.attrib["href"]))
            if href_file in merged_files:
                # Source file is part of a merge:
                mo = get_merge_object(merged_objects, href_file)
                if mo is not None and not mo.added:
                    # Replacing new merged file tag with old one:
                    new_tag = E.LINK(rel="stylesheet", type="text/css", href=mo.into)
                    tag.getparent().replace(tag, new_tag)
                    mo.added = True
                else:
                    # Merged file tag was already added.
                    tag.getparent().remove(tag)
            elif not href_file.endswith(".min.css"):
                # replacing href file with minified one:
                tag.attrib["href"] = os.path.relpath(href_file, base_dir)[:-3] + "min.css"

    with open(os.path.join(build_dir, os.path.basename(input_file)), "wb") as html_file:
        html_file.write(html.tostring(tree, encoding="utf-8", pretty_print=True))

    print("Done!")
Exemple #22
0
                termin["name"] = aktuelle_veranstaltung
                termin["modul"] = modulname
                termin["studiengang"] = studiengaenge[counter]
                termin["id"] = id
                id += 1
                tabelle.append(termin)
                #if "s_termin_typ" in termin:
                #    print("      " + termin["s_termin_typ"])
                #    print("      " + termin["s_termin_von"] + " - " + termin["s_termin_bis"])
    counter += 1

# Alle Module eingeladen, hoffe ich

htmlfile = E.HTML(
    E.HEAD(E.LINK(rel="stylesheet", href="plan.css", type="text/css"),
           E.SCRIPT(src="plan.js", type="text/javascript"),
           E.META(charset="utf-8"), E.TITLE("Test")),
    E.BODY(E.H1("Stundenplan")))
document = htmlfile.find("body")

for studiengang in studiengaenge:
    print(studiengang)
    document.append(E.H2(studiengang, name=studiengang))
    container = E.DIV(E.CLASS("plancontainer"))
    #        E.DIV(E.CLASS("plancontainer"))

    for stunde in range(59):
        style = "top: " + str(2 + (100 / 60) * stunde) + "%; "
        mnt = str(int((stunde + 2) % 4 * 15))
        if mnt == "0":
            mnt = "00"
Exemple #23
0
 def _lxml_form_generator(self):
     """Is used for generating lxml post form"""
     formargs = []
     formargs.append(E.TR(
                           E.TD('EMAIL'),
                           E.TD(E.INPUT(type = 'text', name = 'email', value = '', id = 'emailfield'),
                                E.INPUT(type = 'submit', value = 'POST', id = 'postbutton')
                                ),
                           )
                     )
     formargs.append(E.TR(
                           E.TD('THEME'),
                           E.TD(E.INPUT(type = 'text', name = 'theme', value = '', size = '50')),
                           )
                     )
     formargs.append(E.TR(
                           E.TD('NAME'),
                           E.TD(E.INPUT(type = 'text', name = 'name', value = '', size = '50')),
                           )
                     )
     formargs.append(E.TR(
                           E.TD('TEXT'),
                           E.TD(E.TEXTAREA(name = 'text', rows = '8', cols = '50', placeholder = 'POST')),
                           )
                     )
     if self.pictures == 0:
         pass
     elif self.pictures == 1:
         formargs.append(E.TR(#should add checking if pics are available
                           E.TD('PICTURE'),
                           E.TD(E.INPUT(type = 'file', name = 'file0', accept = 'image/*'),
                                id = 'filecellone'),
                           )
                         )
     else:
         formargs.append(E.TR(#should add checking if pics are available
                           E.TD('PICTURE'),
                           E.TD(E.INPUT(type = 'file', name = 'file0', accept = 'image/*'),
                                E.BUTTON('+', type = 'button', onclick = 'add_file_input(this);', id = '0filebutton'),
                                E.SPAN(str(self.pictures), style = 'display:none;', id = 'maxfiles'),
                                id = 'filecellmany'),
                           )
                         )
     formargs.append(E.TR(#should add checking if deleting is available
                           E.TD('PASSWORD'),
                           E.TD(E.INPUT(type = 'password', name = 'password', value = '', size = '10'),
                                id = 'passwordcell'),
                           )
                     )
     if True:#should add checking if captcha is available
         formargs.append(E.TR(
                           E.TD(
                               E.CENTER('CAPTCHA WILL BE HERE'),
                               colspan = '2'
                               )
                           )
                         )
         formargs.append(E.TR(E.TD('CAPTCHA'),
                              E.TD(E.INPUT(type = 'text', name = 'captcha', value = '')),
                              )
                         )
         
     
     form = E.FORM(E.CLASS("postform"), #postform
                   E.INPUT(type = 'hidden', name = 'action', value = 'post'),
                   E.INPUT(type = 'hidden', name = 'op', value = '0', id = 'op_referer'),
                   E.SCRIPT('document.getElementById("op_referer").value = document.getElementById("thread").innerHTML;'),
                   E.TABLE(*formargs),
                   method = 'POST', action = '/'+self.address, enctype = 'multipart/form-data', id = 'postform')
     return form