Blog

  • Change FreePBX default MySQL connection

    我可能吹毛求疵了:我感觉如果要修改 FreePBX 里默认的 MySQL 的连接位置好麻烦。

    我修改成 MySQL socket 方式连接,而且也修改了 socket file 的位置,然后要修改 FreePBX 好多个文件才能让 FreePBX 对接 MySQL。大部分文件属于 FreePBX 配置文件,还好办,象填表格一样填就是。但 /var/www/html/admin/modules/userman/DB_Helper.class.php 根本没为 MySQL socket 连接方式考虑,DSN 只兼容 host 连接,所以要大改 262 行(以FreePBX 2.11.0.39为例)。

    要改成多行:

    
    if (preg_match('/^unix\((.+)\)$/', $amp_conf['AMPDBHOST'], $matches) === 1) {
    	$ampdbsocket = $matches[1];
    	$dsn = "mysql:unix_socket=".$ampdbsocket.";dbname=".$amp_conf['AMPDBNAME'];
    }
    else {
    	$dsn = "mysql:host=".$amp_conf['AMPDBHOST'].";dbname=".$amp_conf['AMPDBNAME'];
    }
    
    

    直接修改程序是我最不愿意的。FreePBX 似乎也没提供安全升级的办法,所以 User Management 模块一升级,上述修改就作废,FreePBX web portal 就出错。

  • Allow specific “anonymous” inbound SIP calls

    之前所有的 SIP 服务商都是提供 SIP 注册的帐号和密码。最近碰上一个新的 SIP 服务商,购买了一个电话号码,它只让我设置 Forward to SIP Server 或 Forward to SIP URI(当然也可以转发到普通电话号码,但那是要额外收费的,不在我考虑范围之内)。

    于是,碰到了新命题:我必须在 FreePBX 的 SIP Settings 里同时启用 Allow SIP Guests 和 Allow Anonymous Inbound SIP Calls 才能收到转发过来的 SIP calls。这两项都是我不愿意启用的设置,因为存在被 SIP hackers spamming 的风险。尽管单独启用 Allow SIP Guests 据说没有太大风险,但还是接不到电话,呼叫方会收到 FreePBX 给出的语音提示:The number you have dialed is not in service. Please check the number and dial again.

    怎样才能让来自 SIP 服务商的 anonymous calls 通过,而把其他的阻挡在外?我甚至想到了启用 Allow SIP Guests 和 Allow Anonymous Inbound SIP Calls ,但用防火墙规则只允许来自特定 host / IP 的流量。这个方法我自我评价是非常 dirty,我希望是 FreePBX 的问题在 FreePBX 内部解决。

    我几乎不带希望,搞了个试验,创建了一个 SIP trunk。它跟之前注册型的 SIP trunk 的区别就是省略了 PEER Details 项里的 username, password 和 Register String。然后,同时禁用 Allow SIP Guests 和 Allow Anonymous Inbound SIP Calls,这时 Forward to SIP URI 已经能工作;再添加一条 Inbound Route,Forward to SIP Server 也能工作了。

    这个事实推翻了我对 trunk 的原有理解—— trunk 只是一条进或出的通路。现在我知道 trunk 还能“命名”符合特定条件的“匿名”来电,起到过滤的作用。

    此外,我猜想,转发型的 SIP 服务比注册型的 SIP 服务更可靠,因为转发型的 SIP 只在有来电时把数据包转发到我的 FreePBX;而注册型的 SIP 则要不时地重注册保持连接,有时连接已经断开,而 FreePBX 不知道,要等到下个周期才重注册,于是会错过来电。不知我猜想对否?请教过路的 VOIP 专家。

     

  • WP Social Login back to working

    WP Social Login 这个插件在芳草苑上好长时间工作不正常了。无法通过 Google 帐号登录,显示的出错信息是:Oops! We ran into an issue. Request failed. Either you have cancelled the authentication or Google refused the connection.

    Google authentication failed
    Google authentication failed

    今天终于找到原因,其实也不是插件的错,而是在 Google 开发者项目设置里没有开启 Google+ API。默认是禁用,启用就行了。

    Enable Google+ API
    Enable Google+ API

    我隐约记得有消息说 Google+ API 发布以后,WP Social Login 从 Google API 转向了 Google+ API。但当时也没留意看,现在也搞不清楚 Google API 和 Google+ API 有什么区别。IT 技术发展太快了,很多概念只能浮于表面,能用足用好已经不错了。

  • Use long established business for your hosting

    前段时间用了一个名不见经传的公司的 VPS 产品。当时看它性能不错才切换过去,但是它操作极不规范,到期前不催续费,我想主动续费都没有链接可以让我续。突然有一天,它意识到有未收账款,也不通知我付款,就停了我的帐号。然后我付款,重新开通服务。中间中断了大约半天的服务,让我损失惨重——那天以后来自 Google 和 Facebook 的流量突然就下降了。这也让我百思不得其解:

    1. 我知道一个网站的 uptime 是很重要的指标,但是,好像影响过头了?以致我怀疑流量下降不是 uptime 的问题,但转折点就在宕机的那一天,是巧合吗?
    2. Google 和 Facebook 使用同样的算法?

    总之,不正规的公司是绝对不敢用了。离开之前,我自己清空数据,以下一行命令删除 MySQL 里所有的数据库,抄来的,很方便。

    mysql -uroot -pPASS -e "show databases" | grep -v Database | grep -v mysql| grep -v information_schema| grep -v test | gawk '{print "drop database " $1 ";"}' | mysql -uroot -pPASS
  • Magento not rebuilding image cache

    I changed a server for Magento sites. When I migrated the sites, they looked fine. However after I flushed Magento image cache, all sites stopped working. Web pages were not completed. The code stopped rendering after the first product image’s “src”. But there was no error message afterwards.

    At first I thought it was file permission problem. But it was not.

    Then I thought it was some rubbish left over after flushing cache. So I took the advice by removing the folder media/catalog/product/cache and clearing everything under var. But the problem was still there.

    Then I realised it was php not generating images for Magento. Magento requires php-gd to generate images. My new server did not have php-gd installed. If I was installing a Magento instance, I would not get through. But I migrated the sites. So they “looked” fine.

    After installed php-gd, product images came back.

    By the way, Magento requires some other PHP extensions to run. I took the chance to install them all.
    pdo_mysql
    simplexml
    mcrypt
    hash
    gd
    dom
    iconv
    curl
    soap

  • Ngnix 502 bad gateway error after a recent php-fpm update

    I recently updated php-fpm from 5.4.16 to 5.5.16. After the update, Nginx comes up with 502 bad gateway error. Googling the error pointed me to look into permission of php socket file.

    In php-fpm 5.4.16, if no value is given to listen.mode, php socket file is assumed to 0666.

    But in php-fpm 5.5.16, if no value is given to listen.mode, php socket file is assumed to 0660.

    That is why Nginx no longer has permission to php socket and occurs 502 error.

  • A simple multi-skills test

    Excellent Excel
    Excellent Excel
    考考各位看官的猜想、推理、数学、EXCEL能力:

    新建一份EXCEL表格(Google Spreadsheet 也行),在 A1:I9 的每个单元格内输入以下公式——

    =IF(COLUMN()>ROW(),"",VLOOKUP(COLUMN(),$L$1:$M$9,2)&VLOOKUP(ROW(),$L$1:$M$9,2)&IF(COLUMN()*ROW()<10,"得","")&IF(COLUMN()*ROW()<10,VLOOKUP(COLUMN()*ROW(),$L$1:$M$9,2),VLOOKUP(INT(COLUMN()*ROW()/10),$L$1:$M$9,2)&"十"&VLOOKUP(MOD(COLUMN()*ROW(),10),$L$1:$M$10,2,FALSE)))

    请问,应该在表格的什么地方填入什么预设值,才能让 A1:I9 的内容变得有意义?

    提示:有 20 个单元格需要预设值。

  • BT Infinity speed tests

    这两天专注于测试 BT Infinity 访问国内外的网速,有了一个总结性呈辞。

    我发现三个较好的测试网站是:

    1. http://myspeedmeter.net/:它是众多带宽测速网站中唯一能测到我的 BT Infinite 满速(下行 76Mbps,上行 19Mbps)的网站。但这个测试结果只能在连接它的伦敦服务器时能达到,连接它在世界各地其他区域的服务器时仍有较大差距,可能瓶颈在海底光缆上。

      BT Infinity speed test result on Myspeedmeter
      BT Infinity speed test result on Myspeedmeter
    2. http://openspeedtest.com/:它用的是纯 HTML5 做测试,没有用到 Flash 或 Java。在你的各种插件都已崩溃或临近崩溃的浏览器里(当然要足够新版),或在手机上不想安装 app 就直接测试,都是很好的选择。但如前所述,它无法测得我的满速,可能我的带宽比它服务器的带宽还强。

      BT Infinity speed test result on Openspeedtest
      BT Infinity speed test result on Openspeedtest
    3. http://sh.189.cn/support/netreport/:它是中国电信搞的网速测试。如果在中国,对连接国外速度没有信心,也可以先测测国内的速度吧。当然我亲测的话,也是不可能满速的。

      BT Infinity speed test result on China Telecom
      BT Infinity speed test result on China Telecom

    至于其他两个名气更响的英国宽带网速测试网站,在我这里不推荐。

    1. http://speedtest.btwholesale.com/:它是 BT 公司嫡出的测试工具,但在测试 BT Infinite 时却无法象 myspeedmeter 那样获得满速的结果。

      BT Infinity speed test result on BT Wholesale
      BT Infinity speed test result on BT Wholesale
    2. http://www.broadbandspeedchecker.co.uk/:它在 Google 搜索 broadband speed test 时排名第一,自己也号称 “THE UK’s No.1 Broadband Speed Test”,也是我在 ADSL 时代用得最多的测网速的工具,但它也是无法满速,在 VDSL 时代中没有与时俱进。

      BT Infinity speed test result on Broadbandspeedchecker
      BT Infinity speed test result on Broadbandspeedchecker
  • First money back from price guarantee

    Asda price guarantee voucher
    Asda price guarantee voucher

    总是见商家讲自己的价格是最低的,如果不是,补你差价(有的甚至补差价的110%)。很久以前不知那位老师分析过,这种价格保证(Price Guarantee)的促销模型是很棒的,但我潜意识里不愿意被这种促销摆布。我认为商家有这个时间、精力搞价格保证,不如实实在在把价格降到最低;消费者有这个时间、精力去拿回这个差价,不如直接从最低售价的商家购买商品。

    但是,不久前有朋友告诉我,各大超市的价格保证并不是我想的那样,是实实在在的退差价,索偿过程在线自助完成,无需找经理,无需提供竞争对手的更低售价的证据。真是活到老、学到老,我真不知道这促销形式已经进化成这样了。我之前在超市购物,浪费了多少索偿机会啊!

    于是,我收集了最近在 ASDA 的四张购物凭证,上网去价格保证网站,输入交易号,竟有两张得到补偿,其中一单交易额为 £93,补偿高达 £14.49,大大出乎我意料。

    看来大超市已经把价格保证落到了实处,当然要享受价格保证有少许条件限制,这些条件并不高,很容易满足,有兴趣大家去读读各超市的条约。唯一例外的是 Waitrose,不务实,只声称它的价格与 Tesco 持平,不参与价格保证行动。

  • Google Story can be an artist

    Google Now 可以当个小蜜,但 Google Story 可以堪称一个艺术家。

    她能把非常稀松平常的照片修饰得别有韵味,还能把本不平常的照片装点得非常有气势。

    对比我们花大价钱请设计师设计宣传画册,得到的效果不过如此,而 Google 是机器生成的 Story 相册,竟能 PK 人类 50% 的设计师,不禁有些气馁。

    Google Story 1
    Google Story 1
    Google Story 2
    Google Story 2
    Google Story 3
    Google Story 3
    Google Story 4
    Google Story 4
    Google Story 5
    Google Story 5
    Google Story 6
    Google Story 6
    Google Story 7
    Google Story 7
    Google Story 8
    Google Story 8