Exemplo n.º 1
0
def killTasks(session, event, stdin_fd, predetermined_input):
    """
    Parameters
    ----------
    session : ikabot.web.session.Session
    event : multiprocessing.Event
    stdin_fd: int
    predetermined_input : multiprocessing.managers.SyncManager.list
    """
    sys.stdin = os.fdopen(stdin_fd)
    config.predetermined_input = predetermined_input
    try:
        while True:
            banner()
            process_list = updateProcessList(session)
            process_list = [
                process for process in process_list
                if process['action'] != 'killTasks'
            ]
            if len(process_list) == 0:
                print(_('There are no tasks running'))
                enter()
                event.set()
                return
            print('Which task do you wish to kill?\n')
            print('(0) Exit')
            for process in process_list:
                if 'date' in process:
                    print("({}) {:<35}{:>20}".format(
                        process_list.index(process) + 1, process['action'],
                        datetime.datetime.fromtimestamp(
                            process['date']).strftime('%b %d %H:%M:%S')))
                else:
                    print("({}) {:<35}".format(
                        process_list.index(process) + 1,
                        process['action'],
                    ))
            choise = read(min=0, max=len(process_list), digit=True)
            if choise == 0:
                event.set()
                return
            else:
                if isWindows:
                    run("taskkill /F /PID {}".format(process_list[choise -
                                                                  1]['pid']))
                else:
                    run("kill -9 {}".format(process_list[choise - 1]['pid']))
    except KeyboardInterrupt:
        event.set()
        return
Exemplo n.º 2
0
def menu(session, checkUpdate=True):
	"""
	Parameters
	----------
	session : ikabot.web.session.Session
	checkUpdate : bool
	"""
	if checkUpdate:
		checkForUpdate()

	banner()

	process_list = updateProcessList(session)
	if len(process_list) > 0:
		print(_('Running tasks:'))
		for process in process_list:
			if len(process['proxies']) == 0:
				proxy = ''
			else:
				proxy = _('proxy: ') + str(process['proxies'])

			print(_('- pid: {} task: {} {}').format(process['pid'], process['action'], proxy))
		print('')

	menu_actions = [
					constructionList,
					sendResources,
					distributeResources,
					getStatus,
					donate,
					searchForIslandSpaces,
					loginDaily,
					alertAttacks,
					donationBot,
					alertLowWine,
					buyResources,
					sellResources,
					vacationMode,
					activateMiracle,
					trainArmy,
					shipMovements,
					constructBuilding,
					update,
					importExportCookie,
					autoPirate,
					updateTelegramData
					]

	print(_('(0)  Exit'))
	print(_('(1)  Construction list'))
	print(_('(2)  Send resources'))
	print(_('(3)  Distribute resources'))
	print(_('(4)  Account status'))
	print(_('(5)  Donate'))
	print(_('(6)  Search for new spaces'))
	print(_('(7)  Login daily'))
	print(_('(8)  Alert attacks'))
	print(_('(9)  Donate automatically'))
	print(_('(10) Alert wine running out'))
	print(_('(11) Buy resources'))
	print(_('(12) Sell resources'))
	print(_('(13) Activate vacation mode'))
	print(_('(14) Activate miracle'))
	print(_('(15) Train army'))
	print(_('(16) See movements'))
	print(_('(17) Construct building'))
	print(_('(18) Update Ikabot'))
	print(_('(19) Import / Export cookie'))
	print(_('(20) Auto-Pirate'))
	if telegramDataIsValid(session):
		print(_('(21) Change the Telegram data'))
	else:
		print(_('(21) Enter the Telegram data'))

	total_options = len(menu_actions)
	selected = read(min=0, max=total_options)
	if selected != 0:
		try:
			selected -= 1
			event = multiprocessing.Event() #creates a new event
			process = multiprocessing.Process(target=menu_actions[selected], args=(session, event, sys.stdin.fileno()), name=menu_actions[selected].__name__)
			process.start()
			process_list.append({'pid': process.pid, 'proxies': session.s.proxies, 'action': menu_actions[selected].__name__ })
			updateProcessList(session, programprocesslist=process_list)
			event.wait() #waits for the process to fire the event that's been given to it. When it does  this process gets back control of the command line and asks user for more input
		except KeyboardInterrupt:
			pass
		menu(session, checkUpdate=False)
	else:
		if isWindows:
			# in unix, you can exit ikabot and close the terminal and the processes will continue to execute
			# in windows, you can exit ikabot but if you close the terminal, the processes will die
			print(_('Closing this console will kill the processes.'))
			enter()
		clear()
		os._exit(0) #kills the process which executes this statement, but it does not kill it's child processes
Exemplo n.º 3
0
def menu(session, checkUpdate=True):
    """
    Parameters
    ----------
    session : ikabot.web.session.Session
    checkUpdate : bool
    """
    if checkUpdate:
        checkForUpdate()

    show_proxy(session)

    banner()

    process_list = updateProcessList(session)
    if len(process_list) > 0:
        print('|{:^6}|{:^35}|{:^15}|'.format('pid', 'task', 'date'))
        print('_'*60)
        for process in process_list:
            if 'date' in process:
                print('|{:^6}|{:^35}|{:^15}|'.format(process['pid'], process['action'], datetime.datetime.fromtimestamp(process['date']).strftime('%b %d %H:%M:%S')))
            else:
                print('|{:^6}|{:^35}|'.format(process['pid'], process['action']))

        print('')

    menu_actions = {
        1:            constructionList,
        2:            sendResources,
        3:            distributeResources,
        4:            getStatus,
        5:            donate,
        6:            searchForIslandSpaces,
        7:            loginDaily,
        8:            alertAttacks,
        9:            donationBot,
        10:            alertLowWine,
        11:            buyResources,
        12:            sellResources,
        13:            vacationMode,
        14:            activateMiracle,
        15:            trainArmy,
        16:            shipMovements,
        17:            constructBuilding,
        18:            update,
        19:            importExportCookie,
        20:            autoPirate,
        21:            investigate,
        22:            attackBarbarians,
        24:            proxyConf,
        25:            updateTelegramData,
        26:            killTasks,
        27:            decaptchaConf,
                    }

    print(_('(0)  Exit'))
    print(_('(1)  Construction list'))
    print(_('(2)  Send resources'))
    print(_('(3)  Distribute resources'))
    print(_('(4)  Account status'))
    print(_('(5)  Donate'))
    print(_('(6)  Search for new spaces'))
    print(_('(7)  Login daily'))
    print(_('(8)  Alert attacks'))
    print(_('(9)  Donate automatically'))
    print(_('(10) Alert wine running out'))
    print(_('(11) Buy resources'))
    print(_('(12) Sell resources'))
    print(_('(13) Activate vacation mode'))
    print(_('(14) Activate miracle'))
    print(_('(15) Train army'))
    print(_('(16) See movements'))
    print(_('(17) Construct building'))
    print(_('(18) Update Ikabot'))
    print(_('(19) Import / Export cookie'))
    print(_('(20) Auto-Pirate'))
    print(_('(21) Investigate'))
    print(_('(22) Attack barbarians'))
    print(_('(23) Options / Settings'))
    total_options = len(menu_actions) + 1
    selected = read(min=0, max=total_options, digit=True)

    if selected == 23:
        banner()
        print(_('(0) Back'))
        print(_('(1) Configure Proxy'))
        if telegramDataIsValid(session):
            print(_('(2) Change the Telegram data'))
        else:
            print(_('(2) Enter the Telegram data'))
        print(_('(3) Kill tasks'))
        print(_('(4) Configure captcha resolver'))

        selected = read(min=0, max=4, digit=True)
        if selected == 0:
            menu(session)
            return
        if selected > 0:
            selected += 23

    if selected != 0:
        try:
            event = multiprocessing.Event()  # creates a new event
            process = multiprocessing.Process(target=menu_actions[selected], args=(session, event, sys.stdin.fileno(), config.predetermined_input), name=menu_actions[selected].__name__)
            process.start()
            process_list.append({'pid': process.pid, 'action': menu_actions[selected].__name__, 'date': time.time()})
            updateProcessList(session, programprocesslist=process_list)
            event.wait()  # waits for the process to fire the event that's been given to it. When it does  this process gets back control of the command line and asks user for more input
        except KeyboardInterrupt:
            pass
        menu(session, checkUpdate=False)
    else:
        if isWindows:
            # in unix, you can exit ikabot and close the terminal and the processes will continue to execute
            # in windows, you can exit ikabot but if you close the terminal, the processes will die
            print(_('Closing this console will kill the processes.'))
            enter()
        clear()
        os._exit(0)  # kills the process which executes this statement, but it does not kill it's child processes