--[[ <HCExtension>@name content length and type as file name (длина и тип содержимого как имя файла)@author bdstd@version 2.2.1@exception upload@exception /videoplayback\?.*\&range=@rule fbsbx\.com/file\_download\.php\?id=[^&]+\&.*@rule 4shared.*/download/.*?\?tsid=.*@rule reverbnation\.com/audio\_player/ec@rule media\.sndcdn\.com/.*?\.mp3@rule \.(3gp|amv|avi|flv|mkv|mpeg|mp4|wmv)@rule /videoplayback\?@rule www[0-9]+\.indowebster\.com/[a-zA-Z0-9]+\.[a-zA-Z0-9]{2,9}$@rule imgprx.livejournal.net/@event BeforeViewInMonitor</HCExtension> ]]function cacheable() if re.find(hc.url, [[\&begin=(?!0)[0-9]+]]) or re.find(hc.url, [[redirector]]) or re.find(hc.url, [[^htt[ps]+://\d+\.\d+\.\d+\.\d+.*]]) or re.find(hc.url, [[(\?|\&)(start|starttime)=\d+\.\d+]]) then return false else if re.find(hc.answer_header, [[HTTP/1.1\s200]]) or re.find(hc.answer_header, [[^HTTP/1.1\s206.*?Content\-Range:\sbytes\s0-.*]]) then return true else return false end endendfunction BeforeViewInMonitor() local x = hc.url if re.match(hc.request_header, [[^X\-Via:\sHandyCache\r\n]]) then hc.request_header = re.replace(hc.request_header, [[^X\-Via:\sHandyCache\r\n]], nil) hc.monitor_string = 'getting_id' hc.call_me_for('AnswerHeaderReceived', 'get_id') else hc.white_mask = 'W' local xdomain = re.replace(x, [[^.*?//(.*?)/.*]], '\\1') local xget = hc.request_header -- local xget = re.replace(xget, [[GET]], 'HEAD') -- beberapa webserver menolak jika menggunakan request method head local xget = re.replace(xget, [[^Range:.*?\r\n]], nil) local xget = re.replace(xget, [[\r\n\r\n]], '\r\nX-Via: HandyCache\r\n\r\n') local xtunnel = 'CONNECT '..xdomain..':443 HTTP/1.1\r\nHost: '..xdomain..'\r\nUser-Agent: HandyCache\r\nConnection: keep-alive\r\n\r\n' if re.find(hc.url, [[^https://]]) then hc.send_request(xget, '', xtunnel) else hc.send_request(xget) end repeat hc.sleep(50) if hc.client_connected=='false' then hc.set_global(x, 'reset') end until hc.get_global(x)~=nil if hc.get_global(x)=='reset' then hc.set_global(x, nil) else if re.find(x, [[\?]]) then hc.request_header = re.replace(hc.request_header, [[(^GET.*?)(\sHTTP/1.1\r\n)]], '\\1&'..hc.get_global(x)..'\\2') hc.call_me_for('URLToFileNameConverting', 'conv') hc.call_me_for('BeforeRequestHeaderSend', 'hit_check') else hc.request_header = re.replace(hc.request_header, [[(^GET.*?)(\sHTTP/1.1\r\n)]], '\\1?'..hc.get_global(x)..'\\2') hc.call_me_for('URLToFileNameConverting', 'conv') hc.call_me_for('BeforeRequestHeaderSend', 'hit_check') end end hc.set_global(x, nil) endendfunction get_id() if cacheable()==true then local x1 = re.find(hc.answer_header, [[^Content\-Length:\s[0-9]+\r\n]]) local x2 = re.replace(x1, [[^Content\-Length:\s([0-9]+)\r\n]], '\\1') local y1 = re.find(hc.answer_header, [[^Content\-Type:\s[a-zA-Z0-9\-\_]+/[a-zA-Z0-9\-\_]+.*?\r\n]]) local y2 = re.replace(y1, [[^Content\-Type:\s([a-zA-Z0-9\-\_]+)/([a-zA-Z0-9\-\_]+).*?\r\n]], '\\1_\\2') if x2 and y2 then hc.set_global(hc.url, 'x-hc='..x2..'.'..y2) else hc.set_global(hc.url, 'reset') end else hc.set_global(hc.url, 'reset') end hc.client_disconnect()endfunction conv() local x = hc.url local x = re.replace(x, [[dropboxusercontent]], 'dropbox') local x = re.replace(x, [[^.*?([a-zA-Z0-9\-]{4,20}\.[a-z]{2,3}\.[a-z]{2,3})(/|:\d+/).*x\-hc=(.*)$]], '!content-length-and-type-as-file-name/\\1/\\3') local x = re.replace(x, [[^.*?([a-zA-Z0-9\-]{4,20}\.[a-z]{2,3})(/|:\d+/).*x\-hc=(.*)$]], '!content-length-and-type-as-file-name/\\1/\\3') local x = re.replace(x, [[/]], '\\', true) hc.preform_cache_file_name(x) -- hc.put_msg(x)endfunction hit_check() if hc.cache_file_name=='' then hc.call_me_for('AnswerHeaderReceived', 'saver') else hc.action = 'dont_update-' hc.monitor_string = 'Hit-Cache' endendfunction saver() if cacheable()==true then hc.action = 'save-' hc.monitor_string = 'Saving-Content' endend
--[[ <HCExtension>@name Длина/дата последнего изменения и тип содержимого, как имя файла (LTFN)@author bdstd, kichrot@version 2.2.2@exception upload@exception /videoplayback\?.*\&range=@exception s.ytimg.com/@rule fbsbx\.com/file\_download\.php\?id=[^&]+\&.*@rule 4shared.*/download/.*?\?tsid=.*@rule reverbnation\.com/audio\_player/ec@rule imgprx.livejournal.net/@rule .*ytimg.com/@rule yt3.ggpht.com/@event BeforeViewInMonitor</HCExtension> ]]function cacheable() if re.find(hc.url, [[\&begin=(?!0)[0-9]+]]) or re.find(hc.url, [[redirector]]) or re.find(hc.url, [[^htt[ps]+://\d+\.\d+\.\d+\.\d+.*]]) or re.find(hc.url, [[(\?|\&)(start|starttime)=\d+\.\d+]]) then return false else if re.find(hc.answer_header, [[HTTP/1.1\s200]]) or re.find(hc.answer_header, [[^HTTP/1.1\s206.*?Content\-Range:\sbytes\s0-.*]]) then return true else return false end endendfunction GetContentLength(s) _,_,x = string.find(s, '[cC]ontent%-[lL]ength: *(%d+)') if x==nil then return -1 else return tonumber(x) endendfunction get_id() if cacheable()==true then local x2 = GetContentLength(hc.answer_header) -- Забираем размер файла из заголовка 'Content-Length' local y1 = re.find(hc.answer_header, [[^Content\-Type:\s[a-zA-Z0-9\-\_]+/[a-zA-Z0-9\-\_]+.*?\r\n]]) local y2 = re.replace(y1, [[^Content\-Type:\s([a-zA-Z0-9\-\_]+)/([a-zA-Z0-9\-\_]+).*?\r\n]], '\\1_\\2') -- если в заголовке нет Content-Length то используем Last-Modified if x2 == -1 then local lmdf = re.find(hc.answer_header, [[^Last-Modified:\s([^\r\n]+)]]) local lmdf = re.replace(lmdf, [[Last-Modified:\s]], '', true) local lmdf = re.replace(lmdf, [[([\s,:])]], '', true) x2 = lmdf -- hc.put_msg(x2) end if x2 ~= -1 and y2 then hc.set_global(hc.url, 'x-hc='..x2..'.'..y2) else hc.set_global(hc.url, 'reset') end else hc.set_global(hc.url, 'reset') end hc.client_disconnect() hc.hide_in_active_list = true hc.hide_in_monitor = trueendfunction conv() local x = hc.url local x = re.replace(x, [[dropboxusercontent]], 'dropbox') local x = re.replace(x, [[^.*?([a-zA-Z0-9\-]{4,20}\.[a-z]{2,3}\.[a-z]{2,3})(/|:\d+/).*x\-hc=(.*)$]], '!content-length-and-type-as-file-name/\\1/\\3') local x = re.replace(x, [[^.*?([a-zA-Z0-9\-]{4,20}\.[a-z]{2,3})(/|:\d+/).*x\-hc=(.*)$]], '!content-length-and-type-as-file-name/\\1/\\3') local x = re.replace(x, [[/]], '\\', true) hc.preform_cache_file_name(x) -- hc.put_msg(x)endfunction hit_check() if hc.cache_file_name=='' then hc.call_me_for('AnswerHeaderReceived', 'saver') else hc.action = 'dont_update-' hc.monitor_string = 'LTFN-Cache' endendfunction saver() if cacheable()==true then hc.action = 'save-' hc.monitor_string = 'LTFN-Saving_Content' endendfunction BeforeViewInMonitor() local x = hc.url if re.match(hc.request_header, [[^X\-Via:\sHandyCache\r\n]]) then hc.request_header = re.replace(hc.request_header, [[^X\-Via:\sHandyCache\r\n]], nil) hc.monitor_string = 'LTFN-getting_id' hc.call_me_for('AnswerHeaderReceived', 'get_id') else hc.white_mask = 'W' local xdomain = re.replace(x, [[^.*?//(.*?)/.*]], '\\1') local xget = hc.request_header -- local xget = re.replace(xget, [[GET]], 'HEAD') -- некоторый веб-сервер отклоняется, если использует метод метода запроса local xget = re.replace(xget, [[^Range:.*?\r\n]], nil) local xget = re.replace(xget, [[\r\n\r\n]], '\r\nX-Via: HandyCache\r\n\r\n') local xtunnel = 'CONNECT '..xdomain..':443 HTTP/1.1\r\nHost: '..xdomain..'\r\nUser-Agent: HandyCache\r\nConnection: keep-alive\r\n\r\n' if re.find(hc.url, [[^https://]]) then hc.send_request(xget, '', xtunnel) else hc.send_request(xget) end repeat hc.sleep(50) if hc.client_connected=='false' then hc.set_global(x, 'reset') end until hc.get_global(x)~=nil if hc.get_global(x)=='reset' then hc.set_global(x, nil) else if re.find(x, [[\?]]) then hc.request_header = re.replace(hc.request_header, [[(^GET.*?)(\sHTTP/1.1\r\n)]], '\\1&'..hc.get_global(x)..'\\2') hc.call_me_for('URLToFileNameConverting', 'conv') hc.call_me_for('BeforeRequestHeaderSend', 'hit_check') else hc.request_header = re.replace(hc.request_header, [[(^GET.*?)(\sHTTP/1.1\r\n)]], '\\1?'..hc.get_global(x)..'\\2') hc.call_me_for('URLToFileNameConverting', 'conv') hc.call_me_for('BeforeRequestHeaderSend', 'hit_check') end end hc.set_global(x, nil) endend
--[[ <HCExtension>@name Длина/дата последнего изменения и тип содержимого, как имя файла (LDTFN)@author bdstd, kichrot@version 2.2.4@exception upload@exception /videoplayback\?.*\&range=@exception s.ytimg.com/@rule fbsbx\.com/file\_download\.php\?id=[^&]+\&.*@rule 4shared.*/download/.*?\?tsid=.*@rule reverbnation\.com/audio\_player/ec@rule imgprx.livejournal.net/@rule .*ytimg.com/@rule yt3.ggpht.com/@event BeforeViewInMonitor</HCExtension> ]]function cacheable() if re.find(hc.url, [[\&begin=(?!0)[0-9]+]]) or re.find(hc.url, [[redirector]]) or re.find(hc.url, [[^htt[ps]+://\d+\.\d+\.\d+\.\d+.*]]) or re.find(hc.url, [[(\?|\&)(start|starttime)=\d+\.\d+]]) then return false else if re.find(hc.answer_header, [[HTTP/1.1\s200]]) or re.find(hc.answer_header, [[^HTTP/1.1\s206.*?Content\-Range:\sbytes\s0-.*]]) then return true else return false end endendfunction GetContentLength(s) _,_,x = string.find(s, '[cC]ontent%-[lL]ength: *(%d+)') if x==nil then return -1 else return tonumber(x) endendfunction GetLastModified(d) x = re.find(d, [[^[lL]ast-[mM]odified:\s]]) -- hc.put_msg(x) if x then x = re.find(d, [[^[lL]ast-[mM]odified:\s([^\r\n]+)]]) x = re.replace(x, [[[lL]ast-[mM]odified:\s]], '', true) x = re.replace(x, [[([\s,:])]], '', true) return x else return -1 endendfunction get_id() hc.action = 'dont_save' hc.client_disconnect() hc.hide_in_active_list = true hc.hide_in_monitor = true if cacheable()==true then local z = GetLastModified(hc.answer_header) -- Забираем время последнего изменения файла из заголовка 'Last-Modified' local x1 = GetContentLength(hc.answer_header) -- Забираем размер файла из заголовка 'Content-Length' local x2 = x1 .. '_' .. z local y1 = re.find(hc.answer_header, [[^Content\-Type:\s[a-zA-Z0-9\-\_]+/[a-zA-Z0-9\-\_]+.*?\r\n]]) local y2 = re.replace(y1, [[^Content\-Type:\s([a-zA-Z0-9\-\_]+)/([a-zA-Z0-9\-\_]+).*?\r\n]], '\\1_\\2') -- hc.put_msg(x2) if x2 and y2 then hc.set_global(hc.url, 'x-hc='..x2..'.'..y2) else hc.set_global(hc.url, 'reset') end else hc.set_global(hc.url, 'reset') endendfunction conv() local x = hc.url local x = re.replace(x, [[dropboxusercontent]], 'dropbox') local x = re.replace(x, [[^.*?([a-zA-Z0-9\-]{4,20}\.[a-z]{2,3}\.[a-z]{2,3})(/|:\d+/).*x\-hc=(.*)$]], '!content-length-and-type-as-file-name/\\1/\\3') local x = re.replace(x, [[^.*?([a-zA-Z0-9\-]{4,20}\.[a-z]{2,3})(/|:\d+/).*x\-hc=(.*)$]], '!content-length-and-type-as-file-name/\\1/\\3') local x = re.replace(x, [[/]], '\\', true) hc.preform_cache_file_name(x) -- hc.put_msg(x)endfunction saver() if cacheable()==true then hc.action = 'save-' hc.monitor_string = 'LDTFN-Saving_Content' endendfunction hit_check() if hc.cache_file_name=='' then hc.call_me_for('AnswerHeaderReceived', 'saver') else hc.action = 'dont_update-' hc.monitor_string = 'LDTFN-Cache' endendfunction BeforeViewInMonitor() local x = hc.url if re.match(hc.request_header, [[^X\-Via:\sHandyCache\r\n]]) then hc.request_header = re.replace(hc.request_header, [[^X\-Via:\sHandyCache\r\n]], nil) hc.monitor_string = 'LDTFN-getting_id' hc.call_me_for('AnswerHeaderReceived', 'get_id') else hc.white_mask = 'W' local xdomain = re.replace(x, [[^.*?//(.*?)/.*]], '\\1') local xget = hc.request_header -- local xget = re.replace(xget, [[GET]], 'HEAD') -- beberapa webserver menolak jika menggunakan request method head local xget = re.replace(xget, [[^Range:.*?\r\n]], nil) local xget = re.replace(xget, [[\r\n\r\n]], '\r\nX-Via: HandyCache\r\n\r\n') local xtunnel = 'CONNECT '..xdomain..':443 HTTP/1.1\r\nHost: '..xdomain..'\r\nUser-Agent: HandyCache\r\nConnection: keep-alive\r\n\r\n' if re.find(hc.url, [[^https://]]) then hc.send_request(xget, '', xtunnel) else hc.send_request(xget) end repeat hc.sleep(50) if hc.client_connected=='false' then hc.set_global(x, 'reset') end until hc.get_global(x)~=nil if hc.get_global(x)=='reset' then hc.set_global(x, nil) else if re.find(x, [[\?]]) then hc.request_header = re.replace(hc.request_header, [[(^GET.*?)(\sHTTP/1.1\r\n)]], '\\1&'..hc.get_global(x)..'\\2') hc.call_me_for('URLToFileNameConverting', 'conv') hc.call_me_for('BeforeRequestHeaderSend', 'hit_check') else hc.request_header = re.replace(hc.request_header, [[(^GET.*?)(\sHTTP/1.1\r\n)]], '\\1?'..hc.get_global(x)..'\\2') hc.call_me_for('URLToFileNameConverting', 'conv') hc.call_me_for('BeforeRequestHeaderSend', 'hit_check') end end hc.set_global(x, nil) endend
--[[ <HCExtension>@name Длина, дата последнего изменения и тип содержимого, как имя файла (LDTFN)@author bdstd, kichrot@version 2.2.5@exception upload@exception /videoplayback\?.*\&range=@exception s.ytimg.com/@rule imgprx.livejournal.net/@rule .*ytimg.com/@rule yt3.ggpht.com/@event BeforeViewInMonitor</HCExtension> ]]function cacheable() if re.find(hc.url, [[\&begin=(?!0)[0-9]+]]) or re.find(hc.url, [[redirector]]) or re.find(hc.url, [[^htt[ps]+://\d+\.\d+\.\d+\.\d+.*]]) or re.find(hc.url, [[(\?|\&)(start|starttime)=\d+\.\d+]]) then return false else if re.find(hc.answer_header, [[HTTP/1.1\s200]]) or re.find(hc.answer_header, [[^HTTP/1.1\s206.*?Content\-Range:\sbytes\s0-.*]]) then return true else return false end endendfunction GetContentType(s) _,_,x = string.find(s, '[cC]ontent%-[tT]ype: *([^;\r\n]+)') if x~=nil then x = string.lower(x) end return xendfunction GetContentLength(s) _,_,x = string.find(s, '[cC]ontent%-[lL]ength: *(%d+)') if x==nil then return -1 else return tonumber(x) endendfunction GetLastModified(d) x = re.find(d, [[^[lL]ast-[mM]odified:\s]]) -- hc.put_msg(x) if x then x = re.find(d, [[^[lL]ast-[mM]odified:\s([^\r\n]+)]]) x = re.replace(x, [[[lL]ast-[mM]odified:\s]], '', true) x = re.replace(x, [[([\s,:])]], '', true) return x else return -1 endendfunction get_id() hc.action = 'dont_save' hc.client_disconnect() hc.hide_in_active_list = true hc.hide_in_monitor = true if cacheable()==true then local z = GetLastModified(hc.answer_header) -- Забираем время последнего изменения файла из заголовка 'Last-Modified' local x1 = GetContentLength(hc.answer_header) -- Забираем размер файла из заголовка 'Content-Length' local x2 = x1 .. '_' .. z local y1 = GetContentType(hc.answer_header) -- Забираем тип файла из заголовка 'Content-Type' local y2 = re.replace(y1, [[(.+?(?=/)+/)]], '', true) if x2 and y2 then hc.set_global(hc.url, 'x-hc='..x2..'.'..y2) else hc.set_global(hc.url, 'reset') end else hc.set_global(hc.url, 'reset') endendfunction conv() local x = hc.url local x = re.replace(x, [[dropboxusercontent]], 'dropbox') local x = re.replace(x, [[^.*?([a-zA-Z0-9\-]{4,20}\.[a-z]{2,3}\.[a-z]{2,3})(/|:\d+/).*x\-hc=(.*)$]], '!content-length-and-type-as-file-name/\\1/\\3') local x = re.replace(x, [[^.*?([a-zA-Z0-9\-]{4,20}\.[a-z]{2,3})(/|:\d+/).*x\-hc=(.*)$]], '!content-length-and-type-as-file-name/\\1/\\3') local x = re.replace(x, [[/]], '\\', true) hc.preform_cache_file_name(x) -- hc.put_msg(x)endfunction saver() if cacheable()==true then hc.action = 'save-' hc.monitor_string = 'LDTFN-Saving_Content' endendfunction hit_check() if hc.cache_file_name=='' then hc.call_me_for('AnswerHeaderReceived', 'saver') else hc.action = 'dont_update-' hc.monitor_string = 'LDTFN-Cache' endendfunction BeforeViewInMonitor() local x = hc.url if re.match(hc.request_header, [[^X\-Via:\sHandyCache\r\n]]) then hc.request_header = re.replace(hc.request_header, [[^X\-Via:\sHandyCache\r\n]], nil) hc.monitor_string = 'LDTFN-getting_id' hc.call_me_for('AnswerHeaderReceived', 'get_id') else hc.white_mask = 'W' local xdomain = re.replace(x, [[^.*?//(.*?)/.*]], '\\1') local xget = hc.request_header -- local xget = re.replace(xget, [[GET]], 'HEAD') -- beberapa webserver menolak jika menggunakan request method head local xget = re.replace(xget, [[^Range:.*?\r\n]], nil) local xget = re.replace(xget, [[\r\n\r\n]], '\r\nX-Via: HandyCache\r\n\r\n') local xtunnel = 'CONNECT '..xdomain..':443 HTTP/1.1\r\nHost: '..xdomain..'\r\nUser-Agent: HandyCache\r\nConnection: keep-alive\r\n\r\n' if re.find(hc.url, [[^https://]]) then hc.send_request(xget, '', xtunnel) else hc.send_request(xget) end repeat hc.sleep(50) if hc.client_connected=='false' then hc.set_global(x, 'reset') end until hc.get_global(x)~=nil if hc.get_global(x)=='reset' then hc.set_global(x, nil) else if re.find(x, [[\?]]) then hc.request_header = re.replace(hc.request_header, [[(^GET.*?)(\sHTTP/1.1\r\n)]], '\\1&'..hc.get_global(x)..'\\2') hc.call_me_for('URLToFileNameConverting', 'conv') hc.call_me_for('BeforeRequestHeaderSend', 'hit_check') else hc.request_header = re.replace(hc.request_header, [[(^GET.*?)(\sHTTP/1.1\r\n)]], '\\1?'..hc.get_global(x)..'\\2') hc.call_me_for('URLToFileNameConverting', 'conv') hc.call_me_for('BeforeRequestHeaderSend', 'hit_check') end end hc.set_global(x, nil) endend
--[[ <HCExtension>@name Длина, дата последнего изменения и тип содержимого, как имя файла (LDTFN)@author bdstd, kichrot@version 2.2.6@rule imgprx.livejournal.net/@event BeforeViewInMonitor</HCExtension> ]]function cacheable() if re.find(hc.url, [[\&begin=(?!0)[0-9]+]]) or re.find(hc.url, [[redirector]]) or re.find(hc.url, [[^htt[ps]+://\d+\.\d+\.\d+\.\d+.*]]) or re.find(hc.url, [[(\?|\&)(start|starttime)=\d+\.\d+]]) then return false else if re.find(hc.answer_header, [[HTTP/1.1\s200]]) or re.find(hc.answer_header, [[^HTTP/1.1\s206.*?Content\-Range:\sbytes\s0-.*]]) then return true else return false end endendfunction GetContentType(s) _,_,x = string.find(s, '[cC]ontent%-[tT]ype: *([^;\r\n]+)') if x~=nil then x = string.lower(x) end return xendfunction GetContentLength(s) _,_,x = string.find(s, '[cC]ontent%-[lL]ength: *(%d+)') if x==nil then return -1 else return tonumber(x) endendfunction GetLastModified(d) x = re.find(d, [[^[lL]ast-[mM]odified:\s]]) -- hc.put_msg(x) if x then x = re.find(d, [[^[lL]ast-[mM]odified:\s([^\r\n]+)]]) x = re.replace(x, [[[lL]ast-[mM]odified:\s]], '', true) x = re.replace(x, [[([\s,:])]], '', true) return x else return -1 endendfunction get_id() hc.white_mask="ЗНП" hc.action = 'dont_save' hc.client_disconnect() hc.hide_in_active_list = true hc.hide_in_monitor = true if cacheable()==true then local z = GetLastModified(hc.answer_header) -- Забираем время последнего изменения файла из заголовка 'Last-Modified' local x1 = GetContentLength(hc.answer_header) -- Забираем размер файла из заголовка 'Content-Length' local x2 = x1 .. '_' .. z local y1 = GetContentType(hc.answer_header) -- Забираем тип файла из заголовка 'Content-Type' -- local y2 = re.replace(y1, [[([/])]], '_', true) local y2 = re.replace(y1, [[(.+?(?=/)+/)]], '', true) -- hc.put_msg(y2) if x2 and y2 then hc.set_global(hc.url, 'x-hc='..x2..'.'..y2) hc.white_mask="Н" else hc.set_global(hc.url, 'reset') end else hc.set_global(hc.url, 'reset') endendfunction conv() local x = hc.url local x = re.replace(x, [[dropboxusercontent]], 'dropbox') local x = re.replace(x, [[^.*?([a-zA-Z0-9\-]{4,20}\.[a-z]{2,3}\.[a-z]{2,3})(/|:\d+/).*x\-hc=(.*)$]], '!content-length-and-type-as-file-name/\\1/\\3') local x = re.replace(x, [[^.*?([a-zA-Z0-9\-]{4,20}\.[a-z]{2,3})(/|:\d+/).*x\-hc=(.*)$]], '!content-length-and-type-as-file-name/\\1/\\3') local x = re.replace(x, [[/]], '\\', true) hc.preform_cache_file_name(x) -- hc.put_msg(x)endfunction saver() if cacheable()==true then hc.action = 'save' hc.monitor_string = 'LDTFN-Saving_Content' endendfunction hit_check() if hc.cache_file_name=='' then hc.call_me_for('AnswerHeaderReceived', 'saver') else hc.white_mask="З" hc.action = 'dont_update' hc.monitor_string = 'LDTFN-Cache' endendfunction BeforeViewInMonitor() local x = hc.url if re.match(hc.request_header, [[^X\-Via:\sHandyCache\r\n]]) then hc.request_header = re.replace(hc.request_header, [[^X\-Via:\sHandyCache\r\n]], nil) hc.monitor_string = 'LDTFN-getting_id' hc.call_me_for('AnswerHeaderReceived', 'get_id') else hc.white_mask = 'W' local xdomain = re.replace(x, [[^.*?//(.*?)/.*]], '\\1') local xget = hc.request_header -- local xget = re.replace(xget, [[GET]], 'HEAD') -- beberapa webserver menolak jika menggunakan request method head local xget = re.replace(xget, [[^Range:.*?\r\n]], nil) local xget = re.replace(xget, [[\r\n\r\n]], '\r\nX-Via: HandyCache\r\n\r\n') local xtunnel = 'CONNECT '..xdomain..':443 HTTP/1.1\r\nHost: '..xdomain..'\r\nUser-Agent: HandyCache\r\nConnection: keep-alive\r\n\r\n' if re.find(hc.url, [[^https://]]) then hc.send_request(xget, '', xtunnel) else hc.send_request(xget) end repeat hc.sleep(50) if hc.client_connected=='false' then hc.set_global(x, 'reset') end until hc.get_global(x)~=nil if hc.get_global(x)=='reset' then hc.set_global(x, nil) else hc.white_mask="Н" if re.find(x, [[\?]]) then hc.request_header = re.replace(hc.request_header, [[(^GET.*?)(\sHTTP/1.1\r\n)]], '\\1&'..hc.get_global(x)..'\\2') hc.call_me_for('URLToFileNameConverting', 'conv') hc.call_me_for('BeforeRequestHeaderSend', 'hit_check') else hc.request_header = re.replace(hc.request_header, [[(^GET.*?)(\sHTTP/1.1\r\n)]], '\\1?'..hc.get_global(x)..'\\2') hc.call_me_for('URLToFileNameConverting', 'conv') hc.call_me_for('BeforeRequestHeaderSend', 'hit_check') end end hc.set_global(x, nil) endend
--[[ <HCExtension>@name Длина, дата последнего изменения и тип содержимого, как имя файла (LDTFN)@author bdstd, kichrot@version 2.2.9@rule imgprx.livejournal.net/@event BeforeViewInMonitor</HCExtension> ]]function cacheable() if re.find(hc.url, [[\&begin=(?!0)[0-9]+]]) or re.find(hc.url, [[redirector]]) or re.find(hc.url, [[^htt[ps]+://\d+\.\d+\.\d+\.\d+.*]]) or re.find(hc.url, [[(\?|\&)(start|starttime)=\d+\.\d+]]) then return false else if re.find(hc.answer_header, [[HTTP/1.1\s200]]) or re.find(hc.answer_header, [[^HTTP/1.1\s206.*?Content\-Range:\sbytes\s0-.*]]) then return true else return false end endendfunction GetContentType(s) _,_,x = string.find(s, '[cC]ontent%-[tT]ype: *([^;\r\n]+)') if x~=nil then x = string.lower(x) end return xendfunction GetContentLength(s) _,_,x = string.find(s, '[cC]ontent%-[lL]ength: *(%d+)') if x==nil then return -1 else return tonumber(x) endendfunction GetLastModified(d) local x = re.find(d, [[^[lL]ast-[mM]odified:\s]]) if x then x = re.find(d, [[^[lL]ast-[mM]odified:\s([^\r\n]+)]]) x = re.replace(x, [[[lL]ast-[mM]odified:\s]], '', true) return x else return -1 endendfunction GetAnswerCode(s) _,_,x = string.find(s, 'HTTP/1%.%d +(%d+)') if x==nil then return -1 else return tonumber(x) endendfunction get_id() hc.monitor_string = 'LDTFN-getting_id' hc.white_mask="ЗНП" hc.action = 'dont_save' hc.client_disconnect() hc.hide_in_active_list = true hc.hide_in_monitor = true if cacheable()==true then local z = GetLastModified(hc.answer_header) -- Забираем время последнего изменения файла из заголовка 'Last-Modified' z = re.replace(z, [[([\s,:])]], '', true) -- Убираем пробелы из значения 'Last-Modified' local x1 = GetContentLength(hc.answer_header) -- Забираем размер файла из заголовка 'Content-Length' local x2 = x1 .. '_' .. z local y1 = GetContentType(hc.answer_header) -- Забираем тип файла из заголовка 'Content-Type' -- local y2 = re.replace(y1, [[([/])]], '_', true) local y2 = re.replace(y1, [[(.+?(?=/)+/)]], '', true) -- hc.put_msg(y2) if x2 and y2 then hc.set_global(hc.url, 'x-hc='..x2..'.'..y2) hc.white_mask="Н" else hc.set_global(hc.url, 'reset') end else hc.set_global(hc.url, 'reset') endendfunction conv() local x = hc.url local x = re.replace(x, [[dropboxusercontent]], 'dropbox') local x = re.replace(x, [[^.*?([a-zA-Z0-9\-]{4,20}\.[a-z]{2,3}\.[a-z]{2,3})(/|:\d+/).*x\-hc=(.*)$]], '!content-length-and-type-as-file-name/\\1/\\3') local x = re.replace(x, [[^.*?([a-zA-Z0-9\-]{4,20}\.[a-z]{2,3})(/|:\d+/).*x\-hc=(.*)$]], '!content-length-and-type-as-file-name/\\1/\\3') local x = re.replace(x, [[/]], '\\', true) hc.preform_cache_file_name(x) -- hc.put_msg(x)endfunction saver() if cacheable()==true then hc.action = 'save' hc.monitor_string = 'LDTFN-Saving' endendfunction hit_check() if hc.cache_file_name=='' then hc.call_me_for('AnswerHeaderReceived', 'saver') else hc.white_mask="З" hc.action = 'dont_update' hc.monitor_string = 'LDTFN-Cache' endendfunction BeforeViewInMonitor() -- выясняем код ответа из заголовка local answ_code = GetAnswerCode(hc.answer_header) -- если код ответа не равен 301, 302, 303, 307, 308 if answ_code~=301 and answ_code~=302 and answ_code~=303 and answ_code~=307 and answ_code~=308 then local x = hc.url if re.match(hc.request_header, [[^X\-Via:\sHandyCache\r\n]]) then hc.request_header = re.replace(hc.request_header, [[^X\-Via:\sHandyCache\r\n]], nil) hc.call_me_for('AnswerHeaderReceived', 'get_id') else hc.white_mask = 'W' local xdomain = re.replace(x, [[^.*?//(.*?)/.*]], '\\1') local xget = hc.request_header -- local xget = re.replace(xget, [[GET]], 'HEAD') -- beberapa webserver menolak jika menggunakan request method head local xget = re.replace(xget, [[^Range:.*?\r\n]], nil) local xget = re.replace(xget, [[\r\n\r\n]], '\r\nX-Via: HandyCache\r\n\r\n') local xtunnel = 'CONNECT '..xdomain..':443 HTTP/1.1\r\nHost: '..xdomain..'\r\nUser-Agent: HandyCache\r\nConnection: keep-alive\r\n\r\n' if re.find(hc.url, [[^https://]]) then hc.send_request(xget, '', xtunnel) else hc.send_request(xget) end repeat hc.sleep(50) if hc.client_connected=='false' then hc.set_global(x, 'reset') end until hc.get_global(x)~=nil if hc.get_global(x)=='reset' then hc.set_global(x, nil) else hc.white_mask="Н" if re.find(x, [[\?]]) then hc.request_header = re.replace(hc.request_header, [[(^GET.*?)(\sHTTP/1.1\r\n)]], '\\1&'..hc.get_global(x)..'\\2') hc.call_me_for('URLToFileNameConverting', 'conv') hc.call_me_for('BeforeRequestHeaderSend', 'hit_check') else hc.request_header = re.replace(hc.request_header, [[(^GET.*?)(\sHTTP/1.1\r\n)]], '\\1?'..hc.get_global(x)..'\\2') hc.call_me_for('URLToFileNameConverting', 'conv') hc.call_me_for('BeforeRequestHeaderSend', 'hit_check') end end hc.set_global(x, nil) end end end
--[[ <HCExtension>@name Не сохранять ответ 301, 302, 303, 307 и 308 (30(x) Dont_save )@author kichrot@version 0.1@description Не сохранять файл в заголовке которого ответ сервера "HTTP/1.1 30X ..."@event AnswerHeaderReceived/Answer</HCExtension> ]]function GetAnswerCode(s) _,_,x = string.find(s, 'HTTP/1%.%d +(%d+)') if x==nil then return -1 else return tonumber(x) endendfunction Answer() -- выясняем код ответа из заголовка answ_code = GetAnswerCode(hc.answer_header) -- если код ответа 301, 302, 303, 307 или 308 if answ_code==301 or answ_code==302 or answ_code==303 or answ_code==307 or answ_code==308 then hc.action = 'dont_save' hc.monitor_string = hc.monitor_string..'30(x) Dont_save ' endend -- Конец функции Answer
function GetAnswerCode(s) _,_,x = string.find(s,'HTTP/1%.%d +(%d+)') if x==nil then return -1 else return tonumber(x) endendfunction Answer() local answ_code = GetAnswerCode(hc.answer_header) if answ_code == 200 then hc.action = 'save' hc.monitor_string = 'Save' endend