@@ -25,9 +25,11 @@ |
||
| 25 | 25 | * @return bool true on success or false on failure |
| 26 | 26 | */ |
| 27 | 27 | public function execute() { |
| 28 | - foreach ($this->data as $actionType => $actionData) try { |
|
| 28 | + foreach ($this->data as $actionType => $actionData) { |
|
| 29 | + try { |
|
| 29 | 30 | if (!isset($actionType)) |
| 30 | 31 | continue; |
| 32 | + } |
|
| 31 | 33 | switch ($actionType) { |
| 32 | 34 | case 'certificate': |
| 33 | 35 | $data = $this->verifyCertificate($actionData); |
@@ -98,8 +98,9 @@ |
||
| 98 | 98 | // Get messages from certificates |
| 99 | 99 | foreach ($privateCerts as $privateCert) { |
| 100 | 100 | $privateCertMessage = mapi_msgstore_openentry($store, $privateCert[PR_ENTRYID]); |
| 101 | - if ($privateCertMessage === false) |
|
| 102 | - continue; |
|
| 101 | + if ($privateCertMessage === false) { |
|
| 102 | + continue; |
|
| 103 | + } |
|
| 103 | 104 | $pkcs12 = ""; |
| 104 | 105 | $certs = []; |
| 105 | 106 | // Read pkcs12 cert from message |
@@ -96,7 +96,8 @@ |
||
| 96 | 96 | <div class="disclaimer"> |
| 97 | 97 | <?php include '/etc/grommunio-web/disclaimer.html'; ?> |
| 98 | 98 | </div> |
| 99 | - <?php } elseif (file_exists('disclaimer.html')) { ?> |
|
| 99 | + <?php } |
|
| 100 | +elseif (file_exists('disclaimer.html')) { ?> |
|
| 100 | 101 | <div class="disclaimer"> |
| 101 | 102 | <?php include 'disclaimer.html'; ?> |
| 102 | 103 | </div> |
@@ -186,7 +186,8 @@ |
||
| 186 | 186 | // Read message properties |
| 187 | 187 | try { |
| 188 | 188 | $messageProps = mapi_getprops($this->mapiMessage, [PR_SUBJECT, PR_MESSAGE_CLASS]); |
| 189 | - } catch (Exception $ex) { |
|
| 189 | + } |
|
| 190 | + catch (Exception $ex) { |
|
| 190 | 191 | $this->logErrorAndThrow("Error on getting MAPI message properties", $ex); |
| 191 | 192 | } |
| 192 | 193 | |
@@ -25,9 +25,10 @@ discard block |
||
| 25 | 25 | */ |
| 26 | 26 | public $ConnectionId = null; |
| 27 | 27 | |
| 28 | - function __construct($serviceEndpoint) |
|
| 29 | - {
|
|
| 30 | - if (!str_ends_with($serviceEndpoint, '/')) $serviceEndpoint .= '/'; |
|
| 28 | + function __construct($serviceEndpoint) { |
|
| 29 | + if (!str_ends_with($serviceEndpoint, '/')) { |
|
| 30 | + $serviceEndpoint .= '/'; |
|
| 31 | + } |
|
| 31 | 32 | $this->ServiceEndpoint = $serviceEndpoint; |
| 32 | 33 | } |
| 33 | 34 | |
@@ -40,7 +41,7 @@ discard block |
||
| 40 | 41 | * |
| 41 | 42 | * @return bool |
| 42 | 43 | */ |
| 43 | - public function loginWithToken($pfxFile, $pfxPassword, $userName) {
|
|
| 44 | + public function loginWithToken($pfxFile, $pfxPassword, $userName) { |
|
| 44 | 45 | try {
|
| 45 | 46 | $issuer = gethostname(); |
| 46 | 47 | $tokenGenerator = new \Kendox\TokenGenerator($issuer, $pfxFile, $pfxPassword); |
@@ -53,7 +54,8 @@ discard block |
||
| 53 | 54 | $result = $this->post("Authentication/LogonWithToken", $logonParameters);
|
| 54 | 55 | $this->ConnectionId = $result->LogonWithTokenResult->ConnectionId; |
| 55 | 56 | return true; |
| 56 | - } catch(\Exception $ex) {
|
|
| 57 | + } |
|
| 58 | + catch(\Exception $ex) {
|
|
| 57 | 59 | throw new \Exception("Token-Login failed: ".$ex->getMessage());
|
| 58 | 60 | } |
| 59 | 61 | } |
@@ -63,7 +65,7 @@ discard block |
||
| 63 | 65 | * |
| 64 | 66 | * @return bool |
| 65 | 67 | */ |
| 66 | - public function logout() {
|
|
| 68 | + public function logout() { |
|
| 67 | 69 | try {
|
| 68 | 70 | $logoutParameters = [ |
| 69 | 71 | "connectionId" => $this->ConnectionId |
@@ -71,7 +73,8 @@ discard block |
||
| 71 | 73 | $result = $this->post("Authentication/Logout", $logoutParameters);
|
| 72 | 74 | $this->ConnectionId = null; |
| 73 | 75 | return true; |
| 74 | - } catch(\Exception $ex) {
|
|
| 76 | + } |
|
| 77 | + catch(\Exception $ex) {
|
|
| 75 | 78 | throw new \Exception("Token-Login failed: ".$ex->getMessage());
|
| 76 | 79 | } |
| 77 | 80 | } |
@@ -85,7 +88,7 @@ discard block |
||
| 85 | 88 | * |
| 86 | 89 | * @return array The data result as an array |
| 87 | 90 | */ |
| 88 | - public function userTableQuery($userTableName, $whereClauseElements, $addColumnHeaders) {
|
|
| 91 | + public function userTableQuery($userTableName, $whereClauseElements, $addColumnHeaders) { |
|
| 89 | 92 | try {
|
| 90 | 93 | $parameters = [ |
| 91 | 94 | "connectionId" => $this->ConnectionId, |
@@ -94,9 +97,12 @@ discard block |
||
| 94 | 97 | "addColumnHeaders" => $addColumnHeaders |
| 95 | 98 | ]; |
| 96 | 99 | $result = $this->post("UserTable/UserTableGetRecords", $parameters);
|
| 97 | - if (!isset($result->UserTableGetRecordsResult)) throw new \Exception("Unexpected result");
|
|
| 100 | + if (!isset($result->UserTableGetRecordsResult)) { |
|
| 101 | + throw new \Exception("Unexpected result"); |
|
| 102 | + } |
|
| 98 | 103 | return $result->UserTableGetRecordsResult; |
| 99 | - } catch(\Exception $ex) {
|
|
| 104 | + } |
|
| 105 | + catch(\Exception $ex) {
|
|
| 100 | 106 | throw new \Exception("User table query failed: ".$ex->getMessage());
|
| 101 | 107 | } |
| 102 | 108 | } |
@@ -105,7 +111,7 @@ discard block |
||
| 105 | 111 | * Uploading a file |
| 106 | 112 | * @param string $file Path and file name of file to upload |
| 107 | 113 | */ |
| 108 | - public function uploadFile($file) {
|
|
| 114 | + public function uploadFile($file) { |
|
| 109 | 115 | $content = file_get_contents($file); |
| 110 | 116 | return $this->uploadContent($content); |
| 111 | 117 | } |
@@ -114,12 +120,12 @@ discard block |
||
| 114 | 120 | * Uploading a stream of data |
| 115 | 121 | * @param Stream $stream Stream of content to upload |
| 116 | 122 | */ |
| 117 | - public function uploadStream($stream) {
|
|
| 123 | + public function uploadStream($stream) { |
|
| 118 | 124 | $content = stream_get_contents($stream); |
| 119 | 125 | return $this->uploadContent($content); |
| 120 | 126 | } |
| 121 | 127 | |
| 122 | - private function uploadContent($content) {
|
|
| 128 | + private function uploadContent($content) { |
|
| 123 | 129 | $base64 = base64_encode($content); |
| 124 | 130 | $uploadParameters = [ |
| 125 | 131 | "connectionId" => $this->ConnectionId, |
@@ -137,8 +143,7 @@ discard block |
||
| 137 | 143 | * |
| 138 | 144 | * @return object Returns object with data. If service returns an error an exception will be thrown with detailed information |
| 139 | 145 | */ |
| 140 | - private function post($path, $data) |
|
| 141 | - {
|
|
| 146 | + private function post($path, $data) { |
|
| 142 | 147 | $ch = curl_init(); |
| 143 | 148 | //curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); |
| 144 | 149 | curl_setopt($ch, CURLOPT_URL, $this->ServiceEndpoint.$path); |
@@ -154,8 +159,7 @@ discard block |
||
| 154 | 159 | |
| 155 | 160 | } |
| 156 | 161 | |
| 157 | - private function handleJsonResult($json) |
|
| 158 | - {
|
|
| 162 | + private function handleJsonResult($json) { |
|
| 159 | 163 | if ($json === FALSE) {
|
| 160 | 164 | throw new \Exception("No valid JSON has been returned from service.");
|
| 161 | 165 | } |
@@ -44,8 +44,7 @@ discard block |
||
| 44 | 44 | private $PfxFile, /** |
| 45 | 45 | * Password for PFX-File (Certificate) |
| 46 | 46 | */ |
| 47 | - private $PfxPassword) |
|
| 48 | - {
|
|
| 47 | + private $PfxPassword) { |
|
| 49 | 48 | $this->loadCertificateFromPfx(); |
| 50 | 49 | } |
| 51 | 50 | |
@@ -56,8 +55,7 @@ discard block |
||
| 56 | 55 | * |
| 57 | 56 | * @return string Token in XML format |
| 58 | 57 | */ |
| 59 | - public function generateToken($userEMail) |
|
| 60 | - {
|
|
| 58 | + public function generateToken($userEMail) { |
|
| 61 | 59 | try {
|
| 62 | 60 | $now = new \DateTime("now", new \DateTimeZone("utc"));
|
| 63 | 61 | $guid = $this->createGUID(); |
@@ -73,7 +71,8 @@ discard block |
||
| 73 | 71 | xmlwriter_end_element($writer); |
| 74 | 72 | xmlwriter_end_element($writer); |
| 75 | 73 | return xmlwriter_output_memory($writer); |
| 76 | - } catch(\Exception $ex) {
|
|
| 74 | + } |
|
| 75 | + catch(\Exception $ex) {
|
|
| 77 | 76 | throw new \Exception("Generating token failed: ".$ex->getMessage());
|
| 78 | 77 | } |
| 79 | 78 | } |
@@ -81,21 +80,27 @@ discard block |
||
| 81 | 80 | /** |
| 82 | 81 | * Loads the X509-certificate from PFX-File |
| 83 | 82 | */ |
| 84 | - private function loadCertificateFromPfx() |
|
| 85 | - {
|
|
| 86 | - if ($this->PfxFile == null) throw new \Exception("No PFX-File available.");
|
|
| 87 | - if (!file_exists($this->PfxFile)) throw new \Exception("PFX-File not found.");
|
|
| 88 | - if (empty($this->PfxPassword)) throw new \Exception("Password not set for PFX-File.");
|
|
| 83 | + private function loadCertificateFromPfx() { |
|
| 84 | + if ($this->PfxFile == null) { |
|
| 85 | + throw new \Exception("No PFX-File available."); |
|
| 86 | + } |
|
| 87 | + if (!file_exists($this->PfxFile)) { |
|
| 88 | + throw new \Exception("PFX-File not found."); |
|
| 89 | + } |
|
| 90 | + if (empty($this->PfxPassword)) { |
|
| 91 | + throw new \Exception("Password not set for PFX-File."); |
|
| 92 | + } |
|
| 89 | 93 | $pfxContent = file_get_contents($this->PfxFile); |
| 90 | 94 | $results = []; |
| 91 | 95 | $read = openssl_pkcs12_read($pfxContent, $results, $this->PfxPassword); |
| 92 | - if ($read == false) throw new \Exception("Error on reading PFX-File: ".openssl_error_string());
|
|
| 96 | + if ($read == false) { |
|
| 97 | + throw new \Exception("Error on reading PFX-File: ".openssl_error_string()); |
|
| 98 | + } |
|
| 93 | 99 | $this->Certificate = $results['pkey'].$results['cert']; |
| 94 | 100 | $this->CertPrivateKey = $results['pkey']; |
| 95 | 101 | } |
| 96 | 102 | |
| 97 | - private function writeSignedInfo($writer, $userEMail, $time, $uniqueId) |
|
| 98 | - {
|
|
| 103 | + private function writeSignedInfo($writer, $userEMail, $time, $uniqueId) { |
|
| 99 | 104 | $utcTime = $time->format('Y-m-d H:i:s');
|
| 100 | 105 | $utcTime = str_replace(" ", "T", $utcTime)."Z";
|
| 101 | 106 | xmlwriter_start_element($writer, "SignedInfo"); |
@@ -136,8 +141,7 @@ discard block |
||
| 136 | 141 | * |
| 137 | 142 | * @return string |
| 138 | 143 | */ |
| 139 | - function SignXmlString($signedInfoXml) |
|
| 140 | - {
|
|
| 144 | + function SignXmlString($signedInfoXml) { |
|
| 141 | 145 | try {
|
| 142 | 146 | $data = iconv('utf-8', 'utf-16le', $signedInfoXml);
|
| 143 | 147 | $privateKey = \phpseclib3\Crypt\RSA::loadFormat('PKCS8', $this->CertPrivateKey)
|
@@ -145,7 +149,8 @@ discard block |
||
| 145 | 149 | ->withHash('sha512');
|
| 146 | 150 | $base64 = base64_encode($privateKey->sign($data)); |
| 147 | 151 | return $base64; |
| 148 | - } catch (\Exception $ex) {
|
|
| 152 | + } |
|
| 153 | + catch (\Exception $ex) {
|
|
| 149 | 154 | throw new \Exception("XML signing failed: ".$ex->getMessage());
|
| 150 | 155 | } |
| 151 | 156 | } |
@@ -154,10 +159,10 @@ discard block |
||
| 154 | 159 | * Creates a unique ID |
| 155 | 160 | * @return string |
| 156 | 161 | */ |
| 157 | - private function createGUID(){
|
|
| 162 | + private function createGUID() { |
|
| 158 | 163 | if (function_exists('com_create_guid')){
|
| 159 | 164 | return com_create_guid(); |
| 160 | - } |
|
| 165 | + } |
|
| 161 | 166 | else {
|
| 162 | 167 | mt_srand((double)microtime()*10000); |
| 163 | 168 | $charid = strtoupper(md5(uniqid(random_int(0, mt_getrandmax()), true))); |
@@ -386,8 +386,7 @@ discard block |
||
| 386 | 386 | unlink($tmpUserCert); |
| 387 | 387 | } |
| 388 | 388 | |
| 389 | - function join_xph(&$prop, $msg) |
|
| 390 | - { |
|
| 389 | + function join_xph(&$prop, $msg) { |
|
| 391 | 390 | $a = mapi_getprops($msg, [PR_TRANSPORT_MESSAGE_HEADERS]); |
| 392 | 391 | $a = $a === false ? "" : ($a[PR_TRANSPORT_MESSAGE_HEADERS] ?? ""); |
| 393 | 392 | $prop[PR_TRANSPORT_MESSAGE_HEADERS] = |
@@ -988,8 +987,7 @@ discard block |
||
| 988 | 987 | return !empty($rows); |
| 989 | 988 | } |
| 990 | 989 | |
| 991 | - public function clear_openssl_error() |
|
| 992 | - { |
|
| 990 | + public function clear_openssl_error() { |
|
| 993 | 991 | while (@openssl_error_string() !== false) |
| 994 | 992 | /* nothing */; |
| 995 | 993 | } |
@@ -1003,11 +1001,13 @@ discard block |
||
| 1003 | 1001 | */ |
| 1004 | 1002 | public function extract_openssl_error() { |
| 1005 | 1003 | $this->openssl_error = ""; |
| 1006 | - while (($s = @openssl_error_string()) !== false) |
|
| 1007 | - if (strlen($this->openssl_error) == 0) |
|
| 1004 | + while (($s = @openssl_error_string()) !== false) { |
|
| 1005 | + if (strlen($this->openssl_error) == 0) |
|
| 1008 | 1006 | $this->openssl_error = $s; |
| 1009 | - else |
|
| 1010 | - $this->openssl_error .= "\n".$s; |
|
| 1007 | + } |
|
| 1008 | + else { |
|
| 1009 | + $this->openssl_error .= "\n".$s; |
|
| 1010 | + } |
|
| 1011 | 1011 | $openssl_error_code = 0; |
| 1012 | 1012 | if ($this->openssl_error) { |
| 1013 | 1013 | $openssl_error_list = explode(":", $this->openssl_error); |
@@ -17,8 +17,9 @@ discard block |
||
| 17 | 17 | * It also sends the eml file to the client. |
| 18 | 18 | */ |
| 19 | 19 | public function downloadMessageAsFile() { |
| 20 | - if (!$this->message || !$this->store) |
|
| 21 | - return; |
|
| 20 | + if (!$this->message || !$this->store) { |
|
| 21 | + return; |
|
| 22 | + } |
|
| 22 | 23 | // get message properties. |
| 23 | 24 | $messageProps = mapi_getprops($this->message, [PR_SUBJECT, PR_MESSAGE_CLASS]); |
| 24 | 25 | |
@@ -49,8 +50,9 @@ discard block |
||
| 49 | 50 | * Send ZIP to the client if all the requested eml files included successfully into the same. |
| 50 | 51 | */ |
| 51 | 52 | public function downloadMessageAsZipFile() { |
| 52 | - if (!$this->store) |
|
| 53 | - return; |
|
| 53 | + if (!$this->store) { |
|
| 54 | + return; |
|
| 55 | + } |
|
| 54 | 56 | // Generate random ZIP file name at default temporary path of PHP |
| 55 | 57 | $randomZipName = tempnam(sys_get_temp_dir(), 'zip'); |
| 56 | 58 | |
@@ -475,8 +475,7 @@ |
||
| 475 | 475 | return $default; |
| 476 | 476 | } |
| 477 | 477 | |
| 478 | -function parse_smime__join_xph(&$prop, $msg) |
|
| 479 | -{ |
|
| 478 | +function parse_smime__join_xph(&$prop, $msg) { |
|
| 480 | 479 | $a = mapi_getprops($msg, [PR_TRANSPORT_MESSAGE_HEADERS]); |
| 481 | 480 | $a = $a === false ? "" : ($a[PR_TRANSPORT_MESSAGE_HEADERS] ?? ""); |
| 482 | 481 | $prop[PR_TRANSPORT_MESSAGE_HEADERS] = |