Example #1
0
 /**
  * @param string $page
  */
 static function key($page = '')
 {
     $page = trim($page, '/');
     $session = Net_HTTP_Session::Store();
     $name = 'digital-protect/keystring' . $page;
     $key = isset($session[$name]) ? trim($session[$name]) : '';
     if ($key == '') {
         $key = self::generate_key();
         $session[$name] = $key;
     }
     return $key;
 }
Example #2
0
 /**
  * @param WS_Environment $env
  *
  * @return mixed
  */
 public function run(WS_Environment $env)
 {
     $error = null;
     if (Core::is_cli() && !$env->request->session()) {
         return $this->application->run($env);
     }
     $session = $env->request->session();
     $env->flash = Net_HTTP_Session::Flash($session);
     try {
         $result = $this->application->run($env);
     } catch (Exception $e) {
         $error = $e;
     }
     $value = $env->flash->later;
     if ($value || $env->flash->is_init()) {
         $session['flash'] = $value;
     }
     if ($error) {
         throw $error;
     } else {
         return $result;
     }
 }
Example #3
0
 protected function action_massupdate()
 {
     $session = Net_HTTP_Session::Store();
     $_list = trim($session[$this->list_url_session_name()]);
     if ($_list == '') {
         $_list = $this->admin_url('list', 1);
     }
     if (!$this->can_massupdate) {
         return $this->redirect_to($_list);
     }
     $ids = $this->request['ids'];
     foreach ($ids as $id) {
         $item = $this->load($id);
         $old = clone $item;
         if ($this->list_style == 'gallery') {
             $_isactive = $this->list_field_parm('isactive', 'source', 'isactive');
             $_ord = $this->list_field_parm('ord', 'source', 'ord');
             if ($_isactive) {
                 $item->{$_isactive} = $this->request[$_isactive][$id];
             }
             if ($_ord) {
                 $item->{$_ord} = $this->request[$_ord][$id];
             }
         } else {
             if ($this->list_style == 'lent') {
                 $_isactive = $this->list_field_parm('isactive', 'source', 'isactive');
                 if ($_isactive) {
                     $item->{$_isactive} = $this->request[$_isactive][$id];
                 }
             } else {
                 foreach ($this->list_fields as $name => $parms) {
                     if (is_array($parms) && isset($parms['edit'])) {
                         $p = $parms['edit'];
                         if (is_string($p)) {
                             $p = array('type' => $p);
                         } else {
                             $p = (array) $p;
                         }
                         $item->{$name} = $this->request[$name][$id];
                     }
                 }
             }
         }
         $cu = $this->on_before_mass_update_item($item, $old);
         if ($cu !== false) {
             $this->update($item);
         }
         $this->on_after_mass_update_item($item, $old);
     }
     Events::call('admin.change');
     $this->on_after_change('massupdate');
     return $this->redirect_to($_list);
 }
Example #4
0
 public function __construct()
 {
     Core::load('Net.HTTP.Session');
     $this->session = Net_HTTP_Session::Store();
 }
Example #5
0
 /**
  * @return WS_Session_Store
  */
 public static function Store()
 {
     return isset(self::$store) ? self::$store : (self::$store = Core::is_cli() ? array() : new Net_HTTP_Session_Store());
 }
Example #6
0
 protected function action_update()
 {
     $item = $this->load_item($this->id);
     if (!$item) {
         return $this->page_not_found();
     }
     $error = false;
     if (!$item->installed()) {
         $error = 'Этот компонент еще не установлен. Попробуйте сначала установить его.';
     } elseif ($item->installed() == $item['version']) {
         $error = 'Уже установлена последняя версия этого компонента. Обновление не требуется.';
     } else {
         if ($this->env->request->method == 'post') {
             $files = $this->get_install_pack($item);
             if (is_string($files)) {
                 $error = $files;
             } else {
                 $updated = array();
                 $not_updated = array();
                 foreach ($files as $file => $data) {
                     if ($item->can_update_file($file)) {
                         $from = $data['path'];
                         $to = "../{$file}";
                         if ($m = Core_Regexps::match_with_results('{^(.+)/[^/]+$}', $to)) {
                             $dir = $m[1];
                             if (!IO_FS::exists($dir)) {
                                 @CMS::mkdirs($dir);
                                 if (!IO_FS::exists($dir)) {
                                     $error = "Невозможно создать каталог {$dir}";
                                     break;
                                 }
                             }
                             $new_hash = $data['hash'];
                             $old_hash = $item->get_installed_hash($file);
                             if (!$old_hash || $old_hash != $new_hash) {
                                 if ($item->file_was_changed($file)) {
                                     copy($from, "{$to}.upd");
                                     CMS::chmod_file("{$to}.upd");
                                     $not_updated[] = $file;
                                 } else {
                                     copy($from, $to);
                                     CMS::chmod_file($to);
                                     $updated[] = $file;
                                 }
                                 $item->set_installed_hash($file, $new_hash);
                             }
                         }
                     }
                 }
                 Core::load('Net.HTTP.Session');
                 $session = Net_HTTP_Session::Store();
                 $session['stockroom/updated'] = $updated;
                 $session['stockroom/not_updated'] = $not_updated;
                 $item->save_info_file();
                 CMS::rmdir($item->install_temp_dir());
                 return $this->redirect_to($this->action_url('updok', $item));
             }
         }
     }
     Events::call('cms.stockroom.after_update', $item, $error);
     return $this->render('update', array('item' => $item, 'error' => $error, 'list_url' => $this->action_url('list', $this->page), 'list_button_caption' => $this->button_list()));
 }
Example #7
0
File: HTTP.php Project: techart/tao
 /**
  * Устанавливает объект сессии
  *
  * @param Net_HTTP_SessionInterface $session
  *
  * @return Net_HTTP_Request
  */
 public function session($session = null)
 {
     if ($session instanceof Net_HTTP_SessionInterface) {
         $this->session = $session;
         return $this;
     } else {
         if (empty($this->session)) {
             Core::load('Net.HTTP.Session');
             $this->session = Net_HTTP_Session::Store();
         }
         return $this->session;
     }
 }
Example #8
0
 static function SessionObject()
 {
     return Net_HTTP_Session::Store();
 }
Example #9
0
 public static function access($realm, $extra_auth_callback = null)
 {
     if (!$realm) {
         return array();
     }
     if (isset(self::$realms[$realm]) && self::$realms[$realm]) {
         return self::$realms[$realm];
     }
     $data = false;
     $cfg_name = "{$realm}_realm";
     $cfg = WS::env()->config;
     if (isset($cfg->{$cfg_name})) {
         $data = (array) $cfg->{$cfg_name};
     } elseif (isset(CMS::$restricted_realms[$realm])) {
         $data = CMS::$restricted_realms[$realm];
     } else {
         return self::$realms[$realm] = false;
     }
     if (!$data) {
         return self::$realms[$realm] = false;
     }
     if ($realm == CMS::$admin_realm) {
         CMS::$in_admin = true;
     }
     if (isset($data['page_404'])) {
         CMS::$page_404 = $data['page_404'];
     }
     if (isset($data['navigation_var'])) {
         Core::load(CMS::$nav_module);
         Core_Types::reflection_for(CMS::$nav_module)->setStaticPropertyValue('var', $data['navigation_var']);
     }
     $user = false;
     if (isset($data['auth_type']) && $data['auth_type'] == 'basic' || !isset($data['auth_type'])) {
         $user = WS::env()->admin_auth->user;
     }
     if ($user) {
         $client = false;
         $access = false;
         $mp = false;
         self::passwords($data, $user, $client, $access, $mp);
         Core::load('Net.HTTP.Session');
         $session = Net_HTTP_Session::Store();
         if (!$access && isset($session['auth_url_access']) && $session['auth_url_access']) {
             $access = true;
             $mp = $session['auth_url_parms'];
         }
         if (!$access && isset($data['auth_url'])) {
             Core::load('Net.Agents.HTTP');
             $url = $data['auth_url'];
             $agent = Net_HTTP::Agent();
             $res = $agent->with_credentials($user->login, $user->password)->send(Net_HTTP::Request($url));
             if ($res->status->code == '200') {
                 $r = trim($res->body);
                 if ($r == 'ok' || $r == 'ok:') {
                     $access = true;
                 } else {
                     if ($m = Core_Regexps::match_with_results('{^ok:(.+)$}', $r)) {
                         $access = true;
                         $mp = trim($m[1]);
                     }
                 }
             }
             if ($access) {
                 $session['auth_url_access'] = true;
                 $session['auth_url_parms'] = $mp;
             }
         }
         if (!$access) {
             $args = array($user->login, $user->password, $realm);
             if (Core_Types::is_callable($extra_auth_callback)) {
                 $extra_auth = Core::invoke($extra_auth_callback, $args);
             } else {
                 $extra_auth = self::extra_auth($args[0], $args[1], $args[2]);
             }
             if ($extra_auth || Core_Types::is_iterable($extra_auth)) {
                 $mp = $extra_auth;
                 $access = true;
             } else {
                 return self::$realms[$realm] = false;
             }
         }
         $auth_parms = self::auth_parms($mp, $client);
         $user->parms = $auth_parms;
         if ($access) {
             return self::$realms[$realm] = array('data' => $data, 'auth_parms' => $auth_parms);
         }
     } else {
         return self::$realms[$realm] = false;
     }
     return self::$realms[$realm] = false;
 }