]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
Fix #1574 - imagecache: add option to ignore all invalid SSL certificates
authorAdam Sutton <dev@adamsutton.me.uk>
Wed, 6 Feb 2013 16:17:51 +0000 (16:17 +0000)
committerAdam Sutton <dev@adamsutton.me.uk>
Thu, 7 Feb 2013 21:29:40 +0000 (21:29 +0000)
src/imagecache.c
src/imagecache.h
src/webui/extjs.c
src/webui/static/app/config.js

index 53198945fb79c8a3e80dd8623cc6575245aeef4c..44bd6506d5be41886b466a3676b3348737327ddc 100644 (file)
@@ -76,6 +76,7 @@ static void  _imagecache_save   ( imagecache_image_t *img );
 uint32_t                              imagecache_enabled;
 uint32_t                              imagecache_ok_period;
 uint32_t                              imagecache_fail_period;
+uint32_t                              imagecache_ignore_sslcert;
 
 static pthread_cond_t                 _imagecache_cond;
 static TAILQ_HEAD(, imagecache_image) _imagecache_queue;
@@ -106,11 +107,12 @@ void imagecache_init ( void )
   uint32_t id;
 
   /* Init vars */
-  _imagecache_id         = 0;
+  _imagecache_id            = 0;
 #if ENABLE_IMAGECACHE
-  imagecache_enabled     = 0;
-  imagecache_ok_period   = 24 * 7; // weekly
-  imagecache_fail_period = 24;     // daily
+  imagecache_enabled        = 0;
+  imagecache_ok_period      = 24 * 7; // weekly
+  imagecache_fail_period    = 24;     // daily
+  imagecache_ignore_sslcert = 0;
 #endif
 
   /* Create threads */
@@ -126,6 +128,7 @@ void imagecache_init ( void )
     htsmsg_get_u32(m, "enabled", &imagecache_enabled);
     htsmsg_get_u32(m, "ok_period", &imagecache_ok_period);
     htsmsg_get_u32(m, "fail_period", &imagecache_fail_period);
+    htsmsg_get_u32(m, "ignore_sslcert", &imagecache_ignore_sslcert);
     htsmsg_destroy(m);
   }
 #endif
@@ -173,9 +176,10 @@ void imagecache_init ( void )
 void imagecache_save ( void )
 {
   htsmsg_t *m = htsmsg_create_map();
-  htsmsg_add_u32(m, "enabled",     imagecache_enabled);
-  htsmsg_add_u32(m, "ok_period",   imagecache_ok_period);
-  htsmsg_add_u32(m, "fail_period", imagecache_fail_period);
+  htsmsg_add_u32(m, "enabled",        imagecache_enabled);
+  htsmsg_add_u32(m, "ok_period",      imagecache_ok_period);
+  htsmsg_add_u32(m, "fail_period",    imagecache_fail_period);
+  htsmsg_add_u32(m, "ignore_sslcert", imagecache_ignore_sslcert);
   hts_settings_save(m, "imagecache/config");
 }
 
@@ -213,6 +217,17 @@ int imagecache_set_fail_period ( uint32_t p )
   imagecache_fail_period = p;
   return 1;
 }
+
+/*
+ * Set ignore SSL cert
+ */
+int imagecache_set_ignore_sslcert ( uint32_t p )
+{
+  if (p == imagecache_ignore_sslcert)
+    return 0;
+  imagecache_ignore_sslcert = p;
+  return 1;
+}
 #endif
 
 /*
@@ -406,7 +421,8 @@ static int _imagecache_fetch ( imagecache_image_t *img )
   if (!(fp = fopen(tmp, "wb")))
     return 1;
   
-  /* Fetch file */
+  /* Build command */
+  pthread_mutex_lock(&imagecache_mutex);
   tvhlog(LOG_DEBUG, "imagecache", "fetch %s", img->url);
   curl = curl_easy_init();
   curl_easy_setopt(curl, CURLOPT_URL,         img->url);
@@ -415,6 +431,11 @@ static int _imagecache_fetch ( imagecache_image_t *img )
   curl_easy_setopt(curl, CURLOPT_TIMEOUT,     120);
   curl_easy_setopt(curl, CURLOPT_NOPROGRESS,  1);
   curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1);
+  if (imagecache_ignore_sslcert)
+    curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0);
+  pthread_mutex_unlock(&imagecache_mutex);
+
+  /* Fetch */
   res = curl_easy_perform(curl);
   curl_easy_cleanup(curl);
   fclose(fp);
index 5776f46f9164ce0e76d3ca6d4e125f58d22053ef..c96b3186836e8a9ce1c35d3848c8e56dce62ef6a 100644 (file)
@@ -24,6 +24,7 @@
 extern uint32_t imagecache_enabled;
 extern uint32_t imagecache_ok_period;
 extern uint32_t imagecache_fail_period;
+extern uint32_t imagecache_ignore_sslcert;
 
 extern pthread_mutex_t imagecache_mutex;
 
@@ -37,6 +38,8 @@ int      imagecache_set_ok_period   ( uint32_t e )
   __attribute__((warn_unused_result));
 int      imagecache_set_fail_period ( uint32_t e )
   __attribute__((warn_unused_result));
+int      imagecache_set_ignore_sslcert ( uint32_t e )
+  __attribute__((warn_unused_result));
 
 // Note: will return 0 if invalid (must serve original URL)
 uint32_t imagecache_get_id  ( const char *url );
index 8f1be79797e6290555eea6c92b3856caa8b9536e..c11ec87ae353179e884ff4d9196809bebac0e4f8 100644 (file)
@@ -1982,6 +1982,7 @@ extjs_config(http_connection_t *hc, const char *remain, void *opaque)
     htsmsg_add_u32(m, "imagecache_enabled",     imagecache_enabled);
     htsmsg_add_u32(m, "imagecache_ok_period",   imagecache_ok_period);
     htsmsg_add_u32(m, "imagecache_fail_period", imagecache_fail_period);
+    htsmsg_add_u32(m, "imagecache_ignore_sslcert", imagecache_ignore_sslcert);
     pthread_mutex_unlock(&imagecache_mutex);
 #endif
 
@@ -2011,6 +2012,8 @@ extjs_config(http_connection_t *hc, const char *remain, void *opaque)
       save |= imagecache_set_ok_period(atoi(str));
     if ((str = http_arg_get(&hc->hc_req_args, "imagecache_fail_period")))
       save |= imagecache_set_fail_period(atoi(str));
+    str = http_arg_get(&hc->hc_req_args, "imagecache_ignore_sslcert");
+    save |= imagecache_set_ignore_sslcert(!!str);
     if (save)
       imagecache_save();
     pthread_mutex_unlock(&imagecache_mutex);
index b71a4a5d4232de21c19a6582328cb77995e98103..183b8eef6a9b22150a94d803483b828dc692459e 100644 (file)
@@ -39,7 +39,7 @@ tvheadend.miscconf = function() {
                root : 'config'
        }, [ 'muxconfpath', 'language',
        'imagecache_enabled', 'imagecache_ok_period',
-       'imagecache_fail_period']);
+       'imagecache_fail_period', 'imagecache_ignore_sslcert']);
 
        /* ****************************************************************
         * Form Fields
@@ -93,12 +93,18 @@ tvheadend.miscconf = function() {
     fieldLabel: 'Re-try period (hours)',
   });
 
+  var imagecacheIgnoreSSLCert = new Ext.form.Checkbox({
+    name: 'imagecache_ignore_sslcert',
+    fieldLabel: 'Ignore invalid SSL certificate'
+  });
+
   var imagecachePanel = new Ext.form.FieldSet({
     title: 'Image Caching',
     width: 700,
     autoHeight: true,
     collapsible: true,
-    items : [ imagecacheEnabled, imagecacheOkPeriod, imagecacheFailPeriod ]
+    items : [ imagecacheEnabled, imagecacheOkPeriod, imagecacheFailPeriod,
+              imagecacheIgnoreSSLCert ]
   });
   if (tvheadend.capabilities.indexOf('imagecache') == -1)
     imagecachePanel.hide();