标签归档:openwrt

OpenWRT小米路由器Mini – 不支持所上传的文件格式请确认选择的文件无误

今天尝试给小米路由器mini(MT7620a)上的自编译openwrt刷入原版镜像,后台升级出现上述错误。

遂尝试sysupgrade,依然无法刷入:

Device xiaomi,miwifi-mini not supported by this image
Supported devices: miwifi-mini
Image check ‘fwtool_check_image’ failed.

解决方案也很简单。编辑/lib/upgrade/fwtool.sh

将46行的device="$(cat /tmp/sysinfo/board_name)"修改为device="miwifi-mini"即可。

OpenWrt访客WiFi植入广告

好吧,这确实是一个很奇怪的需求。

1.设置访客WiFi

http://www.right.com.cn/forum/thread-173844-1-1.html

其中网络接口的IP地址设置为172.16.68.1

2.配置Privoxy

Privoxy是一款不进行网页缓存且自带过滤功能的代理服务器,针对HTTP、HTTPS协议。通过其过滤功能,用户可以保护隐私、对网页内容进行过滤、管理Cookie,以及拦阻各种广告等。Privoxy可以单机使用,也可以应用到多用户的网络。它也可以与其他代理相连,更可以突破互联网审查。

安装privoxy:

opkg install privoxy

配置privoxy:

cd /etc/privoxy/
vi config

编辑config

高亮行为需要添加/修改的

confdir /etc/privoxy
logdir /var/log
filterfile default.filter
filterfile user.filter
logfile privoxy
actionsfile match-all.action # Actions that are applied to all sites and maybe overruled later on.
actionsfile default.action   # Main actions file
actionsfile user.action      # User customizations
listen-address  172.16.68.1:8118
toggle  1
enable-remote-toggle  1
enable-remote-http-toggle  0
enable-edit-actions 1
enforce-blocks 0
buffer-limit 4096
forwarded-connect-retries  0
accept-intercepted-requests 1
allow-cgi-request-crunching 0
split-large-forms 0
keep-alive-timeout 300
socket-timeout 300
permit-access  172.16.68.0/24
debug   1    # show each GET/POST/CONNECT request
debug   4096 # Startup banner and warnings
debug   8192 # Errors - *we highly recommended enabling this*
#admin-address privoxy-admin@example.com
#proxy-info-url http://www.example.com/proxy-service.html

user.filter中添加要注入的脚本:

FILTER: guest-wifi
s|</head>|<script type="text/javascript" src="http://example.com/ad.js"></script>$0|

user.action中调用user.filter的规则:

{+filter{guest-wifi}}
.*

3.将流量转发到Privoxy

下面的指令会将所有来自172.16.68.*,访问80端口的请求转发到位于8118端口的privoxy:

iptables -t nat -A PREROUTING -s 172.16.68.1/24 -p tcp --dport 80 -j REDIRECT --to-ports 8118

4.后记

 

  • privoxy会导致访问延迟。
  • privoxy官方文档中明确指出不支持https流量的拦截。

解决openwrt下的redsocks2启动报错

启动redsocks2时出现下列错误:

[root@PandoraBox:/root]#/etc/init.d/redsocks2 restart
file parsing error at line 16: invalid token order
file parsing error at line 16: unclosed section
file parsing error at line 16: stale key_token
file parsing error at line 16: stale value_token
[root@PandoraBox:/root]#

解决方案:修改透明代理设置 – 密码,在两侧加上引号。如图所示:

在openwrt上安装php

1.安装

确保你已经配置好了opkg源。

安装php及其扩展:

opkg update
opkg install php5 php5-cgi php5-mod-mcrypt php5-mod-curl php5-mod-hash php5-mod-json

2.配置

编辑php.ini

vi /etc/php.ini

;extension = curl.so
;extension = hash.so
;extension = json.so

三项前面的;去掉以启用扩展

并将;date.timezone =修改为date.timezone = Asia/Shanghai

如果你没有设置过系统时区的话还需要设置系统时区。打开LUCI界面,进入系统 – 系统属性 – 基本设置中将时区改为Asia/Shanghai

最后你需要安装一个时区信息软件包,否则系统无法识别时区。

opkg install zoneinfo-asia

3.可能遇到的问题

1.can’t load library ‘libpcre.so.0’

当我按照上述步骤安装/配置完成后访问浏览器却得到了一个无情的502,运行/usr/bin/php-cgi得到下面的错误:

/usr/bin/php-cgi: can't load library 'libpcre.so.0'

搜索一番后得出以下解决方案:

ln -s /usr/lib/libpcre.so.1 /usr/lib/libpcre.so.0

2.No input file specified.

解决了502,再次访问浏览器却提示”No input file specified.”。继续搜索后得出下面的方案:

编辑php.ini,注释掉doc_root=”/www”这一行(在前面加上;

 

大功告成!现在访问浏览器一切正常。