public function logoutAction()
 {
     $user = Session::get('user');
     Session::delete('user');
     Session::destroy();
     Log::info("User #{$user['id']} {$user['username']} logged out");
     return Redirect::temporary(Url::href('index'));
 }
 /**
  * Update user settings if needed
  */
 public function editUserAjax()
 {
     // TODO: Finish this
     $params = Input::requireParams('id');
     $id = (int) $params->id;
     $user = User::fetchOne($id);
     if ($user === false) {
         return BootstrapUI::formResponse()->failed('Invalid user');
     }
     $validator = Validator::create(array('id' => 'required|integer', 'username' => "required|min:2|max:32|unique:\\User,username,{$id},id", 'first_name' => 'max:255', 'last_name' => 'max:255', 'pass' => 'min:5|max:255', 'pass2' => 'identical:pass', 'account_type' => 'required', 'timezone' => 'required'));
     if ($validator->failed()) {
         return BootstrapUI::formResponse()->failedOn($validator);
     }
     $params = $validator->getParamsObj();
     $data = $validator->getParams();
     unset($data['id'], $data['pass'], $data['pass2']);
     if ($params->pass !== null && strlen($params->pass) >= 5) {
         $data['pass'] = md5($params->pass);
     }
     if ($user->save($data)) {
         Log::info("Updated user #{$id} {$params->username}");
     }
     return BootstrapUI::formResponse();
 }
Exemple #3
0
 /**
  * (non-PHPdoc)
  * @see \Koldy\Mail\Driver\AbstractDriver::send()
  */
 public function send()
 {
     $from = $this->fromName !== null ? "{$this->fromName} <{$this->fromEmail}>" : $this->fromEmail;
     $to = '';
     foreach ($this->to as $toUser) {
         $to .= $toUser['name'] !== null ? "{$toUser['name']} <{$toUser['email']}>" : $toUser['email'];
         $to .= ', ';
     }
     $to = substr($to, 0, -2);
     Log::info("E-mail [SIMULATED] is sent from {$from} to {$to} with subject: {$this->subject}");
     return true;
 }
 public function stackTracesAction()
 {
     Log::info('Started rebuilding stack traces');
     Stack\Trace::rebuild();
 }
Exemple #5
0
 /**
  * Process the request
  * @param string $os 'Android','iOS' or 'Windows'
  *
  * TODO: This logic shouldn't be in the model
  */
 public static function processRequest($os)
 {
     if (!isset($_POST['PACKAGE_NAME'])) {
         Log::warning('Package name is not set! UAS=' . Request::userAgent() . ' POST=' . Json::encode($_POST));
     }
     $time = time();
     $ip = $_SERVER['REMOTE_ADDR'];
     $host = gethostbyaddr($ip);
     $country = null;
     $provider = null;
     if ($host != $ip && strpos($host, '.') !== false) {
         $country = strtolower(substr($host, strrpos($host, '.') + 1));
         if (strlen($country) != 2) {
             $country = null;
         }
         $provider = \Provider::normalizeHostName($host);
     }
     Log::notice("Got request time={$time} host={$host} country={$country}");
     $values = array('created_at', 'package_name', 'app_version_code', 'app_version_name', 'brand', 'phone_model', 'product', 'stack_trace', 'android_version', 'file_path', 'total_mem_size', 'available_mem_size', 'user_comment', 'user_app_start_date', 'user_crash_date', 'installation_id', 'report_id', 'user_email');
     $data = array();
     $vals = $_POST;
     foreach ($values as $key) {
         $key = strtoupper($key);
         if (isset($vals[$key])) {
             $data[$key] = trim($vals[$key]);
             unset($vals[$key]);
         }
     }
     if (isset($data['user_email']) && ($data['user_email'] == 'N/A' || trim($data['user_email']) == '')) {
         $data['user_email'] = null;
     }
     $data['created_at'] = gmdate('Y-m-d H:i:s');
     $data['country'] = $country;
     $data['provider'] = $provider;
     $data['os'] = $os;
     $secureCount = 0;
     do {
         $submit = static::create($data);
         if ($submit === false) {
             Db::getAdapter()->close();
             Log::info("Failed to insert crash submit report for time={$time}, waiting 5 seconds");
             set_time_limit(60);
             sleep(5);
             Db::getAdapter()->reconnect();
             Log::info("Retry {$secureCount} insert crash submit report for time={$time}");
         }
     } while ($submit === false && $secureCount++ < 3);
     if ($submit !== false) {
         foreach ($vals as $metaName => $metaValue) {
             if ($metaValue !== null) {
                 $metaValue = trim($metaValue);
                 if (strlen($metaValue) > 0) {
                     $secureCount = 0;
                     do {
                         $dbMeta = $submit->insertMeta(strtolower($metaName), trim($metaValue));
                         if ($dbMeta === false) {
                             Db::getAdapter()->close();
                             Log::info("Failed to insert submit meta for meta={$metaName} time={$time}, waiting 5 seconds");
                             set_time_limit(60);
                             sleep(5);
                             Db::getAdapter()->reconnect();
                             Log::info("Retry {$secureCount} meta insert for meta={$metaName} time={$time}");
                         }
                     } while ($dbMeta === false && $secureCount++ < 2);
                 }
             }
         }
     }
     \Email\Trigger::processRequest($_POST);
     Log::notice("Done request time={$time}");
 }
Exemple #6
0
 /**
  * Rebuild stack_trace table
  * CAUTION!!!! If you have a lot of records, this could take hours or days do get done!
  */
 public static function rebuild()
 {
     Status::calculationStarted();
     Status::setCalculationStatus('Initializing');
     Status::setCalculationStatus('Reseting stack_trace_ids to NULL');
     Db::query('UPDATE crash_archive SET stack_trace_id = NULL');
     Status::setCalculationStatus('Emptying stack_trace table');
     Db::query('TRUNCATE TABLE stack_trace');
     $stacks = array();
     // 		foreach (Stack\Trace::all() as $r) {
     // 			$stacks[$r['hash']] = (int) $r['id'];
     // 		}
     $total = \Crash\Archive::count();
     $index = 0;
     $start = 0;
     do {
         $query = new Select('crash_archive');
         $query->field('id')->where('id', '>', $start)->where('id', '<=', $start + 100000);
         Status::setCalculationStatus("Taking IDs from {$start} to " . ($start + 100000));
         $records = $query->fetchAll();
         $sizeofIds = count($records);
         foreach ($records as $r) {
             $id = (int) $r['id'];
             $crash = new \Crash\Archive(array('id' => $id));
             $stackTrace = $crash->getMeta('stack_trace');
             if ($stackTrace !== null) {
                 $summary = static::getSummary($stackTrace);
                 $md5 = md5($summary);
                 if (isset($stacks[$md5])) {
                     $stackTraceId = $stacks[$md5];
                 } else {
                     $tmp = \Stack\Trace::create(array('hash' => $md5, 'summary' => $summary, 'created_at' => $crash->created_at));
                     $stackTraceId = (int) $tmp->id;
                     $stacks[$md5] = $stackTraceId;
                 }
                 $crash->stack_trace_id = $stackTraceId;
                 $crash->save();
                 Log::info("Updated #{$id} with stack={$stackTraceId}");
             } else {
                 Log::info("Crash report #{$id} is skipped because stack_trace is missing in meta table");
             }
             if ($index % 25 == 0) {
                 $percent = round($index / $total * 100, 2);
                 Status::setCalculationStatus("Working on {$index}/{$sizeofIds} {$percent}%");
             }
             $index++;
         }
         $start += 100000;
     } while (sizeof($records) > 0);
     Status::setCalculationStatus('Started stack trace recalculation!');
     Log::info('Started recalculation of stack_trace counts');
     static::recalculate();
     Status::calculationFinished('all');
 }
 /**
  * Calculate for reports
  * @return boolean
  */
 public function calculate()
 {
     if (Status::isCalculationInProgress()) {
         Log::info('Trying to start calculation, but calculation is already in progress. Last was started on ' . Status::getLastCalculationProcessStart() . ' UTC');
         return false;
     }
     ini_set('memory_limit', '512M');
     set_time_limit(0);
     Status::calculationStarted();
     Status::setCalculationStatus('Initializing');
     Log::info('Calculation started');
     /**
      * metas: 'file_path', 'build', 'environment', 'settings_global', 'settings_system', 'settings_secure',
      * 'device_features', 'shared_preferences', 'initial_configuration', 'crash_configuration',
      * 'dumpsys_meminfo', 'display', 'stack_trace', 'logcat', 'tktal_mem_size', '@evice_features', 'installation_id'
      */
     $query = new Select();
     $query->from('crash_submit')->field('id')->limit(0, 200000);
     $maxQuery = CrashArchive::query()->field('MAX(created_at)', 'time');
     $max = $maxQuery->fetchFirstObj();
     unset($maxQuery);
     $lastDatetime = new DateTime(gmdate('Y-m-d H:00:00'));
     $lastDatetime->modify('-1 hour');
     $query->where('created_at', '<', $lastDatetime->format('Y-m-d H:i:s'));
     $ids = $query->fetchAllObj();
     $sizeofIds = sizeof($ids);
     Log::info('Loaded ids: ' . $sizeofIds);
     $brandTotals = $countryTotals = $packageTotals = $packageVersionTotals = $phoneModelTotals = $productTotals = $providerTotals = $stackTraceTotals = $osVersionTotals = array();
     foreach ($ids as $index => $r) {
         // on every 25 records, we should ask ourself: is that it?
         if ($index % 25 == 0) {
             $shouldTerminate = Status::shouldCalcuationTerminate();
             if ($shouldTerminate !== false) {
                 Log::info("Noticed request for calculation termination on {$shouldTerminate}. Aborted!");
                 Status::setCalculationStatus('Terminated after ' . ($index + 1) . ' records');
                 Status::terminateCalculation(false);
                 return false;
             }
         }
         $id = $r->id;
         // record by record
         Log::info("Will now fetch id={$id}");
         if ($index % 15 == 0) {
             $percent = round($index / $sizeofIds * 100, 2);
             Status::setCalculationStatus("Working; {$index}/{$sizeofIds} {$percent}%");
         }
         $submit = CrashSubmit::fetchOne($id);
         if ($submit !== false && $submit->package_name !== null && trim($submit->package_name !== null) != '') {
             $appStartTime = strtotime($submit->user_app_start_date);
             $appCrashTime = strtotime($submit->user_crash_date);
             $appLifetime = $appCrashTime - $appStartTime;
             $metas = $submit->getMetas();
             if ($submit->report_id !== null && trim($submit->report_id) !== '') {
                 $metas['report_id'] = $submit->report_id;
             }
             if ($submit->file_path !== null && trim($submit->file_path) !== '') {
                 $metas['file_path'] = $submit->file_path;
             }
             if ($submit->installation_id !== null && trim($submit->installation_id) !== '') {
                 $metas['installation_id'] = $submit->installation_id;
             }
             $stackTrace = $submit->stack_trace;
             if ($stackTrace === null) {
                 $stackTraceSummary = null;
             } else {
                 $metas['stack_trace'] = $stackTrace;
                 $stackTraceSummary = StackTrace::getSummary($stackTrace);
             }
             $packageId = $this->getPackageId($submit->package_name);
             $packageVersionId = $this->getPackageVersionId($this->getPackageId($submit->package_name), $submit->app_version_name);
             $brandId = $this->getBrandId($submit->brand);
             $phoneModelId = $this->getModelId($this->getBrandId($submit->brand), $submit->phone_model);
             $productId = $this->getProductId($this->getBrandId($submit->brand), $submit->product);
             $osVersionId = $this->getOsVersion($submit->os, $submit->android_version);
             $stackTraceId = $this->getStackTraceId($stackTraceSummary, $submit->created_at);
             $countryId = $this->getCountryId($submit->country);
             $providerId = $this->getProviderId($submit->provider);
             $archive = CrashArchive::create(array('created_at' => $submit->created_at, 'package_id' => $packageId, 'package_version_id' => $packageVersionId, 'brand_id' => $brandId, 'model_id' => $phoneModelId, 'product_id' => $productId, 'os' => $submit->os, 'os_version_id' => $osVersionId, 'total_mem_size' => $submit->total_mem_size, 'available_mem_size' => $submit->available_mem_size, 'user_comment' => trim($submit->user_comment) == '' ? null : trim($submit->user_comment), 'user_email' => trim($submit->user_email) == 'N/A' ? null : trim($submit->user_email), 'user_app_start_date' => $submit->user_app_start_date, 'user_crash_date' => $submit->user_crash_date, 'user_app_lifetime' => $appLifetime, 'stack_trace_id' => $stackTraceId, 'country_id' => $countryId, 'provider_id' => $providerId));
             $archive->insertMeta($metas);
             // prepare increments for totals
             if ($packageId !== null) {
                 if (!isset($packageTotals[$packageId])) {
                     $packageTotals[$packageId] = 0;
                 }
                 $packageTotals[$packageId]++;
             }
             if ($packageVersionTotals !== null) {
                 if (!isset($packageVersionTotals[$packageVersionId])) {
                     $packageVersionTotals[$packageVersionId] = 0;
                 }
                 $packageVersionTotals[$packageVersionId]++;
             }
             if ($brandId !== null) {
                 if (!isset($brandTotals[$brandId])) {
                     $brandTotals[$brandId] = 0;
                 }
                 $brandTotals[$brandId]++;
             }
             if ($phoneModelId !== null) {
                 if (!isset($phoneModelTotals[$phoneModelId])) {
                     $phoneModelTotals[$phoneModelId] = 0;
                 }
                 $phoneModelTotals[$phoneModelId]++;
             }
             if ($productId !== null) {
                 if (!isset($productTotals[$productId])) {
                     $productTotals[$productId] = 0;
                 }
                 $productTotals[$productId]++;
             }
             if ($osVersionTotals !== null) {
                 if (!isset($osVersionTotals[$osVersionId])) {
                     $osVersionTotals[$osVersionId] = 0;
                 }
                 $osVersionTotals[$osVersionId]++;
             }
             if ($stackTraceId !== null) {
                 if (!isset($stackTraceTotals[$stackTraceId])) {
                     $stackTraceTotals[$stackTraceId] = 0;
                 }
                 $stackTraceTotals[$stackTraceId]++;
             }
             if ($countryId !== null) {
                 if (!isset($countryTotals[$countryId])) {
                     $countryTotals[$countryId] = 0;
                 }
                 $countryTotals[$countryId]++;
             }
             if ($providerId !== null) {
                 if (!isset($providerTotals[$providerId])) {
                     $providerTotals[$providerId] = 0;
                 }
                 $providerTotals[$providerId]++;
             }
         }
     }
     if ($sizeofIds > 0) {
         Log::info('Calculation done');
         Status::setCalculationStatus('Starting to delete submit records');
         $deleteIds = array();
         foreach ($ids as $index => $r) {
             $deleteIds[] = $r->id;
             if (sizeof($deleteIds) == 100) {
                 $percent = round($index / $sizeofIds * 100, 2);
                 Status::setCalculationStatus("Deleting submit records {$index}/{$sizeofIds} {$percent}%");
                 Db::delete('crash_submit_meta')->whereIn('submit_id', $deleteIds)->exec();
                 Db::delete('crash_submit')->whereIn('id', $deleteIds)->exec();
                 $deleteIds = array();
             }
         }
         if (sizeof($deleteIds) > 0) {
             Status::setCalculationStatus("Deleting submit records {$index}/{$sizeofIds} 100%");
             Db::delete('crash_submit_meta')->whereIn('submit_id', $deleteIds)->exec();
             Db::delete('crash_submit')->whereIn('id', $deleteIds)->exec();
         }
         Status::setCalculationStatus('Started totals calculations update!');
         // update calculated increments
         foreach ($brandTotals as $id => $total) {
             Status::setCalculationStatus('Brands: Updating calculated totals');
             Db::update('brand')->increment('total', $total)->where('id', $id)->exec();
         }
         foreach ($countryTotals as $id => $total) {
             Status::setCalculationStatus('Countries: Updating calculated totals');
             Db::update('country')->increment('total', $total)->where('id', $id)->exec();
         }
         foreach ($packageTotals as $id => $total) {
             Status::setCalculationStatus('Packages: Updating calculated totals');
             Db::update('package')->increment('total', $total)->where('id', $id)->exec();
         }
         foreach ($packageVersionTotals as $id => $total) {
             Status::setCalculationStatus('Package version: Updating calculated totals');
             Db::update('package_version')->increment('total', $total)->where('id', $id)->exec();
         }
         foreach ($phoneModelTotals as $id => $total) {
             Status::setCalculationStatus('Phone models: Updating calculated totals');
             Db::update('phone_model')->increment('total', $total)->where('id', $id)->exec();
         }
         foreach ($productTotals as $id => $total) {
             Status::setCalculationStatus('Products: Updating calculated totals');
             Db::update('product')->increment('total', $total)->where('id', $id)->exec();
         }
         foreach ($providerTotals as $id => $total) {
             Status::setCalculationStatus('Providers: Updating calculated totals');
             Db::update('provider')->increment('total', $total)->where('id', $id)->exec();
         }
         foreach ($stackTraceTotals as $id => $total) {
             Status::setCalculationStatus('Stack traces: Updating calculated totals');
             Db::update('stack_trace')->increment('total', $total)->where('id', $id)->exec();
         }
         foreach ($osVersionTotals as $id => $total) {
             Status::setCalculationStatus('OS version: Updating calculated totals');
             Db::update('version')->increment('total', $total)->where('id', $id)->exec();
         }
     } else {
         // 			Log::info('Calculation done, no records processed');
     }
     Status::calculationFinished($sizeofIds);
     return true;
 }