Example #1
0
def ensure_admin():
    # Get the is in administrators, is uac, and username and return them

    return (UserAccounts.is_in_admin_group(), UserAccounts.is_uac_admin(),
            UserAccounts.get_current_user())
Example #2
0
    def credential_input_verify_loop():
        # Loop until we quit or get good stuff

        # Return a list of values
        # student_full_name, laptop_admin_user, laptop_admin_password
        ret = []

        mgmt_version = CredentialProcess.get_mgmt_version()

        smc_url = RegistrySettings.get_reg_value(value_name="smc_url", default="https://smc.ed")
        canvas_url = ""
        canvas_access_token = ""
        student_user = RegistrySettings.get_reg_value(value_name="student_user")
        student_full_name = ""
        student_password = ""
        smc_admin_user = RegistrySettings.get_reg_value(app="OPEService", value_name="smc_admin_user", default="admin")
        smc_admin_password = ""

        laptop_admin_user = ""
        laptop_admin_password = ""

        loop_running = True
        while loop_running:
            p("\n}}gb Version: " + mgmt_version + "}}xx")
            
            p("""

}}mn======================================================================
}}mn| }}ybOPE Credential App                                                 }}mn|
}}mn| }}xxThis app will add student credentials to the computer and          }}mn|
}}mn| }}xxsecure the laptop for inmate use.                                  }}mn|
}}mn| }}yn(answer with quit to stop this tool)                               }}mn|
}}mn======================================================================}}xx

            """)

            # 4 - Ask for input (smc server, login, student name, etc...)
            p("}}ynEnter URL for SMC Server }}cn[enter for " + smc_url + "]:}}xx ", False)
            tmp = input()
            tmp = tmp.strip()
            if tmp.lower() == "quit":
                p("}}rnGot QUIT - exiting credential!}}xx")
                return None
            if tmp == "":
                tmp = smc_url
            smc_url = tmp
            # Make sure url has https or http in it
            if "https://" not in smc_url.lower() and "http://" not in smc_url.lower():
                smc_url = "https://" + smc_url

            p("}}ynPlease enter the ADMIN user name }}cn[enter for " + smc_admin_user + "]:}}xx ", False)
            tmp = input()
            tmp = tmp.strip()
            if tmp.lower() == "quit":
                p("}}rnGot QUIT - exiting credential!}}xx")
                return None
            if tmp == "":
                tmp = smc_admin_user
            smc_admin_user = tmp

            p("}}ynPlease enter ADMIN password }}cn[characters will not show]:}}xx", False)
            tmp = getpass.getpass(" ")
            if tmp.lower() == "quit":
                p("}}rnGot QUIT - exiting credential!}}xx")
                return None
            if tmp == "":
                p("}}rbA password is required.}}xx")
                continue
            smc_admin_password = tmp

            tmp = ""
            last_student_user_prompt = ""
            while tmp.strip() == "":
                if student_user != "":
                    last_student_user_prompt = " }}cn[enter for previous student " + student_user + "]"
                    # p("}}mb\t- Found previously credentialed user: }}xx" + str(last_student_user))
                p("}}ynPlease enter the username for the student" + last_student_user_prompt + ":}}xx ", False)
                tmp = input()
                if tmp.lower() == "quit":
                    p("}}rnGot QUIT - exiting credential!}}xx")
                    return None
                if tmp.strip() == "":
                    tmp = student_user
            student_user = tmp.strip()

            # - Bounce off SMC - verify_ope_account_in_smc
            try:
                result = RestClient.verify_ope_account_in_smc(student_user, smc_url, smc_admin_user, smc_admin_password)
                if result is None:
                    # Should show errors during the rest call, so none here
                    #p("}}rbUnable to validate student against SMC!}}xx")
                    # Jump to top of loop and try again
                    continue
                    #return False # sys.exit(-1)
            except Exception as ex:
                p("}}rbError - Unable to verify student in SMC}}xx\n" + str(ex))
                # Jump to top of loop and try again
                continue
            
            # If not None - result will be a tuple of information
            laptop_admin_user, student_full_name, smc_version = result
            
            # Verify that the info is correct
            txt = """
}}mn======================================================================
}}mn| }}gbFound Student - Continue?                                          }}mn|
}}mn| }}ynCredential Version:    }}cn<mgmt_version>}}mn|
}}mn| }}ynSMC URL:               }}cn<smc_url>}}mn|
}}mn| }}ynSMC Version:           }}cn<smc_version>}}mn|
}}mn| }}ynLaptop Admin User:     }}cn<admin_user>}}mn|
}}mn| }}ynStudent Username:      }}cn<student_user>}}mn|
}}mn| }}ynSystem Serial Number:  }}cn<bios_serial_number>}}mn|
}}mn| }}ynDisk Serial Number:    }}cn<disk_serial_number>}}mn|
}}mn======================================================================}}xx
            """
            col_size = 44
            txt = txt.replace("<mgmt_version>", mgmt_version.ljust(col_size))
            txt = txt.replace("<smc_url>", smc_url.ljust(col_size))
            txt = txt.replace("<smc_version>", smc_version.ljust(col_size))
            txt = txt.replace("<admin_user>", laptop_admin_user.ljust(col_size))
            txt = txt.replace("<admin_pass>", "******".ljust(col_size))
            student_text = student_user + " (" + student_full_name + ")"
            txt = txt.replace("<student_user>", student_text.ljust(col_size))
            txt = txt.replace("<bios_serial_number>", 
                CredentialProcess.COMPUTER_INFO['bios_serial_number'].ljust(col_size))
            txt = txt.replace("<disk_serial_number>", 
                CredentialProcess.COMPUTER_INFO['disk_boot_drive_serial_number'].ljust(col_size))

            p(txt)
            p("}}ybPress Y to continue: }}xx", False)
            tmp = input()
            tmp = tmp.strip().lower()
            if tmp != "y":
                p("}}cnCanceled - trying again....}}xx")
                continue

            # Show the warning regarding locking down the boot options
            p("""
}}mn======================================================================
}}mn| }}rb====================       WARNING!!!         ==================== }}mn|
}}mn| }}xxEnsure that the boot from USB or boot from SD card options in      }}mn|
}}mn| }}xxthe bios are disabled and that the admin password is set to a      }}mn|
}}mn| }}xxstrong random password.                                            }}mn|
}}mn======================================================================}}xx
            """)
            p("}}ybHave you locked down the BIOS? Press Y to continue: }}xx", False)
            tmp = input()
            tmp = tmp.strip().lower()
            if tmp != "y":
                p("}}cnCanceled - trying again....}}xx")
                continue

            # - Bounce off SMC - lms/credential_student.json/??
            result = None
            try:
                ex_info = dict()
                ex_info["logged_in_user"] = UserAccounts.get_current_user()
                ex_info["admin_user"] = laptop_admin_user
                ex_info["current_student"] = student_user
                ex_info["mgmt_version"] = mgmt_version
                
                ex_info.update(CredentialProcess.COMPUTER_INFO)

                result = RestClient.credential_student_in_smc(
                    student_user, smc_url, smc_admin_user, smc_admin_password,
                    dict(ex_info=ex_info))
                if result is None:
                    p("}}rbUnable to credential student via SMC!}}xx")
                    # Jump to top of loop and try again
                    continue
                    #return False # sys.exit(-1)
            except Exception as ex:
                p("}}rbError - Unable to credential student via SMC}}xx\n" + str(ex))
                # Jump to top of loop and try again
                continue
            
            (student_full_name, canvas_url, canvas_access_token,
            student_password, laptop_admin_password) = result
            loop_running = False

        ret = (student_user, student_full_name, student_password, laptop_admin_user,
            laptop_admin_password, canvas_access_token, canvas_url, smc_url)

        return ret