Example #1
0
 public function action_edit($user_id = null)
 {
     if (empty($user_id)) {
         return Redirect::to('user/list');
     }
     if (!Auth::user()->permission->solder_full && !Auth::user()->permission->solder_users && $user_id != Auth::user()->id) {
         return Redirect::to('dashboard')->with('permission', 'You do not have permission to access this area.');
     }
     $user = User::find($user_id);
     if (empty($user)) {
         return Redirect::to('user/list');
     }
     if (Input::get('edit-user')) {
         $rules = array("email" => "email|required", "username" => "required|max:20");
         if (Input::get('password1')) {
             $rules['password1'] = "same:password2";
         }
         $validation = Validator::make(Input::all(), $rules);
         if ($validation->fails()) {
             return Redirect::back()->with_errors($validation);
         }
         try {
             $user->email = Input::get('email');
             $user->username = Input::get('username');
             if (Input::get('password1')) {
                 $user->password = Hash::make(Input::get('password1'));
             }
             /* Update User Permissions */
             if (Auth::user()->permission->solder_full || Auth::user()->permission->solder_users) {
                 $perm = $user->permission;
                 /* If user is original admin, always give full access. */
                 if ($user->id == 1) {
                     $perm->solder_full = true;
                 } else {
                     $perm->solder_full = Input::get('solder-full') ? true : false;
                 }
                 $perm->solder_users = Input::get('manage-users') ? true : false;
                 $perm->solder_modpacks = Input::get('manage-packs') ? true : false;
                 $perm->solder_mods = Input::get('manage-mods') ? true : false;
                 $perm->solder_create = Input::get('solder-create') ? true : false;
                 $perm->mods_create = Input::get('mod-create') ? true : false;
                 $perm->mods_manage = Input::get('mod-manage') ? true : false;
                 $perm->mods_delete = Input::get('mod-delete') ? true : false;
                 $modpack = Input::get('modpack');
                 if (!empty($modpack)) {
                     $perm->modpacks = $modpack;
                 } else {
                     $perm->modpacks = null;
                 }
                 $perm->save();
             }
             $user->save();
             return Redirect::back()->with('success', 'User edited successfully!');
         } catch (Exception $e) {
             Log::exception($e);
         }
     }
     return View::make('user.edit')->with('user', $user);
 }
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     $s3 = AWS::get('s3');
     $s3Bucket = 'buildbrighton-bbms';
     if (Request::hasFile('image')) {
         $file = Request::file('image');
         $event = Request::get('textevent');
         $time = Request::get('time');
         $fileData = Image::make($file)->encode('jpg', 80);
         $date = Carbon::createFromFormat('YmdHis', $event);
         $folderName = $date->hour . ':' . $date->minute . ':' . $date->second;
         try {
             $newFilename = \App::environment() . '/cctv/' . $date->year . '/' . $date->month . '/' . $date->day . '/' . $folderName . '/' . $time . '.jpg';
             $s3->putObject(array('Bucket' => $s3Bucket, 'Key' => $newFilename, 'Body' => $fileData, 'ACL' => 'public-read', 'ContentType' => 'image/jpg', 'ServerSideEncryption' => 'AES256'));
         } catch (\Exception $e) {
             \Log::exception($e);
         }
         //Log::debug('Image saved :https://s3-eu-west-1.amazonaws.com/buildbrighton-bbms/'.$newFilename);
     }
     if (Request::get('eventend') == 'true') {
         $event = Request::get('textevent');
         $date = Carbon::createFromFormat('YmdHis', $event);
         $folderName = $date->hour . ':' . $date->minute . ':' . $date->second;
         $iterator = $s3->getIterator('ListObjects', array('Bucket' => $s3Bucket, 'Prefix' => \App::environment() . '/cctv/' . $date->year . '/' . $date->month . '/' . $date->day . '/' . $folderName));
         $images = [];
         $imageDurations = [];
         foreach ($iterator as $object) {
             $images[] = 'https://s3-eu-west-1.amazonaws.com/buildbrighton-bbms/' . $object['Key'];
             $imageDurations[] = 35;
         }
         if (count($images) <= 2) {
             //only two images, probably two bad frames
             //delete them
             foreach ($iterator as $object) {
                 Log::debug("Deleting small event image " . $object['Key']);
                 $s3->deleteObject(['Bucket' => $s3Bucket, 'Key' => $object['Key']]);
             }
             return;
         }
         $gc = new GifCreator();
         $gc->create($images, $imageDurations, 0);
         $gifBinary = $gc->getGif();
         //Delete the individual frames now we have the gif
         foreach ($iterator as $object) {
             //Log::debug("Processed gif, deleting frame, ".$object['Key']);
             $s3->deleteObject(['Bucket' => $s3Bucket, 'Key' => $object['Key']]);
         }
         //Save the gif
         $newFilename = \App::environment() . '/cctv/' . $date->year . '/' . $date->month . '/' . $date->day . '/' . $folderName . '.gif';
         $s3->putObject(array('Bucket' => $s3Bucket, 'Key' => $newFilename, 'Body' => $gifBinary, 'ACL' => 'public-read', 'ContentType' => 'image/gif', 'ServerSideEncryption' => 'AES256'));
         //Log::debug('Event Gif generated :https://s3-eu-west-1.amazonaws.com/buildbrighton-bbms/'.$newFilename);
         \Slack::to("#cctv")->attach(['image_url' => 'https://s3-eu-west-1.amazonaws.com/buildbrighton-bbms/' . $newFilename, 'color' => 'warning'])->send('Movement detected');
     }
 }
Example #3
0
 /**
  * Merge PDF files together in the order they were entered to the $files array.
  *
  * @return string|bool
  * @see http://stackoverflow.com/questions/19855712/merge-multiple-pdf-files-into-one-in-php#answer-19856524
  * @uses FPDI_Protection::setSourceFile()
  * @uses FPDI_Protection::importPage()
  * @uses FPDI_Protection::addPage()
  * @uses FPDI_Protection::useTemplate()
  * @uses FPDI_Protection::SetAuthor()
  * @uses FPDI_Protection::SetCreator()
  * @uses FPDI_Protection::SetTitle()
  * @uses FPDI_Protection::SetSubject()
  * @uses FPDI_Protection::SetKeywords()
  * @uses FPDI_Protection::Output()
  */
 public function merge()
 {
     $this->Log->write(__METHOD__, Log::LOG_LEVEL_SYSTEM_INFORMATION);
     // input validation
     if (!Helpers::is_array_ne($this->files)) {
         $this->Log->write('Files is not an array. Enter at least 1 file before attempting to combine.', Log::LOG_LEVEL_WARNING);
         return false;
     }
     try {
         $pdf = new \FPDI_Protection();
         foreach ($this->files as $file) {
             $page_count = $pdf->setSourceFile($this->directory . $file);
             for ($j = 0; $j < $page_count; $j++) {
                 $template_index = $pdf->importPage($j + 1, '/MediaBox');
                 $pdf->addPage($this->orientation, $this->paper_size);
                 $pdf->useTemplate($template_index, 0, 0, 0, 0, true);
             }
             // CAUTION: Delete the PDF input file if not debugging.
             if (!$this->debug) {
                 unlink($file);
             }
         }
         $pdf->SetAuthor($this->author);
         $pdf->SetCreator($this->creator);
         $pdf->SetTitle($this->title);
         $pdf->SetSubject($this->subject);
         $pdf->SetKeywords(implode(', ', $this->keywords));
         if (Helpers::is_string_ne($this->user_password)) {
             $pdf->SetProtection(array('print', 'copy'), $this->user_password, $this->owner_password);
         }
         $output_path = $this->directory . $this->output_file;
         $this->Log->write('output file path', Log::LOG_LEVEL_USER, $output_path);
         $output = $pdf->Output('F', $output_path);
         if ($output === '') {
             // file was created
             return $output_path;
         } else {
             $this->Log->write('Error writing file to output', Log::LOG_LEVEL_WARNING, $output);
             return $output;
         }
     } catch (\Exception $ex) {
         $this->Log->exception($ex);
         return false;
     }
 }
 /**
  * dispatch
  * Dispatch request to appropriate controller-action by convention according to the HTTP method.
  */
 public function dispatch($request)
 {
     try {
         $this->request = $request;
         $this->id = $request->id;
         $this->params = $request->params;
         if ($request->isRestful()) {
             return $this->dispatchRestful();
         }
         if ($request->action) {
             return $this->{$request->action}();
         } else {
             return $this->index();
         }
     } catch (Exception $ex) {
         Log::exception($ex);
         return new Response(false, false, gettext("Ошибка на сервере пробуйте позже."));
     }
 }
Example #5
0
<?php

return array('ignore' => array(), 'detail' => true, 'log' => true, 'logger' => function ($exception) {
    Log::exception($exception);
});
Example #6
0
 /**
  * Imports XML string.
  *
  * @param string $string
  *
  * @return bool
  */
 public function loadString($string)
 {
     if (is_string($string)) {
         $xml = simplexml_load_string($string, $this->_elementClass);
         if ($xml instanceof \Layout\Layout\Element) {
             $this->_xml = $xml;
             return true;
         }
     } else {
         \Log::exception(new Exception('"$string" parameter for simplexml_load_string is not a string'));
     }
     return false;
 }
Example #7
0
 public function action_do_modify($mod_id = null)
 {
     if (empty($mod_id)) {
         return Redirect::to('mod/list');
     }
     $mod = Mod::find($mod_id);
     if (empty($mod)) {
         return Redirect::to('mod/list');
     }
     $rules = array('pretty_name' => 'required', 'name' => 'required|unique:mods,name,' . $mod->id);
     $messages = array('pretty_name_required' => 'You must enter in a Mod Name', 'name_required' => 'You must enter a Mod Slug', 'name_unique' => 'The slug you entered is already in use by another mod');
     $validation = Validator::make(Input::all(), $rules, $messages);
     if ($validation->fails()) {
         return Redirect::back()->with_errors($validation->errors);
     }
     try {
         $mod->pretty_name = Input::get('pretty_name');
         $mod->name = Input::get('name');
         $mod->author = Input::get('author');
         $mod->description = Input::get('description');
         $mod->link = Input::get('link');
         $mod->save();
         return Redirect::back()->with('success', 'Mod successfully edited.');
     } catch (Exception $e) {
         Log::exception($e);
     }
 }
Example #8
0
 /**
  * Run the application with given URI. If URI is not set, then application
  * will try to detect it automatically.
  * 
  * @param string $uri [optional]
  */
 public static function run($uri = null)
 {
     static::$requestStartTime = isset($_SERVER['REQUEST_TIME_FLOAT']) ? $_SERVER['REQUEST_TIME_FLOAT'] : microtime(true);
     $config = static::getConfig();
     $isCLI = defined('KOLDY_CLI') && KOLDY_CLI === true;
     if (!$isCLI) {
         // this is normal HTTP request that came from Web Server, so we'll handle it
         if ($uri === null && isset($_SERVER['REQUEST_URI'])) {
             static::$uri = $uri = $_SERVER['REQUEST_URI'];
             $questionPos = strpos($uri, '?');
             if ($questionPos !== false) {
                 $uri = substr($uri, 0, $questionPos);
             }
         } else {
             if ($uri === null) {
                 // if your script goes here, then something is really f****d up on your server
                 throw new Exception('URI doesn\'t exists');
             }
         }
         try {
             static::init();
             $routingClassName = $config['routing_class'];
             $routeOptions = isset($config['routing_options']) ? $config['routing_options'] : null;
             static::$routing = new $routingClassName($uri, $routeOptions);
             $response = static::$routing->exec();
             if ($response instanceof Response) {
                 print $response->flush();
             } else {
                 if (is_array($response)) {
                     $className = static::$routing->getControllerClass();
                     $actionName = static::$routing->getActionMethod();
                     throw new Exception("Invalid return value from {$className}->{$actionName}; got array instead of something else");
                 } else {
                     print $response;
                 }
             }
         } catch (\Exception $e) {
             // something threw up
             $route = static::route();
             if ($route === null) {
                 // damn, even route class wasn't initialized
                 header('HTTP/1.1 503 Service Temporarily Unavailable', true, 503);
                 header('Status: 503 Service Temporarily Unavailable');
                 header('Retry-After: 300');
                 // 300 seconds / 5 minutes
                 if (static::inDevelopment()) {
                     print "<p>{$e->getMessage()}</p>";
                     print "<pre>{$e->getTraceAsString()}</pre>";
                 } else {
                     print '<p>Something went really wrong. Please try again later.</p>';
                 }
             } else {
                 // otherwise, route should handle exception
                 // because of this, you can customize almost everything
                 static::route()->handleException($e);
             }
         }
     } else {
         // and this is case when you're dealing with CLI request
         // scripts are stored in /application/scripts, but before that, we need to determin which script is called
         global $argv;
         // $argv[0] - this should be "cli.php", but we don't need this at all
         static::init();
         try {
             // so, if you run your script as "php cli.php backup", you'll have only two elements
             // in the future, we might handle different number of parameters, but until that, we won't
             // you can also call script in module using standard colon as separator
             // example: php cli.php user:backup   -> where "user" is module and "backup" is script name
             $script = $argv[1];
             // this should be the second parameter
             static::$cliName = $script;
             if (preg_match('/^([a-zA-Z0-9\\_\\-\\:]+)$/', $script)) {
                 if (strpos($script, ':') !== false) {
                     // script name has colon - it means that the script needs to be looked for in modules
                     $tmp = explode(':', $script);
                     static::$cliScript = static::getApplicationPath("modules/{$tmp[0]}/scripts/{$tmp[1]}.php");
                     if (is_dir(static::getApplicationPath("modules/{$tmp[0]}"))) {
                         static::registerModule($tmp[0]);
                     }
                 } else {
                     static::$cliScript = static::getApplicationPath("scripts/{$script}.php");
                 }
                 if (!is_file(static::$cliScript)) {
                     throw new Exception('CLI script doesn\'t exist on ' . static::$cliScript);
                 } else {
                     include static::$cliScript;
                 }
             } else {
                 throw new Exception("Invalid script name: {$script}");
             }
         } catch (\Exception $e) {
             echo "{$e->getMessage()} in {$e->getFile()}:{$e->getLine()}\n\n{$e->getTraceAsString()}";
             Log::exception($e);
         }
     }
 }
Example #9
0
 private static function log($exception)
 {
     if (Config::item("errors", "log", false)) {
         Log::exception($exception);
     }
 }
Example #10
0
 public static function log($e)
 {
     if (Config::get('error.log')) {
         Log::exception($e);
     }
 }
Example #11
0
 public function action_do_create()
 {
     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', 'slug' => 'required|checkresources|unique:modpacks');
     $messages = array('name_required' => 'You must enter a modpack name.', 'slug_required' => 'You must enter a modpack slug', 'slug_checkresources' => 'Make sure all the resources required exist before submitting a pack!');
     $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/';
     try {
         $modpack = new Modpack();
         $modpack->name = Input::get('name');
         $modpack->slug = Str::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->save();
         return Redirect::to('modpack/view/' . $modpack->id);
     } catch (Exception $e) {
         Log::exception($e);
     }
 }
Example #12
0
 /**
  * If config set for logging then log the exception
  * @param  Exception  $exception
  * @return void
  */
 public static function log($exception)
 {
     if ($file = Configuration::get('error.log')) {
         Log::exception($exception, $file);
     }
 }
Example #13
0
 public function upload()
 {
     try {
         $folder = BasefileModel::createFromPath($this->params->dir);
         if ($folder) {
             if ($_FILES['file']['error'] == 0) {
                 if ($folder->upload($_FILES['file'], $this->params->name)) {
                     return new Response($folder->getChildren());
                 } else {
                     return new ResponseError(gettext("Не удалось загрузить файл."));
                 }
             } else {
                 switch ($_FILES['file']['error']) {
                     case UPLOAD_ERR_INI_SIZE:
                     case UPLOAD_ERR_FORM_SIZE:
                         return new ResponseError(gettext("Размер принятого файла превысил максимально допустимый размер."));
                     case UPLOAD_ERR_PARTIAL:
                         return new ResponseError(gettext("Загружаемый файл был получен только частично."));
                     case UPLOAD_ERR_NO_FILE:
                         return new ResponseError(gettext("Не удалось загрузить файл."));
                 }
             }
         } else {
             return new ResponseError(gettext("Не найдена директория."));
         }
     } catch (Exception $ex) {
         Log::exception($ex);
         return new ResponseError(gettext("Не возможно загрузить в эту директорию."));
     }
 }
Example #14
0
 public function action_do_create()
 {
     $rules = array('name' => 'required|unique:modpacks', 'slug' => 'required|unique:modpacks');
     $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);
     }
     try {
         $modpack = new Modpack();
         $modpack->name = Input::get('name');
         $modpack->slug = Str::slug(Input::get('slug'));
         $modpack->save();
         return Redirect::to('modpack/view/' . $modpack->id);
     } catch (Exception $e) {
         Log::exception($e);
     }
 }
Example #15
0
 private function getModVersions($mod, $versions)
 {
     foreach ($versions as $version => $data) {
         try {
             $ver = ModVersion::where('mod_id', '=', $mod->id)->where('version', '=', $version)->first();
             if (empty($ver)) {
                 set_time_limit(0);
                 $ver = new ModVersion();
                 $ver->mod_id = $mod->id;
                 $ver->version = $version;
                 $ver->md5 = $this->mod_md5($mod, $version);
                 $ver->save();
             } else {
                 if (empty($ver->md5)) {
                     $ver->md5 = $this->mod_md5($mod, $version);
                     $ver->save();
                 }
             }
         } catch (Exception $e) {
             Log::exception($e);
         }
     }
 }