weixin_39617006
weixin_39617006
2020-11-29 13:20

Local icons - Cache channel icons

This PR adds the ability to cache channel icons locally. Add icons in as normal and enable it through general config tab (Also requires TVH ip to be added in). TVH will then pull all icons down and store them in the ~/.hts/tvheadend/icons/ folder. When an htsp client requests a channel icon it will query TVH via the virtual url /logo/logoname.jpg, the iconserve.c routine will then check if the icon is cached, if it is it will be served via a redirect to the virtual url /iconserve/logoname.jpg If the icon doesn't exist it will try to download it to the cache, if that fails it will simply redirect the user to the real logo url (non-caching).

该提问来源于开源项目:tvheadend/tvheadend

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

10条回答

  • weixin_39657300 weixin_39657300 5月前

    Giving anonymous access to files located on the disk can be dangerous. There are a few tricks that can be used in order to gain access to sensitive information.

    For example, "../../accesscontrol/1" , or if you got limited access to the filesystem, symlinking to /etc/shadow. They might not be exploitable but we should be cautious.

    There is support for issuing tickets to resources that can be used without password access. The tickets are only valid for 5 minutes but perhaps that is enough?

    点赞 评论 复制链接分享
  • weixin_39939303 weixin_39939303 5月前

    -tornblom We should actually fix that in the TVH webserver ;)

    However this is a good point and having not read the PR code I think I might need to suggest an alternative. But I'll leave my comments until AFTER I've read the code :)

    Adam

    点赞 评论 复制链接分享
  • weixin_39939303 weixin_39939303 5月前

    Ok, I've started reading the code and I think it needs simplifying.

    Here's what I would do: 1. All channel logo returns (and references in the the UI) should be re-written to be something like /channellogo/CHANID. 2. You then need a handler within the web server code that will handle ALL /channellogo/* pages and extract the CHANID 3. Lookup the channel. if not found return server error. 4. No lookup in the cache whether the channel logo has been cached, need to define how this is done. But it should explicitly list the orig URL (to ensure its not been changed) and the local file (this might be implicit, such as by using a hash of the original URL?). 5. If logo is in the cache return it, if its not, return the original URL.

    OK that deals with the serving of logos whether cached or not, next... 1. Create a thread that will continually process a list of remote icons that should be fetched and cached. 2. When user changes the configuration (adds icon) it should insert in the above list (Note: possibly need to remove old cached icon? - beware if you're sharing icons need to handle this - ideally don't want to have multiple local copies but it wouldn't be the end of the world). 3. When the thread fetches a logo it should: - store the file - update any info to say the cached file exists (if required) - inform htsp of a channel logo change (so it now uses the cached version).

    OK, think that deals with caching, might be a bit more to that.

    Some things that need to be considered: - what happens if icons are added (uncached) and then user enables caching. Possibly in this case you need to scan all channels to check if icons currently not cached and add to list. - Caching enable/disable only needs to affect the adding of new icons to the fetch thread list (you could stop/start the thread, but not really necessary since if nothing is added to the list the thread should be dormant anyway).

    Adam

    点赞 评论 复制链接分享
  • weixin_39939303 weixin_39939303 5月前

    For reference: http://pastebin.com/eRQUxEuw

    点赞 评论 复制链接分享
  • weixin_39617006 weixin_39617006 5月前

    , when you get a sec can you take a look, have incorporated all the discussions, threading, etc, and running on my local stable.

    点赞 评论 复制链接分享
  • weixin_39939303 weixin_39939303 5月前

    I've added some fairly general comments, I need to review the guts of the code but I've timed out and didn't want you to think I'd forgotten it. I'll try and take a look later this week.

    But on first glance I think some mods will possibly be necessary to the main processing and storage, but I need to read it through properly before commenting.

    点赞 评论 复制链接分享
  • weixin_39617006 weixin_39617006 5月前

    no worries, thanks for the feedback so far, its working a dream on my local setup, but yes I agree the url part in the htsp message would be nice as it'll save that annoying ip request box. Will take your lead on this so catch up with you at some point

    点赞 评论 复制链接分享
  • weixin_39939303 weixin_39939303 5月前

    I've started working on integrating this. Although I've decided to rewrite most of it as I had some ideas to better generalise its usage and to cover some other use cases that have been requested in the past.

    It's mostly working (apart from HTSP and config) but I will try and tidy that up tonight.

    点赞 评论 复制链接分享
  • weixin_39617006 weixin_39617006 5月前

    No worries, thanks for the update, anything I can help with let me know.

    :-) I take it you do as little on new year as I do!

    Adam Sutton notifications.com wrote:

    I've started working on integrating this. Although I've decided to rewrite most of it as I had some ideas to better generalise its usage and to cover some other use cases that have been requested in the past.

    It's mostly working (apart from HTSP and config) but I will try and tidy that up tonight.

    Reply to this email directly or view it on GitHub: https://github.com/tvheadend/tvheadend/pull/174#issuecomment-11782360

    Sent from my Android phone with K-9 Mail. Please excuse my brevity.

    点赞 评论 复制链接分享
  • weixin_39939303 weixin_39939303 5月前

    this has now been merged. I merged your original code (squashed) and then overlayed my own.

    Adam

    点赞 评论 复制链接分享

相关推荐