-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.php
More file actions
180 lines (175 loc) · 6.37 KB
/
config.php
File metadata and controls
180 lines (175 loc) · 6.37 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
<?php
require_once INCLUDE_DIR . 'class.plugin.php';
require_once INCLUDE_DIR . 'class.message.php';
class RewriterPluginConfig extends PluginConfig {
// Provide compatibility function for versions of osTicket prior to
// translation support (v1.9.4)
function translate() {
if (! method_exists('Plugin', 'translate')) {
return array(
function ($x) {
return $x;
},
function ($x, $y, $n) {
return $n != 1 ? $y : $x;
}
);
}
return Plugin::translate('rewriter');
}
function pre_save($config, &$errors) {
// validate expressions, add warnings etc.
if ($config['regex-rewrite']) {
$rules = explode("\n", $config['regex-rewrite']);
foreach ($rules as $rule) {
if (! $rule)
continue;
list ($pattern, $replacement) = explode(':', $rule);
if (false === @preg_match($pattern, null)) {
$errors['err'] = 'Cannot compile regular expression:' . $pattern;
return false;
}
Messages::success("Regex $pattern will be replaced with $replacement");
}
}
if ($config['text-rewrite']) {
$rules = explode("\n", $config['text-rewrite']);
foreach ($rules as $rule) {
if (! $rule)
continue;
list ($pattern, $replacement) = explode(':', $rule);
Messages::success("String $pattern will be replaced with $replacement");
}
}
if ($config['email-rewrite']) {
$rules = explode("\n", $config['email-rewrite']);
foreach ($rules as $rule) {
if (! $rule)
continue;
list ($pattern, $replacement) = explode(':', $rule);
Messages::success(
"Email string $pattern will be replaced with $replacement");
}
}
return TRUE;
}
/**
* Build an Admin settings page.
*
* {@inheritdoc}
*
* @see PluginConfig::getOptions()
*/
function getOptions() {
list ($__, $_N) = self::translate();
// TODO: figure out the domain-name from $cfg->get('helpdesk_url').. except it's not available yet (in bootstrap cycle I mean)
return array(
'ri' => new SectionBreakField(
array(
'label' => $__('Rewriter Configuration')
)),
'log' => new BooleanField(
array(
'default' => FALSE,
'label' => $__('Show rewriting in logs'),
'hint' => $__(
"Enable to aid debugging, logs appear in Admin -> Dashboard -> System Logs")
)),
'domains' => new TextareaField(
array(
'label' => $__('Forward Rewritable Domains'),
'placeholder' => $__(
'Enter your trusted domain names, ie: company.com.tld'),
'hint' => $__(
"Separate with a comma if more than one required, not email addresses, full domains (the part after @), if empty, Nobody is allowed to forward."),
'configuration' => array(
'html' => FALSE
)
)),
'note' => new BooleanField(
array(
'default' => TRUE,
'label' => $__('Show rewriting in text'),
'hint' => $__('Adds the following note.')
)),
'note-text' => new TextareaField(
array(
'default' => $__(
'Ticket modified upon receipt as it was forwarded to us.'),
'label' => $__('Note Text'),
'hint' => $__('This get\'s prepended to the message body')
)),
'dr' => new SectionBreakField(
array(
'label' => 'Explicitly defined parsers'
)),
'drupal' => new BooleanField(
array(
'default' => TRUE,
'label' => $__('Rewrite Drupal Contact Form emails'),
'hint' => $__(
"Rewrite Drupal contact-form emails.")
)),
'zendesk' => new BooleanField(
array(
'default' => FALSE,
'label' => $__('Rewrite Zendesk contact emails'),
'hint' => $__('Rewrite Zendesk chat notification emails.')
)),
'dsf' => new SectionBreakField(
array(
'label' => $__('Attachment Deletion Options')
)),
'delete-attachments' => new BooleanField(
array(
'default' => FALSE,
'label' => $__('Delete all attachments'),
'hint' => $__('Removes all attachments from all incoming emails.')
)),
'delete-for-departments' => new TextboxField(
array(
'label' => $__('Purge email attachments for a department.'),
'default' => FALSE,
'hint' => $__(
"Enter the name of the department or it's ID number to purge incoming email attachments for that department (multiple, seperate with commas).")
)),
'sba' => new SectionBreakField(
array(
'label' => $__(
'Find & Replace: one per line, seperate split with : case insensitive'),
'hint' => $__(
'A missing second value indicates delete the match.')
)),
'email-rewrite' => new TextareaField(
array(
'label' => $__('Arbitrary Rewrite email Addresses'),
'hint' => $__(
'Use find:replace pairs, like: @internal.local:@company.com'),
'configuration' => array(
'html' => FALSE
)
)),
'text-rewrite' => new TextareaField(
array(
'label' => $__('Arbitrary Rewrite on Subject & Message'),
'hint' => $__('Use find:replace pairs'),
'configuration' => array(
'html' => FALSE
)
)),
'sbr' => new SectionBreakField(
array(
'label' => $__('DANGER! DANGER!'),
'hint' => 'http://php.net/manual/en/function.preg-replace.php Learn this!, the $pattern is the value on the left, the $replacement is the value on the right, the $subject is the entire $vars array.'
)),
'regex-rewrite' => new TextareaField(
array(
'configuration' => array(
'html' => FALSE
),
'label' => $__('DANGERZONE: Regex Rewriter'),
'hint' => $__('Use pattern:replacement one per line')
))
);
}
}