📜 ⬆️ ⬇️

Web-gui for wget (light)

Earlier there was a description of possible situations where this solution might be necessary for you, but let's omit it. The ability to easily create remote downloads that are performed by the usual wget (you can safely see their list with the help of ps ), with the progress displayed - the idea is not new. And even there are some solutions , but not actual ones, since they have not been supported by anyone for more than 5 years.

For torrents, everything is simple and trivial - we put Transmission or any similar client with a web-muzzle. But for links to simple files / pages you need something different. Here is a short list of tasks that pushed me to write it:

If it became interesting to you - welcome under kat:



System requirements


The web interface is built on Javascript + css3 from the client side, and php (selected as the most popular) from the server side. To complete the work will require:

')

Features and settings of the server part


As already mentioned above - in the role of the server side is a script written in php. It performs the following tasks:

For his job he needs ps, wget and kill respectively. To obtain the value of the download status (how many percent is completed), the following algorithm is used:

The path for temporary log files is set in the line " define ( 'tmp_path' , '/ tmp' ) ; ";

The path to the directory where all downloaded files will be saved is set in the line " define ( 'download_path' , BASEPATH . '/ Downloads ' ) ; ".

A convenient indication of paths to ps, wget and kill is available. To do this, it is enough to remove the comment at the beginning of the line and specify your path, for example: " define ( 'wget' , '/ usr / bin / wget' ) ; ".

It is possible to set limits on the download speed from the settings section. The line define ( 'wget_download_limit' , '1024' ) ; "is responsible for this. If you leave it commented out - there will be no restriction.

To determine the list of tasks launched through any other GUI, a specific flag unique to the GUI is used. It is set in the line define ( 'wget_secret_flag' , '--max-redirect = 4321' ) ; "and it is not necessary to change it unnecessarily. By the way, if you want your other tasks running from the terminal to be displayed in the web interface, just add this parameter to them. But do not forget that there are some other parameters that are no less mandatory (depending on the settings).

I tried to write with the most economical attitude to resources and minimal dependence on the system, but I do not have much experience in php, so I will appreciate the recommendations for optimization.

The script responds to both POST and GET requests. There is no difference between them. Also responds to parameters passed on the command line. For example: php ./rpc.php get_list or php ./rpc.php add_task http://goo.gl/5Qi0Xs .

Example of POST request and Json response:

Request:
192.168.1.2 / wget / rpc. php ? action = add_task & url = http : //mirror.yandex.ru/linuxmint/stable/17/linuxmint-17-cinnamon-dvd-64bit.iso
Answer:
{
status : 1 ,
msg : "Task added" ,
id : 10910
}

Request:
192.168.1.2 / wget / rpc.php? action = get_list
Answer:
{
status : 1 ,
msg : "Active tasks list" ,
tasks : [
{
url : " mirror.yandex.ru/linuxmint/stable/17/linuxmint-17-cinnamon-dvd-64bit.iso" ,
progress : 95 ,
id : 10910
}
]
}

Conclusion "ps -ax | grep wget "and" cat /tmp/wget{RND}.log.tmp ":

data: ~ # ps -ax | grep wget
10910 ? S < s 0 : 34 wget --progress = bar: force --background --tries = 0 --no-cache --user-agent = Mozilla / 5.0 ( X11; Linux amd64; rv: 21.0 ) Gecko / 20100101 Firefox / 21.0 --directory-prefix = / DataVolume / shares / Public / Downloads / --limit-rate = 2048k --output-file = / tmp / wget9720.log.tmp --max-redirect = 4321 http: // mirror .yandex.ru / linuxmint / stable / 17 / linuxmint- 17 -cinnamon-dvd-64bit.iso
11378 pts / 0 S + 0 : 00 grep wget

data: ~ # cat / tmp / wget9720.log.tmp
- 2014-08-24 12 : 32 : 04-- http: // mirror.yandex.ru / linuxmint / stable / 17 / linuxmint- 17 -cinnamon-dvd-64bit.iso
Resolving mirror.yandex.ru ... 213.180.204.183, 2a02: 6b8 :: 183
Connecting to mirror.yandex.ru | 213.180.204.183 | : 80 ... connected.
HTTP request sent, awaiting response ... 200 OK
Length: 1286799360 ( 1.2G ) [ application / octet-stream ]
Saving to: `/ DataVolume / shares / Public / Downloads / linuxmint- 17- cinnamon-dvd-64bit.iso`

95 % [ =================================== > ] 1 , 225 , 527 , 078 1.37M / s eta 35s
data: ~ #


Features and client settings


“New html5 tags” are not used, but css3 properties are used to design the progress bar of downloads and adaptations. The design is made in a minimalist style without images (the exception is favicon). If there are no tasks in the center of the page, there is a field for adding a download address, if there are tasks - this field is shifted to the top of the page, and the tasks are located below.

All requests are asynchronous (without reloading the page). Page design is responsive:


The state change is also displayed in the tab (window) header:


At the bottom of the page is a javascript bookmark (“Download this”), by moving it to the browser bookmarks panel, you can add new tasks with one click (the active tab will be added when you click; if the tab with the video file is open and this “bookmark” is clicked on the bookmarks - a task will be added to download this video file):


All javascript document code is located in the core file. js . In its upper part are the main settings:

I don’t see a special point in describing the functional moments, but I’ll say that the functions are divided into logical groups, the script is not minified, comments take place.

When you click on F5, a forced update of tasks occurs, the page is reloaded only by clicking on the update button in the browser.

Installation




Change history


As changes will update this post


What to expect:




MIT License
Copyright © 2014 Paramtamtam

This license permits those who receive a copy of this software and related documentation (hereinafter referred to as the “Software”) to use the Software without charge without restriction, including the unrestricted right to use, copy, modify, add, publish, distribute, sublicense and / or sale of copies of the Software, as well as to the persons to whom this Software is provided, subject to the following conditions:

The above copyright notice and these terms and conditions must be included in all copies or significant parts of this Software.

THIS SOFTWARE LIST IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR CLAIMS FOR DAMAGES, LOSSES, OR OTHER REQUIREMENTS UNDER APPLICABLE CONTRACT, TORT OR OTHERWISE, ARISING FROM HAVING THE RESULT OF OR RELATED TO THE SOFTWARE OR THE USE OF THE SOFTWARE OR OTHER DEALINGS IN THE SOFTWARE.


Link to the project: https://github.com/tarampampam/wget-gui-light

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


All Articles