📜 ⬆️ ⬇️

Web file manager Sprut.IO in OpenSource

In Beg, we have long and successfully engaged in virtual hosting, we use a lot of OpenSource solutions, and now it is time to share our development with the community: the file manager Sprut.IO , which we developed for our users and which is used in our control panel. We invite everyone to join its development. How it was developed and why we were not satisfied with the existing analogues, what crutches of technology we used and to whom it can be useful, we will tell in this article.

Project website: https://sprut.io
The demo is available at the link: https://demo.sprut.io:9443
Source code: https://github.com/LTD-Beget/sprutio



Why reinvent your file manager


In 2010, we used NetFTP, which quite tolerably solved the tasks of opening / loading / correcting several files.
However, users sometimes wanted to learn how to transfer sites between hosting or between accounts between us, but the site was large, and the Internet was not the best for users. In the end, we either did it ourselves (which was obviously faster), or explained what SSH, MC, SCP and other terrible things are.
')
Then we had the idea to make a WEB two-panel file manager that works on the server side and can copy between different sources at the speed of the server, and which will include: searching through files and directories, analyzing the occupied space (analogue to ncdu), simple file upload, well, a lot of interesting things. In general, everything that would make life easier for our users and us.

In May 2013, we put it in production on our hosting. In some moments it turned out even better than we originally wanted - to download files and access the local file system, they wrote a Java applet that allows you to select files and copy everything to hosting or vice versa from hosting (where copying is not so important, he knew how to work with remote FTP and the user's home directory, but unfortunately, browsers will not support it soon).

Having read about analogue on Habré , we decided to put our product in OpenSource, which turned out to be, as it seems to us, excellent working and can be useful. It took another nine months to separate it from our infrastructure and bring it to the proper form. Before the new year 2016, we released Sprut.IO.

How does he work


We made for ourselves and used the most, in our opinion, new, stylish, youth tools and technologies. Often used what was already done for something.
There is some difference in the implementation of Sprut.IO and the version for our hosting, due to the interaction with our panel. For ourselves, we use: full-fledged queues, MySQL, an additional authorization server, which is also responsible for selecting the destination server on which the client is located, transport between our servers over the internal network, and so on.

Sprut.IO consists of several logical components:
1) web-muzzle
2) nginx + tornado, accepting all calls from the web,
3) final agents that can be hosted on one or on many servers.

In fact, by adding a separate layer with authorization and server selection, you can make a multi-server file manager (as in our implementation). All elements can be divided into two parts: Frontend (ExtJS, nginx, tornado) and Backend (MessagePack Server, Sqlite, Redis).

The interaction scheme is presented below:



Frontend


Web interface - everything is quite simple, ExtJS and a lot of code. The code was written in CoffeeScript. In the first versions, LocalStorage was used for caching, but in the end they refused because the number of bugs exceeded the benefits. Nginx is used to upload statics, JS code and files via X-Accel-Redirect (detailed below). He simply proxies the rest in Tornado, which, in turn, is a kind of router, redirecting requests to the desired Backend. Tornado scales well, and we hope we cut all the locks we’ve done.

Backend


Backend consists of several demons, which, as usual, are able to receive requests from the Frontend. Daemons are located on each destination server and work with the local file system, upload files via FTP, perform authentication and authorization, work with SQLite (editor settings, access to the user's FTP servers).

Requests to Backend are sent in two types: synchronous, which are performed relatively quickly (for example, listing files, reading a file), and requests to perform any long tasks (uploading a file to a remote server, deleting files / directories, etc.).

Synchronous requests - normal RPC. As a method of data serialization, msgpack is used, which has proven itself in terms of the speed of data serialization / deserialization and support among other languages. We also considered python-specific rfoo and google protobuf, but the first one didn’t work because of its binding to python (and its versions), and protobuf, with its code generators, seemed redundant to us, since the number of remote procedures is not measured in tens and hundreds, and there was no need to move the API into separate proto-files.

We decided to implement requests for long operations as simple as possible: there is a common Redis between Frontend and Backend, which stores the task being executed, its status and any other data. To run the task, use the usual synchronous RPC request. Flow turns out like this:



  1. Frontend puts in a radish task with the status of "wait"
  2. Frontend makes a synchronous request in the backend, passing the task id there
  3. The backend accepts the task, sets the status “running”, does the fork, and performs the task in the child process, immediately returning the response to the backend
  4. Frontend looks at the status of the task or tracks changes to any data (for example, the number of copied files, which is periodically updated from the Backend).


Interesting cases worth mentioning.



Installation


We took the path of least resistance and, instead of manual installation, prepared Docker images. Installation is essentially performed by several commands:

 user@host:~$ wget https://raw.githubusercontent.com/LTD-Beget/sprutio/master/run.sh user@host:~$ chmod +x run.sh user@host:~$ ./run.sh 

run.sh will check for the presence of images, in case they are not downloaded, and will launch 5 containers with system components. To update the images you need to run

 user@host:~$ ./run.sh pull 


Stop and delete images are respectively performed through the parameters stop and rm. Dockerfile assembly is in the project code, the assembly takes 10-20 minutes.
How to raise the environment for the development in the near future we will write on the site and in the wiki on github .

Help us make Sprut.IO better


There are a lot of obvious opportunities for further improvement of the file manager.

As the most useful for users, we see:



If you have add-ons that may be useful to users, tell us about them in the comments or on the mailing list sprutio-ru@groups.google.com .

We will begin to implement them, but I will not be afraid to say this: it will take years if not decades . Therefore, if you want to learn how to program, know Python and ExtJS and want to gain development experience in an open project - we invite you to join the development of Sprut.IO. Moreover, we will pay a reward for each implemented feature, since we will not have to implement it ourselves.

The list of TODO and task execution status can be seen on the project website in the TODO section.

Thanks for attention! If it is interesting, we will be happy to write more details about the organization of the project and answer your questions in the comments.

Project website: https://sprut.io
The demo is available at the link: https://demo.sprut.io:9443
Source code: https://github.com/LTD-Beget/sprutio
Russian mailing list: sprutio-ru@groups.google.com
English mailing list: sprutio@groups.google.com

Source: https://habr.com/ru/post/277449/


All Articles