public function testGetRemoteMD5Non200() { $json = UrlUtils::get_remote_md5("http://speedtest.wdc01.softlayer.com/downloads/testbob.zip", 5); $this->assertTrue(is_array($json)); $this->assertTrue(array_key_exists('success', $json)); $this->assertFalse($json['success']); $this->assertTrue(array_key_exists('message', $json)); $this->assertTrue(array_key_exists('info', $json)); $this->assertEquals('404', $json['info']['http_code']); }
private function remote_mod_md5($mod, $version, $attempts = 0) { $url = Config::get('solder.repo_location') . 'mods/' . $mod->name . '/' . $mod->name . '-' . $version . '.zip'; if ($attempts >= 3) { Log::write("ERROR", "Exceeded maximum number of attempts for remote MD5 on mod " . $mod->name . " version " . $version . " located at " . $url); return ""; } $hash = UrlUtils::get_remote_md5($url); if ($hash != "") { return $hash; } else { Log::write("ERROR", "Attempted to remote MD5 mod " . $mod->name . " version " . $version . " located at " . $url . " but curl response did not return 200!"); return $this->remote_mod_md5($mod, $version, $attempts + 1); } }
public function action_do_edit($modpack_id) { if (empty($modpack_id)) { return Redirect::to('dashboard'); } $modpack = Modpack::find($modpack_id); if (empty($modpack_id)) { return Redirect::to('dashboard'); } Validator::register('checkresources', function ($attribute, $value, $parameters) { if (FileUtils::check_resource($value, "logo_180.png") && FileUtils::check_resource($value, "icon.png") && FileUtils::check_resource($value, "background.jpg")) { return true; } else { return false; } }); $rules = array('name' => 'required|unique:modpacks,name,' . $modpack->id, 'slug' => 'required|checkresources|unique:modpacks,slug,' . $modpack->id); $messages = array('name_required' => 'You must enter a modpack name.', 'slug_required' => 'You must enter a modpack slug', 'slug_checkresources' => 'Make sure to move your resources to the new location! (Based on your slug name)'); $validation = Validator::make(Input::all(), $rules, $messages); if ($validation->fails()) { return Redirect::back()->with_errors($validation->errors); } $url = Config::get('solder.repo_location') . Input::get('slug') . '/resources/'; $modpack->name = Input::get('name'); $modpack->slug = Input::get('slug'); $modpack->icon_md5 = UrlUtils::get_remote_md5($url . 'icon.png'); $modpack->logo_md5 = UrlUtils::get_remote_md5($url . 'logo_180.png'); $modpack->background_md5 = UrlUtils::get_remote_md5($url . 'background.jpg'); $modpack->hidden = Input::get('hidden') ? true : false; $modpack->save(); return Redirect::to('modpack/view/' . $modpack->id)->with('success', 'Modpack edited'); }
private function remote_mod_md5($mod, $version, $location, $attempts = 0) { $URL = $location . 'mods/' . $mod->name . '/' . $mod->name . '-' . $version . '.zip'; $hash = UrlUtils::get_remote_md5($URL); if (!$hash['success'] && $attempts <= 3) { Log::warning("Error attempting to remote MD5 file " . $mod->name . " version " . $version . " located at " . $URL . "."); return $this->remote_mod_md5($mod, $version, $location, $attempts + 1); } return $hash; }
public function action_do_edit($modpack_id) { if (empty($modpack_id)) { return Redirect::to('dashboard'); } $modpack = Modpack::find($modpack_id); if (empty($modpack_id)) { return Redirect::to('dashboard'); } $rules = array('name' => 'required|unique:modpacks,name,' . $modpack->id, 'slug' => 'required|unique:modpacks,slug,' . $modpack->id); $messages = array('name_required' => 'You must enter a modpack name.', 'slug_required' => 'You must enter a modpack slug'); $validation = Validator::make(Input::all(), $rules, $messages); if ($validation->fails()) { return Redirect::back()->with_errors($validation->errors); } $url = Config::get('solder.repo_location') . Input::get('slug') . '/resources/'; $modpack->name = Input::get('name'); $oldSlug = $modpack->slug; $modpack->slug = Input::get('slug'); $modpack->icon_md5 = UrlUtils::get_remote_md5($url . 'icon.png'); $modpack->logo_md5 = UrlUtils::get_remote_md5($url . 'logo_180.png'); $modpack->background_md5 = UrlUtils::get_remote_md5($url . 'background.jpg'); $modpack->hidden = Input::get('hidden') ? true : false; $modpack->private = Input::get('private') ? true : false; $modpack->save(); $useS3 = Config::get('solder.use_s3'); if ($useS3) { $resourcePath = path('storage') . 'resources/' . $modpack->slug; } else { $resourcePath = path('public') . 'resources/' . $modpack->slug; } /* Create new resources directory for modpack */ if (!file_exists($resourcePath)) { mkdir($resourcePath); } /* If slug changed, move resources and delete old slug directory */ if ($oldSlug != $modpack->slug) { $oldPath = path('public') . 'resources/' . $oldSlug; if (Config::get('solder.use_s3')) { try { S3::copyObject(Config::get('solder.bucket'), 'resources/' . $oldSlug . '/logo.png', Config::get('solder.bucket'), 'resources/' . $modpack->slug . '/logo.png', S3::ACL_PUBLIC_READ); S3::copyObject(Config::get('solder.bucket'), 'resources/' . $oldSlug . '/background.png', Config::get('solder.bucket'), 'resources/' . $modpack->slug . '/background.png', S3::ACL_PUBLIC_READ); S3::copyObject(Config::get('solder.bucket'), 'resources/' . $oldSlug . '/icon.png', Config::get('solder.bucket'), 'resources/' . $modpack->slug . '/icon.png', S3::ACL_PUBLIC_READ); S3::deleteObject(Config::get('solder.bucket'), 'resources/' . $oldSlug . '/logo.png'); S3::deleteObject(Config::get('solder.bucket'), 'resources/' . $oldSlug . '/background.png'); S3::deleteObject(Config::get('solder.bucket'), 'resources/' . $oldSlug . '/icon.png'); } catch (Exception $e) { } $oldPath = path('storage') . 'resources/' . $oldSlug; } if (file_exists($oldPath . "/logo.png")) { copy($oldPath . "/logo.png", $resourcePath . "/logo.png"); unlink($oldPath . "/logo.png"); } if (file_exists($oldPath . "/background.png")) { copy($oldPath . "/background.png", $resourcePath . "/background.png"); unlink($oldPath . "/background.png"); } if (file_exists($oldPath . "/icon.png")) { copy($oldPath . "/icon.png", $resourcePath . "/icon.png"); unlink($oldPath . "/icon.png"); } rmdir($oldPath); } /* Image dohickery */ $logo = Input::file('logo'); if (!empty($logo['name'])) { $success = Resizer::open(Input::file('logo'))->resize(180, 110, 'exact')->save($resourcePath . "/logo.png", 90); if ($useS3) { S3::putObject(S3::inputFile($resourcePath . '/logo.png', false), Config::get('solder.bucket'), 'resources/' . $modpack->slug . '/logo.png', S3::ACL_PUBLIC_READ); } if ($success) { $modpack->logo = true; $modpack->logo_md5 = md5_file($resourcePath . "/logo.png"); } } $background = Input::file('background'); if (!empty($background['name'])) { $success = Resizer::open(Input::file('background'))->resize(880, 520, 'exact')->save($resourcePath . "/background.png", 90); if ($useS3) { S3::putObject(S3::inputFile($resourcePath . '/background.png', false), Config::get('solder.bucket'), 'resources/' . $modpack->slug . '/background.png', S3::ACL_PUBLIC_READ); } if ($success) { $modpack->background = true; $modpack->background_md5 = md5_file($resourcePath . "/background.png"); } } $icon = Input::file('icon'); if (!empty($icon['name'])) { $success = Resizer::open(Input::file('icon'))->resize(50, 50, 'exact')->save($resourcePath . "/icon.png", 90); if ($useS3) { S3::putObject(S3::inputFile($resourcePath . '/icon.png', false), Config::get('solder.bucket'), 'resources/' . $modpack->slug . '/icon.png', S3::ACL_PUBLIC_READ); } if ($success) { $modpack->icon = true; $modpack->icon_md5 = md5_file($resourcePath . "/icon.png"); } } $modpack->save(); Cache::forget('modpack.' . $modpack->slug); Cache::forget('modpacks'); /* Client Syncing */ $clients = Input::get('clients'); $modpack->clients()->sync($clients); return Redirect::to('modpack/view/' . $modpack->id)->with('success', 'Modpack edited'); }