All Data Structures Functions Variables Pages
CheckServicesUtil.php
1 <?php
2  /*********************************************************************************
3  * Zurmo is a customer relationship management program developed by
4  * Zurmo, Inc. Copyright (C) 2017 Zurmo Inc.
5  *
6  * Zurmo is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU Affero General Public License version 3 as published by the
8  * Free Software Foundation with the addition of the following permission added
9  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
10  * IN WHICH THE COPYRIGHT IS OWNED BY ZURMO, ZURMO DISCLAIMS THE WARRANTY
11  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
12  *
13  * Zurmo is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Affero General Public License along with
19  * this program; if not, see http://www.gnu.org/licenses or write to the Free
20  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21  * 02110-1301 USA.
22  *
23  * You can contact Zurmo, Inc. with a mailing address at 27 North Wacker Drive
24  * Suite 370 Chicago, IL 60606. or at email address contact@zurmo.com.
25  *
26  * The interactive user interfaces in original and modified versions
27  * of this program must display Appropriate Legal Notices, as required under
28  * Section 5 of the GNU Affero General Public License version 3.
29  *
30  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
31  * these Appropriate Legal Notices must retain the display of the Zurmo
32  * logo and Zurmo copyright notice. If the display of the logo is not reasonably
33  * feasible for technical reasons, the Appropriate Legal Notices must display the words
34  * "Copyright Zurmo Inc. 2017. All rights reserved".
35  ********************************************************************************/
36 
41  {
42  const CHECK_PASSED = 1;
43 
44  const CHECK_FAILED = 2;
45 
51  const CHECK_WARNING = 3;
52 
53  private static function getServicesToCheck()
54  {
55  $services = array('WebServer',
56  'Php',
57  'PhpTimeZone',
58  'PhpMemoryBytes',
59  'PhpFileUploads',
60  'PhpUploadSize',
61  'PhpPostSize',
62  'ServerVariable',
63  'PCRE',
64  'SPL',
65  'Ctype',
66  'FilePermissions',
67  'InstanceFolders',
68  'Soap',
69  'Curl',
70  'Yii',
71  'RedBean',
72  'MbString',
73  'SetIncludePath',
74  'IMAP',
75  'Mysqli',
76  'Pdo',
77  'PdoMysql',
78  'Ldap',
79  'Mcrypt'
80  );
81  $phpVersion = explode('.', phpversion());
82  if ($phpVersion[0] >= 7)
83  {
84  $additionalServices = array('Memcached', 'ZendAssertions');
85  }
86  else
87  {
88  $additionalServices = array('Memcache', 'APC');
89  }
90  return array_merge($services, $additionalServices);
91  }
92 
93  private static function getServicesToCheckOnlyAfterInstallation()
94  {
95  return array(
96  'FilePermissionsAfterInstall',
97  'HostInfo',
98  );
99  }
100 
101  private static function getServicesToExcludeCheckAfterInstallation()
102  {
103  return array(
104  'FilePermissions'
105  );
106  }
107 
108  private static function sanitizeServicesToExcludeCheckAfterInstallation(array & $services)
109  {
110  $servicesToExclude = static::getServicesToExcludeCheckAfterInstallation();
111  foreach ($servicesToExclude as $serviceName)
112  {
113  if (($key = array_search($serviceName, $services)) !== false)
114  {
115  unset($services[$key]);
116  }
117  }
118  }
119 
120  private static function getServicesToCheckAfterInstallation()
121  {
122  $services = CMap::mergeArray(static::getServicesToCheck(),
123  static::getAdditionalServicesToCheck(),
124  static::getServicesToCheckOnlyAfterInstallation());
125  static::sanitizeServicesToExcludeCheckAfterInstallation($services);
126  return $services;
127  }
128 
129  private static function getAdditionalServicesToCheck()
130  {
131  return array('Database',
132  'DatabaseCheckSafeMode',
133  'DatabaseMaxAllowedPacketSize',
134  'DatabaseMaxSpRecursionDepth',
135  'DatabaseThreadStack',
136  'DatabaseDefaultCollation',
137  'DatabaseLogBin',
138  'DatabaseOptimizerSearchDepth',
139  'DatabaseCheckLoadLocalInFile',
140  );
141  }
142 
147  public static function checkServicesAndGetResultsDataForDisplay($checkAdditionalServices = false, $form = null)
148  {
149  if (!$checkAdditionalServices)
150  {
151  $servicesToCheck = self::getServicesToCheck();
152  }
153  else
154  {
155  $servicesToCheck = self::getAdditionalServicesToCheck();
156  }
157  return static::processServicesAndGetResultsData($servicesToCheck, $form);
158  }
159 
160  public static function checkServicesAfterInstallationAndGetResultsDataForDisplay()
161  {
162  $servicesToCheck = self::getServicesToCheckAfterInstallation();
163  $form = new InstallSettingsForm();
164  list(, $form->databaseHostname, $form->databasePort, $form->databaseName) =
165  array_values(RedBeanDatabase::getDatabaseInfoFromDsnString(Yii::app()->db->connectionString));
166  $form->databaseUsername = Yii::app()->db->username;
167  $form->databasePassword = Yii::app()->db->password;
168  return static::processServicesAndGetResultsData($servicesToCheck, $form);
169  }
170 
171  protected static function processServicesAndGetResultsData(array $servicesToCheck, $form = null)
172  {
173  $resultsData = array();
174  $resultsData[self::CHECK_PASSED] = array();
175  $resultsData[self::CHECK_FAILED] = array();
176  $resultsData[self::CHECK_FAILED] [ServiceHelper::REQUIRED_SERVICE] = array();
177  $resultsData[self::CHECK_FAILED] [ServiceHelper::OPTIONAL_SERVICE] = array();
178  $resultsData[self::CHECK_WARNING] = array();
179 
180  foreach ($servicesToCheck as $service)
181  {
182  $serviceHelperClassName = $service . 'ServiceHelper';
183 
184  if ($form && property_exists($serviceHelperClassName, 'form'))
185  {
186  $serviceHelper = new $serviceHelperClassName($form);
187  }
188  else
189  {
190  $serviceHelper = new $serviceHelperClassName();
191  }
192  if ($serviceHelper->runCheckAndGetIfSuccessful())
193  {
194  $resultsData[self::CHECK_PASSED][] = array('service' => $service,
195  'message' => $serviceHelper->getMessage());
196  }
197  elseif ($serviceHelper->didCheckProduceWarningStatus())
198  {
199  $resultsData[self::CHECK_WARNING][] = array('service' => $service,
200  'message' => $serviceHelper->getMessage());
201  }
202  else
203  {
204  $serviceType = $serviceHelper->getServiceType();
205  $resultsData[self::CHECK_FAILED][$serviceType][] = array('service' => $service,
206  'message' => $serviceHelper->getMessage());
207  }
208  }
209  return $resultsData;
210  }
211  }
212 ?>
static checkServicesAndGetResultsDataForDisplay($checkAdditionalServices=false, $form=null)
static getDatabaseInfoFromDsnString($dsn)
Generated on Wed Feb 26 2020 07:10:39