예제 #1
0
  function write($log_file_data, $string)
  {
    $log_dir = $log_file_data[0];
    $log_name = $log_file_data[1];
    $file_name = $log_dir . $log_name;

    if (!is_dir($log_dir))
      Fs :: mkdir($log_dir, 0775, true);

    $oldumask = umask(0);
    $file_existed = file_exists($file_name);
    $log_file = fopen($file_name, 'a');

    if ($log_file)
    {
      $time = gmstrftime("%b %d %Y %H:%M:%S", time());

      $notice = '[ ' . $time . " ]\n";

      $toolkit =& Limb :: toolkit();
      $user =& $toolkit->getUser();

      if(($user_id = $user->getId()) != DEFAULT_USER_ID)
        $notice .= '[ ' . $user_id . ' ] [ '  . $user->getLogin() . ' ] [ ' . $user->get('email', '') . ' ] ';

      $notice .= '[' . Sys::clientIp() . '] [' . (isset($_SERVER['REQUEST_URI']) ?  $_SERVER['REQUEST_URI'] : '') . "]\n" . $string . "\n\n";

      fwrite($log_file, $notice);
      fclose($log_file );
      if (!$file_existed)
        chmod($file_name, 0664);

      umask($oldumask);
      $result = true;
    }
    else
    {
      umask($oldumask);
      return throw_error(new IOException("Cannot open log file '$file_name' for writing\n" .
                         "The web server must be allowed to modify the file.\n" .
                         "File logging for '$file_name' is disabled."));
    }

    return $result;
  }
예제 #2
0
 public function getClientIp()
 {
     return Ip::encodeIp(Sys::clientIp());
 }
예제 #3
0
  function parseHtmlConsole()
  {
    if (!Debug :: isDebugEnabled())
      return '';

    $inst =& Debug :: instance();
    $report = $inst->_parseReportInternal(true);

    $ip = Sys :: clientIp();
    $js_window = "
            <script language='javascript'>
            <!-- hide this script from old browsers

            function show_debug(file_name, title)
            {
              var debug_path = '" . DEBUG_HTTP_CONSOLE_DIR . "';
              rn = Math.random();
              debug_window = window.open(debug_path + file_name + '?rn=' + rn, title, 'top=370,left=550,height=300,width=400,scrollbars,resizable');
            }

            show_debug('{$ip}-debug.html', 'debug');

            //-->
            </script>";

    $header = '<html><head><script>var NEED_TO_FOCUS = false</script><title>debug</title></head><body onload="if(NEED_TO_FOCUS)window.focus();else window.blur()">';
    $footer = '</body></html>';
    $fp = fopen(VAR_DIR . $ip . '-debug.html', 'w+');

    fwrite($fp, $header);
    fwrite($fp, $report);
    fwrite($fp, $footer);
    fclose($fp);

    return $js_window;
  }
 public function registerAnswer($answer_id)
 {
     if (!$answer_id) {
         return false;
     }
     if (!($poll_data = $this->getActivePoll())) {
         return false;
     }
     $poll_id = $poll_data['id'];
     if (!$poll_id) {
         return false;
     }
     if (!$this->canVote()) {
         return false;
     }
     if (!$this->_addVoteToAnswer($poll_data['answers'][$answer_id]['record_id'])) {
         return false;
     }
     $poll_session =& Limb::toolkit()->getSession()->getReference('poll_session');
     $poll_session[$poll_id] = $poll_id;
     switch ($poll_data['restriction']) {
         case 1:
             return true;
             break;
         case 2:
             $cookie = $_COOKIE;
             if (isset($cookie['poll_ids'])) {
                 $poll_ids = $cookie['poll_ids'];
                 $poll_ids += ',' . $poll_id;
             } else {
                 $poll_ids = $poll_id;
             }
             $one_week = 7 * 24 * 60 * 60;
             setcookie('poll_ids', $poll_ids, time() + $one_week, '/');
             break;
         case 3:
             $this->_registerNewIp($poll_id, Sys::clientIp());
             break;
     }
     return true;
 }