function fetch_image($url) { if (function_exists('curl_init')) { $c = curl_init(); curl_setopt($c, CURLOPT_URL, $url); curl_setopt($c, CURLOPT_HEADER, 0); curl_setopt($c, CURLOPT_RETURNTRANSFER, true); curl_setopt($c, CURLOPT_FOLLOWLOCATION, true); curl_setopt($c, CURLOPT_MAXREDIRS, 5); curl_setopt($c, CURLOPT_TIMEOUT, 10); $image_data = curl_exec($c); $status = curl_getinfo($c, CURLINFO_HTTP_CODE); $mime_type = curl_getinfo($c, CURLINFO_CONTENT_TYPE); $image_size = curl_getinfo($c, CURLINFO_SIZE_DOWNLOAD); curl_close($c); } // TODO: fallback for non-cURL-enabled servers if (!in_array($status, array(200, 301, 302))) { error('Invalid image.'); } if ($image_size > MAX_IMAGE_SIZE) { error('Image is too large.'); } if (empty($mime_type) || !preg_match('/^image\\//', $mime_type)) { error('Invalid image type.'); } if (empty($image_data)) { error('Invalid image content.'); } $checksum = calculate_checksum($url); cache_image($image_data, $mime_type, $checksum); }
require_once ANGIE_PATH . '/classes/logger/init.php'; require_once ANGIE_PATH . '/classes/database/init.php'; require_once ANGIE_PATH . '/classes/cache/init.php'; $backup_name = array_var($_POST, 'backup', null); $checksum = array_var($_POST, 'checksum', null); if (!$backup_name || !$checksum) { forbidden(); } // if define('BACKUP_PATH', WORK_PATH . '/backup'); $backup_dir = BACKUP_PATH . '/' . urldecode($backup_name); if (!is_dir($backup_dir)) { not_found(); } // if $calculated_checksum = calculate_checksum($backup_name); if ($calculated_checksum != $checksum) { forbidden(); } // if $database_dir = $backup_dir . '/database'; if (!db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME, true, DB_CHARSET)) { die('Could not connect to database. Check activeCollab database settings'); } // if $database_file = $backup_dir . '/database.sql'; if (!is_file($database_file)) { echo "<p>Could not restore backup. Database dump is missing</p>"; die; } // if