Marius Burkard
2016-04-20 4569cae57f127afd093794310ccd290d2d9fdf36
commit | author | age
b9ea02 1 <?php
F 2
3 /**
b1a6a5 4  Copyright (c) 2007 - 2013, Till Brehm, projektfarm Gmbh
MC 5  Copyright (c) 2013, Florian Schaal, info@schaal-24.de
6  All rights reserved.
b9ea02 7
b1a6a5 8  Redistribution and use in source and binary forms, with or without modification,
MC 9  are permitted provided that the following conditions are met:
b9ea02 10
b1a6a5 11  * Redistributions of source code must retain the above copyright notice,
MC 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.
b9ea02 19
b1a6a5 20  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
MC 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.
b9ea02 30
b1a6a5 31  @author Florian Schaal, info@schaal-24.de
2c7813 32  @copyright Florian Schaal, info@schaal-24.de
b1a6a5 33  */
MC 34
b9ea02 35
F 36 class validate_dkim {
b1a6a5 37
b9ea02 38     function get_error($errmsg) {
F 39         global $app;
b1a6a5 40         if(isset($app->tform->wordbook[$errmsg])) {
b9ea02 41             return $app->tform->wordbook[$errmsg]."<br>\r\n";
F 42         } else {
43             return $errmsg."<br>\r\n";
44         }
b1a6a5 45     }
MC 46
b9ea02 47
F 48     /**
b1a6a5 49      * Validator function for private DKIM-Key
MC 50      */
51     function check_private_key($field_name, $field_value, $validator) {
b9ea02 52         $dkim_enabled=$_POST['dkim'];
F 53         if ($dkim_enabled == 'y') {
54             if (empty($field_value)) return $this->get_error($validator['errmsg']);
b1a6a5 55             exec('echo '.escapeshellarg($field_value).'|openssl rsa -check', $output, $result);
b9ea02 56             if($result != 0) return $this->get_error($validator['errmsg']);
F 57         }
58     }
59
b1a6a5 60     /**
MC 61      * Check function for DNS-Template
62      */
b9ea02 63     function check_template($field_name, $field_value, $validator) {
F 64         $dkim=false;
b41803 65         if(is_array($field_value) && !empty($field_value)){
MC 66             foreach($field_value as $field ) { if($field == 'DKIM') $dkim=true; }
67             if ($dkim && $field_value[0]!='DOMAIN') return $this->get_error($validator['errmsg']);
68         }
b9ea02 69     }
F 70
b1a6a5 71
b9ea02 72     /**
b1a6a5 73      * Validator function for $_POST
MC 74      *
75      * @return boolean - true if $POST contains a real key-file
76      */
c943b4 77     function validate_post($key, $value, $dkim_strength) {
26a914 78         $value=str_replace(array("\n", "-----BEGIN RSA PRIVATE KEY-----", "-----END RSA PRIVATE KEY-----", " "), "", $value);
b9ea02 79         switch ($key) {
b1a6a5 80         case 'public':
cd072a 81             if (preg_match("/(^-----BEGIN PUBLIC KEY-----)[a-zA-Z0-9\r\n\/\+=]{1,221}(-----END PUBLIC KEY-----(\n|\r)?$)/", $value) === 1) { return true; } else { return false; }
b9ea02 82             break;
b1a6a5 83         case 'private':
c943b4 84             if ( $dkim_strength == 1024 ) $range = "{812,816}";
FS 85             if ( $dkim_strength == 2048 ) $range = "{1588,1592}";
86             if ( $dkim_strength == 4096 ) $range = "{3132,3136}";
26a914 87             if ( preg_match("/^[a-zA-Z0-9\/\+=]".$range."$/", $value ) === 1) return true; else return false;
b9ea02 88             break;
F 89         }
b1a6a5 90     }
b9ea02 91
b1a6a5 92 }