Esempio n. 1
0
def initialize(interactive, verbosity):
    levels = {0: logging.ERROR, 1: logging.INFO, 2: logging.DEBUG}
    logger = logging.getLogger('cannula')
    logger.setLevel(levels.get(int(verbosity)))
    logger.debug("Running Cannula Initialize")

    from cannula.conf import conf_dict, write_config
    from cannula.utils import shell

    config = conf_dict()
    # save a copy to see if user altered it.
    original = config.copy()
    create_dirs = ['cannula_base']
    for d in create_dirs:
        config = create_directory(config, d, interactive, logger)

    # Cannula settings module
    config = set_option(
        config,
        'cannula_settings',
        interactive,
        logger,
        message=
        "\nSet %s to (%s) \nor if you are brave you can change this here: ")

    # try to find cannulactl command and prompt user for new setting
    status, cmd = shell('which cannulactl')
    if status == 0:
        config['cannula_cmd'] = cmd.strip()
    config = set_option(config, 'cannula_cmd', interactive, logger)

    # Cannula ssh command, run by authorized keys
    base = config.get('cannula_base')
    ssh_cmd = os.path.join(base, 'bin', 'cannula.sh')
    config['cannula_ssh_cmd'] = ssh_cmd
    config = write_file(config,
                        'cannula_ssh_cmd',
                        'cannula/canner.sh',
                        interactive,
                        logger,
                        perm='755')

    # Make sure we have a semi random secret key
    if not config.get('django_secret_key'):
        config['django_secret_key'] = ''.join([
            choice('abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)')
            for _ in range(50)
        ])
    config = set_option(config, 'django_secret_key', interactive, logger)

    # Configure the database
    config = setup_database(config, interactive, logger)

    # Save the configuration
    if config != original:
        write_config(config)
Esempio n. 2
0
def manage_settings(request):
    if not request.user.is_superuser:
        raise HttpResponseForbidden("You do not have access to this page.")

    if request.method == "POST":
        form = SettingsForm(request.POST)
        if form.is_valid():
            write_config(form.cleaned_data)
            return HttpResponseRedirect('/')
    else:
        form = SettingsForm(initial=conf_dict())

    return render_to_response(
        'cannula/form.html',
        RequestContext(request, {
            'form': form,
            'title': "Edit Settings",
        }))
Esempio n. 3
0
def manage_settings(request):
    if not request.user.is_superuser:
        raise HttpResponseForbidden("You do not have access to this page.")
    
    if request.method == "POST":
        form = SettingsForm(request.POST)
        if form.is_valid():
            write_config(form.cleaned_data)
            return HttpResponseRedirect('/')
    else:
        form = SettingsForm(initial=conf_dict())
    
    return render_to_response('cannula/form.html',
        RequestContext(request, {
            'form': form,
            'title': "Edit Settings",
        })
    )
Esempio n. 4
0
def initialize(interactive, verbosity):
    levels = {0: logging.ERROR, 1: logging.INFO, 2: logging.DEBUG}
    logger = logging.getLogger('cannula')
    logger.setLevel(levels.get(int(verbosity)))
    logger.debug("Running Cannula Initialize")
    
    from cannula.conf import conf_dict, write_config
    from cannula.utils import shell
    
    config = conf_dict()
    # save a copy to see if user altered it.
    original = config.copy()
    create_dirs = ['cannula_base']
    for d in create_dirs:
        config = create_directory(config, d, interactive, logger)
    
    # Cannula settings module
    config = set_option(config, 'cannula_settings', interactive, logger,
        message="\nSet %s to (%s) \nor if you are brave you can change this here: ")

    # try to find cannulactl command and prompt user for new setting
    status, cmd = shell('which cannulactl')
    if status == 0:
        config['cannula_cmd'] = cmd.strip()
    config = set_option(config, 'cannula_cmd', interactive, logger)

    # Cannula ssh command, run by authorized keys
    base = config.get('cannula_base')
    ssh_cmd = os.path.join(base, 'bin', 'cannula.sh')
    config['cannula_ssh_cmd'] = ssh_cmd
    config = write_file(config, 'cannula_ssh_cmd', 'cannula/canner.sh', interactive, logger, perm='755')
    
    # Make sure we have a semi random secret key
    if not config.get('django_secret_key'):
        config['django_secret_key'] = ''.join([choice('abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)') for _ in range(50)])
    config = set_option(config, 'django_secret_key', interactive, logger)
    
    # Configure the database
    config = setup_database(config, interactive, logger)
    
    # Save the configuration
    if config != original:
        write_config(config)