|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | +Copyright (c) 2007 - 2013, Till Brehm, projektfarm Gmbh |
| 5 | +Copyright (c) 2013, Florian Schaal, info@schaal-24.de |
| 6 | +All rights reserved. |
| 7 | +
|
| 8 | +Redistribution and use in source and binary forms, with or without modification, |
| 9 | +are permitted provided that the following conditions are met: |
| 10 | +
|
| 11 | + * Redistributions of source code must retain the above copyright notice, |
| 12 | + this list of conditions and the following disclaimer. |
| 13 | + * Redistributions in binary form must reproduce the above copyright notice, |
| 14 | + this list of conditions and the following disclaimer in the documentation |
| 15 | + and/or other materials provided with the distribution. |
| 16 | + * Neither the name of ISPConfig nor the names of its contributors |
| 17 | + may be used to endorse or promote products derived from this software without |
| 18 | + specific prior written permission. |
| 19 | +
|
| 20 | +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
| 21 | +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 22 | +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 23 | +IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, |
| 24 | +INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
| 25 | +BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 26 | +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 27 | +OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 28 | +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, |
| 29 | +EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 30 | +*/ |
| 31 | + |
| 32 | +class validate_dkim { |
| 33 | + |
| 34 | + function get_error($errmsg) { |
| 35 | + global $app; |
| 36 | + if(isset($app->tform->wordbook[$errmsg])) { |
| 37 | + return $app->tform->wordbook[$errmsg]."<br>\r\n"; |
| 38 | + } else { |
| 39 | + return $errmsg."<br>\r\n"; |
| 40 | + } |
| 41 | + } |
| 42 | + |
| 43 | + /* Validator function for private DKIM-Key */ |
| 44 | + function check_private_key($field_name, $field_value, $validator) { |
| 45 | + $dkim_enabled=$_POST['dkim']; |
| 46 | + if ($dkim_enabled == 'y') { |
| 47 | + if (empty($field_value)) return $this->get_error($validator['errmsg']); |
| 48 | + exec('echo "'.$field_value.'"|openssl rsa -check',$output,$result); |
| 49 | + if($result != 0) return $this->get_error($validator['errmsg']); |
| 50 | + } |
| 51 | + } |
| 52 | + |
| 53 | + /* Validator function for DKIM Path */ |
| 54 | + function check_dkim_path($field_name, $field_value, $validator) { |
| 55 | + if(empty($field_value)) return $this->get_error($validator['errmsg']); |
| 56 | + if (substr(sprintf('%o', fileperms($field_value)),-3) <= 600) |
| 57 | + return $this->get_error($validator['errmsg']); |
| 58 | + } |
| 59 | + |
| 60 | +} |
0 commit comments