implemented varnish conf generator/downloader
[varnish-caching-wordpress-plugin.git] / vcaching.php
blob:a/vcaching.php -> blob:b/vcaching.php
--- a/vcaching.php
+++ b/vcaching.php
@@ -3,7 +3,7 @@
 Plugin Name: VCaching
 Plugin URI: http://wordpress.org/extend/plugins/vcaching/
 Description: WordPress Varnish Cache integration.
-Version: 1.3.3
+Version: 1.4
 Author: Razvan Stanga
 Author URI: http://git.razvi.ro/
 License: http://www.apache.org/licenses/LICENSE-2.0
@@ -504,7 +504,7 @@
                 <a class="nav-tab <?php if($_GET['tab'] == 'console'): ?>nav-tab-active<?php endif; ?>" href="<?php echo admin_url() ?>index.php?page=<?=$this->plugin?>-plugin&amp;tab=console"><?=__('Console', $this->plugin)?></a>
             <?php endif; ?>
             <a class="nav-tab <?php if($_GET['tab'] == 'stats'): ?>nav-tab-active<?php endif; ?>" href="<?php echo admin_url() ?>index.php?page=<?=$this->plugin?>-plugin&amp;tab=stats"><?=__('Statistics', $this->plugin)?></a>
-            <a class="nav-tab <?php if($_GET['tab'] == 'conf'): ?>nav-tab-active<?php endif; ?>" href="<?php echo admin_url() ?>index.php?page=<?=$this->plugin?>-plugin&amp;tab=conf"><?=__('Varnish Config', $this->plugin)?></a>
+            <a class="nav-tab <?php if($_GET['tab'] == 'conf'): ?>nav-tab-active<?php endif; ?>" href="<?php echo admin_url() ?>index.php?page=<?=$this->plugin?>-plugin&amp;tab=conf"><?=__('Varnish VCLs', $this->plugin)?></a>
         </h2>
 
         <?php if(!isset($_GET['tab']) || $_GET['tab'] == 'options'): ?>
@@ -587,13 +587,9 @@
                             jQuery.getJSON("<?=$ipToHost['statsJson']?>", function(data) {
                                 var server = '#server_<?=$server?>';
                                 jQuery(server).html('');
-                                jQuery(server).append("<?= __('Stats generated on', $this->plugin) ?> " + data.timestamp);
-                                jQuery(server).append('<table class="fixed server_<?=$server?>">');
-                                jQuery(server).append('<thead><tr><td><strong><?= __('Description', $this->plugin) ?></strong></td><td><strong><?= __('Value', $this->plugin) ?></strong></td><td><strong><?= __('Key', $this->plugin) ?></strong></td></tr></thead>');
-                                jQuery(server).append('<tbody id="varnishstats_<?=$server?>"></tbody>');
-                                jQuery(server).append('</table>');
+                                jQuery(server).append('<p><?= __('Stats generated on', $this->plugin) ?> ' + data.timestamp + '</p>');
+                                jQuery(server).append('<table class="wp-list-table widefat fixed striped server_<?=$server?>"><thead><tr><td class="manage-column"><strong><?= __('Description', $this->plugin) ?></strong></td><td class="manage-column"><strong><?= __('Value', $this->plugin) ?></strong></td><td class="manage-column"><strong><?= __('Key', $this->plugin) ?></strong></td></tr></thead><tbody id="varnishstats_<?=$server?>"></tbody></table>');
                                 delete data.timestamp;
-                                console.log(data);
                                 jQuery.each(data, function(key, val) {
                                     jQuery('#varnishstats_<?=$server?>').append('<tr><td>'+val.description+'</td><td>'+val.value+'</td><td>'+key+'</td></tr>');
                                 });
@@ -727,7 +723,7 @@
     public function varnish_caching_purge_key()
     {
         ?>
-            <input type="text" name="varnish_caching_purge_key" id="varnish_caching_purge_key" size="100" value="<?php echo get_option($this->prefix . 'purge_key', 'ff93c3cb929cee86901c7eefc8088e9511c005492c6502a930360c02221cf8f4'); ?>" />
+            <input type="text" name="varnish_caching_purge_key" id="varnish_caching_purge_key" size="100" value="<?php echo get_option($this->prefix . 'purge_key'); ?>" />
             <span onclick="generateHash(64, 0, 'varnish_caching_purge_key'); return false;" class="dashicons dashicons-image-rotate" title="<?=__('Generate')?>"></span>
             <p class="description">
                 <?=__('Key used to purge Varnish cache. It is sent to Varnish as X-VC-Purge-Key header. Use a SHA-256 hash.<br />If you can\'t use ACL\'s, use this option. You can set the `purge key` in lib/purge.vcl.<br />Search the default value ff93c3cb929cee86901c7eefc8088e9511c005492c6502a930360c02221cf8f4 to find where to replace it.', $this->plugin)?>
@@ -738,7 +734,7 @@
     public function varnish_caching_cookie()
     {
         ?>
-            <input type="text" name="varnish_caching_cookie" id="varnish_caching_cookie" size="10" maxlength="10" value="<?php echo get_option($this->prefix . 'cookie', 'c005492c65'); ?>" />
+            <input type="text" name="varnish_caching_cookie" id="varnish_caching_cookie" size="10" maxlength="10" value="<?php echo get_option($this->prefix . 'cookie'); ?>" />
             <span onclick="generateHash(10, 0, 'varnish_caching_cookie'); return false;" class="dashicons dashicons-image-rotate" title="<?=__('Generate')?>"></span>
             <p class="description">
                 <?=__('This module sets a special cookie to tell Varnish that the user is logged in. This should be a random 10 chars string [0-9a-z]. You can set the `logged in cookie` in default.vcl.<br />Search the default value <i>c005492c65</i> to find where to replace it.', $this->plugin)?>
@@ -804,18 +800,18 @@
             $zip->open($tmpfile, ZipArchive::OVERWRITE);
             $files = array(
                 'default.vcl' => true,
-                'LICENSE' => '',
-                'README.rst' => '',
-                'conf/acl.vcl' => '',
+                'LICENSE' => false,
+                'README.rst' => false,
+                'conf/acl.vcl' => true,
                 'conf/backend.vcl' => true,
-                'lib/bigfiles.vcl' => array(),
-                'lib/bigfiles_pipe.vcl' => array(),
-                'lib/cloudflare.vcl' => array(),
-                'lib/mobile_cache.vcl' => array(),
-                'lib/mobile_pass.vcl' => array(),
+                'lib/bigfiles.vcl' => false,
+                'lib/bigfiles_pipe.vcl' => false,
+                'lib/cloudflare.vcl' => false,
+                'lib/mobile_cache.vcl' => false,
+                'lib/mobile_pass.vcl' => false,
                 'lib/purge.vcl' => true,
-                'lib/static.vcl' => array(),
-                'lib/xforward.vcl' => array(),
+                'lib/static.vcl' => false,
+                'lib/xforward.vcl' => false,
             );
             foreach ($files as $file => $parse) {
                 $filepath = __DIR__ . '/varnish-conf/v' . $version . '/' . $file;
@@ -912,6 +908,20 @@
                 $content .= "\tset req.backend_hint = backends.backend();\n";
                 $content .= "}\n";
             }
+        } else if ($file == 'conf/acl.vcl') {
+            $acls = get_option($this->prefix . 'varnish_acls');
+            $acls = explode(',', $acls);
+            $content = "acl cloudflare {\n";
+            $content .= "\t# set this ip to your Railgun IP (if applicable)\n";
+            $content .= "\t# \"1.2.3.4\";\n";
+            $content .= "}\n";
+            $content .= "\nacl purge {\n";
+            $content .= "\t\"localhost\";\n";
+            $content .= "\t\"127.0.0.1\";\n";
+            foreach ($acls as $acl) {
+                $content .= "\t\"" . $acl . "\";\n";
+            }
+            $content .= "}\n";
         } else if ($file == 'lib/purge.vcl') {
             $purge_key = get_option($this->prefix . 'purge_key');
             $content = str_replace('ff93c3cb929cee86901c7eefc8088e9511c005492c6502a930360c02221cf8f4', $purge_key, $content);

comments