コード例 #1
0
def add_admin():
    (admin_name, admin_email,
     plaintext_password) = (request.form['admin_name'],
                            request.form['admin_email'],
                            request.form['plaintext_password'])
    if not is_admin(admin_name):
        if add_new_admin(admin_name, admin_email, plaintext_password):
            flash("Admin %s successfully added." % admin_name)
        else:
            flash(
                "Error adding new admin %s.  Check logs for details." %
                admin_name, "error")
    else:
        flash("Admin %s already exists." % admin_name, "error")
    return redirect(url_for('admin_page'))
コード例 #2
0
ファイル: centsecure.py プロジェクト: limefax/centsecure
def main():
    """Main function."""
    # Need to get plugins first for arguments to function
    plugin.find_plugins()

    parser = argparse.ArgumentParser(
        description="Automatically fixes common security vulnerabilities.",
        epilog="Default behaviour is to attempt to run all plugins")
    parser.add_argument("--list-plugins",
                        "-l",
                        action="store_true",
                        help="Lists all plugins",
                        dest="list_plugins")
    parser.add_argument("--run-plugin",
                        "-r",
                        "-p",
                        choices=get_plugins(),
                        nargs="+",
                        metavar="N",
                        help="Run specific plugins",
                        dest="plugins")
    parser.add_argument("--run-all",
                        "-R",
                        action="store_true",
                        help="Run all available plugins",
                        dest="run_all")
    parser.add_argument("--disable-root-check",
                        "--no-root",
                        "-d",
                        action="store_true",
                        help="Disable root check",
                        dest="no_root_check")
    parser.add_argument("--disable-python-check",
                        action="store_true",
                        help="Disable Python version check",
                        dest="disable_python_check")
    args = parser.parse_args()

    info("Welcome to CentSecure!")
    debug("This computer is running {} version {}".format(
        plugin.get_os(), plugin.get_os_version()))

    if args.list_plugins:
        plugins = get_plugins()
        for p in plugins:
            stdout("- {}".format(p))
        sys.exit(0)

    if not args.disable_python_check and not _check_python_version():
        warn(
            "CentSecure requires Python 3.7.x, you are using {}. Use the option --disable-python-check to bypass."
            .format(python_version()))
        sys.exit(1)

    firsttime.run_all()

    if args.run_all:
        to_run = get_plugins()
    elif args.plugins is not None:
        to_run = args.plugins
    else:
        to_run = get_default_plugins()

    if is_admin() or args.no_root_check:
        debug("Running CentSecure with the following {} plugins: {}".format(
            len(to_run), ", ".join(to_run)))
        run(to_run)
    else:
        warn(
            "CentSecure should be run as root or administator. Use the option --disable-root-check to bypass."
        )
        sys.exit(1)
コード例 #3
0
ファイル: interpretor.py プロジェクト: memery/memery-legacy
def main_parse(data, state, myname, settings):
    """ 
    >> Main entry function! <<
    The returned values from this function should be valid
    irc message, minus the trailing \r\n.

    NO IT SHOULD NOT
    """
    if type(data) != ircparser.In_Message:
        return None

    msg = data.message
    channel = data.recipient
    sendernick = data.sender
    senderident = data.senderident

    command_prefix = settings['behaviour']['command_prefix']

    is_admin = common.is_admin(sendernick, senderident)

    if not state['markov_sentences'][channel]:
        try:
            state['markov_sentences'][channel] = markov.run_cmarkov(myname, settings, 'log/{}.log'.format(channel))
        except ValueError as e:
            common.log(str(e), 'error')

    if common.is_blacklisted(sendernick, senderident):
        return None

    startswith_cp = lambda msg, cmd: re.match(r'[{}]{}(\s|$)'.format(command_prefix, cmd), msg)
    url_re = re.compile(r'https?://\S+') #(www[.]\S+?[.]\S+)
    spotify_url_re = re.compile(r'spotify(:\S+)+?')
    plugins = get_plugins()

    # .giveop
    if startswith_cp(msg, 'giveop') and is_admin:
        return giveop(msg, myname, channel, sendernick)

    # memery:
    elif re.match('{}.? '.format(myname), msg):
        if random.randint(1, 2) == 1:
            try:
                sentence = state['markov_sentences'][channel].pop(0)
                return ircparser.Out_Messages(myname, channel, '{}: {}'.format(sendernick, sentence))
            except IndexError:
                pass

    # .help
    elif startswith_cp(msg, 'help'):
        return ircparser.Out_Messages(myname, channel, get_command_help(msg, sendernick, myname,
                                                               command_prefix, plugins))

    # plugins:
    elif msg.startswith(command_prefix)\
             and msg.split()[0][1:] in plugins\
             and msg.split()[0][1:] not in settings['plugins']['blacklist']:
        return ircparser.Out_Messages(myname, channel, run_plugin(sendernick, msg, msg.split()[0][1:]))

    # Title
    elif url_re.search(msg):
        titles = []
        for url in url_re.findall(msg):
            title = common.get_title(url)
            if title and title not in titles:
               titles.append(title)
        return ircparser.Out_Messages(myname, channel, titles)

    # spotify title
    elif spotify_url_re.search(msg):
        titles = []
        for m in spotify_url_re.findall(msg):
            title = common.get_title('http://open.spotify.com' + m.replace(':', '/'))
            if title and title not in titles:
                titles.append(re.sub(r'(.+?) by (.+?) on Spotify', r'Spotify: \1 (\2)', title))
        return ircparser.Out_Messages(myname, channel, titles)

    # Rest of the commands
    else:
        output = get_output(msg, myname, sendernick, channel, command_prefix)
        if output:
            return ircparser.Out_Messages(myname, channel, output)
        # markov chain-style talking
        else:
            if settings['markov']['frequency'] > 0 and \
               random.randint(1, settings['markov']['frequency']) == 1:
                try:
                    sentence = state['markov_sentences'][channel].pop(0)
                    return ircparser.Out_Messages(myname, channel, sentence)
                except IndexError:
                    pass
コード例 #4
0
ファイル: main.py プロジェクト: qtpy-app/mysql-tool
import traceback
from os.path import abspath, dirname, join
import common
from controller import setting_instance
from common import uac_plan_task

logging.debug("main params:" + ','.join(sys.argv))

# 检查是否有额外参数
if len(sys.argv) > 1:
    logging.debug("params count:{0}, save.".format(len(sys.argv)))
    setting_instance.settings['args'] = sys.argv
    setting_instance.save_cfg()

# 获取管理员授权
if not common.is_admin():
    logging.debug("not yet admin, request admin start.")
    # 先检查计划任务是否存在 存在则启动计划任务
    uac_plan_task.start_plan_task()
    ctypes.windll.shell32.ShellExecuteW(None, "runas", sys.executable,
                                        __file__, None, 1)
    sys.exit()
else:
    uac_plan_task.admin_plan()

try:
    from PyQt5.QtCore import QCoreApplication, Qt, QTranslator, qInstallMessageHandler
    from PyQt5.QtGui import QGuiApplication, QIcon
    from PyQt5.QtQml import QQmlApplicationEngine

    # WEB Engine 需引入 Pyinstaller打包时会添加Engine相关的引用