Exemple #1
0
 def __init__(self, config):
     Gtk.Menu.__init__(self)
     self.utils = Utils()
     self.config = config
     item_status = Gtk.MenuItem('Status')
     item_login = Gtk.MenuItem('Login')
     item_connect = Gtk.MenuItem('Connect')
     item_disconnect = Gtk.MenuItem('Disconnect')
     item_display = Gtk.MenuItem('Settings')
     item_logout = Gtk.MenuItem('Logout')
     item_quit = Gtk.MenuItem('Quit')
     item_status.connect('activate', self.status)
     item_login.connect('activate', self.login)
     item_logout.connect('activate', self.logout)
     item_display.connect('activate', self.display)
     item_connect.connect('activate', self.connect)
     item_disconnect.connect('activate', self.disconnect)
     item_quit.connect('activate', quit)
     self.append(item_status)
     self.append(item_login)
     self.append(item_logout)
     self.append(item_connect)
     self.append(item_disconnect)
     self.append(item_display)
     self.append(item_quit)
     self.show_all()
Exemple #2
0
    def set_next_month(self):
        chosen_date = self.get_chosen_date()
        pydate = Utils.from_sapdate_to_pydate(chosen_date)
        days_in_month = calendar.monthrange(pydate.year, pydate.month)[1]

        new_date = pydate + timedelta(days=days_in_month)
        self.set_chosen_date(Utils.from_pydate_to_sapdate(new_date))
Exemple #3
0
    def set_prev_month(self):
        chosen_date = self.get_chosen_date()
        pydate = Utils.from_sapdate_to_pydate(chosen_date)

        first_day = pydate.replace(day=1)
        # days_in_month = calendar.monthrange(pydate.year, pydate.month)[1]

        # new_date = pydate - timedelta(days=days_in_month)
        new_date = first_day - timedelta(days=1)
        self.set_chosen_date(Utils.from_pydate_to_sapdate(new_date))
Exemple #4
0
    def get_string_status_for_date(self, date):
        result = ""

        output_date = Utils.get_output_date(date)

        result += f"Данные за {output_date}\n"

        if self.check_absence(Constants.sick, date):
            result += f"За этот день выбрана болезнь\n\n"
            return result
        elif self.check_absence(Constants.vacation, date):
            result += f"За этот день выбран отпуск\n\n"
            return result
        elif self.check_absence(Constants.mission, date):
            result += f"За за этот день выбрана командировка\n\n"

        result += "Информация по задачам:\n"

        tasks_for_day = self.__TS[date][Constants.task_list]

        for task in tasks_for_day:
            result += f"На задачу {task[Constants.proj_text]}.{task[Constants.task_text]} записано {task[Constants.chours]} часов \n"

        result += "\n\n"

        return result
Exemple #5
0
 def __init__(self, iniPath=os.path.abspath('./resources/config.ini')):
     self.iniPath = iniPath
     self.parser = ConfigParser.ConfigParser()
     self.parser.read(self.iniPath)
     # TODO: read settings from nordvpn and update to/from (?) config file
     result = subprocess.check_output(['nordvpn', 'settings'])
     settings = ConfigParser.ConfigParser()
     str = '[Default]\r\n'
     ini = str + Utils().cleanNotification(result)
     buf = StringIO.StringIO(ini)
     settings.readfp(buf)
     self.setProtocol(settings.get('Default', 'Protocol'))
     self.setKillswitch(settings.get('Default', 'Kill Switch'))
     self.setCybersec(settings.get('Default', 'CyberSec'))
     self.setObfuscate(settings.get('Default', 'Obfuscate'))
     self.setAutoconnect(settings.get('Default', 'Auto connect'))
Exemple #6
0
class Menu(Gtk.Menu):

    def __init__(self, config):
        Gtk.Menu.__init__(self)
        self.utils = Utils()
        self.config = config
        item_status = Gtk.MenuItem('Status')
        item_login = Gtk.MenuItem('Login')
        item_connect = Gtk.MenuItem('Connect')
        item_disconnect = Gtk.MenuItem('Disconnect')
        item_display = Gtk.MenuItem('Settings')
        item_logout = Gtk.MenuItem('Logout')
        item_quit = Gtk.MenuItem('Quit')
        item_status.connect('activate', self.status)
        item_login.connect('activate', self.login)
        item_logout.connect('activate', self.logout)
        item_display.connect('activate', self.display)
        item_connect.connect('activate', self.connect)
        item_disconnect.connect('activate', self.disconnect)
        item_quit.connect('activate', quit)
        self.append(item_status)
        self.append(item_login)
        self.append(item_logout)
        self.append(item_connect)
        self.append(item_disconnect)
        self.append(item_display)
        self.append(item_quit)
        self.show_all()

    def status(self, source):
        result = subprocess.check_output(['nordvpn', 'status'])
        self.utils.showNotification("Status", self.utils.cleanNotification(result))

    def login(self, source):
        os.system("gnome-terminal -e 'nordvpn login'")

    def logout(self, source):
        result = subprocess.check_output(['nordvpn', 'logout'])
        self.utils.showNotification("Logout", self.utils.cleanNotification(result))
        print(result)

    def connect(self, source):
        args = ['nordvpn', 'connect', self.config.getCountry()]
        result = subprocess.check_output(args)
        self.utils.showNotification("Connect", self.utils.cleanNotification(result))
        print(result)

    def disconnect(self, source):
        result = subprocess.check_output(['nordvpn', 'disconnect'])
        self.utils.showNotification("Disconnect", self.utils.cleanNotification(result))
        print(result)

    def display(self, source):
        win = Window(self.config)
        win.show_all()

    def quit(self, source):
        Notify.uninit()
        Gtk.main_quit()
Exemple #7
0
 def set_chosen_date(self, chosen_date):
     if type(chosen_date) != str:
         self.__chosen_date = Utils.from_pydate_to_sapdate(chosen_date)
     else:
         self.__chosen_date = chosen_date
Exemple #8
0
#!/usr/bin/python2

import os
import threading
import time
import subprocess
import ConfigParser
import StringIO
from modules.Utils import Utils
# from modules.Config import Config

utils = Utils()
# config = Config()


class MonitorThread(object):
    """ Threading example class
    The run() method will be started and it will run in the background
    until the application exits.
    """
    def __init__(self, indicator, interval=10):
        """ Constructor
        :type interval: int
        :param interval: Check interval, in seconds
        """
        self.interval = interval
        self.indicator = indicator
        thread = threading.Thread(target=self.run, args=())
        thread.daemon = True  # Daemonize thread
        utils.showNotification('Activated', 'The NordVPN daemon is running')
        thread.start()  # Start the execution
Exemple #9
0
def callback(callback_data):
    data = json.loads(callback_data.data)

    id = callback_data.from_user.id

    if ActiveUsers.check_user(id):
        user = ActiveUsers.get_user(id)
    else:
        user = User(id)

    err_list = []

    bot.delete_message(chat_id=callback_data.message.chat.id,
                       message_id=callback_data.message.message_id)

    keyboard = None
    text = ''

    if data[Constants.type] == ActionsEnum.A_MAIN_DELETE_INFOTYPE:
        Registration.delete_request(user)
        text = "Id удалён из системы"

    elif data[Constants.type] == ActionsEnum.A_MAIN_FILL:

        status_text = Actions.get_fill_status_text(user)

        keyboard = Keyboard.get_fill_keyboard()
        text = f"{status_text}Выберите действие"

    elif data[Constants.type] == ActionsEnum.A_TO_START:
        keyboard = Keyboard.get_main_keyboard()
        text = "Выберите действие"

    elif data[Constants.type] == ActionsEnum.A_FILL_TODAY or \
            data[Constants.type] == ActionsEnum.A_FILL_YESTERDAY or \
            data[Constants.type] == ActionsEnum.A_CALENDAR_ACTION:

        if data.get(Constants.cdate):
            user.set_chosen_date(data[Constants.cdate])
        else:
            Actions.choose_day_by_action_type(data[Constants.type], user)

        task_list = Actions.get_tasks_by_day(user)

        try:
            user.get_TS().update(user.get_id(), user.get_chosen_date(),
                                 task_list)

            status_text = Actions.get_fill_status_text(user)

            keyboard = Keyboard.get_fill_type_keyboard(user)
            text = f"{status_text}\nВыберите действие"
        except TelegramBotError:
            keyboard = Keyboard.get_main_keyboard()
            text = "У вас нет задач!"

    elif data[Constants.type] == ActionsEnum.A_FILL_TYPE_SICK or \
            data[Constants.type] == ActionsEnum.A_FILL_TYPE_VACATION or \
            data[Constants.type] == ActionsEnum.A_FILL_TYPE_MISSION:
        TS = user.get_TS()

        TS.reset_absence(Constants.sick, user.get_chosen_date())
        TS.reset_absence(Constants.vacation, user.get_chosen_date())
        TS.reset_absence(Constants.mission, user.get_chosen_date())

        Actions.add_node(user, data[Constants.type])

        status_text = TS.get_string_status_for_date(user.get_chosen_date())

        keyboard = Keyboard.get_action_keyboard()
        text = f"{status_text}\nВыберите действие"

    elif data[Constants.type] == ActionsEnum.A_FILL_ANOTHER_DAY:
        Actions.move_calendar(data, user)

        month = Utils.get_month_by_chosen_date(user.get_chosen_date())

        keyboard = Keyboard.get_calendar(user)
        text = f"Выбранный месяц: {month}\nВыберите день"

    elif data[Constants.type] == ActionsEnum.A_FILL_TYPE_TIME:
        task_list = Actions.get_tasks_by_day(user)

        user.get_TS().update(user.get_id(), user.get_chosen_date(), task_list)

        keyboard = Keyboard.get_tasks_keyboard(user)
        text = "Выберите задачу"

    elif data[Constants.type] == ActionsEnum.A_FILL_FOR_DATE:
        Actions.create_task_for_user(user, data[Constants.task_id])
        text = "Введите время отведённое на задачу"

    elif data[Constants.type] == ActionsEnum.A_APPROVE:
        Actions.approve_changes(user, err_list)

        if len(err_list) != 0:
            text = ErrorParser.from_list_to_string(err_list)
        else:
            text = "Изменения выполнены"

        keyboard = Keyboard.get_main_keyboard()

    elif data[Constants.type] == ActionsEnum.A_RESET:
        Actions.approve_changes(user)

        keyboard = Keyboard.get_main_keyboard()
        text = "Изменения отклонены"

    elif data[Constants.type] == ActionsEnum.A_RESET_MISSION:
        TS = user.get_TS()
        chosen_date = user.get_chosen_date()
        TS.reset_mission_node(chosen_date)

        status_text = Actions.get_fill_status_text(user)

        keyboard = Keyboard.get_fill_type_keyboard(user)
        text = f"{status_text}\nВыберите действие"

    elif data[Constants.type] == ActionsEnum.A_ACTIVE_MISSION:
        user.get_TS().write_absence(user.get_chosen_date(),
                                    data[Constants.type])

        status_text = Actions.get_fill_status_text(user)

        keyboard = Keyboard.get_fill_type_keyboard(user)
        text = f"{status_text}\nВыберите действие"

    elif data[Constants.type] == ActionsEnum.A_APPROVE_REQUEST:
        user.set_session(data[Constants.session_guid])
        Actions.reset_pass(user, err_list)

        if len(err_list) != 0:
            text = ErrorParser.from_list_to_string(err_list)
        else:
            text = f"Ваш временный пароль: {user.get_password()}"

        keyboard = Keyboard.get_main_keyboard()

    elif data[Constants.type] == ActionsEnum.A_RESET_REQUEST:
        user.set_session(data[Constants.session_guid])
        Actions.drop_reset_session(user)

        text = "Запрос на сброс пароля отменён"
        keyboard = Keyboard.get_main_keyboard()

    elif data[Constants.type] == ActionsEnum.A_RESET_PASSWORD:
        ways = Actions.get_ways(user)
        user.set_ways(ways)

        keyboard = Keyboard.get_ways_keyboard(user)
        text = f"{user.get_request_text()}Выберите способ сброса пароля"

    elif data[Constants.type] == ActionsEnum.A_CHOOSE_WAY:
        way_id = data[Constants.way_id]
        Actions.create_request_for_user(user, way_id)

        systems = Actions.get_systems(user)
        user.set_systems(systems)

        keyboard = Keyboard.get_system_keyboard(user)
        text = f"{user.get_request_text()}Выберите систему"

    elif data[Constants.type] == ActionsEnum.A_CHOOSE_SYSTEM:
        system = data[Constants.full_info]
        Actions.add_system_to_request(user, system)

        keyboard = Keyboard.get_reset_approve_keyboard(user)
        text = f"{user.get_request_text()}"

    elif data[Constants.type] == ActionsEnum.A_APPROVE_DROP:
        Actions.send_drop_request(user, err_list)

        if len(err_list):
            text = ErrorParser.from_list_to_string(err_list)
            keyboard = Keyboard.get_main_keyboard()
        else:
            text = "Запрос на сброс пароля отправлен"

            request_type = Actions.get_request_type(user)

            if request_type == Constants.email_reset:
                keyboard = Keyboard.get_main_keyboard()

            Actions.clear_request(user)

    bot.send_message(user.get_id(), text, reply_markup=keyboard)

    ActiveUsers.update_user(user)