File tree 1 file changed +37
-0
lines changed
1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change
1
+ #!/usr/bin/env php
2
+ <?php /* vim: set colorcolumn=: */
3
+ /**
4
+ * @project bnetdocs-web <https://github.com/BNETDocs/bnetdocs-web/>
5
+ *
6
+ * This script will validate an email address against the current
7
+ * configuration and return whether it is allowed or not.
8
+ * Not exhaustive.
9
+ */
10
+ $ path = __DIR__ . '/../etc/config.phoenix.json ' ;
11
+ $ json = file_get_contents ($ path );
12
+ $ json = json_decode ($ json );
13
+ $ email_denylist = $ json ->email ->recipient_denylist_regexp ;
14
+
15
+ if (!isset ($ argv [1 ]))
16
+ {
17
+ printf ("\e[33mUsage: \e[1;33m%s \e[0;0m " . PHP_EOL , $ argv [0 ] . ' <email-address> ' );
18
+ exit (1 );
19
+ }
20
+ $ email = $ argv [1 ];
21
+
22
+ if (!filter_var ($ email , FILTER_VALIDATE_EMAIL ))
23
+ {
24
+ printf ("\e[31mInvalid: [ \e[1;31m%s \e[0;31m] \e[0m " . PHP_EOL , $ email );
25
+ exit (1 );
26
+ }
27
+
28
+ foreach ($ email_denylist as $ _bad_email ) {
29
+ printf ("\e[33mRegexp: [ \e[0m%s \e[33m] \e[0m " . PHP_EOL , $ _bad_email );
30
+ if (preg_match ($ _bad_email , $ email )) {
31
+ printf ("\e[31mDenied: [ \e[1;31m%s \e[0;31m] \e[0m " . PHP_EOL , $ email );
32
+ exit (1 );
33
+ }
34
+ }
35
+
36
+ printf ("\e[32mAllowed: [ \e[1;32m%s \e[0;32m] \e[0m " . PHP_EOL , $ email );
37
+ exit (0 );
You can’t perform that action at this time.
0 commit comments