diff --git a/lg_webOS/impersonate-lge.com.rb b/lg_webOS/impersonate-lge.com.rb index f49f160..e3e5579 100644 --- a/lg_webOS/impersonate-lge.com.rb +++ b/lg_webOS/impersonate-lge.com.rb @@ -1,8 +1,7 @@ #/usr/bin/env ruby ## impersonate-lge.com.rb - fake version of *.lge.com -# serving a cooked version of busybox and base-files - +require 'base64' require 'sinatra' port = ENV['USER'].eql?('root') ? 80 : 8080 @@ -15,37 +14,42 @@ set :public_folder, '_public' get '/fts/:file' do |file| + t = Time.now + (8 * 60 * 60) + timestamp = t.strftime('%a, %d %b %Y %H:%m:%S GMT') + target_host = request.host if target_host.match(/gfts/) - @type = :ngfts + @type = :gfts + ## app store downloads # http://gfts.lge.com/fts/gftsFilePathDownload.lge?key=777863&hash=6Vsai7Ky71UPgetV&mtime=1479098823000 - # this is the opkg update path - #redirect '/base-files/base-files.ipk' - # unfortunately, we need to set these headers: - # Server: Apache - # Content-Disposition: attachment; filename="16881482.ipk" - # Content-Transfer-Encoding: binary; - # Content-Type: application/octet-stream;charset=UTF-8 + key = params['key'] # 777863 + hash = params['hash'] # 6Vsai7Ky71UPgetV + mtime = params['mtime'] # 1479098823000 - # and currently, we send: - # Content-Type: application/vnd.shana.informed.package - # and the other fields are empty + fake_ipk_name = '16881482.ipk' + real_ipk_file = File.join(settings.public_folder, '/gfts/base-files.ipk') headers( - 'Content-Disposition' => 'attachment; filename="base-files.ipk"', + 'Content-Disposition' => sprintf('attachment; filename="%s"', fake_ipk_name), 'Content-Transfer-Encoding' => 'binary', 'Content-Type' => 'application/octet-stream;charset=UTF-8', 'Server' => 'Apache', ) - send_file File.join(settings.public_folder, '/base-files/base-files.ipk') + send_file real_ipk_file elsif target_host.match(/ngfts/) + ## channel searching -- images / thumbnails + # samples in line @type = :ngfts - biz_code = '' # TODO fill this in + + biz_code = params['biz_code'] + func_code = params['func_code'] + file_path = params['file_path'] + if biz_code.eql?('PREMIUMS') # TODO /fts/gftsDownload.lge?biz_code=PREMIUM&func_code=RECOMM_PROMOTION_IMAGE&file_path=/todayrecomm/template/promotion/w1_8.png elsif biz_code.eql?('META_IMG') @@ -57,33 +61,73 @@ get '/fts/:file' do |file| elsif biz_code.eql?('MAS') # TODO /fts/gftsDownload.lge?biz_code=MAS&func_code=META_THUMBNAIL&file_path=%2Fmas%2Ftms%2Fprogram%2Fp185554_b_ap.jpg end + + # failover redirect '/ngfts/faked-ngfts.zip' + elsif target_host.match(/aic/) + ## channel searching - listing JSON + # http://aic-gfts.lge.com/fts/gftsDownload.lge?biz_code=IBS&func_code=ONLINE_EPG_FILE&file_path=/ibs/online/epg_file/20161116/f_1479280636996tmsepgcrawler_merged000004417_201611160600_06_20161116070000.zip @type = :aic - @real_file = '/aic/faked-aic.zip' - @fake_file = '16881482.ipk' - redirect real_file + + fake_file = 'TODO' # TODO not sure what this is supposed to be + real_file = File.join(settings.public_folder, '/aic/faked-aic.zip') + + if @type.eql?(:aic) + headers( + 'Server' => 'Apache', + 'Content-Disposition' => sprintf('attachment; filename="%s"', fake_file), + 'Content-Transfer-Encoding' => 'binary', + 'Content-Type' => 'image/jpeg;charset=UTF-8', + 'Connection' => 'keep-alive', + 'Content-Length' => File.read(real_file).size, + 'Last-Modified' => timestamp, + 'Date' => timestamp, + ) + end + + send_file real_file + else # failover - 'your princess is in another castle' + 'your princess is in another castle - lge' end end -after do - +post '/CheckSWAutoUpdate.laf' do t = Time.now + (8 * 60 * 60) timestamp = t.strftime('%a, %d %b %Y %H:%m:%S GMT') - if @type.eql?(:aic) - response['Server'] = 'Apache' - response['Content-Disposition'] = sprintf('attachment; filename="%s"', @fake_file) - response['Content-Transfer-Encoding'] = 'binary' - response['Content-Type'] = 'image/jpeg;charset=UTF-8' - response['Connection'] = 'keep-alive' - response['Content-Length'] = File.read(@real_file).size - response['Last-Modified'] = timestamp - response['Date'] = timestamp - end + string = " +900 +Success +00000000008613244660 +http://snu.lge.com/fizbuzz +400 +fizzbuzz +04 +30.50 +Y + +#{timestamp} +01 +http://snu.lge.com/fizzbuzz + +" - @type = @real_file = @fake_file = nil + payload = Base64.strict_encode64(string) + + headers( + 'Date' => timestamp, + 'Pragma' => 'no-cache', + 'Expires' => '-1', + 'Content-Type' => 'application/octet-stream;charset=UTF-8', + 'Content-Length' => payload.size, + ) + + payload +end + +after do + # noop for now end \ No newline at end of file diff --git a/lg_webOS/json-list.rb b/lg_webOS/json-list.rb index 620d2b5..f7ee924 100644 --- a/lg_webOS/json-list.rb +++ b/lg_webOS/json-list.rb @@ -20,8 +20,8 @@ start.downto(0).each do |i| puts sprintf(' [%s/%s] [%.2f%%]', i, start, (start.to_f / i.to_f) * 100) end - url = sprintf('http://%s:%s/json/list?t=%s', h, p, i) - data = nil + url = sprintf('http://%s:%s/json/list?t=%s', h, p, i) + data = nil begin response = Utility.get_url(url) diff --git a/lg_webOS/webos.paw b/lg_webOS/webos.paw index b73613a..3188530 100644 Binary files a/lg_webOS/webos.paw and b/lg_webOS/webos.paw differ