Back to index

d-push  2.0
provisioning.php
Go to the documentation of this file.
00001 <?php
00002 /***********************************************
00003 * File      :   provisioning.php
00004 * Project   :   Z-Push
00005 * Descr     :   Provides the PROVISIONING command
00006 *
00007 * Created   :   16.02.2012
00008 *
00009 * Copyright 2007 - 2012 Zarafa Deutschland GmbH
00010 *
00011 * This program is free software: you can redistribute it and/or modify
00012 * it under the terms of the GNU Affero General Public License, version 3,
00013 * as published by the Free Software Foundation with the following additional
00014 * term according to sec. 7:
00015 *
00016 * According to sec. 7 of the GNU Affero General Public License, version 3,
00017 * the terms of the AGPL are supplemented with the following terms:
00018 *
00019 * "Zarafa" is a registered trademark of Zarafa B.V.
00020 * "Z-Push" is a registered trademark of Zarafa Deutschland GmbH
00021 * The licensing of the Program under the AGPL does not imply a trademark license.
00022 * Therefore any rights, title and interest in our trademarks remain entirely with us.
00023 *
00024 * However, if you propagate an unmodified version of the Program you are
00025 * allowed to use the term "Z-Push" to indicate that you distribute the Program.
00026 * Furthermore you may use our trademarks where it is necessary to indicate
00027 * the intended purpose of a product or service provided you use it in accordance
00028 * with honest practices in industrial or commercial matters.
00029 * If you want to propagate modified versions of the Program under the name "Z-Push",
00030 * you may only do so if you have a written permission by Zarafa Deutschland GmbH
00031 * (to acquire a permission please contact Zarafa at trademark@zarafa.com).
00032 *
00033 * This program is distributed in the hope that it will be useful,
00034 * but WITHOUT ANY WARRANTY; without even the implied warranty of
00035 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00036 * GNU Affero General Public License for more details.
00037 *
00038 * You should have received a copy of the GNU Affero General Public License
00039 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00040 *
00041 * Consult LICENSE file for details
00042 ************************************************/
00043 
00044 class Provisioning extends RequestProcessor {
00045 
00054     public function Handle($commandCode) {
00055         $status = SYNC_PROVISION_STATUS_SUCCESS;
00056         $policystatus = SYNC_PROVISION_POLICYSTATUS_SUCCESS;
00057 
00058         $rwstatus = self::$deviceManager->GetProvisioningWipeStatus();
00059         $rwstatusWiped = false;
00060 
00061         // if this is a regular provisioning require that an authenticated remote user
00062         if ($rwstatus < SYNC_PROVISION_RWSTATUS_PENDING) {
00063             ZLog::Write(LOGLEVEL_DEBUG, "RequestProcessor::HandleProvision(): Forcing delayed Authentication");
00064             self::Authenticate();
00065         }
00066 
00067         $phase2 = true;
00068 
00069         if(!self::$decoder->getElementStartTag(SYNC_PROVISION_PROVISION))
00070             return false;
00071 
00072         //handle android remote wipe.
00073         if (self::$decoder->getElementStartTag(SYNC_PROVISION_REMOTEWIPE)) {
00074             if(!self::$decoder->getElementStartTag(SYNC_PROVISION_STATUS))
00075                 return false;
00076 
00077             $instatus = self::$decoder->getElementContent();
00078 
00079             if(!self::$decoder->getElementEndTag())
00080                 return false;
00081 
00082             if(!self::$decoder->getElementEndTag())
00083                 return false;
00084 
00085             $phase2 = false;
00086             $rwstatusWiped = true;
00087         }
00088         else {
00089 
00090             if(!self::$decoder->getElementStartTag(SYNC_PROVISION_POLICIES))
00091                 return false;
00092 
00093             if(!self::$decoder->getElementStartTag(SYNC_PROVISION_POLICY))
00094                 return false;
00095 
00096             if(!self::$decoder->getElementStartTag(SYNC_PROVISION_POLICYTYPE))
00097                 return false;
00098 
00099             $policytype = self::$decoder->getElementContent();
00100             if ($policytype != 'MS-WAP-Provisioning-XML' && $policytype != 'MS-EAS-Provisioning-WBXML') {
00101                 $status = SYNC_PROVISION_STATUS_SERVERERROR;
00102             }
00103             if(!self::$decoder->getElementEndTag()) //policytype
00104                 return false;
00105 
00106             if (self::$decoder->getElementStartTag(SYNC_PROVISION_POLICYKEY)) {
00107                 $devpolicykey = self::$decoder->getElementContent();
00108 
00109                 if(!self::$decoder->getElementEndTag())
00110                     return false;
00111 
00112                 if(!self::$decoder->getElementStartTag(SYNC_PROVISION_STATUS))
00113                     return false;
00114 
00115                 $instatus = self::$decoder->getElementContent();
00116 
00117                 if(!self::$decoder->getElementEndTag())
00118                     return false;
00119 
00120                 $phase2 = false;
00121             }
00122 
00123             if(!self::$decoder->getElementEndTag()) //policy
00124                 return false;
00125 
00126             if(!self::$decoder->getElementEndTag()) //policies
00127                 return false;
00128 
00129             if (self::$decoder->getElementStartTag(SYNC_PROVISION_REMOTEWIPE)) {
00130                 if(!self::$decoder->getElementStartTag(SYNC_PROVISION_STATUS))
00131                     return false;
00132 
00133                 $status = self::$decoder->getElementContent();
00134 
00135                 if(!self::$decoder->getElementEndTag())
00136                     return false;
00137 
00138                 if(!self::$decoder->getElementEndTag())
00139                     return false;
00140 
00141                 $rwstatusWiped = true;
00142             }
00143         }
00144         if(!self::$decoder->getElementEndTag()) //provision
00145             return false;
00146 
00147         if (PROVISIONING !== true) {
00148             ZLog::Write(LOGLEVEL_INFO, "No policies deployed to device");
00149             $policystatus = SYNC_PROVISION_POLICYSTATUS_NOPOLICY;
00150         }
00151 
00152         self::$encoder->StartWBXML();
00153 
00154         //set the new final policy key in the device manager
00155         // START ADDED dw2412 Android provisioning fix
00156         if (!$phase2) {
00157             $policykey = self::$deviceManager->GenerateProvisioningPolicyKey();
00158             self::$deviceManager->SetProvisioningPolicyKey($policykey);
00159             self::$topCollector->AnnounceInformation("Policies deployed", true);
00160         }
00161         else {
00162             // just create a temporary key (i.e. iPhone OS4 Beta does not like policykey 0 in response)
00163             $policykey = self::$deviceManager->GenerateProvisioningPolicyKey();
00164         }
00165         // END ADDED dw2412 Android provisioning fix
00166 
00167         self::$encoder->startTag(SYNC_PROVISION_PROVISION);
00168         {
00169             self::$encoder->startTag(SYNC_PROVISION_STATUS);
00170                 self::$encoder->content($status);
00171             self::$encoder->endTag();
00172 
00173             self::$encoder->startTag(SYNC_PROVISION_POLICIES);
00174                 self::$encoder->startTag(SYNC_PROVISION_POLICY);
00175 
00176                 if(isset($policytype)) {
00177                     self::$encoder->startTag(SYNC_PROVISION_POLICYTYPE);
00178                         self::$encoder->content($policytype);
00179                     self::$encoder->endTag();
00180                 }
00181 
00182                 self::$encoder->startTag(SYNC_PROVISION_STATUS);
00183                     self::$encoder->content($policystatus);
00184                 self::$encoder->endTag();
00185 
00186                 self::$encoder->startTag(SYNC_PROVISION_POLICYKEY);
00187                        self::$encoder->content($policykey);
00188                 self::$encoder->endTag();
00189 
00190                 if ($phase2 && $policystatus === SYNC_PROVISION_POLICYSTATUS_SUCCESS) {
00191                     self::$encoder->startTag(SYNC_PROVISION_DATA);
00192                     if ($policytype == 'MS-WAP-Provisioning-XML') {
00193                         self::$encoder->content('<wap-provisioningdoc><characteristic type="SecurityPolicy"><parm name="4131" value="1"/><parm name="4133" value="1"/></characteristic></wap-provisioningdoc>');
00194                     }
00195                     elseif ($policytype == 'MS-EAS-Provisioning-WBXML') {
00196                         self::$encoder->startTag(SYNC_PROVISION_EASPROVISIONDOC);
00197 
00198                             $prov = self::$deviceManager->GetProvisioningObject();
00199                             if (!$prov->Check())
00200                                 throw new FatalException("Invalid policies!");
00201 
00202                             $prov->Encode(self::$encoder);
00203                         self::$encoder->endTag();
00204                     }
00205                     else {
00206                         ZLog::Write(LOGLEVEL_WARN, "Wrong policy type");
00207                         self::$topCollector->AnnounceInformation("Policytype not supported", true);
00208                         return false;
00209                     }
00210                     self::$topCollector->AnnounceInformation("Updated provisiong", true);
00211 
00212                     self::$encoder->endTag();//data
00213                 }
00214                 self::$encoder->endTag();//policy
00215             self::$encoder->endTag(); //policies
00216         }
00217 
00218         //wipe data if a higher RWSTATUS is requested
00219         if ($rwstatus > SYNC_PROVISION_RWSTATUS_OK && $policystatus === SYNC_PROVISION_POLICYSTATUS_SUCCESS) {
00220             self::$encoder->startTag(SYNC_PROVISION_REMOTEWIPE, false, true);
00221             self::$deviceManager->SetProvisioningWipeStatus(($rwstatusWiped)?SYNC_PROVISION_RWSTATUS_WIPED:SYNC_PROVISION_RWSTATUS_REQUESTED);
00222             self::$topCollector->AnnounceInformation(sprintf("Remote wipe %s", ($rwstatusWiped)?"executed":"requested"), true);
00223         }
00224 
00225         self::$encoder->endTag();//provision
00226 
00227         return true;
00228     }
00229 }
00230 ?>