Example #1
0
def login():
	system("clear")
	INPUT = False
	VERBOSE = True
	if INPUT: # If set to True, variables collected here
  		username = get_param("Enter the Username")
  		database = get_param("Enter the Database")
  		password = get_param("Enter the Password")
  		addy = get_param("Enter a host address: ")
		curses.endwin()

        else:
  		username = '******' 
  		database = 'TestDC'
  		password = '******'
  		addy = '192.168.1.181'
  		print 'Username:\t' + username
  		print 'Database:\t' + database
  		print 'Password:\t' + password
  		print 'Address:\t' + addy
  		print '\n'
		wait = raw_input("Press [ENTER] to login in with Default credentials.")
	
	screen.refresh()
	print '\n--------------------------------------------'
	print 'Create Connection with Database'
	print '--------------------------------------------'
	print 'Attempting to connect...',
	con = database_queries.dbConnect(username, password, database, addy) # Attempt connection and save session

	if con['state'] == 0: # If connection flag is set - good!
  		print 'Connected!',
		return True
	elif con['state'] == 1: # If connection flag is not set - fail!
  		print 'Failed',
		return False
	if VERBOSE: # If set prints the failure message received in initial call to connect
  		#print '[' + con['msg'] + ']'
		print "\nI am HERE"
		print '\n'
	wait = raw_input("Press [ENTER]")
Example #2
0
def connectToDatabase(stdscr):


    x,y = stdscr.getmaxyx()
    yTest = 130
    xTest = 70
    while x < xTest and y < yTest:
        stdscr.clear()
        stdscr.addstr(10, 5, "Please make your terminal bigger!")
        stdscr.addstr(11, 5, "Make larger until you see the welcome splash screen")
        x,y = stdscr.getmaxyx()
        stdscr.getstr(1, 1, 0)
        if x < 120 or y < 60:
            stdscr.clear()
            stdscr.addstr(12, 5, "Terminal is almost big enough!")
        stdscr.clear()

  # Collect db data and validate connection
    while(1):
        # Clear the curses screen
        stdscr.clear()

        # Overwrite connection data in debug mode
        if DEBUG:
            username = "******"
            host = "192.168.1.3"
            password = ""
            database = "test"

        else:
            stdscr.clear()
            stdscr.nodelay(0)
            stdscr.keypad(1)
            selection = -2
            option = 0

            while selection < 0:
                graphics = [0]*5
                graphics[option] = curses.A_REVERSE
                #ASCII art creddited to: http://patorjk.com/software/taag/#p=display&f=Graffiti&t=Welcome
                stdscr.addstr(10, 5," __      __        __" )                         
                stdscr.addstr(11, 5,"/  \    /  \ ____ |  |   ____  ____   _____   ____"  )
                stdscr.addstr(12, 5,"\   \/\/   // __ \|  | _/ ___\/  _ \ /     \_/ __ \ ")
                stdscr.addstr(13, 5," \        /\  ___/|  |_\  \__(  <_> )  Y Y  \  ___/ ")
                stdscr.addstr(14, 5,"  \__/\  /  \___  >____/\___  >____/|__|_|  /\___  >")
                stdscr.addstr(15, 5,"       \/       \/          \/            \/     \/")
                stdscr.addstr(15, 5,"Press enter to start the application",graphics[0])

                action = stdscr.getch()
                if action == (ord('\n')):
                    selection = option
                    stdscr.clear()

            # Collect necessary connection info
            stdscr.addstr(10, 5, "Enter the database host address:")
            host = stdscr.getstr(10, 38, 15)
            stdscr.clear()

            stdscr.addstr(10, 5, "Enter the database username:"******"Enter the database name:")
            database = stdscr.getstr(10, 38, 15)
            stdscr.clear()

            stdscr.addstr(10, 5, "Enter the database password:"******"Connection to Database Successful! Press Enter to Continue...")
          stdscr.getstr(1, 1, 0)
          break

        # Connection Failed
        else:
            selection = -2
            option = 0
            while selection < 0:
                graphics = [0]*2
                graphics[option] = curses.A_REVERSE
                failure_string = "Connection to Database Failed: %s" % (con['msg'])
                stdscr.addstr(10, 5, failure_string)
                stdscr.addstr(13, 13, "Retry",graphics[0])
                stdscr.addstr(13, 35, "Exit Program",graphics[1])
                stdscr.refresh()
            # Collect user's navigation selection
                action = stdscr.getch()
                if action == curses.KEY_RIGHT:
                    option = (option - 1) % 2
                elif action == curses.KEY_LEFT:
                    option = (option + 1) % 2
                elif action == (ord('\n')):
                    selection = option
                stdscr.clear()
            # If user wants to disconnect... Exit
                #if selection == 0:
                    #add in retry statement
            # Return to main menu
                if selection == 1:
                    curses.endwin()
                    exit()
      
    # Return successful connection
    return con
Example #3
0
  print '--------------------------------------------'
  username = '******'
  database = 'employees'
  password = '******'
  addy = 'localhost'
  print 'Username:\t' + username
  print 'Database:\t' + database
  print 'Password:\t' + password
  print 'Address:\t' + addy
  print '\n'

print '\n--------------------------------------------'
print 'Create Connection with Database'
print '--------------------------------------------'
print 'Attempting to connect...',
con = database_queries.dbConnect(username, password, database, addy) # Attempt connection and save session

if con['state'] == 0: # If connection flag is set - good!
  print 'Connected!',
elif con['state'] == 1: # If connection flag is not set - fail!
  print 'Failed',

#if VERBOSE: # If set prints the failure message received in initial call to connect
  #print '[' + con['msg'] + ']'
print '\n'


print '\n--------------------------------------------'
print 'Get Tables from the Database'
print '--------------------------------------------'
print 'Attempt to query for table list...',
Example #4
0
def connectToDatabase(stdscr):

  # Collect db data and validate connection
    while(1):

        # Clear the curses screen
        stdscr.clear()

        # Overwrite connection data in debug mode
        if DEBUG:
            username = "******"
            host = "192.168.0.109"
            password = ""
            database = "test"

        else:
            # Collect necessary connection info
            stdscr.addstr(10, 5, "Enter the database host address:")
            host = stdscr.getstr(10, 38, 15)
            stdscr.clear()

            stdscr.addstr(10, 5, "Enter the database username:"******"Enter the database name:")
            database = stdscr.getstr(10, 38, 15)
            stdscr.clear()

            stdscr.addstr(10, 5, "Enter the database password:"******"Connection to Database Successful! Press Enter to Continue...")
          stdscr.getstr(1, 1, 0)
          break

        # Connection Failed
        else:
            selection = -2
            option = 0
            while selection < 0:
                graphics = [0]*2
                graphics[option] = curses.A_REVERSE
                failure_string = "Connection to Database Failed: %s" % (con['msg'])
                stdscr.addstr(10, 5, failure_string)
                stdscr.addstr(13, 13, "Retry",graphics[0])
                stdscr.addstr(13, 35, "Exit Program",graphics[1])
                stdscr.refresh()
            # Collect user's navigation selection
                action = stdscr.getch()
                if action == curses.KEY_RIGHT:
                    option = (option - 1) % 2
                elif action == curses.KEY_LEFT:
                    option = (option + 1) % 2
                elif action == (ord('\n')):
                    selection = option
                stdscr.clear()
            # If user wants to disconnect... Exit
                #if selection == 0:
                    #add in retry statement
            # Return to main menu
                if selection == 1:
                    curses.endwin()
                    exit()
      
    # Return successful connection
    return con