Imagoxy: A Picasa Image Proxy for Personal Website and Blog

2009/07/17 | 22:59 | 分类:Linux与开源 | 标签: | 1,572次阅读

Picasa had been banned in Mainland China yesterday. I don't know if it is temporary or persistent. Lots of pictures on my blog are stored in Picasa. Unlike Flickr, I found it difficult to replace domain name or IP to pass the URL/IP filter. So I choose another way: download pictures from Picasa server to my Godaddy host, and replace the picture links in my posts from Picasa to my host. I wrote Imagoxy, a tiny PHP toolkit and Imagoxy-WP, a wordpress plug-in to implement this automatically and dynamically. This mechanism will certainly apply additional overhead and occupy more bandwidth. However, it is sustainable for my small website. Experiment shows it works well with wordpress 2.8.1. I make it open-source under a BSD license and you can get it from SourceForge or WordPress Plugin page.

Security issues should be considered carefully before it being used in significant applications. Some measures had been taken, but I hope you to review my codes and eliminate the hidden dangers. If you are interested in Imagoxy, welcome to join the small project at SourceForge and contribute your codes! Thanks. :)

I do not profit from my open source works. But if you really think they are useful, you can click here.

Imagoxy Version 0.53 - Update: 2009/12/10
Imagoxy-WP Version 0.53 - Update: 2009/12/10

Imagoxy

Imagoxy ("image proxy") is a tiny PHP toolkit. It downloads pictures from remote server to local server and relocate corresponding http requests to the local one. It is used to access pictures when the remote server is banned or slow from the network of clients (e.g. Download pictures from Picasa on an unbanned US server and tranfer them to China's viewers where Picasa is banned sometimes).

Licensed under a BSD license.

Install:

1. Modify Imagoxy 'getimg.php' file:
* Set '$work_dir' to the location you wish Imagoxy works at.
* Set '$cache_dir' to the location you wish files downloaded to. (default is OK in most cases)
* Set '$error_file' as the file relocated to when access control denied. (default is OK in most cases)
* Set '$reffer_list' as the legal HTTP_REFERER prefix list.
* Set '$check_reffer_before_download' as whether to check HTTP_REFERER before downloading new picutre.
* Set '$check_reffer_before_show' as whether to check HTTP_REFERER before showing downloaded picutre.
* Set '$legal_pattern' as the legal file URL patterns. (default is for Picasa; you can add more)
2. Update the 'imagoxy' directory to your '$work_dir' and make the '$cache_dir' writable.
3. Configure and deploy Imagoxy front-ends such as Imagoxy-WP.

Usage:

1. [ http://www.example.com/imagoxy/getimg.php?s={original URL} ] In this format (we called 'Imagoxy URL'), the http request will be relocated to a file on local server which is downloaded from the original URL. You can embed the Imagoxy URL into your <img src="..."> label. 'http://' in original URL is omissible and the other protocols are not allowed. Notice: as a parameter, original URL should be url-encoded again even if it has been url-encoded. e.g. 'Pic%20A.jpg' -> 'Pic%2520A.jpg'.
2. [ http://www.example.com/imagoxy/getimg.php?u={encoded URL} ] Also does downloading and relocation. However, you should base64-encode, reverse and then url-encode the original URL. In PHP, these are done by 'urlencode(strrev(base64_encode($original_url)))'. This encoding method can pass the URL filter in certain regions.

Test:

You can write a html page with an Imagoxy URL in <img src="..."> label. Open it locally, you should see the '$error_file'; after uploading it to the server with the URL prefix in '$reffer_list', you will see the relocated picture correctly.

Enjoy it!

Imagoxy-WP

Imagoxy-WP is a wordpress front-end for Imagoxy. Imagoxy downloads pictures from remote server to local server and relocate corresponding http requests to the local one. It is used to access pictures when the remote server is banned or slow from the network of clients. Imagoxy-WP now converts Picasa URLs to local Imagoxy URLs, and you can also add your customed conversion.

Licensed under a BSD license.

Install:

1. Download Imagoxy. Imagoxy is available at https://sourceforge.net/projects/imagoxy/.
2. Configure and deploy Imagoxy on your server as Imagoxy's README file described.
3. Modify Imagoxy-WP 'imagoxy-wp.php' file:
* Set '$imagoxy_dir' to your Imagoxy location, which is the same as '$work_dir' in Imagoxy.
4. Upload Imagoxy-WP php file or the whole directory to your wordpress '/wp-content/plugins' directory.
5. Enable it in the dashboard.

After that, You will see:
<img src="http://lhX.ggpht.com/_WWW/XXX/YYY/ZZZ/sMMM/IMG_NNN.JPG" />
in your blog posts now becomes:
<img src="http://www.example.com/imagoxy/getimg.php?u=AABBCCDDEEFFGGHH" />
Since pictures are downloaded from your own server, it won't be banned then.

Enjoy it!

MySQL+amoeba,轻量级的分布式数据库实现

2009/03/17 | 21:44 | 分类:Linux与开源 | 标签: | 1,434次阅读

  最近因为一个大作业,我需要建立一个分布式数据库系统。Oracle和DB2固然强大,但巨大的资源占用以及软件授权的限制让我放弃选择它们。我的目标是寻找轻量级的、免费(最好是开源)的解决方案,最终目标锁定在国产的amoeba上。
  amoeba是一个以MySQL为底层数据存储,并对应用提供MySQL协议接口的proxy。它集中地响应应用的请求,依据用户事先设置的规则,将SQL请求发送到特定的数据库上执行。基于此可以实现负载均衡、读写分离、高可用性等需求。与MySQL官方的MySQL Proxy相比,作者强调的是amoeba配置的方便(基于XML的配置文件,用SQLJEP语法书写规则,比基于lua脚本的MySQL Proxy简单)。有关amoeba的更多信息可以参考其文档作者blog。google出来的相关信息并不多,不过作者的这个帖子(含回复)倒是值得一看。
  下面说说我的理解:
  1、amoeba相当于一个SQL请求的路由器,目的是为负载均衡、读写分离、高可用性提供机制,而不是完全实现它们。用户需要结合使用MySQL的Replication等机制来实现副本同步等功能。amoeba对底层数据库连接管理和路由实现也采用了可插拨的机制,第三方可以开发更高级的策略类来替代作者的实现。这个程序总体上比较符合KISS的思想。
  2、由上一条,建议使用MySQL的Replication机制建立Master-Slave来做副本。我一开始理解有误,使用了amoeba的virtual DB(负载均衡pool)做writePool,结果使得本应插入同一个表中的数据被拆分地写入了不同的物理数据库中。这样自然与副本的语义不符了。
  3、amoeba已经实现了数据的垂直切分与水平切分。水平切分方面,粒度是行。使用SQLJEP语句可以设计出复杂的切分规则,个人认为是比较强大的。垂直切分的粒度是表,可以把针对不同表的请求发送到不同的节点上执行,但不能以列作为分片粒度。从作者的说法看,amoeba不做SQL解析和重写。在目前的机制下似乎是难以实现同一个表不同的列在不同节点上的分布。不过对开发人员来说,设计良好的表结构应该可以实现简单的基于关系属性的负载均衡的。
  要说这个项目最大的不足,我想可能是文档方面的:
  1、软件的文档(0.31版)主要在讲解配置文件怎么修改,却没有说怎么运行amoeba。我以前没有MySQL Proxy以及Java工程方面的经验,下载解压amoeba之后,第一感觉这是一个数据库中间件,要通过Java API编程使用,所以我还纳闷文档中为什么没有API的说明。仔细一看才发现bin目录下有启动脚本。回到文档,发现只在最后的“amoeba性能调优”一节才提到了“amoeba启动脚本”。希望作者改进下一版的文档,让新手不要再疑惑。
  2、文档的“amoeba for aladdin”一节说“(amoeba for aladdin)其性能比MySQL Proxy也好,但比amoeba for mysql微微差了点”,看起来性能优劣是“amoeba for mysql>amoeba for aladdin>MySQL Proxy”;但在这个帖子的回复中,作者又说“(amoeba for mysql)比官方的MySQL Proxy性能大致低10%~20%左右”,两处似乎有矛盾。继续翻这个帖子,才发现原来在0.27版本以后,amoeba的性能逐渐超过了MySQL Proxy。所以,希望作者可以完善一下文档,并在官方网站或blog的显著位置说明最新版本的特性,以免引起误会。
  3、amoeba是一项优秀的工作,有必要提供完整的英文文档,以便国际推广。