Merge pull request #776 from cshore/pull-request-statistics-nut
[project/luci.git] / applications / luci-app-aria2 / luasrc / controller / aria2.lua
1 --[[
2 LuCI - Lua Configuration Interface - aria2 support
3
4 Copyright 2014-2015 nanpuyue <nanpuyue@gmail.com>
5 Modified by kuoruan <kuoruan@gmail.com>
6
7 Licensed under the Apache License, Version 2.0 (the "License");
8 you may not use this file except in compliance with the License.
9 You may obtain a copy of the License at
10
11         http://www.apache.org/licenses/LICENSE-2.0
12 ]]--
13
14 module("luci.controller.aria2", package.seeall)
15
16 function index()
17         if not nixio.fs.access("/etc/config/aria2") then
18                 return
19         end
20
21         local page = entry({"admin", "services", "aria2"}, cbi("aria2"), _("Aria2 Settings"))
22         page.dependent = true
23
24         entry({"admin", "services", "aria2", "status"}, call("status")).leaf = true
25
26 end
27
28 function status()
29         local sys  = require "luci.sys"
30         local ipkg = require "luci.model.ipkg"
31         local http = require "luci.http"
32         local uci  = require "luci.model.uci".cursor()
33
34         local status = {
35                 running = (sys.call("pidof aria2c > /dev/null") == 0),
36                 yaaw = ipkg.installed("yaaw"),
37                 webui = ipkg.installed("webui-aria2")
38         }
39
40         http.prepare_content("application/json")
41         http.write_json(status)
42 end