Ejemplo n.º 1
0
def remove_device_menu():
    menu = [
        '1. Remove all devices', '2. Remove user devices', '\n     0. Back'
    ]

    available = build_avaialbe(menu)
    loop = True
    while loop:
        show_menu(menu)
        choice = get_choice(available)
        if choice == '1':
            ds.datasyncBanner()
            if ds.askYesOrNo("Remove all users devices"):
                ds.removeDevice()
        elif choice == '2':
            userConfig = ds.verifyUser()[0]
            if ds.confirm_user(userConfig, 'mobility'):
                if ds.askYesOrNo("Remove all devices for %s" %
                                 userConfig['name']):
                    ds.removeDevice(userConfig)
            else:
                ds.eContinue()
        elif choice == '0':
            loop = False
            return
Ejemplo n.º 2
0
def performance_menu():
	menu = ['1. Top device requests','2. Check manual syncing devices', '\n     0. Back']

	available = build_avaialbe(menu)
	loop = True
	while loop:
		show_menu(menu)
		choice = get_choice(available)
		if choice == '1':
			ds.datasyncBanner(dsappversion)
			if ds.askYesOrNo("Parse debug log for top device requests"):
				log = ds.getFilePath("Enter path to mobility-agent log file: ")
				if log is None:
					return
				dsPerformance.getDeviceCommands(log)
				ds.eContinue()

		elif choice == '2':
			ds.datasyncBanner(dsappversion)
			if ds.askYesOrNo("Parse debug log for devices set to manual sync"):
				log = ds.getFilePath("Enter path to mobility-agent log file: ")
				if log is None:
					return
				dsPerformance.getPinglessDevices(log)
				ds.eContinue()

		elif choice == '0':
			loop = False
			return
Ejemplo n.º 3
0
def viewAttachments_menu():
    menu = [
        '1. View user attachments', '2. View total attachment size by users',
        '3. Check Mobility attachments count', '\n     0. Back'
    ]

    available = build_avaialbe(menu)
    loop = True
    while loop:
        show_menu(menu)
        choice = get_choice(available)
        if choice == '1':
            ds.view_users_attach()
        elif choice == '2':
            ds.view_attach_byUser()
        elif choice == '3':
            ds.datasyncBanner()
            print(
                "Compare the mobility database ID count, with the mobility filestore ID count"
            )
            if ds.askYesOrNo("This may take some time to complete, continue"):
                ds.check_mob_attachments()
                print
                ds.eContinue()
        elif choice == '0':
            loop = False
            return
Ejemplo n.º 4
0
def removeUser_menu():
	menu = ['1. Force remove user(s)/group(s) db references', '2. Remove user/group (restarts configengine)', '3. Remove disabled users & fix referenceCount', '\n     4. Reinitialize user(s)', '5. Reinitialize all failed users', '6. Reinitialize all users', '\n     0. Back']

	available = build_avaialbe(menu)
	loop = True
	while loop:
		show_menu(menu)
		choice = get_choice(available)
		if choice == '1':
			ds.remove_user(dbConfig, 1)
		elif choice == '2':
			ds.remove_user(dbConfig)
		elif choice == '3':
			ds.datasyncBanner(dsappversion)
			ds.removed_disabled(dbConfig)
			print
			ds.fix_referenceCount(dbConfig)
			print; ds.eContinue()
		elif choice == '4':
			ds.setUserState(dbConfig, '7')
		elif choice == '5':
			ds.reinitAllFailedUsers(dbConfig)
			print;ds.eContinue()
		elif choice == '6':
			ds.reinitAllUsers(dbConfig)
			print;ds.eContinue()
		elif choice == '0':
			loop = False
			return
Ejemplo n.º 5
0
def checksQueries_menu():
	menu = ['1. General Health Check', '2. Nightly Maintenance Check', '\n     3. Show Sync Status', '4. GW pending events by User (consumerevents)', '5. Mobility pending events by User (syncevents)', '\n     6. Attachments...', '7. Performance...', '\n     0. Back']

	available = build_avaialbe(menu)
	loop = True
	while loop:
		show_menu(menu)
		choice = get_choice(available)
		if choice == '1':
			ghc.generalHealthCheck(mobilityConfig, gwConfig, XMLconfig ,ldapConfig, dbConfig, trustedConfig, config_files, webConfig)
			print; ds.eContinue()
		elif choice == '2':
			print ds.checkNightlyMaintenance(config_files, mobilityConfig)['output']
			print; ds.eContinue()
		elif choice == '3':
			ds.datasyncBanner(dsappversion)
			ds.showStatus(dbConfig)
			print; ds.eContinue()
		elif choice == '4':
			ds.show_GW_syncEvents(dbConfig)
		elif choice == '5':
			ds.show_Mob_syncEvents(dbConfig)
		elif choice == '6':
			viewAttachments_menu()
		elif choice == '7':
			performance_menu()
		elif choice == '0':
			loop = False
			main_menu()
Ejemplo n.º 6
0
def letsEncrypt_menu():
    a = acme.acme()

    loop = True
    while loop:
        a.clearDNS()
        # Make dynamic menu
        if a.getAcmeInstalled():
            is_acmeInstalled = "Uninstall"
        else:
            is_acmeInstalled = "Install"
        if a.getCronInstalled():
            is_cronInstalled = "Uninstall"
        else:
            is_cronInstalled = "Setup"
    # Dynamic menu based on acme or cron installed
        menu = [
            '1. %s acme.sh' % is_acmeInstalled, '2. Issue certificate',
            '\n     3. %s auto renew' % is_cronInstalled, '\n     0. Back'
        ]

        available = build_avaialbe(menu)

        show_menu(menu)
        choice = get_choice(available)
        if choice == '1':
            if not a.getAcmeInstalled():
                ds.datasyncBanner()
                a.setupAcme()
                print
                ds.eContinue()
            else:
                ds.datasyncBanner()
                a.removeAcme()
                print
                ds.eContinue()
        elif choice == '2':
            ds.datasyncBanner()
            a.autoIssue()
            print
            ds.eContinue()
        elif choice == '3':
            if not a.getCronInstalled():
                ds.datasyncBanner()
                a.setAutoRenew()
                print
                ds.eContinue()
            else:
                ds.datasyncBanner()
                a.uninstallAutoRenew()
                print
                ds.eContinue()
        elif choice == '0':
            loop = False
            return
Ejemplo n.º 7
0
def groupwiseChecks_menu():
	menu = ['1. Check user over SOAP', '2. Check GroupWise folder structure', '\n     3. Count user shared folders', '4. Count all users shared folders', '\n     0. Back']

	available = build_avaialbe(menu)
	loop = True
	while loop:
		show_menu(menu)
		choice = get_choice(available)
		if choice == '1':
			userConfig = ds.verifyUser(dbConfig)[0]
			if userConfig['name'] != None:
				if userConfig['type'] != 'group':
					dsSOAP.soap_printUser(trustedConfig, gwConfig, userConfig)
				else:
					print ("Input '%(name)s' is not a user. Type='%(type)s'" % userConfig)
				print; ds.eContinue()

		elif choice == '2':
			dsSOAP.soap_checkFolderList(trustedConfig, gwConfig, ds.verifyUser(dbConfig)[0])

		elif choice == '3':
			userConfig = ds.verifyUser(dbConfig)[0]
			if userConfig['name'] != None:
				if userConfig['type'] != 'group':
					shared_list = dsSOAP.soap_check_sharedFolders(trustedConfig, gwConfig, userConfig)
					if shared_list is not None:
						pydoc.pager(shared_list)
						if ds.askYesOrNo("Save to file"):
							with open(dsappdata + '/shared_folder_list.txt', 'w') as file:
								file.write(shared_list)
								file.write('\n')
							logger.info("Saving shared list to %s" % (dsappdata + '/shared_folder_list.txt'))
							print ("Saved to %s" % (dsappdata + '/shared_folder_list.txt'))
					print; ds.eContinue()

		elif choice == '4':
			ds.datasyncBanner(dsappversion)
			print ("This can take some time to check every user in mobility")
			if ds.askYesOrNo("Warning! CPU may become busy. Continue"):
				userList = ds.getMobilityUserList(dbConfig)
				shared_list = dsSOAP.soap_check_allSharedFolders(trustedConfig, gwConfig, userList)
				if shared_list is not None:
					pydoc.pager(shared_list)
					if ds.askYesOrNo("Save to file"):
						with open(dsappdata + '/shared_folder_list-allUsers.txt', 'w') as file:
							file.write(shared_list)
							file.write('\n')
						logger.info("Saving shared list to %s" % (dsappdata + '/shared_folder_list-allUsers.txt'))
						print ("Saved to %s" % (dsappdata + '/shared_folder_list-allUsers.txt'))
					print; ds.eContinue()
					
		elif choice == '0':
			loop = False
			return
Ejemplo n.º 8
0
def database_menu():
	ds.datasyncBanner(dsappversion)
	print "The database menu will require Mobility to be stopped"
	if ds.askYesOrNo("Stop Mobility now"):
		ds.datasyncBanner(dsappversion)
		ds.rcDS('stop')
		menu = ['1. Vacuum Databases', '2. Re-Index Databases', '\n     3. Back up Databases', '4. Restore Databases', '\n     5. Recreate Global Address Book (GAL)', '6. Fix targets/membershipCache', '\n     7. CUSO Clean-Up Start-Over', '\n     0. Back -- Start Mobility']

		available = build_avaialbe(menu)
		loop = True
		while loop:
			show_menu(menu)
			choice = get_choice(available)
			if choice == '1':
				ds.datasyncBanner(dsappversion)
				print textwrap.fill("The amount of time this takes can vary depending on the last time it was completed. It is recommended that this be run every 6 months.", 80)
				print
				if ds.askYesOrNo("Do you want to continue"):
					ds.vacuumDB(dbConfig)
					print
					ds.eContinue()
			elif choice == '2':
				ds.datasyncBanner(dsappversion)
				print textwrap.fill("The amount of time this takes can vary depending on the last time it was completed. It is recommended that this be run after a database vacuum.", 80)
				print
				if ds.askYesOrNo("Do you want to continue"):
					ds.indexDB(dbConfig)
					print
					ds.eContinue()
			elif choice == '3':
				ds.backupDatabase(dbConfig)
				print; ds.eContinue()
			elif choice == '4':
				ds.restoreDatabase(dbConfig)
				print; ds.eContinue()
			elif choice == '5':
				ds.fix_gal(dbConfig)
				print; ds.eContinue()
			elif choice == '6':
				ds.addGroup(dbConfig, ldapConfig)
				print; ds.eContinue()
			elif choice == '7':
				cuso_menu()
			elif choice == '0':
				loop = False
				ds.datasyncBanner(dsappversion)
				ds.rcDS('start')
				main_menu()
	else:
		main_menu()
Ejemplo n.º 9
0
def ftf_menu():
    menu = ['1. Show applied FTFs', '2. Apply FTFs', '\n     0. Back']

    available = build_avaialbe(menu)
    loop = True
    while loop:
        show_menu(menu)
        choice = get_choice(available)
        if choice == '1':
            ds.showAppliedPatches()
            ds.eContinue()
        elif choice == '2':
            ds.datasyncBanner()

            Config.read(glb.dsappSettings)
            serviceCheck = Config.get('FTF URL', 'check.service.address')
            serviceCheckPort = Config.getint('FTF URL', 'check.service.port')
            dlPath = Config.get('FTF URL', 'download.address')
            if ds.DoesServiceExist(serviceCheck, serviceCheckPort):
                # Get latest FTFlist.txt file
                FTFfile = glb.dsappConf + '/dsapp_FTFlist.txt'
                if os.path.isfile(FTFfile):
                    os.rename(FTFfile, FTFfile + '.bak')

                if not ds.dlfile('%sdsapp_FTFlist.txt' % dlPath, glb.dsappConf,
                                 False, False):
                    if os.path.isfile(FTFfile + '.bak'):
                        os.rename(FTFfile + '.bak', FTFfile)

                if os.path.isfile(FTFfile):
                    patches = ds.buildFTFPatchList(FTFfile)
                    ds.selectFTFPatch(patches)
                else:
                    print "No FTFs / Patches available"
                    print
                    ds.eContinue()
            else:
                print "FTFs / Patches require FTF access to download"
                print
                ds.eContinue()
        elif choice == '0':
            loop = False
            return
Ejemplo n.º 10
0
def registerUpdate_menu():
	menu = ['1. Register Mobility', '2. Update Mobility', '3. FTF options...', '\n     0. Back']

	available = build_avaialbe(menu)
	loop = True
	while loop:
		show_menu(menu)
		choice = get_choice(available)
		if choice == '1':
			ds.datasyncBanner(dsappversion)
			ds.registerDS()
			print; ds.eContinue()
		elif choice == '2':
			update_menu()
		elif choice == '3':
			ftf_menu()
		elif choice == '0':
			loop = False
			main_menu()
Ejemplo n.º 11
0
def viewAttachments_menu():
	menu = ['1. View user attachments','2. View total attachment size by users', '3. Check Mobility attachments count', '\n     0. Back']

	available = build_avaialbe(menu)
	loop = True
	while loop:
		show_menu(menu)
		choice = get_choice(available)
		if choice == '1':
			ds.view_users_attach(dbConfig)
		elif choice == '2':
			ds.view_attach_byUser(dbConfig)
		elif choice == '3':
			ds.datasyncBanner(dsappversion)
			print ("Compare the mobility database ID count, with the mobility filestore ID count")
			if ds.askYesOrNo("This may take some time to complete, continue"):
				ds.check_mob_attachments(dbConfig)
				print; ds.eContinue()
		elif choice == '0':
			loop = False
			return
Ejemplo n.º 12
0
def cuso_menu():
	menu = ['1. Clean up and start over (Except Users)', '2. Clean up and start over (Everything)', '\n     3. Uninstall Mobility', '\n     0. Back']

	available = build_avaialbe(menu)
	loop = True
	while loop:
		show_menu(menu)
		choice = get_choice(available)
		if choice == '1':
			ds.datasyncBanner(dsappversion)
			if ds.askYesOrNo("Clean up and start over (Except Users)"):
				ds.cuso(dbConfig, 'user')
				print; ds.eContinue()
		elif choice == '2':
			ds.datasyncBanner(dsappversion)
			if ds.askYesOrNo("Clean up and start over (Everything)"):
				ds.cuso(dbConfig, 'everything')
				print; ds.eContinue()
		elif choice == '3':
			ds.datasyncBanner(dsappversion)
			print "Please run 'sh /opt/novell/datasync/uninstall.sh' first"
			if ds.askYesOrNo("Uninstall Mobility"):
				ds.cuso(dbConfig, 'uninstall')
		elif choice == '0':
			loop = False
			return
Ejemplo n.º 13
0
def ftf_menu():
	menu = ['1. Show applied FTFs','2. Apply FTFs', '\n     0. Back']
	
	available = build_avaialbe(menu)
	loop = True
	while loop:
		show_menu(menu)
		choice = get_choice(available)
		if choice == '1':
			ds.showAppliedPatches()
			ds.eContinue()
		elif choice == '2':
			ds.datasyncBanner(dsappversion)

			Config.read(dsappSettings)
			serviceCheck = Config.get('FTF URL', 'check.service.address')
			serviceCheckPort = Config.getint('FTF URL', 'check.service.port')
			dlPath = Config.get('FTF URL', 'download.address')
			if ds.DoesServiceExist(serviceCheck, serviceCheckPort):
				# Get latest FTFlist.txt file
				FTFfile = dsappConf + '/dsapp_FTFlist.txt'
				if os.path.isfile(FTFfile):
					os.rename(FTFfile, FTFfile + '.bak')

				if not ds.dlfile('%sdsapp_FTFlist.txt' % dlPath, dsappConf, False, False):
					if os.path.isfile(FTFfile + '.bak'):
						os.rename(FTFfile + '.bak', FTFfile)

				if os.path.isfile(FTFfile):
					patches = ds.buildFTFPatchList(FTFfile)
					ds.selectFTFPatch(patches)
				else:
					print "No FTFs / Patches available"
					print; ds.eContinue()
			else:
				print "FTFs / Patches require FTF access to download"
				print; ds.eContinue()
		elif choice == '0':
			loop = False
			return
Ejemplo n.º 14
0
def cuso_menu():
    menu = [
        '1. Clean up and start over (Except Users)',
        '2. Clean up and start over (Everything)',
        '\n     3. Uninstall Mobility', '\n     0. Back'
    ]

    available = build_avaialbe(menu)
    loop = True
    while loop:
        show_menu(menu)
        choice = get_choice(available)
        if choice == '1':
            ds.datasyncBanner()
            if ds.askYesOrNo("Clean up and start over (Except Users)"):
                ds.cuso('user')
                print
                ds.eContinue()
        elif choice == '2':
            ds.datasyncBanner()
            if ds.askYesOrNo("Clean up and start over (Everything)"):
                ds.cuso('everything')
                print
                ds.eContinue()
        elif choice == '3':
            ds.datasyncBanner()
            print "Please run 'sh /opt/novell/datasync/uninstall.sh' first"
            if ds.askYesOrNo("Uninstall Mobility"):
                ds.cuso('uninstall')
        elif choice == '0':
            loop = False
            return
Ejemplo n.º 15
0
def removeUser_menu():
    menu = [
        '1. Force remove user(s)/group(s) db references',
        '2. Remove user/group (restarts configengine)',
        '3. Remove disabled users & fix referenceCount',
        '\n     4. Reinitialize user(s)', '5. Reinitialize all failed users',
        '6. Reinitialize all users', '\n     0. Back'
    ]

    available = build_avaialbe(menu)
    loop = True
    while loop:
        show_menu(menu)
        choice = get_choice(available)
        if choice == '1':
            ds.remove_user(1)
        elif choice == '2':
            ds.remove_user()
        elif choice == '3':
            ds.datasyncBanner()
            ds.removed_disabled()
            print
            ds.fix_referenceCount()
            print
            ds.eContinue()
        elif choice == '4':
            ds.setUserState('7')
        elif choice == '5':
            ds.reinitAllFailedUsers()
            print
            ds.eContinue()
        elif choice == '6':
            ds.reinitAllUsers()
            print
            ds.eContinue()
        elif choice == '0':
            loop = False
            return
Ejemplo n.º 16
0
def checksQueries_menu():
    menu = [
        '1. General Health Check', '2. Nightly Maintenance Check',
        '\n     3. Show Sync Status',
        '4. GW pending events by User (consumerevents)',
        '5. Mobility pending events by User (syncevents)',
        '\n     6. Attachments..', '7. Performance..', '\n     0. Back'
    ]

    available = build_avaialbe(menu)
    loop = True
    while loop:
        show_menu(menu)
        choice = get_choice(available)
        if choice == '1':
            ghc.generalHealthCheck()
            print
            ds.eContinue()
        elif choice == '2':
            print ds.checkNightlyMaintenance()['output']
            print
            ds.eContinue()
        elif choice == '3':
            ds.datasyncBanner()
            ds.showStatus()
            print
            ds.eContinue()
        elif choice == '4':
            ds.show_GW_syncEvents()
        elif choice == '5':
            ds.show_Mob_syncEvents()
        elif choice == '6':
            viewAttachments_menu()
        elif choice == '7':
            performance_menu()
        elif choice == '0':
            loop = False
            main_menu()
Ejemplo n.º 17
0
def registerUpdate_menu():
    menu = [
        '1. Register Mobility', '2. Update Mobility', '3. FTF options..',
        '\n     0. Back'
    ]

    available = build_avaialbe(menu)
    loop = True
    while loop:
        show_menu(menu)
        choice = get_choice(available)
        if choice == '1':
            ds.datasyncBanner()
            ds.registerDS()
            print
            ds.eContinue()
        elif choice == '2':
            update_menu()
        elif choice == '3':
            ftf_menu()
        elif choice == '0':
            loop = False
            main_menu()
Ejemplo n.º 18
0
def performance_menu():
    menu = [
        '1. Top device requests', '2. Check manual syncing devices',
        '\n     0. Back'
    ]

    available = build_avaialbe(menu)
    loop = True
    while loop:
        show_menu(menu)
        ds.print_there(23, 6, "DEBUG logging required. Logs parsed for data")
        choice = get_choice(available)
        if choice == '1':
            ds.datasyncBanner()
            if ds.askYesOrNo("Parse debug log for top device requests"):
                log = ds.getFilePath(
                    "mobility-agent log file",
                    '/var/log/datasync/connectors/mobility-agent.log')
                if log is None:
                    return
                dsPerformance.getDeviceCommands(log)
                ds.eContinue()

        elif choice == '2':
            ds.datasyncBanner()
            if ds.askYesOrNo("Parse debug log for devices set to manual sync"):
                log = ds.getFilePath(
                    "mobility-agent log file",
                    '/var/log/datasync/connectors/mobility-agent.log')
                if log is None:
                    return
                dsPerformance.getPinglessDevices(log)
                ds.eContinue()

        elif choice == '0':
            loop = False
            return
Ejemplo n.º 19
0
def show_menu(menu_call):
    ds.datasyncBanner()
    logger.debug("Showing menu options: %s" % menu_call)

    for i in xrange(len(menu_call)):
        print "     %s" % menu_call[i]
Ejemplo n.º 20
0
                    dest='debugMenu',
                    help='Show debug menu for dsapp')
args = parser.parse_args()
logger.debug("Switches: %s" % args)

if args.re == 'restore':
    logger.info("Running switch: restore")
    import dsapp_re
    dsapp_re.install_settings()
    print
    ds.eContinue()
    sys.exit(0)

if args.bug:
    logger.info("Running switch: bug")
    ds.datasyncBanner()
    print "Report issues to: https://github.com/snielson/dsapp_python/issues\n"
    print "Useful logs can be located at:\n/opt/novell/datasync/tools/dsapp/logs/\nSet dsapp logs into debug for more information `dsapp --setlog debug`\n"
    print "Feel free to email %s directly at <%s>" % (__author__, __email__)
    sys.exit(0)

if args.dsUpdate:
    logger.info("Running switch: updateDsapp")
    ds.autoUpdateDsapp(True)
    ds.eContinue()
    sys.exit(0)

# Set logs if loglevel switch passed in
if args.loglevel:
    logger.info("Running switch: setlog")
    Config.read(glb.dsappLogSettings)
Ejemplo n.º 21
0
def show_menu(menu_call):
	ds.datasyncBanner(dsappversion)
	logger.debug("Showing menu options: %s" % menu_call)

	for i in xrange(len(menu_call)):
		print "     %s" % menu_call[i]
Ejemplo n.º 22
0
def groupwiseChecks_menu():
    menu = [
        '1. Check user over SOAP', '2. Check GroupWise folder structure',
        '\n     3. Count user shared folders',
        '4. Count all users shared folders', '\n     0. Back'
    ]

    available = build_avaialbe(menu)
    loop = True
    while loop:
        show_menu(menu)
        choice = get_choice(available)
        if choice == '1':
            userConfig = ds.verifyUser()[0]
            if userConfig['name'] != None:
                if userConfig['type'] != 'group':
                    dsSOAP.soap_printUser(userConfig)
                else:
                    print("Input '%(name)s' is not a user. Type='%(type)s'" %
                          userConfig)
                print
                ds.eContinue()

        elif choice == '2':
            dsSOAP.soap_checkFolderList(ds.verifyUser()[0])

        elif choice == '3':
            userConfig = ds.verifyUser()[0]
            if userConfig['name'] != None:
                if userConfig['type'] != 'group':
                    shared_list = dsSOAP.soap_check_sharedFolders(userConfig)
                    if shared_list is not None:
                        pydoc.pager(shared_list)
                        if ds.askYesOrNo("Save to file"):
                            with open(
                                    glb.dsappdata + '/shared_folder_list.txt',
                                    'w') as file:
                                file.write(shared_list)
                                file.write('\n')
                            logger.info(
                                "Saving shared list to %s" %
                                (glb.dsappdata + '/shared_folder_list.txt'))
                            print("Saved to %s" %
                                  (glb.dsappdata + '/shared_folder_list.txt'))
                    print
                    ds.eContinue()

        elif choice == '4':
            ds.datasyncBanner()
            print("This can take some time to check every user in mobility")
            if ds.askYesOrNo("Warning! CPU may become busy. Continue"):
                userList = ds.getMobilityUserList()
                shared_list = dsSOAP.soap_check_allSharedFolders(userList)
                if shared_list is not None:
                    pydoc.pager(shared_list)
                    if ds.askYesOrNo("Save to file"):
                        with open(
                                glb.dsappdata +
                                '/shared_folder_list-allUsers.txt',
                                'w') as file:
                            file.write(shared_list)
                            file.write('\n')
                        logger.info("Saving shared list to %s" %
                                    (glb.dsappdata +
                                     '/shared_folder_list-allUsers.txt'))
                        print("Saved to %s" %
                              (glb.dsappdata +
                               '/shared_folder_list-allUsers.txt'))
                    print
                    ds.eContinue()

        elif choice == '0':
            loop = False
            return
Ejemplo n.º 23
0
def dumpConfigs():
    ds.datasyncBanner()
    if not ds.askYesOrNo("Backup mobility configuration"):
        return

    DATE = datetime.datetime.now().strftime("%m.%d.%y-%s")

    # Create folder for backup data
    new_folder = glb.dsappdata + '/mobility_backup-%s' % DATE
    if not os.path.exists(new_folder):
        os.makedirs(new_folder)
    print("Dumping settings to %s" % new_folder)
    logger.info("Dumping settings to %s" % new_folder)

    dump_folder = new_folder + '/dumpSettings'
    if not os.path.exists(dump_folder):
        os.makedirs(dump_folder)

    # Dump dsapp settings
    with open(dump_folder + '/glb.dbConfig.p', 'wb') as handle:
        pickle.dump(glb.dbConfig, handle)
        logger.debug("Created %s/glb.dbConfig.p" % dump_folder)

    with open(dump_folder + '/ldapConfig.p', 'wb') as handle:
        pickle.dump(glb.ldapConfig, handle)
        logger.debug("Created %s/ldapConfig.p" % dump_folder)

    with open(dump_folder + '/mobilityConfig.p', 'wb') as handle:
        pickle.dump(glb.mobilityConfig, handle)
        logger.debug("Created %s/mobilityConfig.p" % dump_folder)

    with open(dump_folder + '/gwConfig.p', 'wb') as handle:
        pickle.dump(glb.gwConfig, handle)
        logger.debug("Created %s/gwConfig.p" % dump_folder)

    with open(dump_folder + '/trustedConfig.p', 'wb') as handle:
        pickle.dump(glb.trustedConfig, handle)
        logger.debug("Created %s/trustedConfig.p" % dump_folder)

    with open(dump_folder + '/config_files.p', 'wb') as handle:
        pickle.dump(glb.config_files, handle)
        logger.debug("Created %s/config_files.p" % dump_folder)

    with open(dump_folder + '/webConfig.p', 'wb') as handle:
        pickle.dump(glb.webConfig, handle)
        logger.debug("Created %s/webConfig.p" % dump_folder)

    with open(dump_folder + '/authConfig.p', 'wb') as handle:
        pickle.dump(glb.authConfig, handle)
        logger.debug("Created %s/authConfig.p" % dump_folder)

    # Dumping target, and membershipCache table
    skip_db = False
    for key in glb.dbConfig:
        if glb.dbConfig[key] is None:
            skip_db = True
    if not skip_db:
        print("\nGetting database tables..")
        logger.info("Getting database tables..")
        sql_folder = new_folder + '/SQLsettings'
        if not os.path.exists(sql_folder):
            os.makedirs(sql_folder)
        ds.dumpTable('datasync', 'membershipCache', sql_folder)
        ds.dumpTable('datasync', 'targets', sql_folder)
    else:
        print("\nUnable to dump database table..")
        logger.warning("Unable to dump database table..")

    # Dumping certificate
    print("Getting mobility certificates..")
    logger.info("Getting mobility certificates..")
    cert_folder = new_folder + '/certificates/'
    if not os.path.exists(cert_folder):
        os.makedirs(cert_folder)
    shutil.copy(mobCert, cert_folder)
    shutil.copy(webCert, cert_folder)

    print("Settings have been dumped")
    logger.info("Settings have been dumped")

    # Compress setting directory
    tarSettings(new_folder)

    # Remove setting folder
    shutil.rmtree(new_folder)
Ejemplo n.º 24
0
def database_menu():
    ds.datasyncBanner()
    print "The database menu will require Mobility to be stopped"
    if ds.askYesOrNo("Stop Mobility now"):
        ds.datasyncBanner()
        ds.rcDS('stop')
        menu = [
            '1. Vacuum Databases', '2. Re-Index Databases',
            '\n     3. Back up Databases', '4. Restore Databases',
            '\n     5. Recreate Global Address Book (GAL)',
            '6. Fix targets/membershipCache',
            '\n     7. CUSO Clean-Up Start-Over',
            '\n     0. Back -- Start Mobility'
        ]

        available = build_avaialbe(menu)
        loop = True
        while loop:
            show_menu(menu)
            choice = get_choice(available)
            if choice == '1':
                ds.datasyncBanner()
                print textwrap.fill(
                    "The amount of time this takes can vary depending on the last time it was completed. It is recommended that this be run every 6 months.",
                    80)
                print
                if ds.askYesOrNo("Do you want to continue"):
                    ds.vacuumDB()
                    print
                    ds.eContinue()
            elif choice == '2':
                ds.datasyncBanner()
                print textwrap.fill(
                    "The amount of time this takes can vary depending on the last time it was completed. It is recommended that this be run after a database vacuum.",
                    80)
                print
                if ds.askYesOrNo("Do you want to continue"):
                    ds.indexDB()
                    print
                    ds.eContinue()
            elif choice == '3':
                ds.backupDatabase()
                print
                ds.eContinue()
            elif choice == '4':
                ds.restoreDatabase()
                print
                ds.eContinue()
            elif choice == '5':
                ds.fix_gal()
                print
                ds.eContinue()
            elif choice == '6':
                ds.addGroup()
                print
                ds.eContinue()
            elif choice == '7':
                cuso_menu()
            elif choice == '0':
                loop = False
                ds.datasyncBanner()
                ds.rcDS('start')
                main_menu()
    else:
        main_menu()
Ejemplo n.º 25
0
parser.add_argument('-db', '--database', action='store_true', dest='db', help='Change database password')
parser.add_argument('-cl', '--clear', action='store_true', dest='clear', help='Remove encryption from XMLs')
parser.add_argument('--config', dest='re', choices=['backup', 'restore'], help='Backup settings or install Mobility with backup')
parser.add_argument('--setlog', dest='loglevel', choices=['debug','info','warning'], help='Set the logging level')
parser.add_argument('--debugMenu', action='store_true', dest='debugMenu', help=argparse.SUPPRESS)
args = parser.parse_args()
logger.debug("Switches: %s" % args)

if args.re == 'restore':
	import dsapp_re
	dsapp_re.install_settings()
	print; ds.eContinue()
	sys.exit(0)

if args.bug:
	ds.datasyncBanner(dsappversion)
	print "Report issues to: https://github.com/snielson/dsapp_python/issues\n"
	print "Useful logs can be located at:\n/opt/novell/datasync/tools/dsapp/logs/\nSet dsapp logs into debug for more information `dsapp --setlog debug`\n"
	print "Feel free to email %s directly at <%s>" % (__author__, __email__)
	sys.exit(0)

if args.dsUpdate:
	ds.autoUpdateDsapp(True)
	ds.eContinue()
	sys.exit(0)

# Set logs if loglevel switch passed in
if args.loglevel:
	Config.read(dsappLogSettings)
	Config.set('logger___main__', 'level', args.loglevel.upper())
	Config.set('logger_dsapp_Definitions', 'level', args.loglevel.upper())
Ejemplo n.º 26
0
def install_settings():
    # TODO : DEV : Prompt to continue
    print("This feature is currently under development:\n\nTasks to complete:")
    print(
        "LDAP settings import\nCertificate check / import\nUsers and group import\n"
    )
    if not ds.askYesOrNo("Continue with restore"):
        return

    ds.datasyncBanner()

    # Is mobility already installed? Return if YES
    if os.path.isfile(glb.installedConnector):
        print(
            "Mobility already installed\nOnly use 'restore' to install Mobility from backup"
        )
        logger.warning("Mobility already installed")
        return

    setupDir = glb.dirOptMobility + '/syncengine/connectors/mobility/cli'
    path = getConfig()
    if path is None:
        return

    fileName = ds.file_content(path)[0]
    ds.untar_file(path, extractPath=glb.dsapptmp)
    readConfigs(glb.dsapptmp + '/' + fileName)

    # Validate all needed variabes are NOT None
    missingAttribute = False
    if glb.dbConfig['pass'] is None:
        print(ERROR_MSG)
        logger.error("glb.dbConfig['pass'] = None")
        missingAttribute = True
    if gwConfig['sListenAddress'] is None:
        print(ERROR_MSG)
        logger.error("gwConfig['sListenAddress'] = None")
        missingAttribute = True
    if mobilityConfig['galUserName'] is None:
        print(ERROR_MSG)
        logger.error("mobilityConfig['galUserName'] = None")
        missingAttribute = True
    if mobilityConfig['mPort'] is None:
        print(ERROR_MSG)
        logger.error("mobilityConfig['mPort'] = None")
        missingAttribute = True
    if mobilityConfig['mSecure'] is None:
        print(ERROR_MSG)
        logger.error("mobilityConfig['mSecure'] = None")
        missingAttribute = True
    if gwConfig['gport'] is None:
        print(ERROR_MSG)
        logger.error("gwConfig['gport'] = None")
        missingAttribute = True
    if gwConfig['gListenAddress'] is None:
        print(ERROR_MSG)
        logger.error("gwConfig['gListenAddress'] = None")
        missingAttribute = True
    if gwConfig['sPort'] is None:
        print(ERROR_MSG)
        logger.error("gwConfig['sPort'] = None")
        missingAttribute = True
    if gwConfig['sSecure'] is None:
        print(ERROR_MSG)
        logger.error("gwConfig['sSecure'] = None")
        missingAttribute = True
    if trustedConfig['name'] is None:
        print(ERROR_MSG)
        logger.error("trustedConfig['name'] = None")
        missingAttribute = True
    if trustedConfig['key'] is None:
        print(ERROR_MSG)
        logger.error("trustedConfig['key'] = None")
        missingAttribute = True
    if missingAttribute:
        return

    # Get local IP, and validate IP is NOT 127.0.0.1
    local_IP = socket.gethostbyname(socket.gethostname())
    logger.debug("Detected local address: %s" % local_IP)
    if '127.0.0' in local_IP:
        logger.warning(
            "Detected address defaulted to localhost. Setting to 'None'")
        local_IP = None

    if local_IP is None:
        print("Unable to detect server address")
        logger.warning("Unable to detect server address, or set to None")
        if ds.askYesOrNo("Manually enter server address"):
            local_IP = raw_input("Server address: ")
        else:
            return

    # Does local_IP match sListenAddress
    if local_IP != gwConfig['sListenAddress']:
        print(
            "\nSever address does not match stored backup address\nLocal: %s\nBackup: %s\n"
            % (local_IP, gwConfig['sListenAddress']))
        if not ds.askYesOrNo(
                "Is detected local server address correct (%s)" % local_IP):
            if ds.askYesOrNo("Manually enter server address"):
                local_IP = raw_input("Server address: ")
            else:
                return
        if ds.askYesOrNo("Install with local server address (%s)" % local_IP):
            gwConfig['sListenAddress'] = local_IP
        else:
            if not ds.askYesOrNo("Install with backup address (%s)" %
                                 gwConfig['sListenAddress']):
                return

    # Create a trusted application key
    trustedKey = glb.dsapptmp + '/' + fileName + '/trustedKey.key'
    with open(trustedKey, 'a') as key:
        key.write(trustedConfig['key'])
        logger.info("Created trusted key at: %s" % trustedKey)

    # Get path / file
    isoPath = ds.getMobilityISO()

    # Verify ISO is mobility iso
    if not ds.checkISO_content(isoPath):
        return

    # Prompt to run install
    ds.datasyncBanner()
    print("Mobility Backup: %s" % fileName)
    print("Mobility ISO: %s" % os.path.basename(isoPath))
    if not ds.askYesOrNo("Install with settings"):
        return

    # All checks paasses - Add isoPath as 'mobility' repo
    print("\nSetting up mobility repository..")
    logger.info("Setting up mobility repository")
    cmd = "zypper rr mobility"
    logger.debug("Running: %s" % cmd)
    out = ds.util_subprocess(cmd, True)

    cmd = "zypper addrepo 'iso:///?iso=%s&url=file://%s' mobility" % (
        os.path.basename(isoPath), os.path.dirname(isoPath))
    logger.debug("Running: %s" % cmd)
    out = ds.util_subprocess(cmd, True)

    # Refresh Repo
    print("Refreshing mobility repository")
    logger.info("Refreshing mobility repository")
    cmd = "zypper --gpg-auto-import-keys ref -f mobility"
    logger.debug("Running: %s" % cmd)
    out = ds.util_subprocess(cmd, True)

    # Install mobility pattern
    cmd = "zypper -x pt --repo mobility"
    logger.debug("Running: %s" % cmd)
    out = ds.util_subprocess(cmd, True)
    try:
        patternName = out[0].split('pattern name=')[1].split('"')[1]
        logger.debug("Found Mobility pattern: %s" % patternName)
    except:
        print("Unable to find Mobility pattern")
        logger.error("Unable to find Mobility pattern")
        return

    print("Installing Mobility pattern: %s" % patternName)
    logger.info("Installing Mobility pattern: %s" % patternName)
    cmd = "zypper --non-interactive install -t pattern %s" % patternName
    logger.debug("Running: %s" % cmd)
    out = ds.util_subprocess(cmd, True)

    # Get version of GMS installed
    if gwConfig['sSecure'] == 'https':
        gwConfig['sSecure'] = 'yes'
    elif gwConfig['sSecure'] == 'http':
        gwConfig['sSecure'] = 'no'

    # Swtich msecure 1 or 0 to true or false
    if bool(mobilityConfig['mSecure']):
        mobilityConfig['mSecure'] = 'true'
    else:
        mobilityConfig['mSecure'] = 'false'

    # Create variables for gms installs
    setup_one = "sh " + setupDir + "/postgres_setup_1.sh"
    setup_two = "python " + setupDir + "/odbc_setup_2.pyc"
    setup_three = "python " + setupDir + "/mobility_setup_3.pyc --provision 'groupwise' --dbpass '%s'" % glb.dbConfig[
        'pass']
    setup_four = "sh " + setupDir + "/enable_setup_4.sh"
    setup_five = "python " + setupDir + "/mobility_setup_5.pyc --provision 'groupwise' --galuser '%(galUserName)s' --block false --selfsigned true --path '' --lport '%(mPort)s' --secure %(mSecure)s" % mobilityConfig
    setup_six = "python " + setupDir + "/groupwise_setup_6.pyc --keypath '%s' --lport '%s' --lip '%s' --version '802' --soap %s --key '%s' --sport %s --psecure '%s'" % (
        trustedKey, gwConfig['gport'], gwConfig['sListenAddress'],
        gwConfig['gListenAddress'], trustedConfig['name'], gwConfig['sPort'],
        gwConfig['sSecure'])
    setup_seven = "python " + setupDir + "/start_mobility.pyc"

    # Run through install with all setups
    print("\nConfiguring and extending database..")
    logger.info("Configuring and extending database..")
    logger.debug("Running: %s" % setup_one)
    out = ds.util_subprocess(setup_one, True)
    logger.debug("Running: %s" % setup_two)
    out = ds.util_subprocess(setup_two, True)

    print("Configuring GroupWise Mobility Service..")
    logger.info("Configuring GroupWise Mobility Service..")
    logger.debug("Running: %s" % setup_three)
    out = ds.util_subprocess(setup_three, True)

    print("Enabling and Starting GroupWise Mobility Service..")
    logger.info("Enabling and Starting GroupWise Mobility Service..")
    logger.debug("Running: %s" % setup_four)
    out = ds.util_subprocess(setup_four, True)

    # Manually start mobility as the init script will detect a running [p]ython pid, and fail to start
    ds.rcDS('start', op='nocron', show_spinner=False, show_print=False)

    print("Configuring Device Sync Agent..")
    logger.info("Configuring Device Sync Agent..")
    logger.debug("Running: %s" % setup_five)
    out = ds.util_subprocess(setup_five, True)

    print("Configuring GroupWise Sync Agent..")
    logger.info("Configuring GroupWise Sync Agent..")
    logger.debug("Running: %s" % setup_six)
    out = ds.util_subprocess(setup_six, True)

    print("Starting Sync Agents..")
    logger.info("Starting Sync Agents..")
    logger.debug("Running: %s" % setup_seven)
    out = ds.util_subprocess(setup_seven, True)

    # Build XMLconfigs
    logger.info('Building XML trees started')
    time1 = time.time()
    logger.debug('Building %s tree from: %s' %
                 ('mconfXML', glb.config_files['mconf']))
    glb.XMLconfig['mconf'] = ds.getXMLTree(glb.config_files['mconf'])
    logger.debug('Building %s tree from: %s' %
                 ('econfXML', glb.config_files['econf']))
    glb.XMLconfig['econf'] = ds.getXMLTree(glb.config_files['econf'])
    logger.debug('Building %s tree from: %s' %
                 ('ceconfXML', glb.config_files['ceconf']))
    glb.XMLconfig['ceconf'] = ds.getXMLTree(glb.config_files['ceconf'])
    logger.debug('Building %s tree from: %s' %
                 ('wconfXML', glb.config_files['wconf']))
    glb.XMLconfig['wconf'] = ds.getXMLTree(glb.config_files['wconf'])
    logger.debug('Building %s tree from: %s' %
                 ('gconfXML', glb.config_files['gconf']))
    glb.XMLconfig['gconf'] = ds.getXMLTree(glb.config_files['gconf'])
    time2 = time.time()
    logger.info('Building XML trees complete')
    logger.info("Operation took %0.3f ms" % ((time2 - time1) * 1000))

    # Prompt to match backup ldap settings
    finalChange = False
    if ldapConfig['enabled'] == 'true':
        finalChange = True
        if ds.askYesOrNo("\nRestore LDAP settings"):

            # Restore groups
            print("Restoring group container(s)..")
            logger.info("Restoring group container(s)..")
            if len(ldapConfig['group']) == 1:
                ds.setXML('.//configengine/ldap/groupContainer',
                          glb.XMLconfig['ceconf'], ldapConfig['group'][0],
                          glb.config_files['ceconf'])
            elif len(ldapConfig['group']) > 1:
                ds.setXML('.//configengine/ldap/groupContainer',
                          glb.XMLconfig['ceconf'], ldapConfig['group'][0],
                          glb.config_files['ceconf'])
                groups = iter(ldapConfig['group'])
                next(groups, None)
                for group in groups:
                    ds.insertXML(
                        './/configengine/ldap/groupContainer',
                        glb.XMLconfig['ceconf'],
                        '<groupContainer>' + group + '</groupContainer>',
                        glb.config_files['ceconf'])
            else:
                logger.warning("No group container(s)")

            # Restore users
            print("Restoring user container(s)..")
            logger.info("Restoring user container(s)..")

            # Create base userContainer to insert into
            ds.createXML_tag('.//configengine/ldap',
                             glb.XMLconfig['ceconf'],
                             "userContainer",
                             glb.config_files['ceconf'],
                             value="o=GroupWise")

            if len(ldapConfig['user']) == 1:
                ds.setXML('.//configengine/ldap/userContainer',
                          glb.XMLconfig['ceconf'], ldapConfig['user'][0],
                          glb.config_files['ceconf'])
            elif len(ldapConfig['user']) > 1:
                ds.setXML('.//configengine/ldap/userContainer',
                          glb.XMLconfig['ceconf'], ldapConfig['user'][0],
                          glb.config_files['ceconf'])
                users = iter(ldapConfig['user'])
                next(users, None)
                for user in users:
                    ds.insertXML('.//configengine/ldap/userContainer',
                                 glb.XMLconfig['ceconf'],
                                 '<userContainer>' + user + '</userContainer>',
                                 glb.config_files['ceconf'])
            else:
                logger.warning("No user container(s)")

            # Restore admins
            print("Restoring admin(s)..")
            logger.info("Restoring admin(s)..")
            if len(ldapConfig['admins']) == 1:
                ds.setXML('.//configengine/ldap/admins/dn',
                          glb.XMLconfig['ceconf'], ldapConfig['admins'][0],
                          glb.config_files['ceconf'])
            elif len(ldapConfig['admins']) > 1:
                ds.setXML('.//configengine/ldap/admins/dn',
                          glb.XMLconfig['ceconf'], ldapConfig['admins'][0],
                          glb.config_files['ceconf'])
                admins = iter(ldapConfig['admins'])
                next(admins, None)
                for admin in admins:
                    ds.insertXML('.//configengine/ldap/admins/dn',
                                 glb.XMLconfig['ceconf'],
                                 '<admins>' + admin + '</admins>',
                                 glb.config_files['ceconf'])
            else:
                logger.warning("No admin(s)")

            # Server settings
            print("Restoring server settings..")
            logger.info("Restoring server settings..")
            ds.setXML('.//configengine/ldap/secure', glb.XMLconfig['ceconf'],
                      ldapConfig['secure'], glb.config_files['ceconf'])
            ds.setXML('.//configengine/ldap/enabled', glb.XMLconfig['ceconf'],
                      ldapConfig['enabled'], glb.config_files['ceconf'])
            ds.setXML('.//configengine/ldap/hostname', glb.XMLconfig['ceconf'],
                      ldapConfig['host'], glb.config_files['ceconf'])
            ds.setXML('.//configengine/ldap/port', glb.XMLconfig['ceconf'],
                      ldapConfig['port'], glb.config_files['ceconf'])
            ds.setXML('.//configengine/ldap/login/dn', glb.XMLconfig['ceconf'],
                      ldapConfig['login'], glb.config_files['ceconf'])
            ds.setXML('.//configengine/source/provisioning',
                      glb.XMLconfig['ceconf'], authConfig['provisioning'],
                      glb.config_files['ceconf'])
            ds.setXML('.//configengine/source/authentication',
                      glb.XMLconfig['ceconf'], authConfig['authentication'],
                      glb.config_files['ceconf'])
            hostname = os.popen('echo `hostname -f`').read().rstrip()
            ldapPass = ds.getEncrypted(ldapConfig['pass'],
                                       glb.XMLconfig['ceconf'],
                                       './/configengine/ldap/login/protected',
                                       hostname)
            ds.setXML('.//configengine/ldap/login/password',
                      glb.XMLconfig['ceconf'],
                      ldapPass,
                      glb.config_files['ceconf'],
                      hideValue=True)

    # Prompt for users and group to be imported
    if ds.askYesOrNo("\nRestore users and groups"):
        finalChange = True
        sqlPath = glb.dsapptmp + '/' + fileName + '/SQLsettings'
        conn = ds.getConn('datasync')
        cur = conn.cursor()
        print("Restoring users..")
        cur.execute(open(sqlPath + '/targets.sql', 'r').read())
        logger.info('Imported targets.sql into datasync database')
        print("Restoring groups..")
        cur.execute(open(sqlPath + '/membershipCache.sql', 'r').read())
        logger.info('Imported membershipCache.sql into datasync database')
        cur.close()
        conn.close()

    # Prompt for backup certs to be applied # TODO: Will this be needed?
    # if ds.askYesOrNo("\nRestore backup certificates"):
    # 	finalChange = True

    if finalChange:
        ds.rcDS('restart', show_spinner=False, show_print=False)

    print("Restore complete")
    logger.info("Restore complete")