木须柄的时光工坊

探索技术与游戏乐趣的奇妙之旅

目录
小米路由 SMB 服务自定义教程
/      

小米路由 SMB 服务自定义教程

小米 R1C 路由

这台古早机型的配置很低,而且对系统做了极大的精简,导致很多配置工具和文件缺失,研究的过程相对曲折一些。

首先,为了深入研究路由器内置的 SMB 协议,需要开启 SSH 连接服务

打开 MiWifi 开放平台,下载 miwifi_ssh.bin SSH 插件,密码在绑定了小米账号后,会在网站后台显示;

打开 SSH 连接

查询 SMB 配置文件位置

不同型号的内容会存在差异

 1root@XiaoQiang:~# find / -name "smb.conf*"
 2
 3# 小米R1C结果
 4/extdisks/sda1/xiaomi_router/config/smb.conf.template
 5/extdisks/sda1/xiaomi_router/config/smb.conf
 6/tmp/etc/smb.conf
 7
 8# 小米R3结果
 9/etc/samba/smb.conf.template
10/etc/samba/smb.conf
11/tmp/etc/smb.conf
12/data/etc/samba/smb.conf.template
13/data/etc/samba/smb.conf
14/data/etc_bak/samba/smb.conf.template
15/data/etc_bak/samba/smb.conf
16/extdisks/sda1/xiaomi_router/config/smb.conf.template
17/extdisks/sda1/xiaomi_router/config/smb.conf

可以看到,小米 R1C 的内容比小米 R3 的要少很多,很多内容是写死的,配置工具也是极度精简,接下来会给我们的自定义带来很大困难

查询 SMB 工具位置

 1root@XiaoQiang:~# find / -name "samba*"
 2
 3# 小米R1C结果
 4/extdisks/sda1/xiaomi_router/log/samba.log
 5/extdisks/sda1/xiaomi_router/bin/samba_multicall
 6/extdisks/sda1/xiaomi_router/config/samba
 7/extdisks/sda1/xiaomi_router/config/samba.schema
 8
 9# 小米R3结果
10/etc/init.d/samba
11/etc/samba
12/etc/openldap/schema/samba.schema
13/etc/config/samba
14/tmp/log/samba.log
15/usr/sbin/samba_multicall
16/data/etc/init.d/samba
17/data/etc/samba
18/data/etc/openldap/schema/samba.schema
19/data/etc/config/samba
20/data/etc_bak/init.d/samba
21/data/etc_bak/samba
22/data/etc_bak/openldap/schema/samba.schema
23/data/etc_bak/config/samba
24/extdisks/sda1/xiaomi_router/log/samba.log
25/extdisks/sda1/xiaomi_router/bin/samba_multicall
26/extdisks/sda1/xiaomi_router/config/samba
27/extdisks/sda1/xiaomi_router/config/samba.schema

其中 /extdisks/sda1/ 是路由器外接存储的位置,根据具体情况可能会有动态变化,比如 /sda1 /sdb1 /sdc1 等等

临时编辑 SMB 配置

编辑 /extdisks/sda1/xiaomi_router/config/smb.conf.template 模板文件,在末尾添加以下内容

1[PS2SMB]
2path = /extdisks/sda1/PS2SMB
3browsable = yes
4guest ok = yes
5read only = no
6create mask = 0777
7directory mask = 0777

重启 SMB 服务,即可添加 PS2SMB 共享文件夹,用于连接 PS2

但是这种配置方法,一旦外接存储断开,或者路由器断电,smb.conf.template 模板文件就会重新被路由器刷写覆盖。所以需要找到更上层的修改代码

监测修改模板的进程

由于工具极度匮乏,我写了个脚本用于动态监测是可能是哪个进程修改了 smb.conf.template,每隔 1 秒监测模板文件是否发生变化,并记录当时的进程变化;

由于路由器中的大部分目录都是只读状态, 又不能写在外部存储里,最终确定放在 /etc/watch_smb_template_dynamic.sh 中比较合适

进程状态的输出日志放在 /extdisks/sda1/router_watch/log 中(考虑动态的位置加载)

 1#!/bin/sh
 2
 3SLEEP_INTERVAL=1
 4
 5# 动态寻找挂载目录
 6find_mount_point() {
 7    for mount_point in /extdisks/*; do
 8        if [ -d "$mount_point/router_watch" ]; then
 9            echo "$mount_point"
10            return
11        fi
12    done
13    echo ""
14}
15
16# 初始化:找出初始挂载点
17MOUNT_BASE=`find_mount_point`
18
19if [ -z "$MOUNT_BASE" ]; then
20    echo "[-] No valid storage found under /extdisks/"
21    exit 1
22fi
23
24WATCH_FILE="$MOUNT_BASE/xiaomi_router/config/smb.conf.template"
25LOG_DIR="$MOUNT_BASE/router_watch/logs"
26
27mkdir -p "$LOG_DIR"
28echo "[+] Start watching: $WATCH_FILE"
29
30if [ -f "$WATCH_FILE" ]; then
31    LAST_MODIFY_TIME=`stat "$WATCH_FILE" | grep Modify | awk '{print $2" "$3}'`
32else
33    echo "[-] File not found: $WATCH_FILE"
34    exit 1
35fi
36
37while true
38do
39    # 动态检查挂载点变化
40    NEW_MOUNT_BASE=`find_mount_point`
41    if [ "$NEW_MOUNT_BASE" != "$MOUNT_BASE" ]; then
42        echo "[!] Storage mount point changed: $MOUNT_BASE -> $NEW_MOUNT_BASE"
43        MOUNT_BASE="$NEW_MOUNT_BASE"
44        WATCH_FILE="$MOUNT_BASE/xiaomi_router/config/smb.conf.template"
45        LOG_DIR="$MOUNT_BASE/router_watch/logs"
46        mkdir -p "$LOG_DIR"
47        if [ ! -f "$WATCH_FILE" ]; then
48            echo "[-] New mount found but target file missing."
49            sleep $SLEEP_INTERVAL
50            continue
51        fi
52        LAST_MODIFY_TIME=`stat "$WATCH_FILE" | grep Modify | awk '{print $2" "$3}'`
53    fi
54
55    if [ -f "$WATCH_FILE" ]; then
56        CURRENT_MODIFY_TIME=`stat "$WATCH_FILE" | grep Modify | awk '{print $2" "$3}'`
57        if [ "$CURRENT_MODIFY_TIME" != "$LAST_MODIFY_TIME" ]; then
58            echo "[!] Detected change at `date`"
59            ps > "$LOG_DIR/ps_`date +%Y%m%d_%H%M%S`.txt"
60            LAST_MODIFY_TIME="$CURRENT_MODIFY_TIME"
61        fi
62    else
63        echo "[-] File deleted or not found! `date`"
64    fi
65
66    sleep $SLEEP_INTERVAL
67done

给脚本添加执行权限后,执行脚本,然后断开外部存储,再插上,让脚本观察哪个进程对模板文件执行了修改。

 1root@XiaoQiang:/etc# chmod +x /etc/watch_smb_template_dynamic.sh 
 2
 3root@XiaoQiang:/etc# /etc/watch_smb_template_dynamic.sh 
 4[+] Start watching: /extdisks/sdb1/xiaomi_router/config/smb.conf.template  # 开始监测
 5[-] File deleted or not found! Tue Apr 29 12:04:07 CST 2025  # 插拔U盘
 6[-] File deleted or not found! Tue Apr 29 12:04:08 CST 2025
 7[-] File deleted or not found! Tue Apr 29 12:04:09 CST 2025
 8[-] File deleted or not found! Tue Apr 29 12:04:10 CST 2025
 9[-] File deleted or not found! Tue Apr 29 12:04:11 CST 2025
10[-] File deleted or not found! Tue Apr 29 12:04:12 CST 2025
11[-] File deleted or not found! Tue Apr 29 12:04:13 CST 2025
12[-] File deleted or not found! Tue Apr 29 12:04:14 CST 2025
13[-] File deleted or not found! Tue Apr 29 12:04:15 CST 2025
14[!] Detected change at Tue Apr 29 12:04:16 CST 2025 # 重启 SMB 服务后,发现文件修改!

查询 /extdisks/sda1/router_watch/logs 中输出的日志文件,获取当时的进程状态

  1root@XiaoQiang:/etc# cat /extdisks/sdb1/router_watch/logs/ps_20250429_014104.txt 
  2
  3  PID USER       VSZ STAT COMMAND
  4    1 root      1784 S    init
  5    2 root         0 SW   [kthreadd]
  6    3 root         0 SW   [ksoftirqd/0]
  7    5 root         0 SW   [kworker/u:0]
  8    6 root         0 SW<  [cpuset]
  9    7 root         0 SW<  [khelper]
 10    8 root         0 SW   [sync_supers]
 11    9 root         0 SW   [bdi-default]
 12   10 root         0 SW<  [kblockd]
 13   11 root         0 SW   [khubd]
 14   12 root         0 SW   [kswapd0]
 15   13 root         0 SW   [fsnotify_mark]
 16   14 root         0 SW<  [crypto]
 17   19 root         0 SW   [mtdblock0]
 18   20 root         0 SW   [mtdblock1]
 19   21 root         0 SW   [mtdblock2]
 20   22 root         0 SW   [mtdblock3]
 21   23 root         0 SW   [mtdblock4]
 22   24 root         0 SW   [mtdblock5]
 23   25 root         0 SW   [mtdblock6]
 24   26 root         0 SW   [mtdblock7]
 25   27 root         0 SW   [mtdblock8]
 26   28 root         0 SW   [mtdblock9]
 27   29 root         0 SW   [mtdblock10]
 28   30 root         0 SW<  [et_port_queue]
 29   31 root         0 SW   [kworker/u:1]
 30   38 root         0 SW   [kworker/0:1]
 31  110 root         0 SWN  [jffs2_gcd_mtd7]
 32  228 root      1784 S    init
 33  242 root      5708 S    /usr/sbin/syslog-ng
 34  381 root      1108 S    /sbin/hotplug2 --override --persistent --set-rules-file /etc/hotplug2.rules --set-coldplug-cmd /sbin/ude
 35  446 root      1128 S <  /sbin/ubusd
 36  555 root      5672 S    /usr/sbin/taskmonitorServer
 37  557 root      1188 S    /usr/sbin/taskmonitorDaemon -p /usr/sbin/taskmonitorServer -b /usr/sbin/taskmonitorServer
 38  558 root      1768 S    sleep 300
 39  679 root      1768 S    /sbin/netifd
 40  833 root      1780 S    {watch_smb_templ} /bin/sh /etc/watch_smb_template_dynamic.sh
 41  853 root      1788 S    udhcpc -p /var/run/udhcpc-eth0.2.pid -s /lib/netifd/dhcp.script -f -t 0 -i eth0.2 -H MiWiFi-R1CM
 42 1536 root         0 SW   [RtmpCmdQTask]
 43 1547 root         0 SW   [RtmpWscTask]
 44 1548 root         0 SW   [RtmpMlmeTask]
 45 1635 root         0 SW   [kworker/0:2]
 46 2759 root      1768 S    sleep 120
 47 2851 root         0 SW   [RtmpCmdQTask]
 48 2852 root         0 SW   [RtmpWscTask]
 49 3152 root      1304 S    /usr/bin/trmd
 50 3393 root         0 SW   [scsi_eh_0]
 51 3490 root      1012 S    acsc
 52 3494 root      1188 S    bsd
 53 3514 root         0 SW   [scsi_eh_3]
 54 3521 root         0 SW   [usb-storage]
 55 3636 root         0 SW   [texfatd/sdb1]
 56 3700 root         0 SW   [flush-8:16]
 57 3701 root         0 SW   [flush-mtd-unmap]
 58 3714 root      3688 S <  /usr/bin/fcgi-cgi -c 4
 59 4104 root         0 SW   [texfatd/sda1]
 60 4271 root         0 Z    [sh]
 61 4286 root      1832 S    {usb_deploy_init} /bin/sh /etc/rc.common /etc/init.d/usb_deploy_init_script.sh start
 62 4303 root      4484 D    /usr/sbin/sysapihttpd -s reload
 63 4311 root      1776 R    ps
 64 4545 root     10504 S    nginx: master process /usr/sbin/sysapihttpd -c /tmp/sysapihttpdconf/sysapihttpd.conf
 65 4612 root      3600 S <  /usr/bin/fcgi-cgi -c 2
 66 4622 root      3600 S <  /usr/bin/fcgi-cgi -c 2
 67 4812 root      4492 S    {sysapihttpd} nginx: master process /usr/sbin/sysapihttpd -c /etc/mihttpd/mihttpd.conf
 68 4819 root      4540 S    {sysapihttpd} nginx: worker process
 69 5338 root      1344 S    /usr/sbin/dnsmasq --user=root -C /var/etc/dnsmasq.conf
 70 5339 root      1340 S    /usr/sbin/dnsmasq --user=root -C /var/etc/dnsmasq.conf
 71 5406 root      1776 S    {mald} /bin/sh /usr/bin/mald 2
 72 5419 root     14420 S <  /usr/bin/messagingagent --handler_threads 2
 73 5496 root      1796 S    /usr/sbin/crond -c /etc/crontabs -l 5
 74 5621 root      1388 S    /usr/sbin/dropbear -P /var/run/dropbear.1.pid -p 22
 75 5626 root      1400 S    /usr/sbin/miniupnpd -f /var/etc/miniupnpd.conf
 76 5768 root      1776 S    {iweventd.sh} /bin/sh /usr/sbin/iweventd.sh
 77 5798 root      1200 S    /usr/sbin/iwevent
 78 5799 root      1812 S    {iwevent-call} /bin/sh /usr/sbin/iwevent-call
 79 5833 root      6068 S    /usr/sbin/trafficd
 80 5948 root     21004 S    /usr/sbin/indexservice
 81 5986 root      1892 S    /usr/sbin/netapi
 82 6021 root     36316 S    /usr/sbin/datacenter
 83 6056 root      2276 S    /usr/bin/himan --proxy https://api.miwifi.com/utils/proxy --rule https://api.miwifi.com/data/himan_rule?
 84 6106 root      6432 S    /usr/sbin/uaq-agent
 85 7065 root     15812 S    /usr/sbin/rule_mgr 192.168.31.1 255.255.255.0
 86 7189 root      1264 S    /usr/sbin/http_dpi
 87 7344 root      3428 S    /sbin/lt -f /etc/lt_proxy/main.conf -d
 88 7541 root      4828 S    /usr/bin/lua /usr/sbin/miqosd std
 89 7827 root      3652 S    /usr/sbin/rmonitor
 90 8002 root     13928 S    /usr/sbin/securitypage -c /etc/config/securitypage/securitycenter.conf
 91 8071 root     12524 S    /usr/sbin/smartcontroller
 92 8171 root      1936 S    {syslog-ng.helpe} /bin/sh /usr/sbin/syslog-ng.helper
 93 8172 root      1780 S    tail -F /tmp/stat_points_rom.log /tmp/stat_points_web.log
 94 8173 root      1772 S    grep stat_points_instant
 95 8174 root      1776 S    {stat_points.hel} /bin/sh /usr/sbin/stat_points.helper
 96 8175 root      1940 S    {stat_points.cro} /bin/sh /usr/sbin/stat_points.cron
 97 8222 root      4928 S    statisticsservice -c /etc/statisticsservice/statisticsservice.conf
 98 8250 root      3576 S    lua /usr/sbin/ccgame_service.lua
 99 8262 root      3500 S    lua /usr/sbin/ipv6_service.lua
100 8327 root      2812 S    /usr/bin/wrsst
101 8726 root       996 S <  btnd reset 30
10210513 root      1012 S    /usr/sbin/web_filter_record
10311160 root     10504 S <  {sysapihttpd} nginx: worker process
10412679 root      1456 S    /usr/sbin/dropbear -P /var/run/dropbear.1.pid -p 22
10512680 root      1788 S    -ash
10613661 root      1456 S    /usr/sbin/dropbear -P /var/run/dropbear.1.pid -p 22
10713666 root      1800 S    -ash

最可疑的是这两个:这两条正好是紧挨着的,极大可能是同一个触发链

可疑进程 原因
4271 [sh]僵尸进程 说明刚刚执行了某个shell脚本,然后退出,父进程未回收
4286 /bin/sh /etc/init.d/usb_deploy_init_script.sh start 正在跑usb_deploy_init_script.sh,很可能是外接存储事件处理

结合小米路由器逻辑:

  • 外接U盘插入或重新挂载后,
  • 系统自动触发 /etc/init.d/usb_deploy_init_script.sh start
  • 这个脚本可能会检测新挂载盘
  • 然后重建smb.conf.template文件

经过分析,确认 /etc/init.d/usb_deploy_init_script.sh 就是部署 SMB 和外部存储器时的初始化脚本

完整内容如下:

  1#!/bin/sh /etc/rc.common
  2# Copyright (C) 2010-2012 OpenWrt.org
  3
  4STOP=20
  5
  6#usbDeployRootPath=$(cat /proc/mounts | grep /dev/sd |head -n1|cut -d' ' -f2);
  7usbDeployRootPath=
  8
  9get_root_path(){
 10cat /proc/mounts | grep /dev/sd | while read line
 11do
 12local dev=$(echo $line | cut -d' ' -f1)
 13if [ -n "$dev" ] && [ -e "$dev" ]; then
 14usbDeployRootPath=$(echo $line | cut -d' ' -f2)
 15echo $usbDeployRootPath > /tmp/usbDeployRootPath.conf
 16break
 17fi
 18done
 19}
 20
 21list_alldir(){  
 22local init_root=$1
 23local action=$2
 24for file in `ls $init_root`  
 25do  
 26if [ -f "$init_root/$file" ];then
 27
 28if [ "$file" = "000-cp_preinstall_plugins.sh" ];then
 29continue
 30fi
 31
 32if [ "$file" = "001-samba" ];then
 33continue
 34fi
 35if [ "$file" = "xunlei" ];then
 36continue
 37fi
 38$init_root/$file $action $usbDeployRootPath &
 39fi  
 40done  
 41}  
 42
 43change_stopedApp_status() {
 44dir=$1/appdata/app_infos
 45if [ -d "$dir" ];then
 46for file in `ls $dir | grep [^a-zA-Z]\.manifest$`
 47do
 48sed -i '/^status/s/\(.*\"\)\(7\)\(\".*\)/\1'5'\3/g' $dir/$file
 49done
 50fi
 51}
 52
 53start()
 54{
 55
 56get_root_path
 57usbDeployRootPath=$(cat /tmp/usbDeployRootPath.conf)
 58
 59rm -rf $usbDeployRootPath/xiaomi_router/appdata/app_infos/2882303761517280998.manifest
 60rm -rf $usbDeployRootPath/xiaomi_router/appdata/2882303761517280998/
 61
 62rm -rf $usbDeployRootPath/xiaomi_router/appdata/app_infos/2882303761517410304.manifest
 63rm -rf $usbDeployRootPath/xiaomi_router/appdata/2882303761517410304/
 64
 65rm -rf $usbDeployRootPath/xiaomi_router/appdata/app_infos/2882303761517236139.manifest
 66rm -rf $usbDeployRootPath/xiaomi_router/appdata/2882303761517236139/
 67
 68/usr/sbin/sysapihttpd -s reload
 69
 70if [ -n "$usbDeployRootPath" ];then
 71rm -rf /tmp/xiaomi_router
 72mkdir -p /tmp/xiaomi_router
 73cp -r $usbDeployRootPath/xiaomi_router/init /tmp/xiaomi_router/
 74change_stopedApp_status $usbDeployRootPath/xiaomi_router
 75if [ -f "$usbDeployRootPath/xiaomi_router/init/000-cp_preinstall_plugins.sh" ];then
 76$usbDeployRootPath/xiaomi_router/init/000-cp_preinstall_plugins.sh start $usbDeployRootPath
 77fi
 78if [ -f "$usbDeployRootPath/xiaomi_router/init/001-samba" ];then
 79$usbDeployRootPath/xiaomi_router/init/001-samba start $usbDeployRootPath
 80fi
 81if [ -f "$usbDeployRootPath/xiaomi_router/init/xunlei" ];then
 82$usbDeployRootPath/xiaomi_router/init/xunlei start $usbDeployRootPath
 83fi
 84#if [ -f "/etc/init.d/ad_filter" ];then
 85#/etc/init.d/ad_filter start $usbDeployRootPath
 86#fi
 87if [ -f "/etc/init.d/plugin_start_script.sh" ];then
 88/etc/init.d/plugin_start_script.sh restart $usbDeployRootPath
 89fi
 90list_alldir $usbDeployRootPath/xiaomi_router/init start
 91fi
 92}
 93
 94stop()
 95{
 96usbDeployRootPath=$(cat /tmp/usbDeployRootPath.conf)
 97rm /tmp/usbDeployRootPath.conf
 98if [ -n "$usbDeployRootPath" ];then
 99list_alldir /tmp/xiaomi_router/init stop
100wait
101if [ -f "/tmp/xiaomi_router/init/xunlei" ];then
102/tmp/xiaomi_router/init/xunlei stop $usbDeployRootPath
103fi
104if [ -f "/tmp/xiaomi_router/init/001-samba" ];then
105/tmp/xiaomi_router/init/001-samba stop $usbDeployRootPath
106fi
107#if [ -f "/etc/init.d/ad_filter" ];then
108#/etc/init.d/ad_filter off $usbDeployRootPath
109#fi
110if [ -f "/etc/init.d/plugin_start_script.sh" ];then
111/etc/init.d/plugin_start_script.sh stop $usbDeployRootPath
112fi
113
114#local dev=$(getdisk mnt | grep "$usbDeployRootPath\$" | cut -d',' -f1)
115#if [ -n "$dev" ] && [ -e "$dev" ] ;then
116#list_alldir $usbDeployRootPath/xiaomi_router/init stop
117#else
118#list_alldir /tmp/xiaomi_router/init stop
119#fi
120fi
121}

一劳永逸的修改 SMB 配置

花了半天功夫,找到了罪魁祸首,就是 /etc/init.d/usb_deploy_init_script.sh

我们在初始化 start() 函数后面添加一段代码,用于初始化时添加 PS2SMB 共享文件夹,逻辑和之前是一样的,这样就可以在每次初始化时,自动帮我们添加了

 1# 插到start()最后
 2
 3init_ps2smb_share() {
 4    if [ -n "$usbDeployRootPath" ]; then
 5        PS2SMB_DIR="$usbDeployRootPath/PS2SMB"
 6        SMB_CONF="$usbDeployRootPath/xiaomi_router/config/smb.conf"
 7
 8        if [ ! -d "$PS2SMB_DIR" ]; then
 9            mkdir -p "$PS2SMB_DIR"
10            chmod 755 "$PS2SMB_DIR"
11            echo "[INFO] Created PS2SMB directory at $PS2SMB_DIR"
12        fi
13
14        if [ -f "$SMB_CONF" ] && ! grep -q "\[PS2SMB\]" "$SMB_CONF"; then
15            echo "[INFO] Adding PS2SMB share to $SMB_CONF"
16cat <<EOF >> "$SMB_CONF"
17
18[PS2SMB]
19    path = $PS2SMB_DIR
20    read only = yes
21    guest ok = yes
22    force user = root
23EOF
24        else
25            echo "[INFO] PS2SMB share already exists or smb.conf missing."
26        fi
27    fi
28}
29
30# 调用
31init_ps2smb_share

完整的修改后脚本如下

  1#!/bin/sh /etc/rc.common
  2# Copyright (C) 2010-2012 OpenWrt.org
  3
  4STOP=20
  5
  6#usbDeployRootPath=$(cat /proc/mounts | grep /dev/sd |head -n1|cut -d' ' -f2);
  7usbDeployRootPath=
  8
  9get_root_path(){
 10cat /proc/mounts | grep /dev/sd | while read line
 11do
 12	local dev=$(echo $line | cut -d' ' -f1)
 13	if [ -n "$dev" ] && [ -e "$dev" ]; then
 14		usbDeployRootPath=$(echo $line | cut -d' ' -f2)
 15		echo $usbDeployRootPath > /tmp/usbDeployRootPath.conf
 16		break
 17	fi
 18done
 19}
 20
 21list_alldir(){  
 22	local init_root=$1
 23	local action=$2
 24	for file in `ls $init_root`  
 25	do  
 26		if [ -f "$init_root/$file" ];then
 27
 28			if [ "$file" = "000-cp_preinstall_plugins.sh" ];then
 29				continue
 30			fi
 31
 32			if [ "$file" = "001-samba" ];then
 33				continue
 34			fi
 35			if [ "$file" = "xunlei" ];then
 36				continue
 37			fi
 38			$init_root/$file $action $usbDeployRootPath &
 39		fi  
 40	done  
 41}  
 42
 43change_stopedApp_status() {
 44	dir=$1/appdata/app_infos
 45	if [ -d "$dir" ];then
 46		for file in `ls $dir | grep [^a-zA-Z]\.manifest$`
 47		do
 48			sed -i '/^status/s/\(.*\"\)\(7\)\(\".*\)/\1'5'\3/g' $dir/$file
 49		done
 50	fi
 51}
 52
 53start()
 54{
 55
 56	get_root_path
 57	usbDeployRootPath=$(cat /tmp/usbDeployRootPath.conf)
 58
 59	rm -rf $usbDeployRootPath/xiaomi_router/appdata/app_infos/2882303761517280998.manifest
 60	rm -rf $usbDeployRootPath/xiaomi_router/appdata/2882303761517280998/
 61
 62	rm -rf $usbDeployRootPath/xiaomi_router/appdata/app_infos/2882303761517410304.manifest
 63	rm -rf $usbDeployRootPath/xiaomi_router/appdata/2882303761517410304/
 64
 65	rm -rf $usbDeployRootPath/xiaomi_router/appdata/app_infos/2882303761517236139.manifest
 66	rm -rf $usbDeployRootPath/xiaomi_router/appdata/2882303761517236139/
 67
 68	/usr/sbin/sysapihttpd -s reload
 69
 70	if [ -n "$usbDeployRootPath" ];then
 71		rm -rf /tmp/xiaomi_router
 72		mkdir -p /tmp/xiaomi_router
 73		cp -r $usbDeployRootPath/xiaomi_router/init /tmp/xiaomi_router/
 74		change_stopedApp_status $usbDeployRootPath/xiaomi_router
 75		if [ -f "$usbDeployRootPath/xiaomi_router/init/000-cp_preinstall_plugins.sh" ];then
 76			$usbDeployRootPath/xiaomi_router/init/000-cp_preinstall_plugins.sh start $usbDeployRootPath
 77		fi
 78		if [ -f "$usbDeployRootPath/xiaomi_router/init/001-samba" ];then
 79			$usbDeployRootPath/xiaomi_router/init/001-samba start $usbDeployRootPath
 80		fi
 81		if [ -f "$usbDeployRootPath/xiaomi_router/init/xunlei" ];then
 82			$usbDeployRootPath/xiaomi_router/init/xunlei start $usbDeployRootPath
 83		fi
 84		#if [ -f "/etc/init.d/ad_filter" ];then
 85		#	/etc/init.d/ad_filter start $usbDeployRootPath
 86		#fi
 87		if [ -f "/etc/init.d/plugin_start_script.sh" ];then
 88			/etc/init.d/plugin_start_script.sh restart $usbDeployRootPath
 89		fi
 90		list_alldir $usbDeployRootPath/xiaomi_router/init start
 91	fi
 92
 93	init_ps2smb_share() {
 94		if [ -n "$usbDeployRootPath" ]; then
 95			PS2SMB_DIR="$usbDeployRootPath/PS2SMB"
 96			SMB_CONF="$usbDeployRootPath/xiaomi_router/config/smb.conf"
 97
 98			if [ ! -d "$PS2SMB_DIR" ]; then
 99				mkdir -p "$PS2SMB_DIR"
100				chmod 755 "$PS2SMB_DIR"
101				echo "[INFO] Created PS2SMB directory at $PS2SMB_DIR"
102			fi
103
104			if [ -f "$SMB_CONF" ] && ! grep -q "\[PS2SMB\]" "$SMB_CONF"; then
105				echo "[INFO] Adding PS2SMB share to $SMB_CONF"
106				cat <<EOF >> "$SMB_CONF"
107	
108[PS2SMB]
109path = $PS2SMB_DIR
110read only = yes
111guest ok = yes
112force user = root
113EOF
114			else
115				echo "[INFO] PS2SMB share already exists or smb.conf missing."
116			fi
117		fi
118	}
119
120	init_ps2smb_share
121}
122
123stop()
124{
125	usbDeployRootPath=$(cat /tmp/usbDeployRootPath.conf)
126	rm /tmp/usbDeployRootPath.conf
127	if [ -n "$usbDeployRootPath" ];then
128		list_alldir /tmp/xiaomi_router/init stop
129		wait
130		if [ -f "/tmp/xiaomi_router/init/xunlei" ];then
131			/tmp/xiaomi_router/init/xunlei stop $usbDeployRootPath
132		fi
133		if [ -f "/tmp/xiaomi_router/init/001-samba" ];then
134			/tmp/xiaomi_router/init/001-samba stop $usbDeployRootPath
135		fi
136		#if [ -f "/etc/init.d/ad_filter" ];then
137		#	/etc/init.d/ad_filter off $usbDeployRootPath
138		#fi
139		if [ -f "/etc/init.d/plugin_start_script.sh" ];then
140			/etc/init.d/plugin_start_script.sh stop $usbDeployRootPath
141		fi
142
143		#local dev=$(getdisk mnt | grep "$usbDeployRootPath\$" | cut -d',' -f1)
144		#if [ -n "$dev" ] && [ -e "$dev" ] ;then
145		#	list_alldir $usbDeployRootPath/xiaomi_router/init stop
146		#else
147		#	list_alldir /tmp/xiaomi_router/init stop
148		#fi
149	fi
150}

小米 R3 路由

小米3 的 SMB 配置工具比较齐全,配置起来相对轻松很多

首先,为了深入研究路由器内置的 SMB 协议,需要开启 SSH 连接服务

打开 MiWifi 开放平台,下载 miwifi_ssh.bin SSH 插件,密码在绑定了小米账号后,会在网站后台显示;

打开 SSH 连接

查询 SMB 配置文件位置

不同型号的内容会存在差异

 1root@XiaoQiang:~# find / -name "smb.conf*"
 2
 3# 小米R1C结果
 4/extdisks/sda1/xiaomi_router/config/smb.conf.template
 5/extdisks/sda1/xiaomi_router/config/smb.conf
 6/tmp/etc/smb.conf
 7
 8# 小米R3结果
 9/etc/samba/smb.conf.template
10/etc/samba/smb.conf
11/tmp/etc/smb.conf
12/data/etc/samba/smb.conf.template
13/data/etc/samba/smb.conf
14/data/etc_bak/samba/smb.conf.template
15/data/etc_bak/samba/smb.conf
16/extdisks/sda1/xiaomi_router/config/smb.conf.template
17/extdisks/sda1/xiaomi_router/config/smb.conf

查询 SMB 工具位置

 1root@XiaoQiang:~# find / -name "samba*"
 2
 3# 小米R1C结果
 4/extdisks/sda1/xiaomi_router/log/samba.log
 5/extdisks/sda1/xiaomi_router/bin/samba_multicall
 6/extdisks/sda1/xiaomi_router/config/samba
 7/extdisks/sda1/xiaomi_router/config/samba.schema
 8
 9# 小米R3结果
10/etc/init.d/samba
11/etc/samba
12/etc/openldap/schema/samba.schema
13/etc/config/samba
14/tmp/log/samba.log
15/usr/sbin/samba_multicall
16/data/etc/init.d/samba
17/data/etc/samba
18/data/etc/openldap/schema/samba.schema
19/data/etc/config/samba
20/data/etc_bak/init.d/samba
21/data/etc_bak/samba
22/data/etc_bak/openldap/schema/samba.schema
23/data/etc_bak/config/samba
24/extdisks/sda1/xiaomi_router/log/samba.log
25/extdisks/sda1/xiaomi_router/bin/samba_multicall
26/extdisks/sda1/xiaomi_router/config/samba
27/extdisks/sda1/xiaomi_router/config/samba.schema

其中 /extdisks/sda1/ 是路由器外接存储的位置,根据具体情况可能会有动态变化,比如 /sda1 /sdb1 /sdc1 等等

编辑 SMB 配置

编辑 /etc/samba/smb.conf.template 模板文件,在末尾添加以下内容

1[PS2SMB]
2path = /extdisks/sda1/PS2SMB
3browsable = yes
4guest ok = yes
5read only = no
6create mask = 0777
7directory mask = 0777

重启 SMB 服务,即可添加 PS2SMB 共享文件夹,用于连接 PS2

修改这里的 smb.conf.template 模板文件,不会因为路由器断电、插拔外部存储覆盖。在外部存储的文件目录已经配置好的情况下,可以一劳永逸的实现 SMB 直接连接

好了,这下就一切都完美了

评论
取消