/** * Should validate the Driver settings using the \mithra62\Validate object * @param \mithra62\Validate $validate * @param array $settings * @param array $drivers * @return \mithra62\Validate */ public function validateSettings(\mithra62\Validate $validate, array $settings, array $drivers = array()) { $validate->rule('required', 'gcs_access_key')->message('{field} is required'); $validate->rule('required', 'gcs_secret_key')->message('{field} is required'); $validate->rule('required', 'gcs_bucket')->message('{field} is required'); $validate->rule('gcs_connect', 'gcs_access_key', $settings)->message('Can\'t connect to {field}'); if (!empty($settings['gcs_bucket'])) { $validate->rule('gcs_bucket_exists', 'gcs_bucket', $settings)->message('Your bucket doesn\'t appear to exist...'); $validate->rule('gcs_bucket_readable', 'gcs_bucket', $settings)->message('Your bucket doesn\'t appear to be readable...'); $validate->rule('gcs_bucket_writable', 'gcs_bucket', $settings)->message('Your bucket doesn\'t appear to be writable...'); } return $validate; }
/** * Validates the given driver's data * @param \mithra62\Validate $validate * @param string $driver The name of the driver * @param array $data The data the driver is validating * @param array $locations The existing locations we may want to validate against * @return array */ public function validateDriver(\mithra62\Validate $validate, $driver, array $data, array $locations = array()) { $storage_drivers = $this->getAvailableStorageOptions(); $validate->rule('required', 'storage_location_name')->message('{field} is required'); //pass to the engine to validate what it needs if (isset($storage_drivers[$driver]) && $storage_drivers[$driver]['obj'] instanceof Storage\StorageInterface) { $validate = $storage_drivers[$driver]['obj']->setExistingStorageLocations($locations)->validateSettings($validate, $data); } //now we ahve to make sure we always have at least 1 location active if (count($locations) <= 1 && $data['storage_location_status'] != '1') { $validate->rule('false', 'storage_location_status')->message('{field} is required unless you have more than 1 Storage Location'); } //now we ahve to make sure we always have at least 1 database location active if (count($locations) <= 1 && $data['storage_location_file_use'] != '1') { $validate->rule('false', 'storage_location_file_use')->message('{field} is required unless you have more than 1 Storage Location'); } //now we ahve to make sure we always have at least 1 file location active if (count($locations) <= 1 && $data['storage_location_db_use'] != '1') { $validate->rule('false', 'storage_location_db_use')->message('{field} is required unless you have more than 1 Storage Location'); } $errors = array(); if (!$validate->val($data)) { $errors = $validate->getErrorMessages(); } return $errors; }
/** * Sets up and returns all the objects we'll use * @return \mithra62\Language|\Pimple\Container */ public function getServices() { $this->container['db'] = function ($c) { $db = new Db(); $db->setCredentials($this->getDbConfig()); return $db; }; $this->container['encrypt'] = function ($c) { $encrypt = new Encrypt(); $new_key = $c['platform']->getEncryptionKey(); $encrypt->setKey($new_key); return $encrypt; }; $this->container['lang'] = function ($c) { $lang = new Language(); if (is_array($this->getLangPath())) { foreach ($this->getLangPath() as $path) { $lang->init($path); } } elseif ($this->getLangPath() != '') { $lang->init($this->getLangPath()); } return $lang; }; $this->container['validate'] = function ($c) { $validate = new Validate(); $validate->setRegex($this->container['regex']); return $validate; }; $this->container['files'] = function ($c) { $file = new Files(); return $file; }; $this->container['errors'] = function ($c) { $errors = new Errors(); $errors->setValidation($c['validate']); return $errors; }; $this->container['license'] = function ($c) { $license = new License(); return $license; }; $this->container['email'] = function ($c) { $email = new Email(); $email->setView($c['view']); $email->setLang($c['lang']); return $email; }; $this->container['view'] = function ($c) { $view = new View(); $helpers = array('file_size' => function ($text) { return $this->container['view_helpers']->m62FileSize($text); }, 'lang' => function ($text) { return $this->container['view_helpers']->m62Lang($text); }, 'date_time' => function ($text, $html = true) { return $this->container['view_helpers']->m62DateTime($text, $html = true); }, 'encode' => function ($text) { return $this->container['view_helpers']->m62Encode($text); }, 'decode' => function ($text) { return $this->container['view_helpers']->m62Decode($text); }); $view->addHelper('m62', $helpers); return $view; }; $this->container['regex'] = function ($c) { $regex = new Regex(); return $regex; }; $this->container['shell'] = function ($c) { $shell = new Shell(); return $shell; }; return $this->container; }
/** * Should validate the Driver settings using the \mithra62\Validate object * @param \mithra62\Validate $validate * @param array $settings * @param array $drivers * @return \mithra62\Validate */ public function validateSettings(\mithra62\Validate $validate, array $settings, array $drivers = array()) { $validate->rule('required', 'rcf_username')->message('{field} is required'); $validate->rule('required', 'rcf_api')->message('{field} is required'); $validate->rule('required', 'rcf_container')->message('{field} is required'); $validate->rule('required', 'rcf_location')->message('{field} is required'); if (!empty($settings['rcf_username']) && !empty($settings['rcf_api']) && !empty($settings['rcf_container']) && !empty($settings['rcf_location'])) { if ($settings['storage_location_status'] != '1') { return $validate; //don't validate connection if disabling } $validate->rule('rcf_connect', 'rcf_username', $settings)->message('Can\'t connect to this account'); if (!empty($settings['rcf_container'])) { $validate->rule('rcf_container_exists', 'rcf_container', $settings)->message('Your container doesn\'t appear to exist...'); $validate->rule('rcf_container_readable', 'rcf_container', $settings)->message('Your container doesn\'t appear to be readable...'); $validate->rule('rcf_container_writable', 'rcf_container', $settings)->message('Your container doesn\'t appear to be writable...'); } } return $validate; }
/** * Should validate the Driver settings using the \mithra62\Validate object * @param \mithra62\Validate $validate * @param array $settings * @param array $drivers * @return \mithra62\Validate */ public function validateSettings(\mithra62\Validate $validate, array $settings, array $drivers = array()) { $validate->rule('required', 'ftp_hostname')->message('{field} is required'); $validate->rule('required', 'ftp_username')->message('{field} is required'); $validate->rule('required', 'ftp_password')->message('{field} is required'); $validate->rule('required', 'ftp_port')->message('{field} is required'); $validate->rule('numeric', 'ftp_port')->message('{field} must be a number'); $validate->rule('required', 'ftp_timeout')->message('{field} is required'); $validate->rule('numeric', 'ftp_timeout')->message('{field} must be a number'); $validate->rule('required', 'ftp_store_location')->message('{field} is required'); if (!empty($settings['ftp_hostname']) && !empty($settings['ftp_username']) && !empty($settings['ftp_password']) && !empty($settings['ftp_port'])) { if ($settings['storage_location_status'] != '1') { return $validate; //don't validate connection if disabling } $validate->rule('ftp_connect', 'ftp_hostname', $settings)->message('Can\'t connect to entered {field}'); if (!empty($settings['ftp_store_location'])) { $settings['ftp_store_location'] = $settings['ftp_store_location']; $validate->rule('ftp_writable', 'ftp_store_location', $settings)->message('{field} has to be writable by the FTP user'); } } return $validate; }
/** * Should validate the Driver settings using the \mithra62\Validate object * @param \mithra62\Validate $validate * @param array $settings * @param array $drivers * @return \mithra62\Validate */ public function validateSettings(\mithra62\Validate $validate, array $settings, array $drivers = array()) { $locations = $this->getExistingStorageLocations(); $ignore = array(); foreach ($locations as $location_id => $location) { if ($this->short_name == $location['storage_location_driver']) { if (empty($settings['location_id'])) { //same driver so ensure no duplicate locations $ignore[] = $location['backup_store_location']; } } } if ($ignore) { $validate->rule('notIn', 'backup_store_location', $ignore)->message('{field} is already setup with another Storage Location'); } $validate->rule('required', 'backup_store_location')->message('{field} is required'); $validate->rule('dir', 'backup_store_location')->message('{field} has to be a directory'); $validate->rule('writable', 'backup_store_location')->message('{field} has to be writable'); $validate->rule('readable', 'backup_store_location')->message('{field} has to be readable'); return $validate; }
/** * Should validate the Driver settings using the \mithra62\Validate object * @param \mithra62\Validate $validate * @param array $settings * @param array $drivers * @return \mithra62\Validate */ public function validateSettings(\mithra62\Validate $validate, array $settings, array $drivers = array()) { $validate->rule('required', 'email_storage_attach_threshold')->message('{field} is required'); $validate->rule('numeric', 'email_storage_attach_threshold')->message('{field} must be a number'); $validate->rule('required', 'email_storage_emails')->message('{field} is required'); if (!empty($settings['email_storage_emails'])) { $emails = explode("\n", trim($settings['email_storage_emails'])); if ($emails != '') { if (!is_array($emails)) { $emails = explode("\n", $emails); } foreach ($emails as $email) { if (!filter_var(trim($email), FILTER_VALIDATE_EMAIL)) { $validate->rule('false', 'email_storage_emails')->message('"' . trim($email) . '" isn\'t a valid email'); //break; } } } } return $validate; }