Pages

Friday, 31 July 2015

dabr 的 https 支持


默认的 dabr 推特客户端似乎没怎么支持 https,
将 config.php 中的 $base_url 改为 https 前缀后,在 Chrome 里正常,可是在 OperaMini 下用户页面的 Older / More 链接似乎有些不对,于是干脆给改成根目录的链接
sed -i "s/='user/='\/user/g" `find . -name '*.php'`
然后 OperaMini 里就正常了
嗯,我自己用的是可自定义代理服务器的俄 Opera Mini 英文版,而非黑莓可以试试这个 4.2 Mod 版,支持多窗口、自定义服务器和其他附加特性。另外,这儿有 Handler 修改的其他 OPM 4.2 和 5.1 版本(Android 等更多版本软件可以直接到这儿下载
提示:Android、iOS 等系统用不着修改 OperaMini,直接改 /etc/hosts 文件把 mini5.opera-mini.net 指向自己服务器的 IP 就可以穿越了。

更新
发现新版 dabr 的用 GWT 浏览失效了,
于是写了个补丁

dabr_fix_via_gwt.diff

--- ./common/Autolink.php.old 2011-04-25 23:32:33.000000000 +0100
+++ ./common/Autolink.php 2011-04-25 23:32:16.000000000 +0100
@@ -97,7 +97,11 @@
  private function replacementURLs($matches) {
   $replacement  = $matches[2];
   if (substr($matches[3], 0, 7) == 'http://' || substr($matches[3], 0,  == 'https://') {
-   $replacement .= '<a href="' . $matches[3] . '" target="_blank">' . $matches[3] . '</a>';
+   if (setting_fetch('gwt') == 'on') {
+    $replacement .= '<a href="http://google.com/gwt/n?u=' . urlencode($matches[3]) . '" target="_blank">' . $matches[3] . '</a>';
+   } else {
+    $replacement .= '<a href="' . $matches[3] . '" target="_blank">' . $matches[3] . '</a>';
+   }
   } else {
    $replacement .= '<a href="http://' . $matches[3] . '" target="_blank">' . $matches[3] . '</a>';
   }
另外 dabr 的对话是用坑爹的搜索冒充的
于是又写了个补丁使用 related_results/show/{$thread_id}.json
来显示“真正”的对话线索

dabr_true_thread_timeline.diff

diff --git a/common/twitter.php b/common/twitter.php
--- a/common/twitter.php
+++ b/common/twitter.php
@@ -610,10 +610,22 @@ function twitter_status_page($query) {
   $request = API_URL."statuses/show/{$id}.json";
   $status = twitter_process($request);
   $content = theme('status', $status);
-  if (!$status->user->protected) {
+  $thread_id = $status->id_str;
+  $request = API_URL."related_results/show/{$thread_id}.json";
+  $threadstatus = twitter_process($request);
+  if ($threadstatus && $threadstatus[0] && $threadstatus[0]->results) {
+   $array = array_reverse($threadstatus[0]->results);
+   $tl = array();
+   foreach ($array as $key=>$value) {
+    array_push($tl, $value->value);
+    if ($value->value->in_reply_to_status_id_str && $value->value->in_reply_to_status_id_str == $status->id_str) {
+     array_push($tl, $status);
+    }
+   }
+   $tl = twitter_standard_timeline($tl, 'replies');
+   $content .= '<p>related_results</p>'.theme('timeline', $tl);
+  } elseif (!$status->user->protected) {
    $thread = twitter_thread_timeline($id);
-  }
-  if ($thread) {
    $content .= '<p>And the experimental conversation view...</p>'.theme('timeline', $thread);
    $content .= "<p>Don't like the thread order? Go to <a href='settings'>settings</a> to reverse it. Either way - the dates/times are not always accurate.</p>";
   }

附上 nginx 里 dabr https 配置
server {
      listen 443;
      server_name fanfou.beike.me;

      ssl on;
      ssl_certificate /etc/nginx/ssl/server.crt;
      ssl_certificate_key /etc/nginx/ssl/server.key;

      if ($http_user_agent ~ "MSIE") { return 404; }
      if ($http_user_agent ~ "Firefox") { return 404; }

      root /var/www/webapps/dabr;

      location ~* ^(/images|/favicon.ico) {
        expires max;
      }

      location /itap/ {
        if (!-e $request_filename) {
          rewrite ^(.*) /itap/index.php last;
        }
      }

      location / {
        rewrite "^/([^\.]*)$" /index.php?q=$1 last;
      }

      location ~ \.php$ {
        fastcgi_pass  127.0.0.1:9876;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include /etc/nginx/fastcgi_params;
      }
    }

server {
      listen 80;
      server_name fanfou.beike.me;
      if ($http_user_agent ~ "MSIE") { return 404; }
      if ($http_user_agent ~ "Firefox") { return 404; }
      rewrite ^/(.*) https://fanfou.beike.me/$1 permanent;
}
需要 itab 墙内代理登录的话,
在 dabr 目录执行
hg clone https://bitbucket.org/aveline/itap
下载 itap
并在 common/user.php 修改 $authorise_url 为
$authorise_url = BASE_URL.’/itap/authorize?oauth_token=’.$token['oauth_token'];

再附上

自己搭建 OperaMini 穿越代理服务器

用 nginx 做 OperaMini 的 http 代理服务器配置
server {
  resolver 8.8.8.8;
  listen 80;
  server_name opera.beike.me;
  access_log off;
  location / {
    proxy_pass http://server4.operamini.com$request_uri;
    proxy_redirect off;
    proxy_buffering off;
  }
}
这样就可以在 OperaMini 用代理服务器为 http://opera.beike.me:80/
以及利用 xinetd 做 OperaMini 的 socket 代理服务器
在 /etc/services 添加一行
s4opm  1080/tcp
再在 /etc/xinetd.d/s4opm 写上
service s4opm
{
    disable        = no
    flags          = REUSE
    socket_type    = stream
    wait           = no
    user           = root
    port           = 1080
    protocol       = tcp
    #redirect       = mini5.opera-mini.net 1080
    redirect       = server4.operamini.com 1080
    #log_on_failure += USERID
}
这样就可以在 OperaMini 用代理服务器为 socket://beike.me:1080/
注意:上边配置里的强调部分,请自己按情况修改.
from http://shellexy.wordpress.com/2011/02/28/dabr-%E7%9A%84-https-%E6%94%AF%E6%8C%81/