@@ -141,6 +141,44 @@ function web_apache_directives($field_name, $field_value, $validator) {
141141 }
142142 }
143143
144+ /* Check nginx directives */
145+ function web_nginx_directives ($ field_name , $ field_value , $ validator ) {
146+ global $ app ;
147+
148+ if (trim ($ field_value ) != '' ) {
149+ $ security_config = $ app ->getconf ->get_security_config ('ids ' );
150+
151+ if ($ security_config ['nginx_directives_scan_enabled ' ] == 'yes ' ) {
152+
153+ // Get blacklist
154+ $ blacklist_path = '/usr/local/ispconfig/security/nginx_directives.blacklist ' ;
155+ if (is_file ('/usr/local/ispconfig/security/nginx_directives.blacklist.custom ' )) $ blacklist_path = '/usr/local/ispconfig/security/nginx_directives.blacklist.custom ' ;
156+ if (!is_file ($ blacklist_path )) $ blacklist_path = realpath (ISPC_ROOT_PATH .'/../security/nginx_directives.blacklist ' );
157+
158+ $ directives = explode ("\n" ,$ field_value );
159+ $ regex = explode ("\n" ,file_get_contents ($ blacklist_path ));
160+ $ blocked = false ;
161+ $ blocked_line = '' ;
162+
163+ if (is_array ($ directives ) && is_array ($ regex )) {
164+ foreach ($ directives as $ directive ) {
165+ $ directive = trim ($ directive );
166+ foreach ($ regex as $ r ) {
167+ if (preg_match (trim ($ r ),$ directive )) {
168+ $ blocked = true ;
169+ $ blocked_line .= $ directive .'<br /> ' ;
170+ };
171+ }
172+ }
173+ }
174+ }
175+ }
176+
177+ if ($ blocked === true ) {
178+ return $ this ->get_error ('nginx_directive_blocked_error ' ).' ' .$ blocked_line ;
179+ }
180+ }
181+
144182
145183 /* internal validator function to match regexp */
146184 function _regex_validate ($ domain_name , $ allow_wildcard = false ) {
0 commit comments