示例#1
0
 /**
  * Commits changes (increases serial by 1)
  * 
  * @return Array on success, string on error
  */
 public static function commit()
 {
     // do some checks first
     $pdns_version = trim(shell_exec("sudo /usr/bin/pdns_control version 2>&1"));
     if (!preg_match('/^[0-9,\\.]+$/', $pdns_version)) {
         if (preg_match('/\\[sudo\\] password/', $pdns_version)) {
             return "Unable to run 'sudo /usr/bin/pdns_control'. Is it defined in sudoers file?";
         } else {
             return $pdns_version;
         }
     }
     $commited = array();
     $c = new Criteria();
     $c->add(AuditPeer::OBJECT, 'Record');
     $c->addGroupByColumn(AuditPeer::DOMAIN_ID);
     $c->add(AuditPeer::CREATED_AT, date("Y-m-d H:i:s", MyTools::getLastCommit()), Criteria::GREATER_THAN);
     foreach (AuditPeer::doSelect($c) as $audit) {
         $domain = DomainPeer::retrieveByPK($audit->getDomainId());
         $commited[] = $domain->getName();
         // get SOA record
         $c = new Criteria();
         $c->add(RecordPeer::DOMAIN_ID, $domain->getId());
         $c->add(RecordPeer::TYPE, 'SOA');
         $SOA = RecordPeer::doSelectOne($c);
         $temp = explode(" ", $SOA->getContent());
         $serial = $temp[2];
         $date = substr($serial, 0, 8);
         $id = substr($serial, 8);
         // today ?
         if ($date == date("Ymd")) {
             $id++;
             if (strlen($id) == 1) {
                 $id = "0" . $id;
             }
             $serial = $date . $id;
         } else {
             $serial = date("Ymd") . "01";
         }
         if ($serial >= 4294967295) {
             continue;
         }
         // don't allow >= 32bit unsigned
         $SOA->setContent(implode(" ", array($temp[0], $temp[1], $serial)));
         $SOA->save();
     }
     if ($commited) {
         SettingPeer::setValue('last_commit', time());
         sleep(2);
         if ($also_notify = sfConfig::get('app_default_also-notify')) {
             foreach ($commited as $domain) {
                 foreach ($also_notify as $host) {
                     exec("sudo /usr/bin/pdns_control notify-host {$domain} {$host}");
                 }
             }
         }
     }
     return $commited;
 }
示例#2
0
 public function needsCommit()
 {
     $connection = Propel::getConnection();
     $sql = sprintf("SELECT COUNT(%s) AS count FROM %s \n      WHERE %s = 'Record' \n      AND %s = %d \n      AND %s = %d \n      AND %s > '%s'", AuditPeer::ID, AuditPeer::TABLE_NAME, AuditPeer::OBJECT, AuditPeer::OBJECT_KEY, $this->getId(), AuditPeer::DOMAIN_ID, $this->getDomainId(), AuditPeer::CREATED_AT, date("Y-m-d H:i:s", MyTools::getLastCommit()));
     $statement = $connection->prepareStatement($sql);
     $resultset = $statement->executeQuery();
     $resultset->next();
     return $resultset->getInt('count');
 }
示例#3
0
 public function validateCommit()
 {
     $this->commited = MyTools::commit();
     if (!is_array($this->commited)) {
         $this->getRequest()->setError('commit', $this->commited);
         return false;
     }
     return true;
 }
 static function fromdate($string)
 {
     if (MyTools::slugify($string) == "" or MyTools::slugify($string) == "n-a") {
         return self::emptydate();
     }
     $array = explode(" ", $string);
     $datearray = explode("-", $array[0]);
     return new MyDateTime($datearray[0], $datearray[1], $datearray[2], 0, 0, 0);
 }
示例#5
0
 /**
  * sign in, set the remember key if necessary
  *
  * @param User $user
  * @param boolean $rememberMe
  */
 public function signIn(User $user, $rememberMe = false)
 {
     $this->setAuthenticated(true);
     $this->setUserTypeCredentials($user->getType());
     if ($rememberMe) {
         $cookie_key = MyTools::generateRandomKey();
         $user->setCookieKey($cookie_key);
         $user->save();
         $value = base64_encode(serialize(array($cookie_key, $user->getUsername())));
         sfContext::getInstance()->getResponse()->setCookie('rayku', $value, time() + 60 * 60 * 24 * 15, '/', sfConfig::get('app_cookies_domain'));
     }
     $this->setAttribute('user_id', $user->getId());
     $user->save();
 }
示例#6
0
 public function updateItemFromRequest()
 {
     if ($this->getRequest()->getFileSize('item[image]')) {
         $image = $this->getRequestParameter('item[image]');
         $filename = md5($this->getRequest()->getFileName('item[image]') . time() . rand(0, 99999));
         $ext = substr($this->getRequest()->getFileName('item[image]'), strpos($this->getRequest()->getFileName('item[image]'), "."));
         //var_dump(sfConfig::get('app_items_upload_folder'));die;
         $uploaddir = sfConfig::get('sf_upload_dir') . DIRECTORY_SEPARATOR . sfConfig::get('app_items_upload_folder');
         $this->getRequest()->moveFile('item[image]', $uploaddir . DIRECTORY_SEPARATOR . $filename . $ext);
         MyTools::resample($uploaddir . DIRECTORY_SEPARATOR . $filename . $ext, $uploaddir . DIRECTORY_SEPARATOR . $filename . "_l" . $ext, sfConfig::get('app_items_image_large_width'), sfConfig::get('app_items_image_large_height'));
         MyTools::resample($uploaddir . DIRECTORY_SEPARATOR . $filename . $ext, $uploaddir . DIRECTORY_SEPARATOR . $filename . "_t" . $ext, sfConfig::get('app_items_image_thumb_width'), sfConfig::get('app_items_image_thumb_height'));
     }
     parent::updateItemFromRequest();
     if ($this->getRequest()->getFileSize('item[image]')) {
         $this->item->setImage($filename . $ext);
         $this->item->save();
     }
 }
示例#7
0
 /**
  * ads 'modules/' to path where to find layouts
  * ads reversed order of modules to paths where to find layouts, ie. from Admin:News: to NewsModule:AdminModule
  *
  * @param  string
  * @param  string
  * @return array
  */
 public function formatLayoutTemplateFiles($presenter, $layout)
 {
     $paths = parent::formatTemplateFiles($presenter, $layout);
     $appDir = Environment::getVariable('appDir');
     $path = '/modules/' . str_replace(':', 'Module/', $presenter);
     $pathP = substr_replace($path, '/templates', strrpos($path, '/'), 0);
     $list = array("{$appDir}{$pathP}/@{$layout}.phtml", "{$appDir}{$pathP}.@{$layout}.phtml", "{$appDir}{$path}Module/templates/@{$layout}.phtml");
     //		dump($list);die();
     //		dump($path);
     //		dump($pathP);
     //		dump("$appDir$pathP/@$layout.phtml");
     //		dump($presenter);
     // ked pouzivam aj reversed order, tak nechcem prebublat az do '/app/modules/templates/@layout.phtml', resp. '/app/templates/@layout.phtml', tam sa dostanu az po skuseni reversed order
     //		while (($path = substr($path, 0, strrpos($path, '/'))) !== false) {
     while (($path = substr($path, 0, strrpos($path, '/'))) !== "/modules") {
         $list[] = "{$appDir}{$path}/templates/@{$layout}.phtml";
     }
     /* reversed order for modules, ie. from Admin:News: to NewsModule:AdminModule*/
     $chunks = explode(':', $presenter);
     // if no module [e.g. it's ErrorPresenter from no module] return - @deprecated, should not be needed
     if (!isset($chunks[1])) {
         return $paths;
     }
     $reversedModulePresenter = implode(':', array_merge(array($chunks[1], $chunks[0]), array_splice($chunks, 2)));
     $reversedModulePath = '/modules/' . str_replace(':', 'Module/', $reversedModulePresenter);
     $reversedModulePathP = substr_replace($reversedModulePath, '/templates', strrpos($reversedModulePath, '/'), 0);
     //        $reversedModulePath = substr_replace($reversedModulePath, '/templates', strrpos($reversedModulePath, '/'));
     //        dump($reversedModulePath);
     //        dump($reversedModulePathP);
     $list[] = "{$appDir}{$reversedModulePathP}/@{$layout}.phtml";
     $list[] = "{$appDir}{$reversedModulePathP}.@{$layout}.phtml";
     while (($reversedModulePath = substr($reversedModulePath, 0, strrpos($reversedModulePath, '/'))) !== FALSE) {
         $list[] = "{$appDir}{$reversedModulePath}/templates/@{$layout}.phtml";
     }
     //		dump($paths);
     //		dump($list);
     //		die();
     //      return array_merge($paths, $list);
     // finalize
     foreach ($list as &$l) {
         $l = MyTools::unifyPath($l);
         // if layout is an absolute path, trim everything before
         $absPathPos = strpos($l, '//');
         if ($absPathPos !== false) {
             $l = substr($l, $absPathPos + 2);
         }
     }
     return array_merge($list);
 }
示例#8
0
 /**
  *
  * check if user is loged
  * 
  * @global mysql $db
  */
 function isLoged()
 {
     @session_start();
     global $db;
     // check user agent
     if (isset($_SESSION['HTTP_USER_AGENT'])) {
         if ($_SESSION['HTTP_USER_AGENT'] != md5($_SERVER['HTTP_USER_AGENT'])) {
             self::logout();
             exit;
         }
     }
     /* If session not set, check for cookies set by Remember me */
     if (!isset($_SESSION['usr_email']) && !isset($_SESSION['created_at'])) {
         if (isset($_COOKIE['usr_email']) && isset($_COOKIE['created_at'])) {
             /* we double check cookie expiry time against stored in database */
             $cookie_user_email = DbTools::filterData($_COOKIE['usr_email']);
             $sessionKeyQry = mysql_query("select `session_key`,`last_access` from `users` where `email` ='{$cookie_user_email}'") or die(mysql_error());
             list($sessionkey, $lastaccess) = mysql_fetch_row($sessionKeyQry);
             // check if cookie has expired
             if (time() - time($lastaccess) > 60 * 60 * 24 * APP_COOKIE_EXPIRA) {
                 self::logout();
             }
             /* Security check with untrusted cookies - dont trust value stored in cookie.
                /* We also do authentication check of the `ckey` stored in cookie matches that stored in database during login*/
             if (!empty($sessionkey) && MyTools::isEmail($_COOKIE['usr_email']) && $_COOKIE['usr_session_key'] == sha1($sessionkey)) {
                 session_regenerate_id();
                 //against session fixation attacks.
                 $_SESSION['usr_email'] = $_COOKIE['usr_email'];
                 $_SESSION['created_at'] = $_COOKIE['created_at'];
                 $_SESSION['usr_administrator'] = $_COOKIE['usr_administrator'];
                 $_SESSION['HTTP_USER_AGENT'] = md5($_SERVER['HTTP_USER_AGENT']);
             } else {
                 self::logout();
             }
         } else {
             // return to homepage
             header("Location: /");
             exit;
         }
     }
 }