Ejemplo n.º 1
1
 private function _send_reset($form)
 {
     $user_name = $form->reset->inputs["name"]->value;
     $user = user::lookup_by_name($user_name);
     if ($user && !empty($user->email)) {
         $user->hash = random::hash();
         $user->save();
         $message = new View("reset_password.html");
         $message->confirm_url = url::abs_site("password/do_reset?key={$user->hash}");
         $message->user = $user;
         Sendmail::factory()->to($user->email)->subject(t("Password Reset Request"))->header("Mime-Version", "1.0")->header("Content-type", "text/html; charset=UTF-8")->message($message->render())->send();
         log::success("user", t("Password reset email sent for user %name", array("name" => $user->name)));
     } else {
         if (!$user) {
             // Don't include the username here until you're sure that it's XSS safe
             log::warning("user", t("Password reset email requested for user %user_name, which does not exist.", array("user_name" => $user_name)));
         } else {
             log::warning("user", t("Password reset failed for %user_name (has no email address on record).", array("user_name" => $user->name)));
         }
     }
     // Always pretend that an email has been sent to avoid leaking
     // information on what user names are actually real.
     message::success(t("Password reset email sent"));
     json::reply(array("result" => "success"));
 }
Ejemplo n.º 2
0
 /**
  * Берет список записей и генерирует документы
  */
 public function cron()
 {
     $queue = $this->getList();
     require_once ABS_PATH . '/classes/log.php';
     $log = new log('docgen_cron/' . SERVER . '-%d%m%Y.log', 'a', "%d.%m.%Y %H:%M:%S: ");
     foreach ($queue as $item) {
         try {
             $docGenClass = $this->getClass($item['class_name'], $item['class_params']);
             $docGenClass->setData(mb_unserialize($item['fields']));
             $docGenClass->setDocName($item['type'], $item['original_name']);
             $docGenClass->beforeGenerate();
             if ($docGenClass->isExcel($item['type'])) {
                 $ok = $docGenClass->generateExcel($item['type']);
             } else {
                 $ok = $docGenClass->generate($item['type']);
             }
             if ($ok) {
                 $this->removeItem($item['id']);
             } else {
                 $this->incrementTry($item['id']);
             }
         } catch (Exception $e) {
             $log->writeln(sprintf("id = %s: %s", $item['id'], iconv('CP1251', 'UTF-8', $e->getMessage())));
             $this->incrementTry($item['id']);
         }
     }
 }
 function postNextTopStory()
 {
     // only post one story every three hours
     $tstamp = $this->statusObj->getState('lastTwitterPost');
     if (!isset($_GET['test']) and time() - $tstamp < 60 * TWITTER_INTERVAL_MINUTES) {
         return;
     }
     //echo 'continuing';
     require_once PATH_CORE . '/classes/content.class.php';
     $cObj = new content($this->db);
     require_once PATH_CORE . '/classes/log.class.php';
     $logObj = new log($this->db);
     $topStories = $cObj->fetchUpcomingStories();
     $uid = 1;
     while ($data = $this->db->readQ($topStories)) {
         if (!$this->checkLog($uid, $data->siteContentId) and $data->score >= TWITTER_SCORE_THRESHOLD) {
             // post to twitter
             $result = $this->update($data->siteContentId, $data->title);
             if ($result) {
                 $logItem = $logObj->serialize(0, $uid, 'postTwitter', $data->siteContentId);
                 $logObj->add($logItem);
                 $this->statusObj->setState('lastTwitterPost', time());
             }
             // only do one at a time
             return;
         }
     }
 }
Ejemplo n.º 4
0
 public function actionLog()
 {
     $view = new ViewConstuctor();
     $log = new \log();
     $view->log = $log->getMessage();
     $view->Display('Admin/Log');
 }
Ejemplo n.º 5
0
 public function saveLog($xml)
 {
     // !!!
     // @todo Вот не знаю стоит ли тут делать так, или все же легче вызвать self::initReqXml(); но там у нас сессия инициализируется
     $this->_clientXml = new DOMDocument();
     libxml_use_internal_errors(true);
     if (!$this->_clientXml->loadXML($xml)) {
         $this->_debug = 1;
         $xe_levels = array(LIBXML_ERR_WARNING => 'WARNING', LIBXML_ERR_ERROR => 'ERROR', LIBXML_ERR_FATAL => 'FATAL');
         foreach (libxml_get_errors() as $xe) {
             $err .= $xe_levels[$xe->level] . ": (line: {$xe->line}, column: {$xe->column}): {$xe->message}";
         }
         libxml_clear_errors();
         $this->error(EXTERNAL_ERR_WRONG_REQ, $err);
     }
     $ns_name = basename($this->_clientXml->documentElement->getAttribute('xmlns:f'));
     if ($ns_name == '') {
         $ns_name = basename($this->_clientXml->documentElement->getAttribute('xmlns:hh'));
     } else {
         $ns_name = 'freetray';
     }
     if ($ns_name == '') {
         $ns_name = 'other';
     }
     $log = new log("external/{$ns_name}-%d%m%Y.log");
     $log->writeln('--------------' . getRemoteIP() . '--------------');
     $log->writeln($xml);
 }
Ejemplo n.º 6
0
 /**
  * 通过id获取信息
  */
 public function update($_POST)
 {
     $log = new log();
     $log->addLog("update test", 1);
     $columns[0] = "field1";
     $values[0] = $_POST['field1'];
     $columns[1] = "field2";
     $values[1] = $_POST['field2'];
     $row = $this->db->updateParamById("test", $columns, $values, "id", $_POST['id']);
     return $row;
 }
Ejemplo n.º 7
0
 public function GetOne($id)
 {
     $query = 'SELECT * FROM ' . $this->tableName . ' WHERE id=:id';
     $param[':id'] = $id;
     $res = $this->query($query, $param);
     if (empty($res)) {
         $log = new log();
         $log->write('Trying to get unexisting article');
         throw new E404Exception('The article with id=' . $id . ' was not found');
     }
     return $this->query($query, $param)[0];
 }
Ejemplo n.º 8
0
 public function payment($sum)
 {
     // На бете альфе включаем дебаг режим
     if (!is_release()) {
         //$sum = 0.1;// @debug
         $this->api->setDebug(true);
     }
     $result = $this->api->requestPayment(round((double) $sum, 2), $this->account->id);
     if ($result['status'] == API_Webmoney::STATUS_SUCCESS) {
         $process = $this->api->processPayment($this->api->merchant_transaction_id, $result['processor_transaction_id']);
         switch ($process['status']) {
             case API_Webmoney::STATUS_PAYMENT_PROGRESS:
             case API_Webmoney::STATUS_PAYMENT_SUCCESS:
                 // Зачисляем деньги на бете/альфе
                 //                    if(!is_release()) {
                 //                        $paymentDateTime = date('d.m.Y H:i');
                 //                        $orderNumber     = rand(1, 99999999);
                 //                        $descr = "WebMoney с кошелька {$this->data['wallet']} сумма - {$sum}, обработан {$paymentDateTime}, номер покупки - $orderNumber";
                 //
                 //                        $this->account->deposit($op_id, $this->account->id, $sum, $descr, 3, $sum, 12);
                 //                    }
                 return true;
                 break;
             case API_Webmoney::STATUS_PAYMENT_FAIL:
                 ob_start();
                 var_dump($result);
                 var_dump($process);
                 $content = ob_get_clean();
                 $this->log->writeln("FAIL Payment:\naccount:{$this->account->id}\n");
                 $this->log->write("Request:\n " . $this->api->last_request->getBody());
                 $this->log->write("Result:\n {$content}");
                 return false;
                 break;
                 // Отложить платеж на пол часа
                 // @todo придумать как отложить запрос на потом
                 //case API_Webmoney::STATUS_PAYMENT_PROCESS:
             // Отложить платеж на пол часа
             // @todo придумать как отложить запрос на потом
             //case API_Webmoney::STATUS_PAYMENT_PROCESS:
             default:
                 return;
                 break;
         }
     } else {
         ob_start();
         var_dump($result);
         $content = ob_get_clean();
         $this->log->writeln("FAIL Payment:\naccount:{$this->account->id}\n");
         $this->log->write("Request:\n " . $this->api->last_request->getBody());
         $this->log->write("Result:\n {$content}");
         return false;
     }
 }
Ejemplo n.º 9
0
 /**
  * Esta funcion guarda en el log para el sistema de auditoria
  * @access public
  * @author: fzalazar
  * @param $accion: id de la accion
  * @param $parametro: descripcion de la accion (opcional)
  * @param $torneo: id del torneo (opcional)
  * @param $rueda: rueda (opcional)
  * @param $fecha: numero de fecha (opcional)
  * @param $partido: partido (opcional)
  * @return true si pudo insertar en el log, false en caso contrario
  * @modificacion: dabiricha (agregado de parametros opcionales: torneo, rueda, fecha y partido)
  */
 function registerPartido($accion, $parametro = '', $torneo = 0, $rueda = 0, $fecha = 0, $partido = 0)
 {
     $log = new log();
     $log->id_accion = $accion;
     $log->fecha = date("Y/m/d");
     $log->hora = date("H:i:s");
     $log->parametro = $parametro ? $parametro : NULL;
     $log->torneo = $torneo;
     $log->rueda = $rueda;
     $log->numero_fecha = $fecha;
     $log->partido = $partido;
     $log->id_usuario = RegistryHelper::getIdUsuario();
     return $log->insert();
 }
Ejemplo n.º 10
0
 static function start()
 {
     self::boot();
     // 函数库
     require CORE_PATH . 'load.php';
     load::register();
     // 自动加载,没有找到本地类的
     register_shutdown_function('\\poem\\app::appFatal');
     // 错误和异常处理
     set_error_handler('\\poem\\app::appError');
     set_exception_handler('\\poem\\app::appException');
     t('POEM_TIME');
     $module = defined('NEW_MODULE') ? NEW_MODULE : 'home';
     if (!is_dir(APP_PATH . $module)) {
         \poem\more\Build::checkModule($module);
     }
     Route::run();
     // 路由管理
     self::exec();
     // 执行操作
     t('POEM_TIME', 0);
     if (!config('debug_trace') || IS_AJAX || IS_CLI) {
         exit;
     }
     log::show();
     exit;
 }
Ejemplo n.º 11
0
 private function _save_api_key($form)
 {
     $new_key = $form->sharing->api_key->value;
     if ($new_key && !l10n_client::validate_api_key($new_key)) {
         $form->sharing->api_key->add_error("invalid", 1);
         $valid = false;
     } else {
         $valid = true;
     }
     if ($valid) {
         $old_key = l10n_client::api_key();
         l10n_client::api_key($new_key);
         if ($old_key && !$new_key) {
             message::success(t("Your API key has been cleared."));
         } else {
             if ($old_key && $new_key && $old_key != $new_key) {
                 message::success(t("Your API key has been changed."));
             } else {
                 if (!$old_key && $new_key) {
                     message::success(t("Your API key has been saved."));
                 }
             }
         }
         log::success(t("gallery"), t("l10n_client API key changed."));
         url::redirect("admin/languages");
     } else {
         // Show the page with form errors
         $this->index($form);
     }
 }
Ejemplo n.º 12
0
 /**
  * @see REST_Controller::_update($resource)
  */
 public function _update($photo)
 {
     access::verify_csrf();
     access::required("view", $photo);
     access::required("edit", $photo);
     $form = photo::get_edit_form($photo);
     if ($valid = $form->validate()) {
         if ($form->edit_photo->filename->value != $photo->name) {
             // Make sure that there's not a conflict
             if (Database::instance()->from("items")->where("parent_id", $photo->parent_id)->where("id <>", $photo->id)->where("name", $form->edit_photo->filename->value)->count_records()) {
                 $form->edit_photo->filename->add_error("conflict", 1);
                 $valid = false;
             }
         }
     }
     if ($valid) {
         $photo->title = $form->edit_photo->title->value;
         $photo->description = $form->edit_photo->description->value;
         $photo->rename($form->edit_photo->filename->value);
         $photo->save();
         module::event("photo_edit_form_completed", $photo, $form);
         log::success("content", "Updated photo", "<a href=\"photos/{$photo->id}\">view</a>");
         message::success(t("Saved photo %photo_title", array("photo_title" => p::clean($photo->title))));
         print json_encode(array("result" => "success", "location" => url::site("photos/{$photo->id}")));
     } else {
         print json_encode(array("result" => "error", "form" => $form->__toString()));
     }
 }
Ejemplo n.º 13
0
 public function auth()
 {
     if (!identity::active_user()->admin) {
         access::forbidden();
     }
     access::verify_csrf();
     $form = self::_form();
     $valid = $form->validate();
     $user = identity::active_user();
     if ($valid) {
         module::event("user_auth", $user);
         if (!request::is_ajax()) {
             message::success(t("Successfully re-authenticated!"));
         }
         url::redirect(Session::instance()->get_once("continue_url"));
     } else {
         $name = $user->name;
         log::warning("user", t("Failed re-authentication for %name", array("name" => $name)));
         module::event("user_auth_failed", $name);
         if (request::is_ajax()) {
             $v = new View("reauthenticate.html");
             $v->form = $form;
             $v->user_name = identity::active_user()->name;
             json::reply(array("html" => (string) $v));
         } else {
             self::_show_form($form);
         }
     }
 }
Ejemplo n.º 14
0
 /**
  * @see REST_Controller::_update($resource)
  */
 public function _update($photo)
 {
     access::verify_csrf();
     access::required("view", $photo);
     access::required("edit", $photo);
     $form = photo::get_edit_form($photo);
     $valid = $form->validate();
     if ($valid = $form->validate()) {
         if ($form->edit_item->filename->value != $photo->name || $form->edit_item->slug->value != $photo->slug) {
             // Make sure that there's not a name or slug conflict
             if ($row = Database::instance()->select(array("name", "slug"))->from("items")->where("parent_id", $photo->parent_id)->where("id <>", $photo->id)->open_paren()->where("name", $form->edit_item->filename->value)->orwhere("slug", $form->edit_item->slug->value)->close_paren()->get()->current()) {
                 if ($row->name == $form->edit_item->filename->value) {
                     $form->edit_item->filename->add_error("name_conflict", 1);
                 }
                 if ($row->slug == $form->edit_item->slug->value) {
                     $form->edit_item->slug->add_error("slug_conflict", 1);
                 }
                 $valid = false;
             }
         }
     }
     if ($valid) {
         $photo->title = $form->edit_item->title->value;
         $photo->description = $form->edit_item->description->value;
         $photo->slug = $form->edit_item->slug->value;
         $photo->rename($form->edit_item->filename->value);
         $photo->save();
         module::event("item_edit_form_completed", $photo, $form);
         log::success("content", "Updated photo", "<a href=\"{$photo->url()}\">view</a>");
         message::success(t("Saved photo %photo_title", array("photo_title" => html::purify($photo->title))));
         print json_encode(array("result" => "success"));
     } else {
         print json_encode(array("result" => "error", "form" => $form->__toString()));
     }
 }
Ejemplo n.º 15
0
 public function test()
 {
     $username = "******";
     $password = "******";
     $email = "*****@*****.**";
     $username2 = "bla2";
     $password2 = "pass2";
     $email2 = "*****@*****.**";
     $username3 = "gue";
     $password3 = "pass3";
     $email3 = "*****@*****.**";
     user::create_new_user($username, $password, $email);
     $this->assertEquals(1, user::getNumberOfUsers(), "number of users is not correct after adding a new user");
     user::create_new_user($username2, $password2, $email2);
     $this->assertEquals(2, user::getNumberOfUsers(), "number of users is not correct after adding a new user");
     user::create_new_user($username3, $password3, $email3);
     $this->assertEquals(3, user::getNumberOfUsers(), "number of users is not correct after adding a new user");
     $user1ID = user::getUserByUsername($username)['id'];
     $user2ID = user::getUserByUsername($username2)['id'];
     $user3ID = user::getUserByUsername($username3)['id'];
     $uuid1 = "352584060201362";
     $this->assertTrue(safe_input::is_valid_uuid($uuid1), "safe_input::is_valid_uuid()");
     $ip1 = '196.168.2.16';
     $this->assertTrue(safe_input::is_valid_ip($ip1), "safe_input::is_valid_ip()");
     $this->assertEquals(0, log::get_logs_count(), "[get_logs_count()]");
     $this->assertTrue(log::addNewLog($user1ID, $ip1, $uuid1), "[log::addNewLog()]");
     $this->assertEquals(1, log::get_logs_count(), "[get_logs_count()]");
     $this->assertTrue(log::addNewLog($user1ID, $ip1, $uuid1), "[log::addNewLog()]");
     $this->assertEquals(2, log::get_logs_count(), "[get_logs_count()]");
     //$this->assertTrue(log::deleteSimilarLogs(),"[deleteSimilarLogs()]") ;
     //$this->assertEquals(1,log::get_logs_count(),"[get_logs_count()]") ;
 }
 public function doAction()
 {
     if (empty($this->source)) {
         $this->result['error'][] = array("code" => -1, "message" => "missing source segment");
     }
     if (empty($this->target)) {
         $this->result['error'][] = array("code" => -2, "message" => "missing target segment");
     }
     if (empty($this->source_lang)) {
         $this->result['error'][] = array("code" => -3, "message" => "missing source lang");
     }
     if (empty($this->target_lang)) {
         $this->result['error'][] = array("code" => -2, "message" => "missing target lang");
     }
     if (!empty($this->result['error'])) {
         return -1;
     }
     if (!empty($this->id_translator)) {
         $this->key = $this->calculateMyMemoryKey($this->id_translator);
         log::doLog("key is {$this->key}");
     }
     $set_results = addToMM($this->source, $this->target, $this->source_lang, $this->target_lang, $this->id_translator, $this->key);
     $this->result['code'] = 1;
     $this->result['data'] = "OK";
 }
Ejemplo n.º 17
0
 public static function instance()
 {
     if (!isset(self::$log)) {
         self::$log = new log();
     }
     return self::$log;
 }
 public function doAction()
 {
     //check if id file and job is a number
     //if (is_numeric($this->id_file) && is_numeric($this->id_job))
     //convert id_file and id_job into a numbers
     $id_file = (int) $this->id_file;
     $id_job = (int) $this->id_job;
     ini_set('max_execution_time', 6000);
     $ret = -1;
     if (substr(php_uname(), 0, 7) == "Windows") {
         log::doLog("windows");
         $ret = pclose(popen("start C:\\wamp\\bin\\php\\php5.4.3\\php " . INIT::$MODEL_ROOT . "/exportLog.php " . $id_file . " " . $id_job . " 1", "r"));
     } else {
         $ret = pclose(popen("nohup php " . INIT::$MODEL_ROOT . "/exportLog.php " . $id_file . " " . $id_job . " 1 &", "r"));
     }
     log::doLog("CASMACAT: return exportLog: " . $ret);
     ini_set('max_execution_time', 30);
     //        $this->filename ="log_id".$this->id_file."_".$this->file_name.".xml";
     //        header('Content-Type: text/xml; charset=UTF-8');
     //        header('Content-Disposition: attachment; filename="' . $this->file_name . '.xml"');
     //
     //        //log::doLog("CASMACAT: file: ".INIT::$LOG_DOWNLOAD . "/" .$this->filename);
     //
     //        $this->content = file_get_contents(INIT::$LOG_DOWNLOAD . "/" . $this->filename);
     if ($ret == "END") {
         $this->result['code'] = 0;
         $this->result['data'] = "OK";
     } else {
         $this->result['errors'] = "It is not possible to get the log file";
         $this->result['code'] = -1;
     }
 }
Ejemplo n.º 19
0
 /**
  * debug a message. Writes to stdout and to log file 
  * if debug = 1 is set in config
  * @param string $message 
  */
 public static function debug($message)
 {
     if (config::getMainIni('debug')) {
         log::error($message);
         return;
     }
 }
Ejemplo n.º 20
0
 public function add_photo($id)
 {
     $album = ORM::factory("item", $id);
     access::required("view", $album);
     access::required("add", $album);
     access::verify_csrf();
     $file_validation = new Validation($_FILES);
     $file_validation->add_rules("Filedata", "upload::valid", "upload::type[gif,jpg,png,flv,mp4]");
     if ($file_validation->validate()) {
         // SimpleUploader.swf does not yet call /start directly, so simulate it here for now.
         if (!batch::in_progress()) {
             batch::start();
         }
         $temp_filename = upload::save("Filedata");
         try {
             $name = substr(basename($temp_filename), 10);
             // Skip unique identifier Kohana adds
             $title = item::convert_filename_to_title($name);
             $path_info = pathinfo($temp_filename);
             if (array_key_exists("extension", $path_info) && in_array(strtolower($path_info["extension"]), array("flv", "mp4"))) {
                 $movie = movie::create($album, $temp_filename, $name, $title);
                 log::success("content", t("Added a movie"), html::anchor("movies/{$movie->id}", t("view movie")));
             } else {
                 $photo = photo::create($album, $temp_filename, $name, $title);
                 log::success("content", t("Added a photo"), html::anchor("photos/{$photo->id}", t("view photo")));
             }
         } catch (Exception $e) {
             unlink($temp_filename);
             throw $e;
         }
         unlink($temp_filename);
     }
     print "File Received";
 }
Ejemplo n.º 21
0
 private function _send_reset()
 {
     $form = $this->_reset_form();
     $valid = $form->validate();
     if ($valid) {
         $user = user::lookup_by_name($form->reset->inputs["name"]->value);
         if (!$user->loaded || empty($user->email)) {
             $form->reset->inputs["name"]->add_error("no_email", 1);
             $valid = false;
         }
     }
     if ($valid) {
         $user->hash = md5(rand());
         $user->save();
         $message = new View("reset_password.html");
         $message->confirm_url = url::abs_site("password/do_reset?key={$user->hash}");
         $message->user = $user;
         Sendmail::factory()->to($user->email)->subject(t("Password Reset Request"))->header("Mime-Version", "1.0")->header("Content-type", "text/html; charset=iso-8859-1")->message($message->render())->send();
         log::success("user", t("Password reset email sent for user %name", array("name" => $user->name)));
     } else {
         // Don't include the username here until you're sure that it's XSS safe
         log::warning("user", "Password reset email requested for bogus user");
     }
     message::success(t("Password reset email sent"));
     print json_encode(array("result" => "success"));
 }
 public function postOrder()
 {
     log::debug('postOrder::Input params');
     log::debug(Input::all());
     //Validation rules
     $rules = array('pizza_marinara' => array('required', 'integer', 'between:0,3'), 'pizza_margherita' => array('required', 'integer', 'between:0,3'), 'olio' => array('min:1|max:20'), 'name' => array('required', 'min:1|max:20'), 'email' => array('required', 'email', 'min:1|max:20'), 'freeOrder' => array('exists:menu,dish'));
     // The validator
     $validation = Validator::make(Input::all(), $rules);
     // Check for fails
     if ($validation->fails()) {
         // Validation has failed.
         log::error('Validation has failed');
         $messages = $validation->messages();
         $returnedMsg = "";
         foreach ($messages->all() as $message) {
             $returnedMsg = $returnedMsg . " - " . $message;
         }
         log::error('Validation fail reason: ' . $returnedMsg);
         return redirect()->back()->withErrors($validation);
     }
     log::debug('Validation passed');
     $msg = array('email' => Input::get('email'), 'name' => Input::get('name'));
     $response = Event::fire(new ExampleEvent($msg));
     $response = Event::fire(new OrderCreated($msg));
     return view('orderdone', ['msg' => $msg]);
 }
Ejemplo n.º 23
0
/**
 * アクションプラグイン処理
 */
function plugin_log_whois_convert()
{
    global $log;
    global $log_ua;
    global $_log_whois_msg;
    if (!$log['guess_user']['use']) {
        return '';
    }
    // 推定ユーザ処理が無効の場合
    $filename = log::set_filename('guess_user', '');
    // ログファイル名
    // ログの読み込み
    if (!file_exists($filename)) {
        return '';
    }
    $src = @file($filename);
    $guess = array();
    foreach ($src as $_src) {
        $data = log::table2array($_src);
        // 0:ua 1:host 2:user
        $guess[$data[0]][$data[1]][$data[2]] = '';
    }
    $host = log::ip2host();
    if (!isset($guess[$log_ua][$host])) {
        return '';
    }
    $uname = '';
    foreach ($guess[$log_ua][$host] as $user => $val) {
        $uname .= !empty($uname) ? ',' . $user : $user;
    }
    return sprintf($_log_whois_msg['msg_whois'], $uname);
}
Ejemplo n.º 24
0
 static function upgrade($version)
 {
     log::info("aws_s3", "Commencing module upgrade (" . $version . ")");
     switch ($version) {
         case 0:
             log::info("aws_s3", "Installing version 1");
             @mkdir(VARPATH . "modules/aws_s3");
             @mkdir(VARPATH . "modules/aws_s3/log");
             // installation's unique identifier - allows multiple g3's pointing to the same s3 bucket.
             if (!module::get_var("aws_s3", "g3id")) {
                 module::set_var("aws_s3", "g3id", md5(time()));
             }
             module::set_var("aws_s3", "synced", false);
             module::set_var("aws_s3", "enabled", false);
             module::set_var("aws_s3", "access_key", "");
             module::set_var("aws_s3", "secret_key", "");
             module::set_var("aws_s3", "bucket_name", "");
             module::set_version("aws_s3", 1);
         case 1:
             log::info("aws_s3", "Upgrading to version 2");
             $db = Database::instance();
             $db->query("CREATE TABLE {aws_s3_meta} (\n                                `item_id` int(9) NOT NULL,\n                                `item_hash` varchar(32) NOT NULL DEFAULT '',\n                                `thumb_uploaded` smallint(1) NOT NULL DEFAULT 0,\n                                `resize_uploaded` smallint(1) NOT NULL DEFAULT 0,\n                                `fullsize_uploaded` smallint(1) NOT NULL DEFAULT 0,\n                                `local_deleted` smallint(1) NOT NULL DEFAULT 0,\n                                PRIMARY KEY (`item_id`)\n                ) DEFAULT CHARSET=utf8;");
             module::set_var("aws_s3", "upload_thumbs", true);
             module::set_var("aws_s3", "upload_resizes", true);
             module::set_var("aws_s3", "upload_fullsizes", true);
             module::set_var("aws_s3", "s3_storage_only", false);
             if (module::get_var("aws_s3", "synced")) {
                 // v1 has already synced this installation to s3. mark all the items with the relevant meta data
                 $items = ORM::factory("item")->find_all();
                 foreach ($items as $item) {
                     aws_s3::log("Updating S3 meta for item ID: " . $item->id);
                     $item->s3_thumb_uploaded = true;
                     if (!$item->is_album()) {
                         $item->s3_resize_uploaded = true;
                         $item->s3_fullsize_uploaded = true;
                     }
                     $item->s3_local_deleted = false;
                     $item->s3_item_hash = md5($item->relative_path());
                     $item->save_s3_meta();
                 }
             } else {
                 // check various states after upgrade from v1..
                 if (module::get_var("aws_s3", "access_key") != "" && module::get_var("aws_s3", "secret_key") != "" && module::get_var("aws_s3", "bucket_name") != "" && aws_s3::validate_access_details(module::get_var("aws_s3", "access_key"), module::get_var("aws_s3", "secret_key"), module::get_var("aws_s3", "bucket_name"))) {
                     // details are correct but hasn't been synced.
                     if (aws_s3::can_schedule()) {
                         // i can schedule this task
                         aws_s3::schedule_full_sync2();
                         site_status::warning("Your site has been scheduled for full Amazon S3 re-synchronisation. This message will clear when this has been completed.", "aws_s3_not_synced");
                     } else {
                         // i CAN'T schedule it..
                         site_status::warning(t('Your site has not been synchronised to Amazon S3. Until it has, your server will continue to serve image content to your visitors.<br />Click <a href="%url" class="g-dialog-link">here</a> to start the synchronisation task.', array("url" => html::mark_clean(url::site("admin/maintenance/start/aws_s3_task::manual_sync?csrf=__CSRF__")))), "aws_s3_not_synced");
                     }
                 } else {
                     site_status::warning(t('Amazon S3 module needs configuration. Click <a href="%url">here</a> to go to the configuration page.', array("url" => html::mark_clean(url::site("admin/aws_s3")))), "aws_s3_not_configured");
                 }
             }
             module::set_version("aws_s3", 2);
     }
     log::info("aws_s3", "Module upgrade complete");
 }
Ejemplo n.º 25
0
 /**
  * Пишет сообщение в лог.
  * @param string $msg   сообщение.
  */
 private function _log($msg)
 {
     if (!$this->log) {
         return;
     }
     $this->log->writeln($msg);
 }
Ejemplo n.º 26
0
 public function index()
 {
     log::prn_log(DEBUG, json_encode($this->content));
     log::prn_log(DEBUG, json_encode($this->param));
     $db = $this->mysql;
     $result = $db->gearman_queue->insert(['unique_key' => 'd847233c-1ef2-11e5-9130-2c44fd7aee72', 'function_name' => 'test', 'priority' => 1, 'data' => 'test', 'when_to_run' => 0]);
     if ($result === false) {
         return 'error';
     }
     $result = $db->select_one("select * from gearman_queue where unique_key='d847233c-1ef2-11e5-9130-2c44fd7aee72'");
     if ($result === false) {
         return 'error';
     }
     var_dump($result);
     $result = $db->gearman_queue->update(['function_name' => 'testtest', 'priority' => 100, 'data' => 'testtesttesttest', 'when_to_run' => 100], ['unique_key' => 'd847233c-1ef2-11e5-9130-2c44fd7aee72']);
     if ($result === false) {
         return 'error';
     }
     var_dump($db->select_one("select * from gearman_queue where unique_key='d847233c-1ef2-11e5-9130-2c44fd7aee72'"));
     $result = $db->gearman_queue->delete(['unique_key' => 'd847233c-1ef2-11e5-9130-2c44fd7aee72']);
     if ($result === false) {
         return 'error';
     }
     $result = $db->select_more("select * from gearman_queue limit 3");
     if ($result === false) {
         return 'error';
     }
     var_dump($result);
     return 'ok';
 }
Ejemplo n.º 27
0
	public function query($sql){
		$rs = mysql_query($sql);
		log::write(date('Y-m-d H:i:s', time()).'--->'.$sql); //记录日志

		return $rs;

	}
 public function doAction()
 {
     try {
         log::doLog("CASMACAT: loadLogChunkController->doAction(): Loading logListChunk...");
         $logListChunk = fetchLogChunk($this->jobId, $this->fileId, $this->startOffset, $this->endOffset);
         if ($logListChunk < 0) {
             $this->result["code"] = -1;
             $this->result["errors"][] = array("code" => -1, "message" => "Error loading logListChunk");
         } else {
             if (!$logListChunk) {
                 $this->result["code"] = 1;
                 $this->result["data"] = "No more data";
             } else {
                 $this->result["code"] = 0;
                 //            $this->result["data"]["logListChunk"] = json_encode($logListChunk);
                 $this->result["data"]["logListChunk"] = $logListChunk;
             }
         }
         log::doLog("CASMACAT: loadLogChunkController->doAction(): Loading of logListChunk finished, " . count($logListChunk) . " events loaded.");
     } catch (Exception $e) {
         $this->result["code"] = -1;
         $this->result["errors"][] = array("code" => -1, "message" => "Unexcpected error: '" . $e->GetMessage() . "'");
         log::doLog("CASMACAT: loadLogChunkController->doAction(): Unexcpected error: '" . $e->GetMessage() . "'");
     }
 }
Ejemplo n.º 29
0
 public static function instance()
 {
     if (!isset(self::$_instance)) {
         self::$_instance = new self();
     }
     return self::$_instance;
 }
Ejemplo n.º 30
0
 public function query($sql)
 {
     $rs = mysqli_query($this->conn, $sql);
     log::write($sql);
     log::write(time());
     return $rs;
 }