Exemplo n.º 1
0
 def afterCheckBoxToggled(self, checkBoxes):
     if self.after_checkBox.isChecked() == True:
         self.after_frame.setEnabled(True)
     else:
         self.after_frame.setEnabled(False)
         shutdown_file = os.path.join(persepolis_tmp, 'shutdown', self.gid)
         f = Open(shutdown_file, 'w')
         f.writelines('canceled')
         f.close()
Exemplo n.º 2
0
def shutDown(gid, password=None):
    shutdown_notification_file = os.path.join(persepolis_tmp, 'shutdown', gid)
    f = Open(shutdown_notification_file, 'w')
    f.writelines('wait')
    f.close()

    shutdown_notification = "wait"

    while shutdown_notification == "wait":
        sleep(1)

        f = Open(shutdown_notification_file, 'r')
        shutdown_notification_file_lines = f.readlines()
        f.close()

        shutdown_notification = str(
            shutdown_notification_file_lines[0].strip())

    osCommands.remove(shutdown_notification_file)

    if shutdown_notification == "shutdown":

        print("shutdown in 20 seconds")
        logger.sendToLog("Shutting down in 20 seconds", "INFO")
        sleep(20)
        if os_type == 'Linux':
            os.system('echo "' + password + '" |sudo -S poweroff')

        elif os_type == 'Darwin':
            os.system('echo "' + password + '" |sudo -S shutdown -h now ')

        elif os_type == 'Windows':
            CREATE_NO_WINDOW = 0x08000000
            subprocess.Popen(['shutdown', '-S'], shell=False,
                             creationflags=CREATE_NO_WINDOW)

        elif os_type == 'FreeBSD' or os_type == 'OpenBSD':
            os.system('echo "' + password + '" |sudo -S shutdown -p now ')
def browserIntegration(browser):
    # for GNU/Linux
    if os_type == 'Linux':
        # persepolis execution path
        config_folder = os.path.join(
            str(home_address), ".config/persepolis_download_manager")
        exec_path = os.path.join(config_folder, 'persepolis_run_shell')

        # Native Messaging Hosts folder path for every browser
        if browser == 'chromium':
            native_message_folder = home_address + '/.config/chromium/NativeMessagingHosts'

        elif browser == 'chrome':
            native_message_folder = home_address + \
                                    '/.config/google-chrome/NativeMessagingHosts'

        elif browser == 'firefox':
            native_message_folder = home_address + \
                                    '/.mozilla/native-messaging-hosts'

        elif browser == 'vivaldi':
            native_message_folder = home_address + \
                                    '/.config/vivaldi/NativeMessagingHosts'

        elif browser == 'opera':
            native_message_folder = home_address + \
                                    '/.config/opera/NativeMessagingHosts'

    # for FreeBSD and OpenBSD
    elif os_type == 'FreeBSD' or os_type == 'OpenBSD':
        # persepolis execution path
        config_folder = os.path.join(
            str(home_address), ".config/persepolis_download_manager")
        exec_path = os.path.join(config_folder, 'persepolis_run_shell')


        # Native Messaging Hosts folder path for every browser
        if browser == 'chromium':
            native_message_folder = home_address + '/.config/chromium/NativeMessagingHosts'

        elif browser == 'chrome':
            native_message_folder = home_address + \
                                    '/.config/google-chrome/NativeMessagingHosts'

        elif browser == 'firefox':
            native_message_folder = home_address + \
                                    '/.mozilla/native-messaging-hosts'
        elif browser == 'vivaldi':
            native_message_folder = home_address + \
                                    '/.config/vivaldi/NativeMessagingHosts'

        elif browser == 'opera':
            native_message_folder = home_address + \
                                    '/.config/opera/NativeMessagingHosts'



    # for Mac OSX
    elif os_type == 'Darwin':
        # finding Persepolis execution path
        cwd = sys.argv[0]
        current_directory = os.path.dirname(cwd)

        exec_path = os.path.join(
            current_directory, 'Persepolis Download Manager')

        # Native Messaging Hosts folder path for every browser
        if browser == 'chromium':
            native_message_folder = home_address + \
                                    '/Library/Application Support/Chromium/NativeMessagingHosts'

        elif browser == 'chrome':
            native_message_folder = home_address + \
                                    '/Library/Application Support/Google/Chrome/NativeMessagingHosts'

        elif browser == 'firefox':
            native_message_folder = home_address + \
                                    '/Library/Application Support/Mozilla/NativeMessagingHosts'

        elif browser == 'vivaldi':
            native_message_folder = home_address + \
                                    '/Library/Application Support/Vivaldi/NativeMessagingHosts'

        elif browser == 'opera':
            native_message_folder = home_address + \
                                    '/Library/Application Support/Opera/NativeMessagingHosts/'

    # for MicroSoft Windows os (windows 7 , ...)
    elif os_type == 'Windows':
        # finding Persepolis execution path
        cwd = sys.argv[0]
        current_directory = os.path.dirname(cwd)

        exec_path = os.path.join(
            current_directory, 'Persepolis Download Manager.exe')

        # the execution path in jason file for Windows must in form of
        # c:\\Users\\...\\Persepolis Download Manager.exe , so we need 2
        # "\" in address
        exec_path = exec_path.replace('\\', r'\\')

        if browser == 'chrome' or browser == 'chromium' or browser == 'opera' or browser == 'vivaldi':
            native_message_folder = os.path.join(
                home_address, 'AppData\Local\persepolis_download_manager', 'chrome')
        else:
            native_message_folder = os.path.join(
                home_address, 'AppData\Local\persepolis_download_manager', 'firefox')
 

    # WebExtension native hosts file prototype
    webextension_json_connector = {
        "name": "com.persepolis.pdmchromewrapper",
        "type": "stdio",
        "path": str(exec_path),
        "description": "Integrate Persepolis with %s using WebExtensions" % (browser)
    }

    # Add chrom* keys
    if browser == 'chrome' or browser == 'chromium' or browser == 'opera' or browser == 'vivaldi':
        webextension_json_connector["allowed_origins"] = [ "chrome-extension://legimlagjjoghkoedakdjhocbeomojao/" ]

    # Add firefox keys
    elif browser == 'firefox':
        webextension_json_connector["allowed_extensions"] = [
            "*****@*****.**",
            "*****@*****.**"
        ]

    # Build final path
    native_message_file = os.path.join(
        native_message_folder, 'com.persepolis.pdmchromewrapper.json')

    osCommands.makeDirs(native_message_folder)

    # Write NMH file
    f = open(native_message_file, 'w')
    f.write(str(webextension_json_connector).replace("'", "\""))
    f.close()

    if os_type != 'Windows':
        os.system('chmod +x "' + str(native_message_file) + '"')

    else:
        import winreg
        # add the key to the windows registry
        if browser == 'chrome' or browser == 'chromium' or browser == 'opera' or browser == 'vivaldi':
            try:
                # create pdmchromewrapper key under NativeMessagingHosts
                winreg.CreateKey(winreg.HKEY_CURRENT_USER, "SOFTWARE\\Google\\Chrome\\NativeMessagingHosts\\com.persepolis.pdmchromewrapper")
                # open a connection to pdmchromewrapper key
                gintKey = winreg.OpenKey(winreg.HKEY_CURRENT_USER, "SOFTWARE\\Google\\Chrome\\NativeMessagingHosts\\com.persepolis.pdmchromewrapper", 0, winreg.KEY_ALL_ACCESS)
                # set native_message_file as key value
                winreg.SetValueEx(gintKey, '', 0,winreg.REG_SZ, native_message_file)
                # close connection to pdmchromewrapper
                winreg.CloseKey(gintKey)
                return True
            except WindowsError:
                return False
        elif browser == 'firefox':
            try:
                # create pdmchromewrapper key under NativeMessagingHosts for firefox
                winreg.CreateKey(winreg.HKEY_CURRENT_USER, "SOFTWARE\\Mozilla\\NativeMessagingHosts\\com.persepolis.pdmchromewrapper")
                # open a connection to pdmchromewrapper key for firefox
                fintKey = winreg.OpenKey(winreg.HKEY_CURRENT_USER, "SOFTWARE\\Mozilla\\NativeMessagingHosts\\com.persepolis.pdmchromewrapper", 0, winreg.KEY_ALL_ACCESS)
                # set native_message_file as key value
                winreg.SetValueEx(fintKey, '', 0,winreg.REG_SZ, native_message_file)
                # close connection to pdmchromewrapper
                winreg.CloseKey(fintKey)
                return True
            except WindowsError:
                return False

    # browsers will call persepolis with persepolis_run_shell file in gnu/linux and bsd  

    # creating persepolis_run_shell file for gnu/linux and bsd 
    if os_type == 'Linux' or os_type == 'OpenBSD' or os_type == 'FreeBSD':
        # finding shell
        shell_list = ['/bin/bash', '/usr/local/bin/bash', '/bin/sh', '/usr/local/bin/sh', '/bin/ksh', '/bin/tcsh']

        for shell in shell_list:
            if os.path.isfile(shell):
                # defining shebang
                shebang = '#!' + shell
                break

    
        persepolis_run_shell_contents = shebang + '\n' + 'persepolis "$@"'
    
        f = Open(exec_path, 'w')
        f.writelines(persepolis_run_shell_contents)
        f.close()

        # making persepolis_run_shell executable
        os.system('chmod +x ' + exec_path)
Exemplo n.º 4
0
def browserIntegration(browser):
    # for GNU/Linux
    if os_type == 'Linux':
        # find Persepolis execution path
        # persepolis execution path
        exec_path = os.path.join(config_folder, 'persepolis_run_shell')

        # Native Messaging Hosts folder path for every browser
        if browser == 'chromium':
            native_message_folder = home_address + '/.config/chromium/NativeMessagingHosts'

        elif browser == 'chrome':
            native_message_folder = home_address + \
                                    '/.config/google-chrome/NativeMessagingHosts'

        elif browser == 'firefox':
            native_message_folder = home_address + \
                                    '/.mozilla/native-messaging-hosts'

        elif browser == 'vivaldi':
            native_message_folder = home_address + \
                                    '/.config/vivaldi/NativeMessagingHosts'

        elif browser == 'opera':
            native_message_folder = home_address + \
                                    '/.config/opera/NativeMessagingHosts'

    # for FreeBSD and OpenBSD
    elif os_type == 'FreeBSD' or os_type == 'OpenBSD':
        # find Persepolis execution path
        # persepolis execution path
        exec_path = os.path.join(config_folder, 'persepolis_run_shell')

        # Native Messaging Hosts folder path for every browser
        if browser == 'chromium':
            native_message_folder = home_address + '/.config/chromium/NativeMessagingHosts'

        elif browser == 'chrome':
            native_message_folder = home_address + \
                                    '/.config/google-chrome/NativeMessagingHosts'

        elif browser == 'firefox':
            native_message_folder = home_address + \
                                    '/.mozilla/native-messaging-hosts'
        elif browser == 'vivaldi':
            native_message_folder = home_address + \
                                    '/.config/vivaldi/NativeMessagingHosts'

        elif browser == 'opera':
            native_message_folder = home_address + \
                                    '/.config/opera/NativeMessagingHosts'

    # for Mac OSX
    elif os_type == 'Darwin':
        # find Persepolis execution path
        # persepolis execution path
        exec_path = os.path.join(config_folder, 'persepolis_run_shell')

        # Native Messaging Hosts folder path for every browser
        if browser == 'chromium':
            native_message_folder = home_address + \
                                    '/Library/Application Support/Chromium/NativeMessagingHosts'

        elif browser == 'chrome':
            native_message_folder = home_address + \
                                    '/Library/Application Support/Google/Chrome/NativeMessagingHosts'

        elif browser == 'firefox':
            native_message_folder = home_address + \
                                    '/Library/Application Support/Mozilla/NativeMessagingHosts'

        elif browser == 'vivaldi':
            native_message_folder = home_address + \
                                    '/Library/Application Support/Vivaldi/NativeMessagingHosts'

        elif browser == 'opera':
            native_message_folder = home_address + \
                                    '/Library/Application Support/Opera/NativeMessagingHosts/'

    # for MicroSoft Windows os (windows 7 , ...)
    elif os_type == 'Windows':
        # finding Persepolis execution path
        cwd = sys.argv[0]

        current_directory = os.path.dirname(cwd)

        exec_path = os.path.join(current_directory,
                                 'Persepolis Download Manager.exe')

        # the execution path in jason file for Windows must in form of
        # c:\\Users\\...\\Persepolis Download Manager.exe , so we need 2
        # "\" in address
        exec_path = exec_path.replace('\\', r'\\')

        if browser in ['chrome', 'chromium', 'opera', 'vivaldi']:
            native_message_folder = os.path.join(
                home_address, 'AppData\Local\persepolis_download_manager',
                'chrome')
        else:
            native_message_folder = os.path.join(
                home_address, 'AppData\Local\persepolis_download_manager',
                'firefox')

    # WebExtension native hosts file prototype
    webextension_json_connector = {
        "name":
        "com.persepolis.pdmchromewrapper",
        "type":
        "stdio",
        "path":
        str(exec_path),
        "description":
        "Integrate Persepolis with %s using WebExtensions" % (browser)
    }

    # Add chrom* keys
    if browser in ['chrome', 'chromium', 'opera', 'vivaldi']:
        webextension_json_connector["allowed_origins"] = [
            "chrome-extension://legimlagjjoghkoedakdjhocbeomojao/"
        ]

    # Add firefox keys
    elif browser == 'firefox':
        webextension_json_connector["allowed_extensions"] = [
            "*****@*****.**",
            "*****@*****.**"
        ]

    # Build final path
    native_message_file = os.path.join(native_message_folder,
                                       'com.persepolis.pdmchromewrapper.json')

    osCommands.makeDirs(native_message_folder)

    # Write NMH file
    f = open(native_message_file, 'w')
    f.write(str(webextension_json_connector).replace("'", "\""))
    f.close()

    if os_type != 'Windows':
        os.system('chmod +x \"' + str(native_message_file) + '\"')

    else:
        import winreg
        # add the key to the windows registry
        if browser in ['chrome', 'chromium', 'opera', 'vivaldi']:
            try:
                # create pdmchromewrapper key under NativeMessagingHosts
                winreg.CreateKey(
                    winreg.HKEY_CURRENT_USER,
                    "SOFTWARE\\Google\\Chrome\\NativeMessagingHosts\\com.persepolis.pdmchromewrapper"
                )
                # open a connection to pdmchromewrapper key
                gintKey = winreg.OpenKey(
                    winreg.HKEY_CURRENT_USER,
                    "SOFTWARE\\Google\\Chrome\\NativeMessagingHosts\\com.persepolis.pdmchromewrapper",
                    0, winreg.KEY_ALL_ACCESS)
                # set native_message_file as key value
                winreg.SetValueEx(gintKey, '', 0, winreg.REG_SZ,
                                  native_message_file)
                # close connection to pdmchromewrapper
                winreg.CloseKey(gintKey)
                return True
            except WindowsError:
                return False
        elif browser == 'firefox':
            try:
                # create pdmchromewrapper key under NativeMessagingHosts for firefox
                winreg.CreateKey(
                    winreg.HKEY_CURRENT_USER,
                    "SOFTWARE\\Mozilla\\NativeMessagingHosts\\com.persepolis.pdmchromewrapper"
                )
                # open a connection to pdmchromewrapper key for firefox
                fintKey = winreg.OpenKey(
                    winreg.HKEY_CURRENT_USER,
                    "SOFTWARE\\Mozilla\\NativeMessagingHosts\\com.persepolis.pdmchromewrapper",
                    0, winreg.KEY_ALL_ACCESS)
                # set native_message_file as key value
                winreg.SetValueEx(fintKey, '', 0, winreg.REG_SZ,
                                  native_message_file)
                # close connection to pdmchromewrapper
                winreg.CloseKey(fintKey)
                return True
            except WindowsError:
                return False

    # create persepolis_run_shell file for gnu/linux and BSD and Mac
    # firefox and chromium and ... call persepolis with Native Messaging system.
    # json file calls persepolis_run_shell file.
    if os_type == 'Linux' or os_type == 'OpenBSD' or os_type == 'FreeBSD' or os_type == 'Darwin':
        # find available shell
        shell_list = [
            '/bin/bash', '/usr/local/bin/bash', '/bin/sh', '/usr/local/bin/sh',
            '/bin/ksh', '/bin/tcsh'
        ]

        for shell in shell_list:
            if os.path.isfile(shell):
                # define shebang
                shebang = '#!' + shell
                break

        if os_type == 'Darwin':
            # finding Persepolis execution path
            cwd = sys.argv[0]

            current_directory = os.path.dirname(cwd)

            persepolis_path = os.path.join(current_directory,
                                           'Persepolis Download Manager')
        else:
            persepolis_path = 'persepolis'

        persepolis_run_shell_contents = shebang + '\n' + '"' + persepolis_path + '" "$@"'

        f = Open(exec_path, 'w')
        f.writelines(persepolis_run_shell_contents)
        f.close()

        # make persepolis_run_shell executable

        os.system('chmod +x \"' + exec_path + '\"')
Exemplo n.º 5
0
    def okButtonPressed(self, button):
        if self.proxy_checkBox.isChecked() == False:
            ip = None
            port = None
            proxy_user = None
            proxy_passwd = None
        else:
            ip = self.ip_lineEdit.text()
            if not (ip):
                ip = None
            port = str(self.port_spinBox.value())
            if not (port):
                port = None
            proxy_user = self.proxy_user_lineEdit.text()
            if not (proxy_user):
                proxy_user = None
            proxy_passwd = self.proxy_pass_lineEdit.text()
            if not (proxy_passwd):
                proxy_passwd = None

        if self.download_checkBox.isChecked() == False:
            download_user = None
            download_passwd = None
        else:
            download_user = self.download_user_lineEdit.text()
            if not (download_user):
                download_user = None
            download_passwd = self.download_pass_lineEdit.text()
            if not (download_passwd):
                download_passwd = None

        if self.limit_checkBox.isChecked() == False:
            limit = 0
        else:
            if self.limit_comboBox.currentText() == "KB/S":
                limit = str(self.limit_spinBox.value()) + str("K")
            else:
                limit = str(self.limit_spinBox.value()) + str("M")

        if self.start_checkBox.isChecked() == False:
            start_hour = None
            start_minute = None
        else:
            start_hour = str(self.start_hour_spinBox.value())
            start_minute = str(self.start_minute_spinBox.value())

        if self.end_checkBox.isChecked() == False:
            end_hour = None
            end_minute = None
        else:
            end_hour = str(self.end_hour_spinBox.value())
            end_minute = str(self.end_minute_spinBox.value())

        link = self.link_lineEdit.text()
        connections = self.connections_spinBox.value()
        download_path = self.download_folder_lineEdit.text()

        self.add_link_dictionary['start_hour'] = start_hour
        self.add_link_dictionary['start_minute'] = start_minute
        self.add_link_dictionary['end_hour'] = end_hour
        self.add_link_dictionary['end_minute'] = end_minute
        self.add_link_dictionary['link'] = link
        self.add_link_dictionary['ip'] = ip
        self.add_link_dictionary['port'] = port
        self.add_link_dictionary['proxy_user'] = proxy_user
        self.add_link_dictionary['proxy_passwd'] = proxy_passwd
        self.add_link_dictionary['download_user'] = download_user
        self.add_link_dictionary['download_passwd'] = download_passwd
        self.add_link_dictionary['download_path'] = download_path
        self.add_link_dictionary['limit'] = limit
        self.add_link_dictionary['connections'] = connections

        new_category = str(self.add_queue_comboBox.currentText())
        if new_category != self.current_category:  # it means category changed
            # first download must eliminated form former category
            # reading current_category
            current_category_file = os.path.join(category_folder,
                                                 self.current_category)

            f = Open(current_category_file)
            f_list = f.readlines()
            f.close()
            # eliminating gid of download from current_category_file
            f = Open(current_category_file, 'w')
            for line in f_list:
                gid = line.strip()
                if gid != self.gid:
                    f.writelines(gid + '\n')

            f.close()

            # adding download to the new category
            new_category_file = os.path.join(category_folder,
                                             str(new_category))

            f = Open(new_category_file, 'a')
            f.writelines(self.gid + '\n')
            f.close()

        self.callback(self.add_link_dictionary, self.gid, new_category)

        self.close()
Exemplo n.º 6
0
def compatibility():
    if os.path.isdir(download_info_folder) == True:
        f = Open(download_list_file)
        download_list_file_lines = f.readlines()
        f.close()

        for line in download_list_file_lines:
            gid = line.strip()
            download_info_file = download_info_folder + "/" + gid
            f_download_info_file = Open(download_info_file)
            download_info_file_lines = f_download_info_file.readlines()
            f_download_info_file.close()
            if len(download_info_file_lines) == 10:
                list = []
                for i in range(10):
                    line_strip = download_info_file_lines[i].strip()
                    if i == 9:
                        line_strip = ast.literal_eval(line_strip)
                    list.append(line_strip)
                dictionary = {'list': list}
                os.system('echo "' + str(dictionary) + '"  >  "' +
                          str(download_info_file) + '"')
                f_download_info_file = Open(download_info_file, 'w')
                f_download_info_file.writelines(str(dictionary))
                f_download_info_file.close()

# compatibility between version 2.2 and version 2.3
        date_list = []
        for i in ['%Y', '%m', '%d', '%H', '%M', '%S']:
            date_list.append(time.strftime(i))

        for line in download_list_file_lines:
            gid = line.strip()
            download_info_file = download_info_folder + "/" + gid
            f = Open(download_info_file, 'r')
            f_string = f.readline()
            f.close()
            dictionary = ast.literal_eval(f_string.strip())
            list = dictionary['list']

            if len(list) == 10:
                add_link_dictionary = list[9]
                add_link_dictionary['firs_try_date'] = date_list
                add_link_dictionary['last_try_date'] = date_list

                list[9] = add_link_dictionary

                try_date = str(date_list[0]) + '/' + str(
                    date_list[1]) + '/' + str(date_list[2]) + ' , ' + str(
                        date_list[3]) + ':' + str(date_list[4]) + ':' + str(
                            date_list[5])

                list.append(try_date)
                list.append(try_date)
                list.append('Single Downloads')

                dictionary = {'list': list}
                f = Open(download_info_file, 'w')
                f.writelines(str(dictionary))
                f.close()

                print(str(dictionary))
                f = Open(download_list_file)
                f_lines = f.readlines()
                f.close()

                f = Open(single_downloads_list_file, 'w')
                for line in f_lines:
                    f.writelines(line)

                f.close()
            elif len(list) == 12:
                list.append('Single Downloads')
                dictionary = {'list': list}
                f = Open(download_info_file, 'w')
                f.writelines(str(dictionary))
                f.close()

                f = Open(download_list_file)
                f_lines = f.readlines()
                f.close()

                f = Open(single_downloads_list_file, 'w')
                for line in f_lines:
                    gid = line.strip()
                    f.writelines(gid + '\n')

                f.close()