-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshortcode-mailman-token.php
More file actions
80 lines (67 loc) · 2.06 KB
/
shortcode-mailman-token.php
File metadata and controls
80 lines (67 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
function initlab_shortcode_mailman_token($attrs, $content = null) {
$attrs = shortcode_atts([
'list_name' => '',
], $attrs);
if (empty($attrs['list_name'])) {
return '';
}
$options = get_option('initlab_options');
if (
empty($options) ||
!array_key_exists('mailman_secret', $options) ||
!array_key_exists('mailman_version', $options)
) {
return '';
}
$now = time();
if ($options['mailman_version'] === '2.1.16') {
$remote = $_SERVER['REMOTE_HOST'];
if (empty($remote)) {
$remote = $_SERVER['REMOTE_ADDR'];
}
if (empty($remote)) {
$remote = 'w.x.y.z';
}
}
else {
$remote = $_SERVER['REMOTE_ADDR'];
$separator = strpos($remote, '.') === false ? ':' : '.';
$parts = explode($separator, $remote);
if (count($parts) > 1) {
array_pop($parts);
}
$remote = implode($separator, $parts);
}
// TODO
$captchaIdx = '';
switch ($options['mailman_version']) {
case '2.1.16':
case '2.1.21':
$str = $options['mailman_secret'] . $now . $attrs['list_name'] . $remote;
break;
case '2.1.27':
$str = $options['mailman_secret'] . ':' . $now . ':' . $attrs['list_name'] . ':' . $remote;
break;
case '2.1.30':
$str = $options['mailman_secret'] . ':' . $now . ':' . $captchaIdx . ':' . $attrs['list_name'] . ':' . $remote;
break;
default:
return '';
}
$hash = sha1($str);
switch ($options['mailman_version']) {
case '2.1.16':
case '2.1.21':
case '2.1.27':
$token = $now . ':' . $hash;
break;
case '2.1.30':
$token = $now . ':' . $captchaIdx . ':' . $hash;
break;
default:
return '';
}
return '<input type="hidden" name="sub_form_token" value="' . $token . '">';
}
add_shortcode('initlab_mailman_token', 'initlab_shortcode_mailman_token');