Browse files

now supporting secrets in admin port

  • Loading branch information...
1 parent ec3b596 commit a0c63701c66aaae3bb79321ed3a043771db8ea4d @wfelipe wfelipe committed Oct 21, 2010
Showing with 158 additions and 72 deletions.
  1. +53 −30 lang/wp-varnish-pt_BR.po
  2. +40 −25 lang/wp-varnish.pot
  3. +14 −4 wp-varnish.js
  4. +51 −13 wp-varnish.php
View
83 lang/wp-varnish-pt_BR.po
@@ -5,7 +5,8 @@ msgstr ""
"POT-Creation-Date: 2010-08-04 17:15-0300\n"
"PO-Revision-Date: 2010-10-20 23:30-0300\n"
"Last-Translator: Wilson Felipe <wfelipe@gmail.com>\n"
-"Language-Team: Hugo Cisneiros <hugo.cisneiros@gmail.com>, Wilson Felipe <wfelipe@gmail.com>\n"
+"Language-Team: Hugo Cisneiros <hugo.cisneiros@gmail.com>, Wilson Felipe "
+"<wfelipe@gmail.com>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
@@ -17,83 +18,105 @@ msgstr ""
"X-Poedit-SourceCharset: utf-8\n"
"X-Poedit-SearchPath-0: wp-varnish\n"
-#: ../wp-varnish.php:145
+#: ../wp-varnish.php:152
msgid "WP-Varnish Configuration"
msgstr "Configuração do WP-Varnish"
-#: ../wp-varnish.php:190
+#: ../wp-varnish.php:202
msgid "Settings Saved!"
msgstr "Configurações Salvas!"
-#: ../wp-varnish.php:192
+#: ../wp-varnish.php:204
msgid "You do not have the privileges."
msgstr "Você não tem os privilégios necessários."
-#: ../wp-varnish.php:203
+#: ../wp-varnish.php:215
msgid "WordPress Varnish Administration"
msgstr "Administração do Varnish no WordPress"
-#: ../wp-varnish.php:204
+#: ../wp-varnish.php:216
msgid "IP address and port configuration"
msgstr "Configuração de Endereços IP e Portas"
-#: ../wp-varnish.php:210
-msgid "These values can't be edited since there's a global configuration located in <em>wp-config.php</em>. If you want to change these settings, please update the file or contact the administrator."
-msgstr "Estes valores não podem ser editados, pois existe uma configuração global localizada no <em>wp-config.php</em>. Se você deseja mudar estas configurações, por favor atualize o arquivo ou entre em contato com o administrador."
+#: ../wp-varnish.php:222
+msgid ""
+"These values can't be edited since there's a global configuration located in "
+"<em>wp-config.php</em>. If you want to change these settings, please update "
+"the file or contact the administrator."
+msgstr ""
+"Estes valores não podem ser editados, pois existe uma configuração global "
+"localizada no <em>wp-config.php</em>. Se você deseja mudar estas "
+"configurações, por favor atualize o arquivo ou entre em contato com o "
+"administrador."
-#: ../wp-varnish.php:213
+#: ../wp-varnish.php:225
msgid "Current configuration:"
msgstr "Configuração atual:"
-#: ../wp-varnish.php:217
+#: ../wp-varnish.php:229
msgid "Server: "
msgstr "Servidor: "
-#: ../wp-varnish.php:217
+#: ../wp-varnish.php:229
msgid "Port: "
msgstr "Porta: "
-#: ../wp-varnish.php:227
+#: ../wp-varnish.php:239
msgid "Varnish Administration IP Address"
msgstr "Endereço IP de Administração do Varnish"
-#: ../wp-varnish.php:228
+#: ../wp-varnish.php:240
msgid "Varnish Administration Port"
msgstr "Porta de Administração do Varnish"
-#: ../wp-varnish.php:246
+#: ../wp-varnish.php:241
+msgid "Varnish Secret"
+msgstr "Varnish Secret"
+
+#: ../wp-varnish.php:260
msgid "Add one more server"
msgstr "Adicionar mais um servidor"
-#: ../wp-varnish.php:252
+#: ../wp-varnish.php:266
msgid "Timeout"
msgstr "Timeout"
-#: ../wp-varnish.php:252
+#: ../wp-varnish.php:266
msgid "seconds"
msgstr "segundos"
-#: ../wp-varnish.php:254
+#: ../wp-varnish.php:268
msgid "Use admin port instead of PURGE method."
msgstr "Usar porta de administração ao invés do método PURGE."
-#: ../wp-varnish.php:256
-msgid "Also purge all page navigation (experimental, use carefully, it will include a bit more load on varnish servers.)"
-msgstr "Também limpar o cache de toda navegação de páginas (experimental, use com cuidado, irá colocar um pouco de carga a mais nos servidores varnish.)"
+#: ../wp-varnish.php:270
+msgid ""
+"Also purge all page navigation (experimental, use carefully, it will include "
+"a bit more load on varnish servers.)"
+msgstr ""
+"Também limpar o cache de toda navegação de páginas (experimental, use com "
+"cuidado, irá colocar um pouco de carga a mais nos servidores varnish.)"
-#: ../wp-varnish.php:258
-msgid "Also purge all comment navigation (experimental, use carefully, it will include a bit more load on varnish servers.)"
-msgstr "Também limpar o cache de toda navegação de comentários (experimental, use com cuidado, irá colocar um pouco de carga a mais nos servidores varnish.)"
+#: ../wp-varnish.php:272
+msgid ""
+"Also purge all comment navigation (experimental, use carefully, it will "
+"include a bit more load on varnish servers.)"
+msgstr ""
+"Também limpar o cache de toda navegação de comentários (experimental, use "
+"com cuidado, irá colocar um pouco de carga a mais nos servidores varnish.)"
-#: ../wp-varnish.php:260
+#: ../wp-varnish.php:274
msgid "Save Changes"
msgstr "Salvar Mudanças"
-#: ../wp-varnish.php:262
+#: ../wp-varnish.php:276
msgid "Purge All Blog Cache"
msgstr "Limpar Todo Cache do Blog"
-#: ../wp-varnish.php:262
-msgid "Use only if necessary, and carefully as this will include a bit more load on varnish servers."
-msgstr "Use apenas se necessário, e com cuidado pois irá colocar um pouco de carga a mais nos servidores varnish."
-
+#: ../wp-varnish.php:276
+msgid ""
+"Use only if necessary, and carefully as this will include a bit more load on "
+"varnish servers."
+msgstr ""
+"Use apenas se necessário, e com cuidado pois irá colocar um pouco de carga a "
+"mais nos servidores varnish."
View
65 lang/wp-varnish.pot
@@ -5,90 +5,105 @@ msgstr ""
"POT-Creation-Date: 2010-08-04 17:15-0300\n"
"PO-Revision-Date: 2010-10-20 23:33-0200\n"
"Last-Translator: Wilson Felipe <wfelipe@gmail.com>\n"
-"Language-Team: Hugo Cisneiros <hugo.cisneiros@gmail.com>, Wilson Felipe <wfelipe@gmail.com>\n"
+"Language-Team: Hugo Cisneiros <hugo.cisneiros@gmail.com>, Wilson Felipe "
+"<wfelipe@gmail.com>\n"
+"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Poedit-KeywordsList: __;_;gettext;gettext_noop\n"
"X-Poedit-Basepath: .\n"
"X-Poedit-SearchPath-0: ..\n"
-#: ../wp-varnish.php:145
+#: ../wp-varnish.php:152
msgid "WP-Varnish Configuration"
msgstr ""
-#: ../wp-varnish.php:190
+#: ../wp-varnish.php:202
msgid "Settings Saved!"
msgstr ""
-#: ../wp-varnish.php:192
+#: ../wp-varnish.php:204
msgid "You do not have the privileges."
msgstr ""
-#: ../wp-varnish.php:203
+#: ../wp-varnish.php:215
msgid "WordPress Varnish Administration"
msgstr ""
-#: ../wp-varnish.php:204
+#: ../wp-varnish.php:216
msgid "IP address and port configuration"
msgstr ""
-#: ../wp-varnish.php:210
-msgid "These values can't be edited since there's a global configuration located in <em>wp-config.php</em>. If you want to change these settings, please update the file or contact the administrator."
+#: ../wp-varnish.php:222
+msgid ""
+"These values can't be edited since there's a global configuration located in "
+"<em>wp-config.php</em>. If you want to change these settings, please update "
+"the file or contact the administrator."
msgstr ""
-#: ../wp-varnish.php:213
+#: ../wp-varnish.php:225
msgid "Current configuration:"
msgstr ""
-#: ../wp-varnish.php:217
+#: ../wp-varnish.php:229
msgid "Server: "
msgstr ""
-#: ../wp-varnish.php:217
+#: ../wp-varnish.php:229
msgid "Port: "
msgstr ""
-#: ../wp-varnish.php:227
+#: ../wp-varnish.php:239
msgid "Varnish Administration IP Address"
msgstr ""
-#: ../wp-varnish.php:228
+#: ../wp-varnish.php:240
msgid "Varnish Administration Port"
msgstr ""
-#: ../wp-varnish.php:246
+#: ../wp-varnish.php:241
+msgid "Varnish Secret"
+msgstr ""
+
+#: ../wp-varnish.php:260
msgid "Add one more server"
msgstr ""
-#: ../wp-varnish.php:252
+#: ../wp-varnish.php:266
msgid "Timeout"
msgstr ""
-#: ../wp-varnish.php:252
+#: ../wp-varnish.php:266
msgid "seconds"
msgstr ""
-#: ../wp-varnish.php:254
+#: ../wp-varnish.php:268
msgid "Use admin port instead of PURGE method."
msgstr ""
-#: ../wp-varnish.php:256
-msgid "Also purge all page navigation (experimental, use carefully, it will include a bit more load on varnish servers.)"
+#: ../wp-varnish.php:270
+msgid ""
+"Also purge all page navigation (experimental, use carefully, it will include "
+"a bit more load on varnish servers.)"
msgstr ""
-#: ../wp-varnish.php:258
-msgid "Also purge all comment navigation (experimental, use carefully, it will include a bit more load on varnish servers.)"
+#: ../wp-varnish.php:272
+msgid ""
+"Also purge all comment navigation (experimental, use carefully, it will "
+"include a bit more load on varnish servers.)"
msgstr ""
-#: ../wp-varnish.php:260
+#: ../wp-varnish.php:274
msgid "Save Changes"
msgstr ""
-#: ../wp-varnish.php:262
+#: ../wp-varnish.php:276
msgid "Purge All Blog Cache"
msgstr ""
-#: ../wp-varnish.php:262
-msgid "Use only if necessary, and carefully as this will include a bit more load on varnish servers."
+#: ../wp-varnish.php:276
+msgid ""
+"Use only if necessary, and carefully as this will include a bit more load on "
+"varnish servers."
msgstr ""
View
18 wp-varnish.js
@@ -2,13 +2,15 @@
// so we need a base
var rowCount = 0;
-function createRow(tableID, id, addr, port) {
+function createRow(tableID, id, addr, port, secret) {
var row = document.createElement ('tr');
var td1 = document.createElement ('td');
var td2 = document.createElement ('td');
var td3 = document.createElement ('td');
+ var td4 = document.createElement ('td');
var wpv_addr = document.createElement ('input');
var wpv_port = document.createElement ('input');
+ var wpv_secret = document.createElement ('input');
var dRow = document.createElement ('input');
wpv_addr.className = "regular-text";
@@ -23,6 +25,12 @@ function createRow(tableID, id, addr, port) {
wpv_port.name = "wpvarnish_port[]";
wpv_port.value = port || "";
+ wpv_secret.className = "regular-text";
+ wpv_secret.type = "text";
+ wpv_secret.id = id;
+ wpv_secret.name = "wpvarnish_secret[]";
+ wpv_secret.value = secret || "";
+
dRow.className = "";
dRow.type = "button";
dRow.name = "deleteRow";
@@ -32,19 +40,21 @@ function createRow(tableID, id, addr, port) {
td1.appendChild (wpv_addr);
td2.appendChild (wpv_port);
- td3.appendChild (dRow);
+ td3.appendChild (wpv_secret);
+ td4.appendChild (dRow);
row.appendChild (td1);
row.appendChild (td2);
row.appendChild (td3);
+ row.appendChild (td4);
return row;
}
-function addRow(tableID, id, addr, port) {
+function addRow(tableID, id, addr, port, secret) {
var tbody = document.getElementById(tableID).getElementsByTagName ('tbody')[0];
rowCount++;
- var row = createRow(tableID, id, addr, port);
+ var row = createRow(tableID, id, addr, port, secret);
tbody.appendChild (row);
}
View
64 wp-varnish.php
@@ -26,6 +26,7 @@
class WPVarnish {
public $wpv_addr_optname;
public $wpv_port_optname;
+ public $wpv_secret_optname;
public $wpv_timeout_optname;
public $wpv_update_pagenavi_optname;
public $wpv_update_commentnavi_optname;
@@ -35,12 +36,14 @@ function WPVarnish() {
$this->wpv_addr_optname = "wpvarnish_addr";
$this->wpv_port_optname = "wpvarnish_port";
+ $this->wpv_secret_optname = "wpvarnish_secret";
$this->wpv_timeout_optname = "wpvarnish_timeout";
$this->wpv_update_pagenavi_optname = "wpvarnish_update_pagenavi";
$this->wpv_update_commentnavi_optname = "wpvarnish_update_commentnavi";
$this->wpv_use_adminport_optname = "wpvarnish_use_adminport";
$wpv_addr_optval = array ("127.0.0.1");
$wpv_port_optval = array (80);
+ $wpv_secret_optval = array ("");
$wpv_timeout_optval = 5;
$wpv_update_pagenavi_optval = 0;
$wpv_update_commentnavi_optval = 0;
@@ -54,6 +57,10 @@ function WPVarnish() {
add_option($this->wpv_port_optname, $wpv_port_optval, '', 'yes');
}
+ if ( (get_option($this->wpv_secret_optname) == FALSE) ) {
+ add_option($this->wpv_secret_optname, $wpv_secret_optval, '', 'yes');
+ }
+
if ( (get_option($this->wpv_timeout_optname) == FALSE) ) {
add_option($this->wpv_timeout_optname, $wpv_timeout_optval, '', 'yes');
}
@@ -160,6 +167,11 @@ function WPVarnishAdmin() {
update_option($this->wpv_port_optname, $wpv_port_optval);
}
+ if (!empty($_POST["$this->wpv_secret_optname"])) {
+ $wpv_secret_optval = $_POST["$this->wpv_secret_optname"];
+ update_option($this->wpv_secret_optname, $wpv_secret_optval);
+ }
+
if (!empty($_POST["$this->wpv_timeout_optname"])) {
$wpv_timeout_optval = $_POST["$this->wpv_timeout_optname"];
update_option($this->wpv_timeout_optname, $wpv_timeout_optval);
@@ -213,7 +225,7 @@ function WPVarnishAdmin() {
echo "<h3>" . __("Current configuration:",'wp-varnish') . "</h3>\n";
echo "<ul>";
foreach ($varnish_servers as $server) {
- list ($host, $port) = explode(':', $server);
+ list ($host, $port, $secret) = explode(':', $server);
echo "<li>" . __("Server: ",'wp-varnish') . $host . "<br/>" . __("Port: ",'wp-varnish') . $port . "</li>";
}
echo "</ul>";
@@ -226,15 +238,17 @@ function WPVarnishAdmin() {
<tr valign="top">
<th scope="row"><?php echo __("Varnish Administration IP Address",'wp-varnish'); ?></th>
<th scope="row"><?php echo __("Varnish Administration Port",'wp-varnish'); ?></th>
+ <th scope="row"><?php echo __("Varnish Secret",'wp-varnish'); ?></th>
</tr>
<script>
<?php
$addrs = get_option($this->wpv_addr_optname);
$ports = get_option($this->wpv_port_optname);
+ $secrets = get_option($this->wpv_secret_optname);
echo "rowCount = $i\n";
for ($i = 0; $i < count ($addrs); $i++) {
// let's center the row creation in one spot, in javascript
- echo "addRow('form-table', $i, '$addrs[$i]', $ports[$i]);\n";
+ echo "addRow('form-table', $i, '$addrs[$i]', $ports[$i], '$secrets[$i]');\n";
} ?>
</script>
</table>
@@ -279,6 +293,7 @@ function WPVarnishPurgeObject($wpv_url) {
} else {
$wpv_purgeaddr = get_option($this->wpv_addr_optname);
$wpv_purgeport = get_option($this->wpv_port_optname);
+ $wpv_secret = get_option($this->wpv_secret_optname);
}
$wpv_timeout = get_option($this->wpv_timeout_optname);
@@ -290,25 +305,48 @@ function WPVarnishPurgeObject($wpv_url) {
$wpv_blogaddr = preg_replace($wpv_replace_wpurl, "$2", $wpv_wpurl);
$wpv_url = $wpv_blogaddr . $wpv_url;
- echo "ADMIN PORT";
for ($i = 0; $i < count ($wpv_purgeaddr); $i++) {
$varnish_sock = fsockopen($wpv_purgeaddr[$i], $wpv_purgeport[$i], $errno, $errstr, $wpv_timeout);
if (!$varnish_sock) {
error_log("wp-varnish error: $errstr ($errno)");
- } else {
- # use admin port instead of PURGE?
- if($wpv_use_adminport) {
- $out = "purge req.url ~ ^$wpv_url && req.http.host == $wpv_host\n";
- } else {
- $out = "PURGE $wpv_url HTTP/1.0\r\n";
- $out .= "Host: $wpv_host\r\n";
- $out .= "Connection: Close\r\n\r\n";
+ return;
+ }
+
+ if($wpv_use_adminport) {
+ $buf = fread($varnish_sock, 1024);
+ if(preg_match('/(\w+)\s+Authentication required./', $buf, &$matches)) {
+ # get the secret
+ $secret = "1beb871d-987a-4bbd-98aa-408e3de596cb";
+ fwrite($varnish_sock, "auth " . $this->WPAuth($matches[1], $secret) . "\n");
+ $buf = fread($varnish_sock, 1024);
+ if(!preg_match('/^200/', $buf)) {
+ error_log("wp-varnish error: authentication failed using admin port");
+ fclose($varnish_sock);
+ return;
+ }
}
- fwrite($varnish_sock, $out);
- fclose($varnish_sock);
+ $out = "purge req.url ~ ^$wpv_url && req.http.host == $wpv_host\n";
+ } else {
+ $out = "PURGE $wpv_url HTTP/1.0\r\n";
+ $out .= "Host: $wpv_host\r\n";
+ $out .= "Connection: Close\r\n\r\n";
}
+ fwrite($varnish_sock, $out);
+ fclose($varnish_sock);
}
}
+
+ function WPAuth($challenge, $secret) {
+ $ctx = hash_init('sha256');
+ hash_update($ctx, $challenge);
+ hash_update($ctx, "\n");
+ hash_update($ctx, $secret . "\n");
+ hash_update($ctx, $challenge);
+ hash_update($ctx, "\n");
+ $sha256 = hash_final($ctx);
+
+ return $sha256;
+ }
}
$wpvarnish = & new WPVarnish();

0 comments on commit a0c6370

Please sign in to comment.