Ejemplo n.º 1
0
def test_01_test_session_handler(mock_open, mock_chown, domain):
    with patch('requests.Session.get') as get:
        with patch('pwd.getpwnam') as pwnam:
            pwnam.return_value = ['', '', 0, 0]
            get_return = collections.namedtuple('get_return', 'text')
            get_return.text = 'test'
            get.return_value = get_return

            assert "Session handler OK." in php.test_session_handler(domain.user, domain.domain,
                                                                     checkstring='test')
            # Make it return something else for the session.
            get_return.text = 'foobar'
            get.return_value = get_return

            # Again with modified return handler for session.
            with pytest.raises(exceptions.TestException) as err:
                php.test_session_handler(domain.user, domain.domain)
            assert "Session handler not working" in err.value.message

        # Again with non-existing user.
        with pytest.raises(exceptions.TestException) as err:
            php.test_session_handler("foobar", domain.domain)
        assert "User foobar does not seem to exist on this system." in err.value.message
Ejemplo n.º 2
0
def main(argv=None):
    if os.geteuid() != 0:
        print warning("This script requires root privileges to run.")
        sys.exit(-1)

    if argv is None:
        argv = sys.argv[1:]
    args = parse_args(argv)

    domain = user = password = None

    try:
        # Detect DirectAdmin.
        if os.path.isfile("/usr/local/directadmin/conf/directadmin.conf"):
            print header("DirectAdmin")

            # Ask the user for a DirectAdmin login information.
            admin_user = raw_input(bcolors.BOLD + "DirectAdmin admin username: "******"DirectAdmin admin password: "******"/usr/bin/pure-pw"):
                ret = subprocess.Popen(["/usr/bin/pure-pw", "mkdb", "/etc/pureftpd.pdb", "-f", "/etc/proftpd.passwd"])
                ret.wait()

            # Enable SpamAssassin.
            directadmin.enable_spamassassin(user, password, domain)

        else:
            print error("Only DirectAdmin servers are currently supported!")
            sys.exit(-1)

        if args.mysql:
            print header("MySQL")
            print ok(directadmin.test_mysql_connection())

        if args.php:
            print header("PHP")
            print ok(php.check_config())
            print ok(php.test_session_handler(user, domain))
            print ok(php.test_mod_ruid2(user, domain))
            print ok(php.test_mail(user, domain))

        if args.pop3:
            print header("POP3")
            print ok(pop3.test_pop3(user, domain, password))
            print ok(pop3.test_pop3(user, domain, password, ssl=True))

        if args.imap:
            print header("IMAP")
            print ok(imap.test_imap(user, domain, password))
            print ok(imap.test_imap(user, domain, password, ssl=True))

        if args.smtp:
            print header("SMTP")
            print ok(smtp.test_smtp(user, domain, password, ssl=False, submission=False))
            print ok(smtp.test_smtp(user, domain, password, ssl=False, submission=True))
            print ok(smtp.test_smtp(user, domain, password, ssl=False, submission=False,
                                    start_tls=True))
            if '465' in open('/etc/exim.conf').read():
                print ok(smtp.test_smtp(user, domain, password, ssl=True, submission=False))

        if args.ftp:
            print header("FTP")
            print ok(ftp.test_ftp(user, domain, password))
            if sys.version_info[0] > 2 or (sys.version_info[0] == 2 and sys.version_info[1] > 6):
                print ok(ftp.test_ftp(user, domain, password, ssl=True))

        if args.spamassassin:
            print header("SpamAssassin")
            print ok(spamassassin.test_spamassassin(user, domain, password))

        if args.phpmyadmin:
            print header("phpMyAdmin")
            print ok(phpmyadmin.test_phpmyadmin())

        if args.roundcube:
            print header("Roundcube")
            print ok(roundcube.test_roundcube())

        # Finally, remove the account alltogether.
        directadmin.remove_account(admin_user, admin_pass, user)
    except Exception as err:
        print error(err)

    return True