rclone.lua 7.2 KB
Newer Older
1 2 3
require('luci.sys')
require('luci.util')

4 5
local ipkg = require('luci.model.ipkg')

6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
local fs = require 'nixio.fs'

local uci = require 'luci.model.uci'.cursor()

local m, s

local running = (luci.sys.call('pidof rclone > /dev/null') == 0)

local state_msg = ''
local trport = uci:get('rclone', 'config', 'port')

local triptype = uci:get('rclone', 'config', 'addr_type')
local trip = ''

if triptype == 'local' then
    trip = uci:get('network', 'loopback', 'ipaddr')
elseif triptype == 'lan' then
    trip = uci:get('network', 'lan', 'ipaddr')
else
    trip = '[ip]'
end

if running then
    state_msg = '<b><font color="green">' .. translate('rclone running') .. '</font></b>'
    address_msg = translate('rclone address') .. ' : http://' .. trip .. ':' .. trport .. '<br/> <br/>'
else
    state_msg = '<b><font color="red">' .. translate('rclone not run') .. '</font></b>'
    address_msg = ''
end

36
if ipkg.installed("rclone-webui-react") and ipkg.installed("rclone-ng") then
37 38 39 40 41 42 43
m =
    Map(
    'rclone',
    translate('Rclone'),
    translate('Rclone ("rsync for cloud storage") is a command line program to sync root/usr/bin and directories to and from different cloud storage providers.') ..
        ' <br/> <br/> ' .. translate('rclone state') .. ' : ' .. state_msg .. '<br/> <br/>'
        .. address_msg ..
E
ElonH 已提交
44 45 46 47 48 49 50
        translate('Installed Web Interface') ..                                                                                                                     
        '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" class="cbi-button" style="margin: 0 5px;" value=" ' ..                                            
        translate('Webui React') ..                                                                                                                                 
        " \" onclick=\"window.open('http://'+window.location.hostname+'/rclone-webui-react')\"/>" ..                                                                
        '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" class="cbi-button" style="margin: 0 5px;" value=" ' ..                                            
        translate('RcloneNg') ..                                                                                                                                    
        " \" onclick=\"window.open('http://'+window.location.hostname+'/RcloneNg')\"/> <br/><br/>"  
51
)
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
elseif ipkg.installed("rclone-webui-react") then
m =
    Map(
    'rclone',
    translate('Rclone'),
    translate('Rclone ("rsync for cloud storage") is a command line program to sync root/usr/bin and directories to and from different cloud storage providers.') ..
        ' <br/> <br/> ' .. translate('rclone state') .. ' : ' .. state_msg .. '<br/> <br/>'
        .. address_msg ..
        translate('Installed Web Interface') ..   
	
        '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" class="cbi-button" style="margin: 0 5px;" value=" ' ..                                            
        translate('Webui React') ..                                                                                                                                 
        " \" onclick=\"window.open('http://'+window.location.hostname+'/rclone-webui-react')\"/>" 
)
elseif ipkg.installed("rclone-ng") then
m =
    Map(
    'rclone',
    translate('Rclone'),
    translate('Rclone ("rsync for cloud storage") is a command line program to sync root/usr/bin and directories to and from different cloud storage providers.') ..
        ' <br/> <br/> ' .. translate('rclone state') .. ' : ' .. state_msg .. '<br/> <br/>'
        .. address_msg ..
        translate('Installed Web Interface') ..     
	
        '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" class="cbi-button" style="margin: 0 5px;" value=" ' ..                                            
        translate('RcloneNg') ..                                                                                                                                    
        " \" onclick=\"window.open('http://'+window.location.hostname+'/RcloneNg')\"/> <br/><br/>"  
)
else
m =
    Map(
    'rclone',
    translate('Rclone'),
    translate('Rclone ("rsync for cloud storage") is a command line program to sync root/usr/bin and directories to and from different cloud storage providers.') ..
        ' <br/> <br/> ' .. translate('rclone state') .. ' : ' .. state_msg .. '<br/> <br/>'
        .. address_msg
)
end
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182

s = m:section(TypedSection, 'global', translate('global'))
s.addremove = false
s.anonymous = true

enable = s:option(Flag, 'enabled', translate('run Rclone as daemon'))
enable.rmempty = false

s = m:section(TypedSection, 'conf', translate('configure'))
s.addremove = false
s.anonymous = true

o = s:option(ListValue, 'addr_type', translate('listen address'))
o:value('local', translate('localhost address'))
o:value('lan', translate('local network address'))
o:value('all', translate('all address'))
o.default = 'lan'
o.rmempty = false

o = s:option(Value, 'port', translate('listen port'))
o.placeholder = 5572
o.default = 5572
o.datatype = 'port'
o.rmempty = false

o = s:option(Value, 'config_path', translate('rclone configuration file path'))
o.placeholder = '/etc/rclone/rclone.conf'
o.default = '/etc/rclone/rclone.conf'
o.rmempty = false
o.description = translate("Recommand: run ") ..
    "<span style=\"background: lightgray;border-radius: 4px;padding-left: 4px;padding-right: 4px;\">rclone config --config rclone.conf</span>" ..
    translate(" to setup configuration on pc,") .. "</br>" .. translate("than updaload configuration to here.")

o = s:option(Button,"config_download",translate("download configuration"))
o.inputtitle = translate("download")
o.inputstyle = "apply"
o.write = function()
  	Download()
end

function Download()
	local t,e
	t=nixio.open(uci:get('rclone', 'config', 'config_path'),"r")
	luci.http.header('Content-Disposition','attachment; filename="rclone.conf"')
	luci.http.prepare_content("application/octet-stream")
	while true do
		e=t:read(nixio.const.buffersize)
		if(not e)or(#e==0)then
			break
		else
			luci.http.write(e)
		end
	end
	t:close()
	luci.http.close()
end

o = s:option(Value, 'username', translate('username'))
o.placeholder = 'admin'
o.default = 'admin'
o.rmempty = false

o = s:option(Value, 'password', translate('password'))
o.password = true
o.placeholder = 'admin'
o.default = 'admin'
o.rmempty = false

s = m:section(TypedSection, 'proxy', translate('proxy'))
s.addremove = false
s.anonymous = true
s.description = "<a style=\"color:#fb6340;\" href=\"#\" onclick=\"window.open('https://rclone.org/faq/#can-i-use-rclone-with-an-http-proxy')\">"
    ..translate("FAQ").."</a>"

enable = s:option(Flag, 'enabled', translate('enable proxy'))
enable.rmempty = false

o = s:option(Value, 'proxy_addr', translate('proxy address'))
o.placeholder = 'socks5://127.0.0.1:1080'
o.default = 'socks5://127.0.0.1:1080'
o.rmempty = false
o.description = translate("The content of the variable is protocol://server:port. The protocol value is commonly either http or socks5.")

s = m:section(TypedSection, 'log', translate('log'))
s.addremove = false
s.anonymous = true

o = s:option(Value, 'path', translate('path'))
o.placeholder = '/var/log/rclone/output'
o.default = '/var/log/rclone/output'
o.rmempty = false

return m