private function simpleResponse($method, $path, $body, $expected) { $path = $this->cleanPath($path); try { $response = $this->client->request($method, $path, $body); return $response['statusCode'] == $expected; } catch (\Exception $e) { return false; } }
/** * Initialises the connection to the CDN * */ public function createConnection() { require_once CST_DIR . 'lib/pages/Options.php'; if ($this->connectionType == 'S3') { require_once CST_DIR . 'lib/api/S3.php'; $awsAccessKey = get_option('cst-s3-accesskey'); $awsSecretKey = get_option('cst-s3-secretkey'); $awsEndpoint = get_option('cst-s3-endpoint'); if (empty($awsEndpoint)) { $awsEndpoint = 's3.amazonaws.com'; } // default endpoint to AWS S3 $this->cdnConnection = new S3($awsAccessKey, $awsSecretKey, false, $awsEndpoint); if (@$this->cdnConnection->listBuckets() === false) { CST_page::$messages[] = 'S3 connection error, please check details'; } } else { if ($this->connectionType == 'FTP') { if (get_option('cst-ftp-sftp') == 'yes') { $connection = @ssh2_connect(get_option('cst-ftp-server'), get_option('cst-ftp-port')); if ($connection === false) { CST_Page::$messages[] = 'SFTP connection error, please check details.'; } else { if (@ssh2_auth_password($connection, get_option('cst-ftp-username'), get_option('cst-ftp-password'))) { $this->cdnConnection = $connection; } else { CST_Page::$messages[] = 'SFTP username/password authentication failed, please check details.'; } } } else { $this->cdnConnection = ftp_connect(get_option('cst-ftp-server'), get_option('cst-ftp-port'), 30); if ($this->cdnConnection === false) { CST_Page::$messages[] = 'FTP connection error, please check details.'; } else { if (ftp_login($this->cdnConnection, get_option('cst-ftp-username'), get_option('cst-ftp-password')) === false) { CST_Page::$messages[] = 'FTP login error, please check details.'; } $this->ftpHome = ftp_pwd($this->cdnConnection); } } } else { if ($this->connectionType == 'Cloudfiles') { require_once CST_DIR . '/lib/api/cloudfiles.php'; try { if (get_option('cst-cf-region') == 'uk') { $region = UK_AUTHURL; } else { $region = US_AUTHURL; } $cfAuth = new CF_Authentication(get_option('cst-cf-username'), get_option('cst-cf-api'), NULL, $region); $cfAuth->authenticate(); $this->cdnConnection = new CF_Connection($cfAuth); $this->cdnConnection = $this->cdnConnection->create_container(get_option('cst-cf-container')); } catch (Exception $e) { CST_Page::$messages[] = 'Cloudfiles connection error, please check details.'; } } else { if ($this->connectionType == 'WebDAV') { require_once CST_DIR . 'lib/api/webdav/Sabre/autoload.php'; $settings = array('baseUri' => get_option('cst-webdav-host'), 'userName' => get_option('cst-webdav-username'), 'password' => get_option('cst-webdav-password')); $client = new Sabre_DAV_Client($settings); $response = $client->request('GET'); if ($response['statusCode'] >= 400) { CST_Page::$messages[] = 'WebDAV connection error, server responded with code ' . $response['statusCode'] . '.'; } $this->cdnConnection = $client; } } } } }