예제 #1
0
def pty_based_auth():
    """
    Show a username/password login prompt.
    Return username when authentication succeeded.
    """
    tries = 0
    while True:
        # Password authentication required for this session?
        sys.stdout.write('\033[2J\033[0;0H')  # Clear screen
        sys.stdout.write(colored('Please authenticate\r\n\r\n', 'cyan'))

        if tries:
            sys.stdout.write(
                colored('  Authentication failed, try again\r\n', 'red'))

        try:
            username = input('Username', False)
            password = input('Password', True)
        except NoInput:
            raise NotAuthenticated

        if backend.authenticate(username, password):
            sys.stdout.write(
                colored(' ' * 40 + 'Authentication successful\r\n\r\n',
                        'green'))
            return username
        else:
            tries += 1
            if tries == 3:
                raise NotAuthenticated
예제 #2
0
def pty_based_auth():
    """
    Show a username/password login prompt.
    Return username when authentication succeeded.
    """
    tries = 0
    while True:
        # Password authentication required for this session?
        sys.stdout.write('\033[2J\033[0;0H') # Clear screen
        sys.stdout.write(colored('Please authenticate\r\n\r\n', 'cyan'))

        if tries:
            sys.stdout.write(colored('  Authentication failed, try again\r\n', 'red'))

        try:
            username = input('Username', False)
            password = input('Password', True)
        except NoInput:
            raise NotAuthenticated

        if backend.authenticate(username, password):
            sys.stdout.write(colored(' ' * 40 + 'Authentication successful\r\n\r\n', 'green'))
            return username
        else:
            tries += 1
            if tries == 3:
                raise NotAuthenticated
예제 #3
0
    def __call__(self, context):
        print 'Create a new user'
        username = input('Username')
        password = input('Password', True)

        if username and password:
            backend.create_user(username, password)
        else:
            print 'Invalid username/password'
예제 #4
0
    def __call__(self, context):
        print 'Create a new user'
        username = input('Username')
        password = input('Password', True)

        if username and password:
            backend.create_user(username, password)
        else:
            print 'Invalid username/password'
예제 #5
0
    def scp(self):
        # TODO: Add progress bar for large files.

        host1 = input('Host 1')
        host2 = input('Host 2')
        path1 = input('Path 1')
        path2 = input('Path 2')

        host1 = self.hosts.get_from_slug(host1)
        host2 = self.hosts.get_from_slug(host2)

        data = host1.open(path1, 'r').read()
        host2.open(path2, 'w').write(data)
예제 #6
0
 def rmpidfile(self):
     """
     Remove pidfile, sometimes it can happen that the pidfile was created, and the
     server crached due to a bad configuration, without removing the pidfile.
     """
     if input('Remove pidfile', answers=['y', 'n']) == 'y':
         self.hosts.sudo("kill -SIGQUIT ` cat '%s' ` || rm '%s' " % (esc1(self.pidfile), esc1(self.pidfile)))
예제 #7
0
    def scp(env):
        # TODO: - make from 'host1' and 'host2' parameters, and add
        #         autocompletion for both
        #
        #       - Add progress bar for large files.

        host1 = input('Host 1')
        host2 = input('Host 2')
        path1 = input('Path 1')
        path2 = input('Path 2')

        host1 = env.hosts.get_from_slug(host1)
        host2 = env.hosts.get_from_slug(host2)

        data = host1.open(path1, 'r').read()
        host2.open(path2, 'w').write(data)
예제 #8
0
 def rmpidfile(self):
     """
     Remove pidfile, sometimes it can happen that the pidfile was created, and the
     server crached due to a bad configuration, without removing the pidfile.
     """
     if input('Remove pidfile', answers=['y', 'n']) == 'y':
         self.hosts.sudo("kill -SIGQUIT ` cat '%s' ` || rm '%s' " %
                         (esc1(self.pidfile), esc1(self.pidfile)))
예제 #9
0
    def test(self):
        """
        Test connection to database.
        """
        database = input('Enter database name')

        self.hosts.run("psql --host '%s' --port '%s' '%s'" %
                (self.socket_directory, self.listen_port, database))
예제 #10
0
    def set_hostname(self):
        """
        Set the hostname, according to the slug, given in the Host instance.
        """
        h = self.host

        if input('Do you really want to set the hostname for %s to %s' % (host.address, host.slug), answers=['y', 'n']) == 'y':
            h.sudo("echo '%s' > /etc/hostname" % host.slug)
            h.sudo("echo '127.0.0.1  %s' >> /etc/hosts" % host.slug)
            h.sudo("hostname -F /etc/hostname")
예제 #11
0
    def checkout(self, commit=None):
        # NOTE: this public 'checkout'-method uses @dont_isolate_yet, so that
        # in case of a parrallel checkout, we only ask once for the commit
        # name, and fork only to several threads after calling '_checkout'.

        # If no commit was given, ask for commit.
        if not commit:
            commit = input('Git commit', default=self.default_revision)
            if not commit: raise Exception('No commit given')

        self._checkout(commit)
예제 #12
0
    def set_hostname(self):
        """
        Set the hostname, according to the slug, given in the Host instance.
        """
        host = self.host

        if input('Do you really want to set the hostname for %s to %s' %
                 (host.address, host.slug),
                 answers=['y', 'n']) == 'y':
            host.sudo("echo '%s' > /etc/hostname" % host.slug)
            host.sudo("echo '127.0.0.1  %s' >> /etc/hosts" % host.slug)
            host.sudo("hostname -F /etc/hostname")
예제 #13
0
    def checkout(self, commit=None):
        # NOTE: this public 'checkout'-method uses @dont_isolate_yet, so that
        # in case of a parrallel checkout, we only ask once for the commit
        # name, and fork only to several threads after calling '_checkout'.

        # If no commit was given, ask for commit.
        if not commit:
            commit = input("Git commit", default="master")
            if not commit:
                raise Exception("No commit given")

        self._checkout(commit)
예제 #14
0
    def attach(self):
        # Test whether tmux is installed
        try:
            self.host.run('which tmux > /dev/null')
        except ExecCommandFailed:
            # Not installed -> ask for compiling tmux
            if input('Tmux binary not found. Do you want to compile tmux on %s?' % self.host.slug, answers=['y', 'n']) == 'y':
                setup = self.initialize_service(TmuxSetup, host=self.host)
                setup.install()
            else:
                return

        # Attach or start tmux
        self.host.run('tmux attach-session || tmux')
예제 #15
0
    def attach(self):
        # Test whether tmux is installed
        try:
            self.host.run('which tmux > /dev/null')
        except ExecCommandFailed:
            # Not installed -> ask for compiling tmux
            if input(
                    'Tmux binary not found. Do you want to compile tmux on %s?'
                    % self.host.slug,
                    answers=['y', 'n']) == 'y':
                setup = self.initialize_service(TmuxSetup, host=self.host)
                setup.install()
            else:
                return

        # Attach or start tmux
        self.host.run('tmux attach-session || tmux')
예제 #16
0
 def _manage_py(self, command=None):
     command = command or input('python manage.py (...)')
     self._run_management_command(command)
예제 #17
0
 def _manage_py(self, command=None):
     command = command or input('python manage.py (...)')
     self._run_management_command(command)
예제 #18
0
 def install_package(self, package=None):
     if not package:
         package = input('Enter package')
     self._install_package(package)
예제 #19
0
 def __call__(self, context):
     password = input('New password for %s' % self.username, True)
     if password:
         backend.set_password(self.username, password)
     else:
         print 'Invalid password given'
예제 #20
0
 def __call__(self, context):
     password = input('New password for %s' % self.username, True)
     if password:
         backend.set_password(self.username, password)
     else:
         print 'Invalid password given'
예제 #21
0
 def install_package(self, package=None):
     if not package:
         package = input('Enter package')
     self._install_package(package)
예제 #22
0
 def restore_backup_from_url(self):
     # ' /usr/local/pgsql/bin/psql -p %s -d template1 -U postgres < backup.sql'
     backup_url = input('Enter the URL of the backup location (an .sql.gz file)')
     for h in self.hosts.filter('master'):
         h.sudo("curl '%s' | gunzip | /usr/local/pgsql/bin/psql -U postgres" % esc1(backup_url),
                             user='******')
예제 #23
0
 def restore_backup_from_url(self):
     backup_url = input('Enter the URL of the backup location (an .sql.gz file)')
     self.hosts.run("curl '%s' | gunzip | /usr/bin/mysql --user '%s' --password='******' --host '%s' '%s' " %
                 (esc1(backup_url), esc1(self.username), esc1(self.password), esc1(self.hostname), esc1(self.database)))