Exemplo n.º 1
0
def get_download_ids(browser):
    browser.switch_to.window(browser.window_handles[2])
    browser.delete_all_cookies()
    cookies = config.get_cookies()
    if len(cookies) < 4:
        config.login(browser)
        return
    for cookie in cookies:
        browser.add_cookie({'name': cookie[0], 'value': cookie[1]})
    url = get_url()
    browser.get(url)
    content = browser.page_source
    if u'你今天的访问超出正常用户的最大访问限制!' in content:
        config.change_account()
        # 清理cookie,下次换账号登录
        f = open(sys.path[0] + '/cookie.txt', 'w')
        f.close()
    print config.echo_time() + " get download urls success: " + url + "\n"
    # print content
    p = re.compile(r'((?<=("/judgement/))[a-zA-Z0-9]+(?=(")))')
    result = p.findall(content)
    if len(result) == 0:
        config.login(browser)
        return
    f = open(sys.path[0] + '/ids.txt', 'w')
    for id in result:
        f.write(id[0] + ",\n")
    f.close()
Exemplo n.º 2
0
def run():
    cf.login()
    time.sleep(1)
    cf.driver.get('https://www.facebook.com/blackjackhuy')
    time.sleep(.5)
    friend_button = cf.driver.find_element_by_class_name('FriendButton')
    hover = ActionChains(cf.driver).move_to_element(friend_button)
    hover.perform()
    time.sleep(.3)
    unfriend_button = cf.driver.find_element_by_class_name(
        'FriendListUnfriend')
    unfriend_button.click()
    time.sleep(2)
Exemplo n.º 3
0
def main():
    client = config.login()
    tweets = process_mentions(client)
    for i in range(len(tweets)):
        client.create_favorite(tweets[i].id)
        new_tweet = "https://twitter.com/"
        new_tweet += tweets[i].user.screen_name
        new_tweet += "/status/"
        new_tweet += str(tweets[i].id)
        words = extract_words(client, tweets[i])
        new_tweet += "\n"
        try:
            new_tweet_list = get_lyrics(words)
        except (RuntimeError, KeyError, IndexError):
            new_tweet += "One of your requested words cannot be used. Here's a random verse instead:\n"
            new_tweet_list = get_lyrics()
            for bar in new_tweet_list:
                new_tweet += bar
                new_tweet += "\n"
        else:
            for bar in new_tweet_list:
                new_tweet += bar
                new_tweet += "\n"
        tweet = client.update_status(status=new_tweet)
        client.create_favorite(tweet.id)
    return
Exemplo n.º 4
0
def main():

    client = config.login()
    # could also use this, in case i want to like things on this account
    # dictionary_index = client.me().statuses_count
    # but then couldn't retweet phrases that begin with "imagine" - is a tradeoff
    dictionary_index = client.me().favourites_count

    try:
        word = load_word(dictionary_index)
    except UnboundLocalError:  # out of bounds
        word = None

    if word:
        tweet_text = "imagine " + word
        tweeter(client, tweet_text)
        return

    else:
        # last message
        if dictionary_index == 61336:
            tweet_text = "imagine manually tweeting every word in the english language for years"
            tweeter(client, tweet_text)
        else:
            personal_account_id = int(config.os.getenv("PERSONAL_ACCOUNT_ID"))
            dm = "The years are up!"
            client.send_direct_message(personal_account_id, dm)
        return
Exemplo n.º 5
0
def tweet_random_verse(event, context):
    client = config.login()
    new_tweet = ""
    new_tweet_list = get_lyrics()
    for bar in new_tweet_list:
        new_tweet += bar
        new_tweet += "\n"
    tweet = client.update_status(status=new_tweet)
    client.create_favorite(tweet.id)
    return
Exemplo n.º 6
0
def download(browser):
    browser.switch_to.window(browser.window_handles[0])
    browser.delete_all_cookies()
    cookies = config.get_cookies()
    if len(cookies) < 4:
        config.login(browser)
        return
    for cookie in cookies:
        browser.add_cookie({'name': cookie[0], 'value': cookie[1]})
    ids = config.get_ids()
    f = open(sys.path[0] + '/ids.txt', 'w')
    f.close()
    if len(ids) == 0:
        spiderUrl.get_download_ids(browser)
        return
    for id in ids:
        browser.get(document_url(id[0]))
        #print driver.page_source
        page_source = browser.page_source
        soup = BeautifulSoup(page_source, 'lxml')

        content = get_content(soup)
        save_content(content, id[0])
        print config.echo_time() + " download " + id[0] + " success \n"
Exemplo n.º 7
0
def handler(req, profiling = True):
    req.content_type = "text/html; charset=UTF-8"
    req.header_sent = False

    # All URIs end in .py. We strip away the .py and get the
    # name of the page.
    req.myfile = req.uri.split("/")[-1][:-3]

    # Create an object that contains all data about the request and
    # helper functions for creating valid HTML. Parse URI and
    # store results in the request object for later usage.
    html = htmllib.html(req)
    html.id = {} # create unique ID for this request
    __builtin__.html = html
    req.uriinfo = htmllib.uriinfo(req)

    response_code = apache.OK
    try:
        # Do not parse variables again if profiling (and second run is done)
        if profiling:
            read_get_vars(req)
            read_cookies(req)

        # Ajax-Functions want no HTML output in case of an error but
        # just a plain server result code of 500
        fail_silently = html.has_var("_ajaxid")

        # Webservice functions may decide to get a normal result code
        # but a text with an error message in case of an error
        plain_error = html.has_var("_plain_error")

        config.load_config() # load multisite.mk
        if html.var("debug"): # Debug flag may be set via URL
            config.debug = True
        html.set_buffering(config.buffered_http_stream)

        # profiling can be enabled in multisite.mk
        if profiling and config.profile:
            import cProfile # , pstats, sys, StringIO, tempfile
            # the profiler looses the memory about all modules. We need to park
            # the request object in the apache module. This seems to be persistent.
            # Ubuntu: install python-profiler when using this feature
            apache._profiling_req = req
            profilefile = defaults.var_dir + "/web/multisite.profile"
            retcode = cProfile.run("import index; from mod_python import apache; index.handler(apache._profiling_req, False)", profilefile)
            file(profilefile + ".py", "w").write("#!/usr/bin/python\nimport pstats\nstats = pstats.Stats(%r)\nstats.sort_stats('time').print_stats()\n" % profilefile)
            os.chmod(profilefile + ".py", 0755)
            release_all_locks()
            return apache.OK

        # Make sure all plugins are avaiable as early as possible. At least
        # we need the plugins (i.e. the permissions declared in these) at the
        # time before the first login for generating auth.php.
        load_all_plugins()

        # Detect mobile devices
        if html.has_var("mobile"):
            html.mobile = not not html.var("mobile")
        else:
            user_agent = html.req.headers_in.get('User-Agent', '')
            html.mobile = mobile.is_mobile(user_agent)

        # Redirect to mobile GUI if we are a mobile device and
        # the URL is /
        if req.myfile == "index" and html.mobile:
            req.myfile = "mobile"

        # Get page handler
        handler = pagehandlers.get(req.myfile, page_not_found)

        # First initialization of the default permissions. Needs to be done before the auth_file
        # (auth.php) ist written (it's done during showing the login page for the first time).
        # Must be loaded before the "automation" call to have the general.* permissions available
        # during automation action processing (e.g. hooks triggered by restart)
        default_permissions.load()

        # Special handling for automation.py. Sorry, this must be hardcoded
        # here. Automation calls bybass the normal authentication stuff
        if req.myfile == "automation":
            try:
                handler()
            except Exception, e:
                html.write(str(e))
            release_all_locks()
            return apache.OK

        # Prepare output format
        output_format = html.var("output_format", "html")
        html.set_output_format(output_format)

        # Is the user set by the webserver? otherwise use the cookie based auth
        if not req.user or type(req.user) != str:
            config.auth_type = 'cookie'
            # When not authed tell the browser to ask for the password
            req.user = login.check_auth()
            if req.user == '':
                if fail_silently:
                    # While api call don't show the login dialog
                    raise MKUnauthenticatedException(_('You are not authenticated.'))

                # Initialize the i18n for the login dialog. This might be overridden
                # later after user login
                load_language(html.var("lang", config.get_language()))

                # After auth check the regular page can be shown
                result = login.page_login(plain_error)
                if type(result) == tuple:
                    # This is the redirect to the requested page directly after successful login
                    req.user = result[0]
                    req.uri  = result[1]
                    req.myfile = req.uri.split("/")[-1][:-3]
                    handler = pagehandlers.get(req.myfile, page_not_found)
                else:
                    release_all_locks()
                    return result

        # Call userdb page hooks which are executed on a regular base to e.g. syncronize
        # information withough explicit user triggered actions
        userdb.hook_page()

        # Set all permissions, read site config, and similar stuff
        config.login(html.req.user)

        # Initialize the multiste i18n. This will be replaced by
        # language settings stored in the user profile after the user
        # has been initialized
        load_language(html.var("lang", config.get_language()))

        # All plugins might have to be reloaded due to a language change
        load_all_plugins()

        # Reload default permissions (maybe reload due to language change)
        default_permissions.load()

        # User allowed to login at all?
        if not config.may("general.use"):
            reason = _("You are not authorized to use Check_MK Multisite. Sorry. "
                       "You are logged in as <b>%s</b>.") % config.user_id
            if len(config.user_role_ids):
                reason += _("Your roles are <b>%s</b>. " % ", ".join(config.user_role_ids))
            else:
                reason += _("<b>You do not have any roles.</b> ")
            reason += _("If you think this is an error, "
                        "please ask your administrator to check the permissions configuration.")

            if config.auth_type == 'cookie':
                reason += _('<p>You have been logged out. Please reload the page to re-authenticate.</p>')
                login.del_auth_cookie()

            raise MKAuthException(reason)

        # General access allowed. Now connect to livestatus
        connect_to_livestatus(html)

        handler()
Exemplo n.º 8
0
def handler(req, fields = None, profiling = True):
    req.content_type = "text/html; charset=UTF-8"
    req.header_sent = False

    # Create an object that contains all data about the request and
    # helper functions for creating valid HTML. Parse URI and
    # store results in the request object for later usage.
    html = html_mod_python(req, fields)
    html.enable_debug = config.debug
    html.id = {} # create unique ID for this request
    __builtin__.html = html
    response_code = apache.OK

    try:

        # Ajax-Functions want no HTML output in case of an error but
        # just a plain server result code of 500
        fail_silently = html.has_var("_ajaxid")

        # Webservice functions may decide to get a normal result code
        # but a text with an error message in case of an error
        plain_error = html.has_var("_plain_error")

        config.load_config() # load multisite.mk
        if html.var("debug"): # Debug flag may be set via URL
            config.debug = True

        if html.var("screenshotmode") or config.screenshotmode: # Omit fancy background, make it white
            html.screenshotmode = True

        html.enable_debug = config.debug
        html.set_buffering(config.buffered_http_stream)

        # profiling can be enabled in multisite.mk
        if profiling and config.profile:
            import cProfile # , pstats, sys, StringIO, tempfile
            # the profiler loses the memory about all modules. We need to hand over
            # the request object in the apache module.
            # Ubuntu: install python-profiler when using this feature
            profilefile = defaults.var_dir + "/web/multisite.profile"
            retcode = cProfile.runctx(
                "import index; "
                "index.handler(profile_req, profile_fields, False)",
                {'profile_req': req, 'profile_fields': html.fields}, {}, profilefile)
            file(profilefile + ".py", "w").write(
                "#!/usr/bin/python\n"
                "import pstats\n"
                "stats = pstats.Stats(%r)\n"
                "stats.sort_stats('time').print_stats()\n" % profilefile)
            os.chmod(profilefile + ".py", 0755)
            release_all_locks()
            return apache.OK

        # Make sure all plugins are avaiable as early as possible. At least
        # we need the plugins (i.e. the permissions declared in these) at the
        # time before the first login for generating auth.php.
        load_all_plugins()

        # Detect mobile devices
        if html.has_var("mobile"):
            html.mobile = not not html.var("mobile")
        else:
            user_agent = html.req.headers_in.get('User-Agent', '')
            html.mobile = mobile.is_mobile(user_agent)

        # Redirect to mobile GUI if we are a mobile device and
        # the URL is /
        if html.myfile == "index" and html.mobile:
            html.myfile = "mobile"

        # Get page handler.
        handler = pagehandlers.get(html.myfile, page_not_found)

        # First initialization of the default permissions. Needs to be done before the auth_file
        # (auth.php) ist written (it's done during showing the login page for the first time).
        # Must be loaded before the "automation" call to have the general.* permissions available
        # during automation action processing (e.g. hooks triggered by restart)
        default_permissions.load()

        # Some pages do skip authentication. This is done by adding
        # noauth: to the page hander, e.g. "noauth:run_cron" : ...
        if handler == page_not_found:
            handler = pagehandlers.get("noauth:" + html.myfile, page_not_found)
            if handler != page_not_found:
                try:
                    # Call userdb page hooks which are executed on a regular base to e.g. syncronize
                    # information withough explicit user triggered actions
                    userdb.hook_page()

                    handler()
                except Exception, e:
                    html.write(str(e))
                    if config.debug:
                        html.write(html.attrencode(format_exception()))
                release_all_locks()
                return apache.OK

        # Prepare output format
        output_format = html.var("output_format", "html")
        html.set_output_format(output_format)

        # Is the user set by the webserver? otherwise use the cookie based auth
        if not html.user or type(html.user) != str:
            config.auth_type = 'cookie'
            # When not authed tell the browser to ask for the password
            html.user = login.check_auth()
            if html.user == '':
                if fail_silently:
                    # While api call don't show the login dialog
                    raise MKUnauthenticatedException(_('You are not authenticated.'))

                # Redirect to the login-dialog with the current url as original target
                # Never render the login form directly when accessing urls like "index.py"
                # or "dashboard.py". This results in strange problems.
                if html.myfile != 'login':
                    html.http_redirect(defaults.url_prefix + 'check_mk/login.py?_origtarget=%s' %
                                                html.urlencode(html.makeuri([])))

                # Initialize the i18n for the login dialog. This might be overridden
                # later after user login
                load_language(html.var("lang", config.get_language()))

                # This either displays the login page or validates the information submitted
                # to the login form. After successful login a http redirect to the originally
                # requested page is performed.
                login.page_login(plain_error)
                release_all_locks()
                return apache.OK
        else:
            # In case of basic auth the user is already known, but we still need to decide
            # whether or not the user is an automation user (which is allowed to use transid=-1)
            if html.var("_secret"):
                login.check_auth_automation()

        # Call userdb page hooks which are executed on a regular base to e.g. syncronize
        # information withough explicit user triggered actions
        userdb.hook_page()

        # Set all permissions, read site config, and similar stuff
        config.login(html.user)
        html.load_help_visible()

        # Initialize the multiste i18n. This will be replaced by
        # language settings stored in the user profile after the user
        # has been initialized
        load_language(html.var("lang", config.get_language()))

        # All plugins might have to be reloaded due to a language change
        load_all_plugins()

        # Reload default permissions (maybe reload due to language change)
        default_permissions.load()

        # User allowed to login at all?
        if not config.may("general.use"):
            reason = _("You are not authorized to use Check_MK Multisite. Sorry. "
                       "You are logged in as <b>%s</b>.") % config.user_id
            if len(config.user_role_ids):
                reason += _("Your roles are <b>%s</b>. " % ", ".join(config.user_role_ids))
            else:
                reason += _("<b>You do not have any roles.</b> ")
            reason += _("If you think this is an error, "
                        "please ask your administrator to check the permissions configuration.")

            if config.auth_type == 'cookie':
                reason += _('<p>You have been logged out. Please reload the page to re-authenticate.</p>')
                login.del_auth_cookie()

            raise MKAuthException(reason)

        handler()
Exemplo n.º 9
0
def main():
    client = config.login()
    recent_liked = get_recent_tweet(client)
    if recent_liked:
        update_pin(client, recent_liked)
    return
Exemplo n.º 10
0
def handler(req, fields = None, is_profiling = False):
    # Create an object that contains all data about the request and
    # helper functions for creating valid HTML. Parse URI and
    # store results in the request object for later usage.
    __builtin__.html = html_mod_python(req, fields)

    response_code = apache.OK
    try:
        config.load_config() # load multisite.mk etc.
        html.init_modes()
        init_profiling(is_profiling)

        # Make sure all plugins are avaiable as early as possible. At least
        # we need the plugins (i.e. the permissions declared in these) at the
        # time before the first login for generating auth.php.
        modules.load_all_plugins()

        # Get page handler.
        handler = modules.get_handler(html.myfile, page_not_found)

        # Some pages do skip authentication. This is done by adding
        # noauth: to the page hander, e.g. "noauth:run_cron" : ...
        if handler == page_not_found:
            handler = modules.get_handler("noauth:" + html.myfile, page_not_found)
            if handler != page_not_found:
                try:
                    # Call userdb page hooks which are executed on a regular base to e.g. syncronize
                    # information withough explicit user triggered actions
                    userdb.hook_page()

                    handler()
                except Exception, e:
                    html.write(str(e))
                    if config.debug:
                        html.write(html.attrencode(format_exception()))
                raise FinalizeRequest()

        # Is the user set by the webserver? otherwise use the cookie based auth
        if not html.is_logged_in():
            config.auth_type = 'cookie'
            # When not authed tell the browser to ask for the password
            html.login(login.check_auth())
            if not html.is_logged_in():
                if fail_silently():
                    # While api call don't show the login dialog
                    raise MKUnauthenticatedException(_('You are not authenticated.'))

                # Redirect to the login-dialog with the current url as original target
                # Never render the login form directly when accessing urls like "index.py"
                # or "dashboard.py". This results in strange problems.
                if html.myfile != 'login':
                    html.http_redirect(defaults.url_prefix + 'check_mk/login.py?_origtarget=%s' %
                                                html.urlencode(html.makeuri([])))

                # Initialize the i18n for the login dialog. This might be overridden
                # later after user login
                i18n.localize(html.var("lang", config.get_language()))

                # This either displays the login page or validates the information submitted
                # to the login form. After successful login a http redirect to the originally
                # requested page is performed.
                login.page_login(plain_error())
                raise FinalizeRequest()
        else:
            # In case of basic auth the user is already known, but we still need to decide
            # whether or not the user is an automation user (which is allowed to use transid=-1)
            if html.var("_secret"):
                login.check_auth_automation()

        # Call userdb page hooks which are executed on a regular base to e.g. syncronize
        # information withough explicit user triggered actions
        userdb.hook_page()

        # Set all permissions, read site config, and similar stuff
        config.login(html.user)
        html.load_help_visible()

        # Initialize the multiste i18n. This will be replaced by
        # language settings stored in the user profile after the user
        # has been initialized
        i18n.localize(html.var("lang", config.get_language()))

        # All plugins might have to be reloaded due to a language change
        modules.load_all_plugins()

        # User allowed to login at all?
        if not config.may("general.use"):
            reason = _("You are not authorized to use Check_MK Multisite. Sorry. "
                       "You are logged in as <b>%s</b>.") % config.user_id
            if len(config.user_role_ids):
                reason += _("Your roles are <b>%s</b>. " % ", ".join(config.user_role_ids))
            else:
                reason += _("<b>You do not have any roles.</b> ")
            reason += _("If you think this is an error, "
                        "please ask your administrator to check the permissions configuration.")

            if config.auth_type == 'cookie':
                reason += _('<p>You have been logged out. Please reload the page to re-authenticate.</p>')
                login.del_auth_cookie()

            raise MKAuthException(reason)

        handler()
Exemplo n.º 11
0
def handler(req, fields = None, is_profiling = False):
    # Create an object that contains all data about the request and
    # helper functions for creating valid HTML. Parse URI and
    # store results in the request object for later usage.
    __builtin__.html = html_mod_python(req, fields)

    response_code = apache.OK
    try:
        config.load_config() # load multisite.mk etc.
        init_profiling(is_profiling)
        html.init_modes()

        # Make sure all plugins are avaiable as early as possible. At least
        # we need the plugins (i.e. the permissions declared in these) at the
        # time before the first login for generating auth.php.
        modules.load_all_plugins()

        # Get page handler.
        handler = modules.get_handler(html.myfile, page_not_found)

        # Some pages do skip authentication. This is done by adding
        # noauth: to the page hander, e.g. "noauth:run_cron" : ...
        if handler == page_not_found:
            handler = modules.get_handler("noauth:" + html.myfile, page_not_found)
            if handler != page_not_found:
                try:
                    handler()
                except Exception, e:
                    html.write("%s" % e)
                    if config.debug:
                        html.write(html.attrencode(format_exception()))
                raise FinalizeRequest()

        # Is the user set by the webserver? otherwise use the cookie based auth
        if not html.is_logged_in():
            config.auth_type = 'cookie'
            # When not authed tell the browser to ask for the password
            html.login(login.check_auth())
            if not html.is_logged_in():
                if fail_silently():
                    # While api call don't show the login dialog
                    raise MKUnauthenticatedException(_('You are not authenticated.'))

                # Redirect to the login-dialog with the current url as original target
                # Never render the login form directly when accessing urls like "index.py"
                # or "dashboard.py". This results in strange problems.
                if html.myfile != 'login':
                    html.http_redirect(defaults.url_prefix + 'check_mk/login.py?_origtarget=%s' %
                                                html.urlencode(html.makeuri([])))

                # Initialize the i18n for the login dialog. This might be overridden
                # later after user login
                i18n.localize(html.var("lang", config.get_language()))

                # This either displays the login page or validates the information submitted
                # to the login form. After successful login a http redirect to the originally
                # requested page is performed.
                login.page_login(plain_error())
                raise FinalizeRequest()
        else:
            # In case of basic auth the user is already known, but we still need to decide
            # whether or not the user is an automation user (which is allowed to use transid=-1)
            if html.var("_secret"):
                login.check_auth_automation()

        # Set all permissions, read site config, and similar stuff
        config.login(html.user)
        html.load_help_visible()

        # Initialize the multiste i18n. This will be replaced by
        # language settings stored in the user profile after the user
        # has been initialized
        previous_language = current_language
        i18n.localize(html.var("lang", config.get_language()))

        # All plugins might have to be reloaded due to a language change. Only trigger
        # a second plugin loading when the user is really using a custom localized GUI.
        # Otherwise the load_all_plugins() at the beginning of the request is sufficient.
        if current_language != previous_language:
            modules.load_all_plugins()

        # User allowed to login at all?
        if not config.may("general.use"):
            reason = _("You are not authorized to use Check_MK Multisite. Sorry. "
                       "You are logged in as <b>%s</b>.") % config.user_id
            if len(config.user_role_ids):
                reason += _("Your roles are <b>%s</b>. " % ", ".join(config.user_role_ids))
            else:
                reason += _("<b>You do not have any roles.</b> ")
            reason += _("If you think this is an error, "
                        "please ask your administrator to check the permissions configuration.")

            if config.auth_type == 'cookie':
                reason += _('<p>You have been logged out. Please reload the page to re-authenticate.</p>')
                login.del_auth_cookie()

            raise MKAuthException(reason)

        handler()
Exemplo n.º 12
0
    def handle(self):
        i = 0
        while 1:
            login = config.login()
            loginfo = self.request.recv(1024).strip().split(
                '\t')[:2]  #接收客户端的用户信息
            user = loginfo[0]
            passwd = loginfo[1]
            log_statu = login.login(user, passwd)  #获取登陆的状态发送给客户端 由客户端来判断是否登陆成功
            if i >= 2:
                u_id = config.exists(user)
                config.con.update('user_info', 'lockedtime', int(time.time()),
                                  u_id)
                break
            i += 1
            if log_statu == 'passwrong':
                self.request.sendall('passwrong')
            elif log_statu == 'nouser':
                self.request.sendall('nouser')
            elif log_statu == 'locked':
                self.request.sendall('locked')
            elif log_statu == True:
                home_dir = login.home
                if os.path.exists(home_dir) == False:
                    os.system('mkdir -p %s' % home_dir)
                self.request.sendall('true')
                while 1:
                    print "等待命令----------"
                    get_data = self.request.recv(1024).strip().split()  #等待命令接收
                    print get_data, '从客户端接收的参数。。。'
                    if len(get_data) >= 2:
                        cmd, filename = get_data[:2]  #取前两个列表的元素
                        target_file = '%s/%s' % (home_dir, filename)  #目标文件名
                        if cmd == 'get':
                            len_buf = 0
                            if os.path.exists(
                                    target_file
                            ) == True and os.path.getsize(target_file) != 0:
                                size = os.path.getsize(target_file)  #文件的总大小
                                print '正在发送 大小%s的文件' % size
                                self.request.send(str(size))  #将要下载的文件大小传值过去
                                time.sleep(0.05)
                                with open(target_file, 'rb') as f:
                                    while 1:
                                        #if not f.readline():break
                                        a = f.read(819600)  #一次读16392byte
                                        if len(a) == 0:
                                            g = self.request.recv(1024)
                                            self.request.sendall(
                                                md5sum(target_file))
                                            break
                                        else:
                                            self.request.sendall(a)

                            else:
                                self.request.sendall('no')
                        elif cmd == 'put':
                            len_data = 0  #标记
                            while 1:
                                str_tmp = self.request.recv(
                                    819600)  #本地有一个缓冲区接收文件块
                                if str_tmp == 'ok':
                                    self.request.sendall('down')
                                    get_md5 = self.request.recv(
                                        1024)  #接shou client MD5
                                    locmd5 = md5sum(target_file)
                                    print "server:%s  client:%s" % (locmd5,
                                                                    get_md5)
                                    if locmd5 == get_md5:
                                        self.request.sendall('ok')
                                    else:
                                        self.request.sendall('no')
                                    break
                                if not len_data:  #如果不存在len_data则创建文件并且赋值
                                    ofh = open(target_file, 'wb+')
                                    ofh.writelines(str_tmp)
                                    len_data = 1
                                    ofh.close()
                                    size = os.path.getsize(target_file)
                                    self.request.send(str(size))
                                else:
                                    ofh = open(target_file, 'ab+')
                                    ofh.writelines(str_tmp)
                                    ofh.close()
                                    size = os.path.getsize(target_file)
                                    self.request.send(str(size))  #文件现在的大小

                        elif cmd == 'del':
                            statu = commands.getstatusoutput('rm -rf %s' %
                                                             target_file)
                            if statu[0] == 0:
                                self.request.sendall('删除%s成功' % get_data[1])
                            else:
                                self.request.sendall("操作错误")
                        else:
                            statu = commands.getstatusoutput(get_data[0])
                            if statu[0] == 0:
                                self.request.sendall(statu[1])
                            else:
                                self.request.sendall("操作错误")
                    elif len(get_data) < 2:
                        print '%s %s' % (get_data[0], home_dir)
                        statu = commands.getstatusoutput(
                            '%s %s' % (get_data[0], home_dir))
                        if statu[0] == 0 and len(statu[1]) != 0:
                            self.request.sendall(statu[1])
                            print statu[1], '命令执行成功.'
                            continue
                        elif len(statu[1]) == 0:
                            self.request.sendall("NUll")
                        else:
                            self.request.sendall("false")
                            print '命令执行失败.'
                            continue
Exemplo n.º 13
0
options = base_parser.parse_args()


if not os.path.exists(CONFIG_FILE):
    create_config()

if options.create:
    project_name = options.repository
    description = options.descriptions
    organization = options.organization
    create_repository(project_name, description, organization=organization)
elif options.issues:
    url = find_github_remote()
    username, url = get_username_and_repo(url)
    if options.create:
        title = options.title
        description = options.description
        create_issue(username, url, title, description)
    elif options.list:
        get_issues(username, url, options.assigned)
    elif options.view:
        view_issue(username, url, options.issue)
    elif options.close:
        close_issue(username, url, options.issue)
    else:
        get_issues(username, url, False)
elif options.login:
    username = options.username
    password = options.password
    login(username, password)
Exemplo n.º 14
0
 def guitest_fake_login(self, user_id):
     config.login(user_id)
     self.user = user_id
Exemplo n.º 15
0
 def guitest_fake_login(self, user_id):
     config.login(user_id)
     self.user = user_id
# Get the final forecasts published
""""The project uses some python 36 code efficiencies.
The general flow of the script is as follows
1. Use the bearer and the basic connection parameters to extract the data spec for the project we want the forecasts for
2. One the data definition ID is obtained from the spec, we can then use it to export forecasts to a caslib of our choice
3. Before #2 happens, we also need to ensure that we delete any old tables with the same name from the caslib of interest
for table export"""

import requests, json
from config import login
import swat

creds = login()

#  Target Caslib for export
caslib_short = "Public"
# Target CasTable
castable_dest = "outfor"
# Initiate a new CAS Session
conn = swat.CAS(creds["hostname"],
                8777,
                creds["username"],
                creds["password"],
                protocol="http")
# change the current caslib to cas us
conn.setsessopt(caslib=caslib_short)


def get_auth_token(host, user, pswd):
    """Get bearer for requests"""
    print('Get authorization token...')
Exemplo n.º 17
0
    def handle(self):
      i=0  
      while 1:
        login=config.login()  
        loginfo = self.request.recv(1024).strip().split('\t')[:2]#接收客户端的用户信息
        user=loginfo[0]
        passwd=loginfo[1]
        log_statu=login.login(user,passwd)#获取登陆的状态发送给客户端 由客户端来判断是否登陆成功
        if i>=2:
            u_id=config.exists(user)
            config.con.update('user_info','lockedtime',int(time.time()),u_id)
	    break
        i+=1
        if log_statu=='passwrong':
            self.request.sendall('passwrong')
        elif log_statu=='nouser':
            self.request.sendall('nouser')
        elif log_statu=='locked':
            self.request.sendall('locked')
        elif log_statu==True:
            home_dir=login.home
            if os.path.exists(home_dir)==False:
                os.system('mkdir -p %s'%home_dir)
            self.request.sendall('true')
            while 1:
                print "等待命令----------"
                get_data = self.request.recv(1024).strip().split()#等待命令接收
                print get_data,'从客户端接收的参数。。。'
                if len(get_data)>=2:
                    cmd, filename = get_data[:2]#取前两个列表的元素
                    target_file='%s/%s'%(home_dir,filename)#目标文件名
                    if cmd == 'get':
                        len_buf=0
                        if os.path.exists(target_file)==True and os.path.getsize(target_file)!=0:
                            size=os.path.getsize(target_file)#文件的总大小
                            print '正在发送 大小%s的文件'%size
                            self.request.send(str(size))#将要下载的文件大小传值过去
                            time.sleep(0.05)
                            with open(target_file,'rb')as f:
                                while 1:
                                    #if not f.readline():break
                                    a=f.read(819600)#一次读16392byte
                                    if len(a)==0:
                                        g=self.request.recv(1024)
                                        self.request.sendall(md5sum(target_file))   
                                        break
                                    else:    
                                        self.request.sendall(a)
                                        
                        else:
                             self.request.sendall('no')
                    elif cmd == 'put':
                        len_data=0#标记
                        while 1:
                            str_tmp = self.request.recv(819600)#本地有一个缓冲区接收文件块
                            if str_tmp=='ok':
                                self.request.sendall('down')
                                get_md5=self.request.recv(1024)#接shou client MD5
                                locmd5=md5sum(target_file)
                                print "server:%s  client:%s"%(locmd5,get_md5)
                                if locmd5==get_md5:
                                    self.request.sendall('ok')
                                else:
                                    self.request.sendall('no')
                                break
                            if not len_data:#如果不存在len_data则创建文件并且赋值
                                ofh=open(target_file, 'wb+')
                                ofh.writelines(str_tmp)
                                len_data=1
                                ofh.close()
				size=os.path.getsize(target_file)
                                self.request.send(str(size))
                            else:    
                                ofh=open(target_file, 'ab+')
                                ofh.writelines(str_tmp)
                                ofh.close()
                                size=os.path.getsize(target_file)
                                self.request.send(str(size))#文件现在的大小
                                
                    elif cmd == 'del':
                        statu=commands.getstatusoutput('rm -rf %s'%target_file)
                        if statu[0]==0:
                            self.request.sendall('删除%s成功'%get_data[1])
                        else:
                            self.request.sendall("操作错误")
                    else:
                        statu=commands.getstatusoutput(get_data[0])
                        if statu[0]==0:
                            self.request.sendall(statu[1])
                        else:
                            self.request.sendall("操作错误")
                elif len(get_data)<2:
                    print '%s %s'%(get_data[0],home_dir)
                    statu=commands.getstatusoutput('%s %s'%(get_data[0],home_dir))
                    if statu[0]==0 and len(statu[1])!=0:
                        self.request.sendall(statu[1])
                        print statu[1],'命令执行成功.'
                        continue
                    elif len(statu[1])==0:
                        self.request.sendall("NUll") 
                    else:
                        self.request.sendall("false")
                        print '命令执行失败.'
                        continue
Exemplo n.º 18
0
def handler(req, fields = None, profiling = True):
    req.content_type = "text/html; charset=UTF-8"
    req.header_sent = False

    # Create an object that contains all data about the request and
    # helper functions for creating valid HTML. Parse URI and
    # store results in the request object for later usage.
    html = html_mod_python(req, fields)
    html.enable_debug = config.debug
    html.id = {} # create unique ID for this request
    __builtin__.html = html
    response_code = apache.OK

    try:

        # Ajax-Functions want no HTML output in case of an error but
        # just a plain server result code of 500
        fail_silently = html.has_var("_ajaxid")

        # Webservice functions may decide to get a normal result code
        # but a text with an error message in case of an error
        plain_error = html.has_var("_plain_error")

        config.load_config() # load multisite.mk
        if html.var("debug"): # Debug flag may be set via URL
            config.debug = True

        if html.var("screenshotmode") or config.screenshotmode: # Omit fancy background, make it white
            html.screenshotmode = True

        html.enable_debug = config.debug
        html.set_buffering(config.buffered_http_stream)

        # profiling can be enabled in multisite.mk
        if profiling and config.profile:
            import cProfile # , pstats, sys, StringIO, tempfile
            # the profiler looses the memory about all modules. We need to hand over
            # the request object in the apache module.
            # Ubuntu: install python-profiler when using this feature
            profilefile = defaults.var_dir + "/web/multisite.profile"
            retcode = cProfile.runctx(
                "import index; "
                "index.handler(profile_req, profile_fields, False)",
                {'profile_req': req, 'profile_fields': html.fields}, {}, profilefile)
            file(profilefile + ".py", "w").write(
                "#!/usr/bin/python\n"
                "import pstats\n"
                "stats = pstats.Stats(%r)\n"
                "stats.sort_stats('time').print_stats()\n" % profilefile)
            os.chmod(profilefile + ".py", 0755)
            release_all_locks()
            return apache.OK

        # Make sure all plugins are avaiable as early as possible. At least
        # we need the plugins (i.e. the permissions declared in these) at the
        # time before the first login for generating auth.php.
        load_all_plugins()

        # Detect mobile devices
        if html.has_var("mobile"):
            html.mobile = not not html.var("mobile")
        else:
            user_agent = html.req.headers_in.get('User-Agent', '')
            html.mobile = mobile.is_mobile(user_agent)

        # Redirect to mobile GUI if we are a mobile device and
        # the URL is /
        if html.myfile == "index" and html.mobile:
            html.myfile = "mobile"

        # Get page handler.
        handler = pagehandlers.get(html.myfile, page_not_found)

        # First initialization of the default permissions. Needs to be done before the auth_file
        # (auth.php) ist written (it's done during showing the login page for the first time).
        # Must be loaded before the "automation" call to have the general.* permissions available
        # during automation action processing (e.g. hooks triggered by restart)
        default_permissions.load()

        # Special handling for automation.py. Sorry, this must be hardcoded
        # here. Automation calls bybass the normal authentication stuff
        if html.myfile in [ "automation", "run_cron" ]:
            try:
                handler()
            except Exception, e:
                html.write(str(e))
                if config.debug:
                    html.write(html.attrencode(format_exception()))
            release_all_locks()
            return apache.OK

        # Prepare output format
        output_format = html.var("output_format", "html")
        html.set_output_format(output_format)

        # Is the user set by the webserver? otherwise use the cookie based auth
        if not html.user or type(html.user) != str:
            config.auth_type = 'cookie'
            # When not authed tell the browser to ask for the password
            html.user = login.check_auth()
            if html.user == '':
                if fail_silently:
                    # While api call don't show the login dialog
                    raise MKUnauthenticatedException(_('You are not authenticated.'))

                # Redirect to the login-dialog with the current url as original target
                # Never render the login form directly when accessing urls like "index.py"
                # or "dashboard.py". This results in strange problems.
                if html.myfile != 'login':
                    html.http_redirect(defaults.url_prefix + 'check_mk/login.py?_origtarget=%s' %
                                                html.urlencode(html.makeuri([])))

                # Initialize the i18n for the login dialog. This might be overridden
                # later after user login
                load_language(html.var("lang", config.get_language()))

                # This either displays the login page or validates the information submitted
                # to the login form. After successful login a http redirect to the originally
                # requested page is performed.
                login.page_login(plain_error)
                release_all_locks()
                return apache.OK

        # Call userdb page hooks which are executed on a regular base to e.g. syncronize
        # information withough explicit user triggered actions
        userdb.hook_page()

        # Set all permissions, read site config, and similar stuff
        config.login(html.user)
        html.load_help_visible()

        # Initialize the multiste i18n. This will be replaced by
        # language settings stored in the user profile after the user
        # has been initialized
        load_language(html.var("lang", config.get_language()))

        # All plugins might have to be reloaded due to a language change
        load_all_plugins()

        # Reload default permissions (maybe reload due to language change)
        default_permissions.load()

        # User allowed to login at all?
        if not config.may("general.use"):
            reason = _("You are not authorized to use Check_MK Multisite. Sorry. "
                       "You are logged in as <b>%s</b>.") % config.user_id
            if len(config.user_role_ids):
                reason += _("Your roles are <b>%s</b>. " % ", ".join(config.user_role_ids))
            else:
                reason += _("<b>You do not have any roles.</b> ")
            reason += _("If you think this is an error, "
                        "please ask your administrator to check the permissions configuration.")

            if config.auth_type == 'cookie':
                reason += _('<p>You have been logged out. Please reload the page to re-authenticate.</p>')
                login.del_auth_cookie()

            raise MKAuthException(reason)

        handler()
Exemplo n.º 19
0
import json
import os
import re
import time

import pymysql
import uuid
import requests
from pyquery import PyQuery as pq

import config

config.login()


def downloadJson():
    data = []
    for i in range(19):
        resp = config.sess.get(
            "http://xkzsp.cnis.gov.cn/works/report/list?page=" + str(i))
        time.sleep(1)
        resp.encoding = 'utf8'
        tbody = re.search('<tbody>.*?</tbody>', resp.text, re.DOTALL).group()
        trs = pq(tbody)('tr')
        for i in range(trs.length):
            tr = trs.eq(i)
            tds = tr("td")
            it = dict()
            it['name'] = tds.eq(0).text()
            nodeid = tds.eq(0).find('a').attr('href')
            nodeid = re.search('\d+', nodeid).group()
Exemplo n.º 20
0
def handler(req, profiling=True):
    req.content_type = "text/html; charset=UTF-8"
    req.header_sent = False

    # All URIs end in .py. We strip away the .py and get the
    # name of the page.
    req.myfile = req.uri.split("/")[-1][:-3]

    # Create an object that contains all data about the request and
    # helper functions for creating valid HTML. Parse URI and
    # store results in the request object for later usage.
    html = htmllib.html(req)
    html.id = {}  # create unique ID for this request
    __builtin__.html = html
    req.uriinfo = htmllib.uriinfo(req)

    response_code = apache.OK
    try:
        # Do not parse variables again if profiling (and second run is done)
        if profiling:
            read_get_vars(req)
            read_cookies(req)

        # Ajax-Functions want no HTML output in case of an error but
        # just a plain server result code of 500
        fail_silently = html.has_var("_ajaxid")

        # Webservice functions may decide to get a normal result code
        # but a text with an error message in case of an error
        plain_error = html.has_var("_plain_error")

        config.load_config()  # load multisite.mk
        if html.var("debug"):  # Debug flag may be set via URL
            config.debug = True
        html.set_buffering(config.buffered_http_stream)

        # profiling can be enabled in multisite.mk
        if profiling and config.profile:
            import cProfile  # , pstats, sys, StringIO, tempfile
            # the profiler looses the memory about all modules. We need to park
            # the request object in the apache module. This seems to be persistent.
            # Ubuntu: install python-profiler when using this feature
            apache._profiling_req = req
            profilefile = defaults.var_dir + "/web/multisite.profile"
            retcode = cProfile.run(
                "import index; from mod_python import apache; index.handler(apache._profiling_req, False)",
                profilefile)
            file(profilefile + ".py", "w").write(
                "#!/usr/bin/python\nimport pstats\nstats = pstats.Stats(%r)\nstats.sort_stats('time').print_stats()\n"
                % profilefile)
            os.chmod(profilefile + ".py", 0755)
            return apache.OK

        # Make sure all plugins are avaiable as early as possible. At least
        # we need the plugins (i.e. the permissions declared in these) at the
        # time before the first login for generating auth.php.
        load_all_plugins()

        # Detect mobile devices
        if html.has_var("mobile"):
            html.mobile = not not html.var("mobile")
        else:
            user_agent = html.req.headers_in.get('User-Agent', '')
            html.mobile = mobile.is_mobile(user_agent)

        # Redirect to mobile GUI if we are a mobile device and
        # the URL is /
        if req.myfile == "index" and html.mobile:
            req.myfile = "mobile"

        # Get page handler
        handler = pagehandlers.get(req.myfile, page_not_found)

        # Special handling for automation.py. Sorry, this must be hardcoded
        # here. Automation calls bybass the normal authentication stuff
        if req.myfile == "automation":
            try:
                handler()
            except Exception, e:
                html.write(str(e))
            return apache.OK

        # Prepare output format
        output_format = html.var("output_format", "html")
        html.set_output_format(output_format)

        # Is the user set by the webserver? otherwise use the cookie based auth
        if not req.user or type(req.user) != str:
            config.auth_type = 'cookie'
            # When not authed tell the browser to ask for the password
            req.user = login.check_auth()
            if req.user == '':
                if fail_silently:
                    # While api call don't show the login dialog
                    raise MKUnauthenticatedException(
                        _('You are not authenticated.'))

                # Initialize the i18n for the login dialog. This might be overridden
                # later after user login
                load_language(html.var("lang", config.get_language()))

                # After auth check the regular page can be shown
                result = login.page_login(plain_error)
                if type(result) == tuple:
                    # This is the redirect to the requested page directly after successful login
                    req.user = result[0]
                    req.uri = result[1]
                    req.myfile = req.uri.split("/")[-1][:-3]
                    handler = pagehandlers.get(req.myfile, page_not_found)
                else:
                    return result

        # Set all permissions, read site config, and similar stuff
        config.login(html.req.user)

        # Initialize the multiste i18n. This will be replaced by
        # language settings stored in the user profile after the user
        # has been initialized
        load_language(html.var("lang", config.get_language()))

        # All plugins might have to be reloaded due to a language change
        load_all_plugins()

        # Initialize default permissions (maybe reload due to language change)
        import default_permissions
        default_permissions.load()

        # User allowed to login at all?
        if not config.may("general.use"):
            reason = _(
                "You are not authorized to use Check_MK Multisite. Sorry. "
                "You are logged in as <b>%s</b>.") % config.user_id
            if len(config.user_role_ids):
                reason += _("Your roles are <b>%s</b>. " %
                            ", ".join(config.user_role_ids))
            else:
                reason += _("<b>You do not have any roles.</b> ")
            reason += _(
                "If you think this is an error, "
                "please ask your administrator to check the permissions configuration."
            )

            if config.auth_type == 'cookie':
                reason += _(
                    '<p>You have been logged out. Please reload the page to re-authenticate.</p>'
                )
                login.del_auth_cookie()

            raise MKAuthException(reason)

        # General access allowed. Now connect to livestatus
        connect_to_livestatus(html)

        handler()
Exemplo n.º 21
0
    def handle(self):
      i=0  
      while 1:
        login=config.login()  
        loginfo = self.request.recv(1024).strip().split('\t')[:2]
        user=loginfo[0]
        passwd=loginfo[1]
        log_statu=login.login(user,passwd)
        if i>=2:
            u_id=config.exists(user)
            config.con.update('user_info','lockedtime',int(time.time()),u_id)
	    break
        i+=1
        if log_statu=='passwrong':
            self.request.sendall('passwrong')
        elif log_statu=='nouser':
            self.request.sendall('nouser')
        elif log_statu=='locked':
            self.request.sendall('locked')
        elif log_statu==True:
            home_dir=login.home
            if os.path.exists(home_dir)==False:
                os.system('mkdir -p %s'%home_dir)
            self.request.sendall('true')
            while 1:
                print "Waiting command----------"
                get_data = self.request.recv(1024).strip().split()
                print get_data,'paraeter from client'
                if len(get_data)>=2:
                    cmd, filename = get_data[:2]
                    target_file='%s/%s'%(home_dir,filename)
                    if cmd == 'get':
                        len_buf=0
                        if os.path.exists(target_file)==True and os.path.getsize(target_file)!=0:
                            size=os.path.getsize(target_file)
                            print 'Sending size%s file'%size
                            self.request.send(str(size))
                            time.sleep(0.05)
                            with open(target_file,'rb')as f:
                                while 1:
                                    #if not f.readline():break
                                    a=f.read(819600)#read 16392byte once time
                                    if len(a)==0:
                                        g=self.request.recv(1024)
                                        self.request.sendall(md5sum(target_file))   
                                        break
                                    else:    
                                        self.request.sendall(a)
                                        
                        else:
                             self.request.sendall('no')
                    elif cmd == 'put':
                        len_data=0
                        while 1:
                            str_tmp = self.request.recv(819600)
                            if str_tmp=='ok':
                                self.request.sendall('down')
                                get_md5=self.request.recv(1024)#recieve client MD5
                                locmd5=md5sum(target_file)
                                print "server:%s  client:%s"%(locmd5,get_md5)
                                if locmd5==get_md5:
                                    self.request.sendall('ok')
                                else:
                                    self.request.sendall('no')
                                break
                            if not len_data:
                                ofh=open(target_file, 'wb+')
                                ofh.writelines(str_tmp)
                                len_data=1
                                ofh.close()
				size=os.path.getsize(target_file)
                                self.request.send(str(size))
                            else:    
                                ofh=open(target_file, 'ab+')
                                ofh.writelines(str_tmp)
                                ofh.close()
                                size=os.path.getsize(target_file)
                                self.request.send(str(size))
                                
                    elif cmd == 'del':
                        statu=commands.getstatusoutput('rm -rf %s'%target_file)
                        if statu[0]==0:
                            self.request.sendall('Delete%sSuccess'%get_data[1])
                        else:
                            self.request.sendall("Wrong Operration")
                    else:
                        statu=commands.getstatusoutput(get_data[0])
                        if statu[0]==0:
                            self.request.sendall(statu[1])
                        else:
                            self.request.sendall("Wrong Operration")
                elif len(get_data)<2:
                    print '%s %s'%(get_data[0],home_dir)
                    statu=commands.getstatusoutput('%s %s'%(get_data[0],home_dir))
                    if statu[0]==0 and len(statu[1])!=0:
                        self.request.sendall(statu[1])
                        print statu[1],'Command excute successfull.'
                        continue
                    elif len(statu[1])==0:
                        self.request.sendall("NUll") 
                    else:
                        self.request.sendall("false")
                        print 'Command excute fail.'
                        continue