Esempio n. 1
0
 /**
  * Вывод каптчи:
  */
 public function indexAction(Application $application, Template $template)
 {
     $kvs = KVS::getInstance();
     /*
     		if ($kvs -> exists(__CLASS__, 'captcha_ban', $_SERVER['REMOTE_ADDR']))
     			return false;
     		$kvs -> set(__CLASS__, 'captcha', $_SERVER['REMOTE_ADDR'], $kvs -> get(__CLASS__, 'captcha', $_SERVER['REMOTE_ADDR']) + 1);
     		$kvs -> expire(__CLASS__, 'captcha', $_SERVER['REMOTE_ADDR'], 5);
     
     		if ($kvs -> get(__CLASS__, 'captcha', $_SERVER['REMOTE_ADDR']) > 10) {
     			$kvs -> set(__CLASS__, 'captcha_ban', $_SERVER['REMOTE_ADDR'], true);
     			$kvs -> expire(__CLASS__, 'captcha_ban', $_SERVER['REMOTE_ADDR'], 60 * 15);
     			return false;
     		}
     */
     if (!isset($_GET['key'])) {
         return false;
     }
     /*
     		if (!preg_match('~^http://1chan\.ru/~i', $_SERVER['HTTP_REFERER']))
     		    return false;
     */
     $session = Session::getInstance();
     if ($session->instantGet('captcha_' . $_GET['key'], false)) {
         $captcha = new KCAPTCHA();
         $session->instantSet('captcha_' . $_GET['key'], $captcha->getKeyString());
     }
     return false;
 }
Esempio n. 2
0
 /**
  * Загрузка:
  */
 public function upload($url)
 {
     $kvs = KVS::getInstance();
     if ($kvs->exists(__CLASS__, $url)) {
         return $kvs->get(__CLASS__, $url);
     }
     $data = @get_headers($url, 1);
     if (in_array($data['Content-Type'], array('image/jpeg', 'image/jpg', 'image/png', 'image/gif'))) {
         $tm = tempnam('/tmp', 'img');
         $nam = md5(uniqid('', true));
         $dir = substr($nam, 0, 1);
         $im = fopen($url, 'r');
         $fp = fopen($tm, 'w');
         $start = time();
         while (!feof($im) && time() - $start < 5) {
             fputs($fp, fgets($im, 24));
         }
         fclose($im);
         fclose($fp);
         if (time() - $start > 5) {
             return false;
         }
         self::createThumbnail($tm, UPLOAD_PATH . '/news/' . $dir . '/' . $nam . '.png');
         $p = '/uploads/news/' . $dir . '/' . $nam . '.png';
         @unlink(tm);
         $kvs->set(__CLASS__, $url, null, '/uploads/news/' . $dir . '/' . $nam . '.png');
         $kvs->expire(__CLASS__, $url, null, 60 * 60 * 24 * 30);
         return $p;
     }
     return false;
 }
Esempio n. 3
0
 /**
  * Poo chan:
  */
 public function pooAjaxAction(Application $application)
 {
     $cache = KVS::getInstance();
     if ($cache->exists(__CLASS__, 'poo', $_SERVER['REMOTE_ADDR'])) {
         return false;
     }
     EventModel::getInstance()->ClientBroadcast('page_' . $_POST['target'], "poo", array('top' => $_POST['top'], 'left' => $_POST['left']));
     $cache->set(__CLASS__, 'poo', $_SERVER['REMOTE_ADDR'], 1);
     $cache->expire(__CLASS__, 'poo', $_SERVER['REMOTE_ADDR'], 1);
     return true;
 }
Esempio n. 4
0
 /**
  * Действие "поделиться ссылкой" через букмарклет:
  */
 public function shareLinkAction(Application $application, Template $template)
 {
     $kvs = KVS::getInstance();
     $validator = new ValidatorHelper($_GET);
     $validator->assertExists('title', '');
     $validator->assertLength('title', 70, '');
     $validator->assertExists('link', '');
     $validator->assertRegexp('link', ValidatorHelper::URL_REGEXP, '');
     $validator->assertLength('description', 128, '');
     if ($validator->isValid()) {
         $key = md5(strtolower($_GET['link']));
         $ip = md5($_SERVER['REMOTE_ADDR']);
         $counter = $kvs->get(__CLASS__, 'shared_links_ip', $ip);
         if (!$kvs->exists(__CLASS__, 'shared_links', $key) && !$kvs->exists(__CLASS__, 'shared_links_ban', $ip)) {
             if ($kvs->exists(__CLASS__, 'shared_links_ip', $ip)) {
                 if ($counter > 5) {
                     $kvs->set(__CLASS__, 'shared_links_ban', $ip, true);
                     $kvs->expire(__CLASS__, 'shared_links_ban', $ip, 5 * 60);
                 } else {
                     $lifetime = $kvs->lifetime(__CLASS__, 'shared_links_ip', $ip);
                     $kvs->set(__CLASS__, 'shared_links_ip', $ip, ++$counter);
                     $kvs->expire(__CLASS__, 'shared_links_ip', $ip, $lifetime);
                 }
             } else {
                 $kvs->set(__CLASS__, 'shared_links_ip', $ip, 1);
                 $kvs->expire(__CLASS__, 'shared_links_ip', $ip, 60);
             }
             JabberBot::send('-=% /me Отправлена ссылка: ' . $_GET['link'] . ' (' . $_GET['title'] . ')' . "\n" . (!empty($_GET['description']) ? 'С описанием: ' . $_GET['description'] : ''));
             $kvs->set(__CLASS__, 'shared_links', $key, true);
             $kvs->expire(__CLASS__, 'shared_links', $key, 60 * 60);
             $template->headerOk();
             $template->headerContentTypeWOCharset('image/png');
             readfile(WEB_DIR . '/ico/tick.png');
             exit;
         }
     }
     $template->headerBadRequest();
     exit;
 }
Esempio n. 5
0
 /**
  * Функция проверки обновлений в разделе "онлайн":
  */
 public static function isLiveUpdated()
 {
     $session = Session::getInstance();
     $cache = KVS::getInstance();
     $last_visit = $session->persistenceGet('live_last_visit', time());
     return $cache->get('Blog_BlogOnlineModel', null, 'lastUpdate') > $last_visit;
 }
Esempio n. 6
0
 /**
  * Функция счетчика переходов:
  */
 public static function Click($id)
 {
     $cache = KVS::getInstance();
     $link = unserialize($cache->get(__CLASS__, 'links', $id));
     if (!in_array($_SERVER['REMOTE_ADDR'], $link['visitors'])) {
         $link['visitors'][] = $_SERVER['REMOTE_ADDR'];
         $link['clicks']++;
         $ttl = $cache->lifetime(__CLASS__, 'links', $id);
         $cache->set(__CLASS__, 'links', $id, serialize($link));
         $cache->expire(__CLASS__, 'links', $id, $ttl);
         EventModel::getInstance()->Broadcast('visit_online_link', array('id' => $id, 'clicks' => $link['clicks']));
     }
     return true;
 }
Esempio n. 7
0
 /**
  * Оценка поста:
  */
 public static function RatePost($id, $increment = true)
 {
     $dbh = PDOQuery::getInstance();
     $ip = $_SERVER['REMOTE_ADDR'];
     $cache = KVS::getInstance();
     $post = Blog_BlogPostsModel::GetPost($id);
     if ($post && !$post['rateable']) {
         return false;
     }
     $raters = unserialize($cache->get(__CLASS__, $id, 'raters'));
     if (!$raters) {
         return false;
     }
     if (in_array($ip, $raters)) {
         return false;
     } else {
         $raters[] = $ip;
         $cache->set(__CLASS__, $id, 'raters', serialize($raters));
     }
     $dbh->update_insecure('1chan_post', array('rate' => '`rate`' . ($increment ? '+1' : '-1')), 'id = ' . $dbh->q($id), 1, true);
     $post = Blog_BlogPostsModel::GetPost($id);
     EventModel::getInstance()->Broadcast('rate_post', array($id, $post['rate']));
     /**
     		if ($post['rate'] >= ControlModel::getRatedCount() && !$post['rated'])
     			self::RatedPost($id, true);
     		**/
     return true;
 }
Esempio n. 8
0
 /**
  * Загрузка и обработка файла:
  */
 public function process($board)
 {
     if (array_key_exists('upload', $_FILES) && $_FILES['upload']['error'] != 4) {
         $kvs = KVS::getInstance();
         $upload = $_FILES['upload'];
         $pathinfo = pathinfo($upload['name']);
         $data = array();
         $data['board'] = $board;
         $data['original_name'] = $upload['name'];
         $data['size'] = TemplateHelper::format_bytes($upload['size']);
         $finfo = finfo_open(FILEINFO_MIME_TYPE);
         switch (finfo_file($finfo, $upload['tmp_name'])) {
             case 'image/jpeg':
             case 'image/jpg':
                 $ext = 'jpg';
                 break;
             case 'image/png':
                 $ext = 'png';
                 break;
             case 'image/gif':
                 $ext = 'gif';
                 break;
             default:
                 return false;
         }
         finfo_close($finfo);
         $name = time() . rand(0, 100000);
         copy($upload['tmp_name'], UPLOAD_PATH . '/' . $board . '/' . $name . '.' . $ext);
         $data['file_name'] = $name . '.' . $ext;
         $full_size = getimagesize(UPLOAD_PATH . '/' . $data['board'] . '/' . $data['file_name']);
         $data['full_size'] = array($full_size[0], $full_size[1]);
         $this->createThumbnail($upload['tmp_name'], UPLOAD_PATH . '/' . $board . '/thumb_' . $name . '.' . $ext);
         $data['thumb_name'] = 'thumb_' . $name . '.' . $ext;
         $thumb_size = getimagesize(UPLOAD_PATH . '/' . $data['board'] . '/' . $data['thumb_name']);
         $data['thumb_size'] = array($thumb_size[0], $thumb_size[1]);
         $data['web_full'] = 'uploads/' . $board . '/' . $data['file_name'];
         $data['web_thumb'] = 'uploads/' . $board . '/' . $data['thumb_name'];
         $this->data = $data;
     }
     /* 
     		elseif (!empty($_POST['upload']))
     		{
     			$kvs      = KVS::getInstance();
     			$upload   = $_POST['upload'];
     			$data     = array();
     
     			$data['board']         = $board;
     			$data['original_name'] = $upload['name'];
     			$data['size']          = TemplateHelper::format_bytes($upload['size']);
     
     			$uploader = new uploader();
     			$uploader -> destDir   = UPLOAD_PATH .'/'. $board;
     			$uploader -> upload($upload['url']);
     
     			$data['file_name'] = $uploader -> fileName;
     			$full_size                 = getimagesize(UPLOAD_PATH .'/'. $data['board'] .'/'. $data['file_name']);
     			$data['full_size']    = array($full_size[0], $full_size[1]);
     
     			$uploader -> resizeDir = UPLOAD_PATH .'/'. $board .'/thumb_';
     
     			$data['thumb_name'] = 'thumb_'. $uploader -> resize('', min(125, $data['full_size'][0]), 200);
     			$thumb_size = getimagesize(UPLOAD_PATH .'/'. $data['board'] .'/'. $data['thumb_name']);
     			$data['thumb_size'] = array($thumb_size[0], $thumb_size[1]);
     
     			$data['web_full']       = 'uploads/'. $board .'/'. $data['file_name'];
     			$data['web_thumb'] = 'uploads/'. $board .'/'. $data['thumb_name'];
     		
     			die;
     		}*/
     return true;
 }
Esempio n. 9
0
 /**
  * Удаление комментария:
  */
 public static function RemoveComment($id)
 {
     $comment = self::GetComment($id);
     $kvs = KVS::getInstance();
     $cache = KVS::getInstance();
     if ($comment) {
         if ($kvs->exists('ControlModel', 'timeblock', $comment['ip'])) {
             $kvs->set('ControlModel', 'timeban', $comment['ip'], true);
             $kvs->expire('ControlModel', 'timeban', $comment['ip'], 60 * 60);
         }
         if ($kvs->exists('ControlModel', 'timeban', $comment['ip'])) {
             $life = $kvs->lifetime('ControlModel', 'timeban', $comment['ip']);
             $kvs->expire('ControlModel', 'timeban', $comment['ip'], $life + 60 * 60);
         }
         $kvs->set('ControlModel', 'timeblock', $comment['ip'], true);
         $kvs->expire('ControlModel', 'timeblock', $comment['ip'], 60 * 60);
         $dbh = PDOQuery::getInstance();
         $dbh->update_insecure('1chan_post', array('comments' => '`comments`-1'), 'id = ' . $dbh->q($comment['post_id']), 1, true);
         $cache->listRemove(__CLASS__, null, 'lastComments', $id);
         EventModel::getInstance()->Broadcast('remove_comment', array('id' => $id, 'post_id' => $comment['post_id']));
         return $dbh->delete('1chan_comment', 'id = ' . $dbh->q($id), 1);
     }
     return false;
 }
Esempio n. 10
0
<?php

chdir(dirname(__FILE__));
/**
 * Проверка статуса доступности серверов:
 */
require '../app/classes/kvs.class.php';
$cache = KVS::getInstance();
$links = unserialize($cache->get('Blog_BlogLinksModel', null, 'links'));
foreach ($links as $section => $section_links) {
    foreach ($section_links as $key => $link) {
        $headers = @get_headers($link['href']);
        if (!in_array(substr($headers[0], 9, 3), array(200, 303, 302))) {
            $links[$section][$key]['offline'] = 1;
        } else {
            $links[$section][$key]['offline'] = 0;
        }
    }
}
$cache->set('Blog_BlogLinksModel', null, 'links', serialize($links));
$links = $cache->listGet('Blog_BlogOnlineModel', null, 'links');
if ($links) {
    foreach ($links as $link) {
        if (($current = unserialize($cache->get('Blog_BlogOnlineModel', 'links', $link))) != null) {
            $headers = @get_headers($current['link']);
            if (!in_array(substr($headers[0], 9, 3), array(200, 303, 302))) {
                $cache->listRemove('Blog_BlogOnlineModel', null, 'links', $link);
            }
        } else {
            $cache->listRemove('Blog_BlogOnlineModel', null, 'links', $link);
        }
Esempio n. 11
0
 /**
  * Деструктор (сохраняет данные в бд):
  */
 public function __destruct()
 {
     $cache = KVS::getInstance();
     $cache->set('Session_ip', $_SERVER['REMOTE_ADDR'], 'key', $this->key);
     $cache->expire('Session_ip', $_SERVER['REMOTE_ADDR'], 'key', 60 * 5);
     $this->update();
 }
Esempio n. 12
0
 /**
  * Действие оценки поста (ajax):
  */
 public function ratePostAjaxAction(Application $application)
 {
     $ip = $_SERVER['REMOTE_ADDR'];
     $cache = KVS::getInstance();
     $raters = (array) unserialize($cache->get('Blog_BlogPostsModel', $_GET['id'], 'raters'));
     if (in_array($ip, $raters)) {
         return array('rate' => false);
     }
     if (ControlModel::isPostRateCaptcha()) {
         return array('rate' => 'captcha');
     }
     if (@$_GET['vote'] == 'up') {
         return array('rate' => Blog_BlogPostsModel::RatePost($_GET['id'], true));
     } elseif (@$_GET['vote'] == 'down') {
         return array('rate' => Blog_BlogPostsModel::RatePost($_GET['id'], false));
     }
 }
Esempio n. 13
0
 /**
  * Получение нотифаеров:
  */
 public function notifyGetAjaxAction(Application $application)
 {
     $kvs = KVS::getInstance();
     $key = Session::getInstance()->getKey();
     $messages = $kvs->hashGetAll('Notify', $key, 'messages');
     $kvs->remove('Notify', $key, 'messages');
     return $messages;
 }
Esempio n. 14
0
 /**
  * Получение лога:
  */
 public static function GetLog($channel)
 {
     $cache = KVS::getInstance();
     $log = $cache->listGet(__CLASS__, $channel, 'log');
     return implode("\n", $log);
 }
Esempio n. 15
0
 /**
  * Удаление файла
  */
 public static function RemoveFile($name)
 {
     $cache = KVS::getInstance();
     $files = (array) unserialize($cache->get(__CLASS__, null, 'file_list'));
     foreach ($files as $k => $file) {
         if ($file['name'] == $name) {
             unset($files[$k]);
         }
     }
     @unlink(WEB_DIR . '/uploads/' . $file['name']);
     $cache->set(__CLASS__, null, 'file_list', serialize($files));
 }
Esempio n. 16
0
 /**
  * Получение "информации" канала:
  */
 public static function GetInfo($id)
 {
     $cache = KVS::getInstance();
     return $cache->get(__CLASS__, $id, 'info');
 }
Esempio n. 17
0
 /**
  * Получение лога управления:
  */
 public static function getLogModEvent()
 {
     $cache = KVS::getInstance();
     return (array) unserialize($cache->get(__CLASS__, null, 'log'));
 }
Esempio n. 18
0
 /**
  * Статистика поста:
  */
 public static function getPostStats($id)
 {
     $cache = KVS::getInstance();
     $stats = unserialize($cache->get(__CLASS__, $id, 'stats'));
     return array('online' => sizeof($stats['online']) == 3 ? 3.5 : sizeof($stats['online']), 'writers' => sizeof($stats['writers']), 'unique' => sizeof($stats['unique']));
 }
Esempio n. 19
0
 /**
  * Установка списка ссылок:
  */
 public static function SetLinks($links = array())
 {
     $cache = KVS::getInstance();
     return $cache->set(__CLASS__, null, 'links', serialize($links));
 }