elfmz / far2l

Linux port of FAR v2
GNU General Public License v2.0
1.79k stars 174 forks source link

sftp/scp support [gvfs,sshfs backends: separate projects; internal backend: see #247] #86

Closed unxed closed 7 years ago

unxed commented 8 years ago

native sftp/scp support (without using sshfs or something like it) would be nice https://github.com/michaellukashov/Far-NetBox/

unxed commented 8 years ago

and thank you all guys for the work you are doing!

invy commented 8 years ago

We've had a discussion in the #14 about netbox. It's questionable, whether it's needed in linux. I think the better solution is to use fuse, how it's done in linux file manager, because linux can mount almost everything and far only need to utilize this capabilities.

unxed commented 8 years ago

What about implementing native far plugin as a helper for establishing ssh connection and mounting remote fs via fuse, while entering and storing ssh credentials inside Far as it is done on windows? Commonly used linux FMs also behave like this.

upd: ssh credentials may be stored inside system wallet if possible.

upd 2: linux can mount ftp via fuse also, but I see ftp plugin ported ;)

invy commented 8 years ago

Yep, in my opinion it's how this should work. Kinda sophisticated mount point manager.

BTW use key based authentication for ssh

unxed commented 8 years ago

Kinda sophisticated mount point manager.

Agree, it would be great.

btw, mount point manager inside far itself - sounds like a miracle :)

BTW use key based authentication for ssh

not worth time for temporary experimental VMs :)

unxed commented 8 years ago

Kinda sophisticated mount point manager.

quoting discussion with one of far manager windows fans:

ведь вот ничего ж сложного совместить вывод всех видимых разделов всех видимых носителей на панельку с автоопределением файловой системы и монтрованием (с автосозданием точки монтирования с именем по метке или серийному номеру раздела) куда-нибудь в /media одним нажатием энтера

invy commented 8 years ago

It's not difficult, but it needs to be implemented, so everybody who has time are welcome to try.

unxed commented 8 years ago

Not sure if I have enough skills to do it. My last c/cpp expirience was years ago. May try to look into the code next week if I have some luck :)

invy commented 8 years ago

It's not that I'm somehow suggesting, that you should do it. I was addressing everybody, who read this issues. I think, good contribution would be for example to investigate which c++ libraries could be utilized for this task and how it's done by nautilus,pcmanfm, dolphin and other file managers.

elfmz commented 8 years ago

There're some limitations of mount: 1) it requires root access to mount something that is not of fstab 2) FS caching prevents using it for 'real-time' file-exchange So netbox is still on the shelf. Lieff disabled most of the unprotable code frpom it and the biggest problem now that it uses Windows-specific async sockets API that needs to be stupidly re-written with select or poll. Or may be cover that API in WinPort..

invy commented 8 years ago

Fuse does not require root priveleges. And it's not a problem to use gksu, or similar mechanism.

invy commented 8 years ago

@volth exactly. This also good point why it makes no sense porting old far plugins and then supporting them.

unxed commented 8 years ago

caja does that somehow without asking for root password. mounts to something like /run/user/1000/gvfs/sftp:host=SERVERNAME,user=SERVERUSER mount says it is gvfsd-fuse on /run/user/1000/gvfs type fuse.gvfsd-fuse (rw,nosuid,nodev,relatime,user_id=1000,group_id=1000)

it's almost comfortably usable with far then, but that I want is establishing connections from far itself :)

unxed commented 8 years ago

looks like caja uses this API for mounting: https://www.freedesktop.org/software/gstreamer-sdk/data/docs/latest/gio/GMountOperation.html

see https://github.com/mate-desktop/caja/blob/master/src/caja-connect-server-operation.c for details

upd: as caja also allows to connect to webdav and windows shares, using this api may solve that issues too.

upd2: possible limitation: not sure if that API supports key based auth.

unxed commented 8 years ago

another issue is the possibility to execute commands remotely (that would be ideal). afaik netbox does that by executing separate putty session. not sure about best solution if implementing sftp panel via mount.

unxed commented 8 years ago

That about implementing GMountOperation shim as a separate plugin as temporary scaffold while proper implementation is discussed? There are still many cases then you even can not choose key based auth but still need sftp access (accessing shared hosting via public wifi, for example). This may be a fastest way to implement windows shares access also.

unxed commented 8 years ago

https://developer.gnome.org/gio/stable/GMountOperation.html

invy commented 8 years ago

I wonder whether there is DE agnostic lib for this.

unxed commented 8 years ago

Had a brief look into the Dolphin's code. It uses KDE's KIO: https://api.kde.org/frameworks/kio/html/classKProtocolManager.html (see https://quickgit.kde.org/?p=dolphin.git&a=blob&h=116168a4b121d33d21c8f753bd18fda77e475c9a&hb=ca53974181c17234f4522bd1635d4c0ab4281e1d&f=src%2Fviews%2Fdolphinremoteencoding.cpp for details).

btw, GMountOperation neither depends on GNOME nor MATE. AFAIK, the only required dependency is GLib.

There is a third-party tool for managing remote fs mounts, called Gigolo, and it also uses gvfs: http://www.uvena.de/gigolo/index.html Guess if there were better choise, authors would have used it instead for sure.

unxed commented 8 years ago

As of XFCE, the most popular answer on "how to do it" also references gvfs: http://askubuntu.com/questions/70423/how-do-i-connect-to-a-server-with-thunar-in-xubuntu

The second answer suggests to use gigolo tool mentioned above (which uses gvfs also).

Looks like it is the most popular/portable choise.

invy commented 8 years ago

Hm, well. Then next thing is to make some kind of proof of concept with gvfs. :)

unxed commented 8 years ago

upd: gvfs is ok for key-based auth. see this thread: https://ubuntuforums.org/showthread.php?t=1443983

unxed commented 8 years ago

gvfs also provides command-line mount tool. Maybe it can be used for proof-of-concept implementation: http://manpages.ubuntu.com/manpages/trusty/man1/gvfs-mount.1.html usage example: gvfs-mount sftp://user@server It will ask for password if needed. If there is a problem sending a password to it via stdin, there are serveral possible solutions available: http://stackoverflow.com/questions/7005876/gvfs-mount-specify-username-password

Remaining task is to store connection info and user credentials, but farftp already implements it (using system wallet may be left to be a future improvement).

unxed commented 8 years ago

btw, is it hard to port something like this: https://github.com/trexinc/evil-programmers/tree/master/pygin

Pygin Very basic adapter to write Far Manager plugins in Python 3.

?

if there were any scripting language adapter for far, I could try to implement this by myself :)

invy commented 8 years ago

The difficult thing is to know FAR plugin API and how to use it, since I've never developed plugins for FAR :) I suppose it's fairly easy to create panel, put link to the panel into drive menu and fill panel with some custom entries (for mount points). And make some dialog which would allow to create/edit this entries. And add action, which causes gvfs to mount the specified mount point.

This looks pretty straight forward (actually another plugin, which should be easy to implement in linux with modern c++): https://github.com/svn2github/farmanager/blob/master/plugins/proclist/Proclist.cpp

    if (Opt.AddToDisksMenu)
    {
        static const wchar_t *DiskMenuStrings[1];
        DiskMenuStrings[0]=GetMsg(MPlistPanel);
        Info->DiskMenu.Guids=&MenuGuid;
        Info->DiskMenu.Strings=DiskMenuStrings;
        Info->DiskMenu.Count=ARRAYSIZE(DiskMenuStrings);
    }

Adds panel to disk menu.

And (I suppose) relevane callbacks for panel:

intptr_t WINAPI GetFilesW(struct GetFilesInfo *Info)
{
    return ((Plist *)Info->hPanel)->GetFiles(Info->PanelItem,(int)Info->ItemsNumber,Info->Move,&Info->DestPath,Info->OpMode);
}
intptr_t WINAPI ProcessPanelEventW(const struct ProcessPanelEventInfo *Info)
{
    return ((Plist *)Info->hPanel)->ProcessEvent(Info->Event,Info->Param);
}

intptr_t WINAPI ProcessPanelInputW(const struct ProcessPanelInputInfo *Info)
{
    return ((Plist *)Info->hPanel)->ProcessKey(&Info->Rec);
}
unxed commented 8 years ago

Not sure if remote fs should be placed inside drive menu. The way I see it is a farftp-like plugin which displays on a panel a list of saved connections, and a) if connected - changes panel's path to mount point b) if not connected - executes gvfs-mount and goto a)

This may be implemented via modifying farftp by removing all ftp protocol releated stuff and adding very little bit of new code.

2-3 extra keystrokes to reach target place are not a problem for proof-of-concept implementation :)

invy commented 8 years ago

This may be implemented via modifying farftp by removing all ftp protocol releated stuff and adding very little bit of new code.

It's MUCH easier to implement this from scratch, then to dig through old poorly written code ;)

unxed commented 8 years ago

This concept is still easier to implement as there is no need to touch drive menu except for adding one entry for plugin itself :)

unxed commented 8 years ago

Implementing this as a simpliest plugin example can be good starting point for newbie linux plugin authors.

invy commented 8 years ago

Well, drive menu already contains link to /run/usr/1000, this is where gvfs puts it's mount points.

unxed commented 8 years ago

Well, drive menu already contains link to /run/usr/1000, this is where far puts it's mount points.

Already using it with gvfs, remaining part is to handle mounts.

Currently using user menu to call gvfs-mount, will appreciate a better solution if possible :) Used menu commands are:

gvfs-mount sftp://USER@HOST
cd /run/user/1000/gvfs/sftp:host=HOST,user=USER

for mount and

gvfs-mount -u sftp
cd ~

for unmount.

Maybe this may be helpfull for someone until some plugin implementation is ready.

A little problem is that I can not paste a password into gvfs-mount running from Far. See #98.

invy commented 8 years ago

Far has terrible plugin api. It took me 2 hours to create an empty panel, that doesn't crash.

unxed commented 8 years ago

Far has terrible plugin api. It took me 2 hours to create an empty panel, that doesn't crash.

Can you please share your attempts as some demo for newbies?)

invy commented 8 years ago

There is nothing to share at the moment since I haven't done anything since last my post.

unxed commented 8 years ago

I mean that "empty panel plugin" effort.

invy commented 8 years ago

definitely not today :)

unxed commented 8 years ago

another way to implement this: wrap around sftp command calls

so if system sftp client is up to date, cipher suites and protocol versions far is using are sill up to date too.

serious bonus from this effort is the possibility to specify remote sftp command (for running remote sftp server under sudo to enable remote config files edition in far, for example). remote command execution can be achieved using wrappers around ssh user@server 'cd workingdir | command'

curl can also be used for that, but, unfortunately, it is build without sftp support for debian/ubntu systems.

invy commented 8 years ago

Here is the draft, if you are interested. but it's really draft, which can't do anything. But it's a try to use terrible api in a modern way. https://github.com/invy/far2l/tree/gvfs (gvfspanel)

invy commented 8 years ago

I was trying today to mount smb by using gvfs. The problem I have is how to find mount point on the filesystem, where gvfs mounts fs. The code (which I ripped from gvfs) appears to mount fs, but I can't find where...

invy commented 8 years ago

So, here is minor small 'breakthrough' (ac7ff3c206f79855f9bbbfe89779bb08aca3422c) . My gvfs plugin now supports mounting of resources which allow anonymous access (i.e. smb shares with anonymous access).

Some implementation of course is needed to allow user interaction for entering passwords etc.

unxed commented 8 years ago

i see gvfs mounts in /run/user/1000/gvfs/sftp:host=SERVERNAME,user=USERNAME/

btw, I am not so familar with git... what should I type to switch local repo to another branch and get updated files?

invy commented 8 years ago

If you give full path to samba share, it puts mount point correctly in there. If you specify only server without a share, no mount points are created somehow (RTFM awaits me...)

To get gvfs, pull from my repo and switch branch with "git checkout gvfs"

But it's not ready and doesn't work with GCC correctly at the moment.

unxed commented 8 years ago

got sources, thanks. so how to build them using clang/llvm?

invy commented 8 years ago

The same way you build far, however you should add command line options to the cmake -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_COMPILER=clang

It builds also with GCC, but dialog is messed up somehow, I'll look into it.

Also at the moment you need libgtkmm-2.4-dev. but eventually I'll get rid of it.

unxed commented 8 years ago

installed libgtkmm-2.4-dev package. still getting

/home/unxed/far2l-gvfs/far2l/gvfspanel/src/GvfsService.h:2:19: fatal error: gtkmm.h: Нет такого файла или каталога                                                    
compilation terminated.                                                            
unxed commented 8 years ago

found gtkmm.h in /usr/include/gtkmm-2.4/gtkmm.h

but how to add this path to build?

invy commented 8 years ago

It should be added by cmake automatically. What does cmake says?

PS: later today I'll eventually get rid of it anyway.

unxed commented 8 years ago

it was wrong cmake command I wrote, thanks

elfmz commented 8 years ago

If you specify only server without a share, no mount points are created somehow (RTFM awaits me...)

AFAIK its impossible to 'mount SMB server'. There should be separate API to list shares, but that's not related to mounting.

invy commented 8 years ago

Then it should at least fail with reasonable error. It looks like bug in gio to me.