コード例 #1
0
    def store_keys(self, event):
        try:
            if event.GetDirection():
                if self._entry_repeat_passphrase.IsShown(
                ) and self.passphrase != self.repeat_passphrase:
                    gui_utils.show_error_dialog(
                        message=_('Passphrases are not equal'),
                        title=_('Error'))
                    event.Veto()
                    return

                # going forward
                if gui_utils.is_valid_input(self.passphrase):
                    getLogger(__name__).debug("storing keys")

                    if not LoginController().store_keys(
                            localbox_client=self.parent.localbox_client,
                            pubkey=self.pubkey,
                            privkey=self.privkey,
                            passphrase=self.passphrase):
                        gui_utils.show_error_dialog(
                            message=_('Wrong passphase'), title=_('Error'))
                        event.Veto()
                        return

                    sync_item = self._add_new_sync_item()
                    create_watchdog(sync_item)
                else:
                    event.Veto()
        except Exception as err:
            getLogger(__name__).exception('Error storing keys %s' % err)
コード例 #2
0
ファイル: taskbar.py プロジェクト: eiwuert/LinWin-PySync
 def do_GET(self):
     getLogger(__name__).debug('Got passphrase request for path=%s' %
                               self.path)
     self.send_response(200)
     self.send_header('Content-type', 'text/plain')
     self.end_headers()
     # Send the html message
     passphrase = LoginController().get_passphrase(self.get_label())
     self.wfile.write(passphrase)
     return
コード例 #3
0
    def on_moved(self, event):
        """

        WARNING:    This is feature is not supported on Windows:
                    https://github.com/gorakhargosh/watchdog/issues/393
        :param event:
        :return:
        """
        super(LocalBoxEventHandler, self).on_moved(event)

        passphrase = LoginController().get_passphrase(
            self.localbox_client.label)

        if event.is_directory:
            key, iv = self.localbox_client.create_directory(
                get_localbox_path(self.localbox_client.path, event.dest_path))

            for root, dirs, files in os.walk(event.dest_path):
                for name in dirs:
                    localbox_path = get_localbox_path(
                        self.localbox_client.path, os.path.join(root, name))
                    self.localbox_client.create_directory(localbox_path)
                for name in files:
                    self.localbox_client.move_file(event.src_path,
                                                   os.path.join(root, name),
                                                   passphrase)

            self.localbox_client.delete(
                get_localbox_path(self.localbox_client.path, event.src_path))
        elif event.src_path.endswith(defaults.LOCALBOX_EXTENSION):
            self.localbox_client.move_file(event.src_path, event.dest_path,
                                           passphrase)
        else:
            self.localbox_client.upload_file(
                fs_path=event.dest_path,
                path=get_localbox_path(self.localbox_client.path,
                                       event.dest_path),
                passphrase=LoginController().get_passphrase(
                    self.localbox_client.label))
コード例 #4
0
    def _add_encryption_keys(self, localbox_path, user_list):
        if localbox_path.startswith('/'):
            localbox_path = localbox_path[1:]
        key, iv = self.call_keys(localbox_path,
                                 LoginController().get_passphrase(self.label))

        # import public key in the user_list
        for user in user_list:
            public_key = user['public_key']
            username = user['username']

            gpg().add_public_key(self.label, username, public_key)
            self.save_key(username, localbox_path, key, iv)
コード例 #5
0
    def test_store_keys(self):
        from sync.localbox import LocalBox
        from sync.controllers.login_ctrl import LoginController
        from sync.auth import Authenticator
        lox_client = LocalBox(url='https://localhost:5001', label=None)
        authenticator = Authenticator(
            authentication_url=
            'http://localhost:5000/loauth/?redirect_uri=http%3A%2F%2Flocalhost%3A5001%2F',
            label=None)
        authenticator.init_authenticate('loxtest', 'p123')
        lox_client._authenticator = authenticator

        result = LoginController().store_keys(lox_client, None, None, 'p123')
コード例 #6
0
    def on_modified(self, event):
        super(LocalBoxEventHandler, self).on_modified(event)

        if _should_modify_file(event.src_path):
            self.localbox_client.upload_file(
                fs_path=event.src_path,
                path=get_localbox_path(self.localbox_client.path,
                                       event.src_path),
                passphrase=LoginController().get_passphrase(
                    self.localbox_client.label),
                remove=False)
        else:
            getLogger(__name__).debug('on_modified ignored: %s' %
                                      event.src_path)
コード例 #7
0
    def on_created(self, event):
        super(LocalBoxEventHandler, self).on_created(event)

        if event.is_directory:
            self.localbox_client.create_directory(
                get_localbox_path(self.localbox_client.path, event.src_path))
        elif _should_upload_file(event.src_path):
            self.localbox_client.upload_file(
                fs_path=event.src_path,
                path=get_localbox_path(self.localbox_client.path,
                                       event.src_path),
                passphrase=LoginController().get_passphrase(
                    self.localbox_client.label))
        else:
            getLogger(__name__).debug('on_created ignored: %s' %
                                      event.src_path)
コード例 #8
0
 def OnClickOk(self, event):
     if event.Id == self._btn_ok.Id:
         try:
             LoginController().store_passphrase(
                 passphrase=self._passphrase.Value,
                 user=self._username,
                 label=self._label)
             self.parent.Destroy()
         except InvalidPassphraseError:
             gui_utils.show_error_dialog(message=_('Wrong passphase'),
                                         title=_('Error'))
         except Exception as err:
             getLogger(__name__).exception(err)
             gui_utils.show_error_dialog(message=_(
                 'Could not authenticate. Please contact the administrator'
             ),
                                         title=_('Error'))
コード例 #9
0
    def __init__(self, parent):
        super(FirstLoginPanel, self).__init__(parent)

        # Attributes
        self.parent = parent
        self._ctrl = LoginController()
        self.login_panel = LoginPanel(self)
        self.main_sizer = wx.BoxSizer(wx.VERTICAL)

        self.welcome_sizer = wx.BoxSizer(wx.VERTICAL)
        self.welcome_sizer.Add(wx.StaticText(self, label=_("WELCOME")), 0,
                               wx.ALL | wx.ALIGN_CENTER)

        self.main_sizer.Add(self.welcome_sizer, 0, wx.ALL | wx.EXPAND)
        self.main_sizer.Add(self.login_panel, 0, wx.ALL | wx.EXPAND)

        self.SetSizer(self.main_sizer)
コード例 #10
0
    def store_keys(self, event):
        try:
            if event.GetDirection():
                # going forward
                if gui_utils.is_valid_input(self.passphrase):
                    getLogger(__name__).debug("storing keys")

                    if not LoginController().store_keys(
                            localbox_client=self.parent.localbox_client,
                            pubkey=self.parent.pubkey,
                            privkey=self.parent.privkey,
                            passphrase=self.passphrase):
                        gui_utils.show_error_dialog(
                            message=_('Wrong passphase'), title=_('Error'))
                        event.Veto()
                        return

                    self.add_new_sync_item()
                else:
                    event.Veto()
        except Exception as err:
            getLogger(__name__).exception('Error storing keys %s' % err)
コード例 #11
0
    def OnClickOk(self, event):
        path = self._selected_dir.GetValue()
        lox_label = self.choice.GetString(self.choice.GetSelection())

        if gui_utils.is_valid_input(
                path) and self.list.GetSelectedItemCount() > 0:
            user_list = self.list.get_users()
            share_path = path.replace(self.localbox_path, '', 1)

            if self.localbox_client.create_share(
                    localbox_path=share_path,
                    passphrase=LoginController().get_passphrase(
                        self.localbox_client.label),
                    user_list=user_list):
                item = ShareItem(user=self.localbox_client.username,
                                 path=share_path,
                                 url=self.localbox_client.url,
                                 label=lox_label)
                SharesController().add(item)
                self.parent.ctrl.populate(SharesController().get_list())
            else:
                gui_utils.show_error_dialog(
                    _('Server error creating the share'), _('Error'))
            self.parent.Destroy()
コード例 #12
0
ファイル: open_file.py プロジェクト: penguin-formula/Localbox
def open_file(data_dic, memory=False):
    # Get passphrase
    passphrase = LoginController().get_passphrase(data_dic["label"])

    if not passphrase:
        passphrase = gui_utils.get_user_secret_input(
            "YourLocalBox - Enter Passphrase",
            "Please provide the passphrase to unlock file.")

    if not passphrase:
        gui_utils.show_error_dialog(_('No passphrase provided. aborting'),
                                    'Error',
                                    standalone=True)
        return None

    # Stat local box instance
    localbox_client = LocalBox(data_dic["url"], data_dic["label"], "")

    # Attempt to decode the file

    # print data_dic, passphrase

    try:
        decoded_contents = localbox_client.decode_file(
            data_dic["localbox_filename"], data_dic["filename"], passphrase)

    # If there was a failure, answer wit ha 404 to state that the file doesn't exist
    except Exception as e:
        gui_utils.show_error_dialog(
            _('Failed to decode contents. aborting : {}').format(e),
            'Error',
            standalone=True)
        getLogger(__name__).info(
            'failed to decode contents. aborting : {}'.format(e))

        return None

    # If the file was decoded, write it to disk
    tmp_decoded_filename = \
        os_utils.remove_extension(data_dic["filename"],
                                  defaults.LOCALBOX_EXTENSION)

    getLogger(__name__).info('tmp_decoded_filename: %s' % tmp_decoded_filename)

    if os.path.exists(tmp_decoded_filename):
        os.remove(tmp_decoded_filename)

    if not memory:
        memory = LocalBoxMemoryFS()

    if not memory:
        localfile = open(tmp_decoded_filename, 'wb')
        localfile.write(decoded_contents)
        localfile.close()
    else:
        tmp_decoded_filename = memory.createfile(
            tmp_decoded_filename.split('/')[-1], decoded_contents)

    # Keep file in list of opened files
    openfiles_ctrl.add(tmp_decoded_filename)

    return tmp_decoded_filename
コード例 #13
0
ファイル: syncer.py プロジェクト: eiwuert/LinWin-PySync
    def syncsync(self):
        label = self.localbox.authenticator.label
        getLogger(__name__).info("Starting syncsync")

        # get passphrase
        getLogger(__name__).debug('waiting for passphrase, label=%s' % label)
        passphrase = LoginController().get_passphrase(label)
        while not passphrase:
            self._should_stop_sync()
            sleep(1)
            passphrase = LoginController().get_passphrase(label)

        getLogger(__name__).debug('got passphrase for label=%s' % label)

        self.localbox_metadata = None
        self.filepath_metadata = None
        self.populate_localbox_metadata(path='/', parent=None)
        self.populate_filepath_metadata(path='/', parent=None)

        full_tree = MetaVFS('0', '/', True, None)
        full_tree.add_paths(self.localbox_metadata)
        full_tree.add_paths(self.filepath_metadata)

        try:
            oldmetadata = self.filepath_metadata.load(OLD_SYNC_STATUS +
                                                      self.name)
            full_tree.add_paths(oldmetadata)
        except (IOError, AttributeError) as error:
            getLogger(__name__).info(str(error) + " Using empty tree instead")
            oldmetadata = MetaVFS(path='/', modified_at=0)

        for metavfs in full_tree.gen():
            self._should_stop_sync()

            try:
                path = metavfs.path

                oldfile = oldmetadata.get_entry(path)
                localfile = self.filepath_metadata.get_entry(path)
                remotefile = self.localbox_metadata.get_entry(path)
                getLogger(__name__).debug(
                    "====Local %s, Remote %s, Old %s ====", localfile,
                    remotefile, oldfile)

                # hammer time :(
                # to fixed directory deletion issue
                if localfile is None and oldfile is not None and remotefile is not None:
                    oldfile.modified_at = remotefile.modified_at

                # if remotefile == oldfile and self.get_file_path(metavfs)is None:
                if remotefile == oldfile and localfile is None:
                    getLogger(__name__).info("Deleting remote %s", path)
                    self.localbox.delete(metavfs)
                    continue
                # if localfile == oldfile and self.get_url_path(metavfs) is None:
                if localfile == oldfile and remotefile is None:
                    getLogger(__name__).info("Deleting local %s", path)
                    self.delete(metavfs)
                    continue

                newest = MetaVFS.newest(oldfile, localfile, remotefile)

                if newest == oldfile and newest is not None:
                    getLogger(__name__).info(
                        "Skipping %s because all files are older then the previous file",
                        newest.path)
                    continue

                newest = MetaVFS.newest(localfile, remotefile)

                localpath = self.get_file_path(metavfs)
                if newest == localfile and os.path.exists(localpath):
                    if not isdir(self.get_file_path(metavfs)):
                        getLogger(__name__).info('Starting upload %s:  %s',
                                                 path, localpath)
                        self.localbox.upload_file(path, localpath, passphrase)
                    elif path != '/' and path not in self.localbox_metadata.get_paths(
                    ):
                        self.localbox.create_directory(path)
                    continue
                if newest == remotefile:
                    getLogger(__name__).info("%s is_dir: %s", metavfs.path,
                                             metavfs.is_dir)
                    if not metavfs.is_dir:
                        getLogger(__name__).info("Downloading %s", newest.path)
                        self.download(path)
                    else:
                        if not isdir(self.get_file_path(metavfs)):
                            self.mkdir(metavfs)

                    continue
            except Exception as error:
                getLogger(__name__).exception(
                    "Problem '%s' with file %s; continuing", error,
                    metavfs.path)
        self.populate_filepath_metadata(path='./', parent=None)
        self.filepath_metadata.save(OLD_SYNC_STATUS + self.name)
コード例 #14
0
import logging

from sync.controllers.login_ctrl import LoginController
from sync.localbox import LocalBox
from sync.syncer import Syncer

logging.getLogger('sync').setLevel(logging.WARNING)

url = 'https://box.yourlocalbox.org'
path = '/home/wilson/git-new/LinWin-PySync/lo-wilson-new/'
direction = 'potatoes'
label = 'lo-wilson'
localbox_client = LocalBox(url, label)

syncer = Syncer(localbox_client, path, direction, name=label)
LoginController().store_passphrase(passphrase='p123',
                                   label=label,
                                   user='******')

syncer.syncsync()
コード例 #15
0
def run_file_decryption(filename):
    try:
        getLogger(__name__).info('Decrypting and opening file: %s', filename)

        # verify if the file belongs to any of the configured syncs
        sync_list = sync_ctrl.list

        localbox_client = None
        localbox_filename = None
        for sync_item in sync_list:
            getLogger(__name__).debug('sync path: %s' % sync_item.path)
            sync_path = sync_item.path if sync_item.path.endswith(
                '/') else sync_item.path + os.path.sep
            if filename.startswith(sync_path):
                localbox_filename = os_utils.remove_extension(
                    filename.replace(sync_item.path, ''),
                    defaults.LOCALBOX_EXTENSION)
                localbox_client = LocalBox(sync_item.url, sync_item.label)
                break

        if not localbox_client or not localbox_filename:
            gui_utils.show_error_dialog(
                _('%s does not belong to any configured localbox') % filename,
                'Error', True)
            getLogger(__name__).error(
                '%s does not belong to any configured localbox' % filename)
            exit(1)

        # get passphrase
        label = localbox_client.authenticator.label
        passphrase = LoginController().get_passphrase(label, remote=True)
        if not passphrase:
            gui_wx.ask_passphrase(localbox_client.username, label)
            passphrase = LoginController().get_passphrase(label, remote=False)
            if not passphrase:
                gui_utils.show_error_dialog(
                    _('Failed to get passphrase for label: %s.') % label,
                    'Error', True)
                getLogger(__name__).error(
                    'failed to get passphrase for label: %s. Exiting..' %
                    label)
                exit(1)

        # decode file
        try:
            decoded_contents = localbox_client.decode_file(
                localbox_filename, filename, passphrase)
        except URLError:
            gui_utils.show_error_dialog(_('Failed to decode contents'),
                                        'Error',
                                        standalone=True)
            getLogger(__name__).info('failed to decode contents. aborting')
            return 1

        # write file
        tmp_decoded_filename = os_utils.remove_extension(
            filename, defaults.LOCALBOX_EXTENSION)
        getLogger(__name__).info('tmp_decoded_filename: %s' %
                                 tmp_decoded_filename)

        if os.path.exists(tmp_decoded_filename):
            os.remove(tmp_decoded_filename)

        localfile = open(tmp_decoded_filename, 'wb')
        localfile.write(decoded_contents)
        localfile.close()

        # open file
        open_file_ext(tmp_decoded_filename)

        openfiles_ctrl.add(tmp_decoded_filename)

        getLogger(__name__).info('Finished decrypting and opening file: %s',
                                 filename)

    except Exception as ex:
        getLogger(__name__).exception(ex)