分类 电脑 下的文章

cPanel - WHM - The SMTP restriction - 限制用户使用外部smtp发信

问题:cPanel用户无法通过php使用外部smtp服务器发信。

尝试:执行如 openssl s_client -connect smtp.gmail.com:465 的命令,显示cPanel/WHM本机的ssl证书,并不是gmail的。

解决:登录到WHM,禁用 The SMTP restriction 功能即可。

This feature prevents users from bypassing the mail server to send mail, a common practice used by spammers.
It will allow only the MTA, mailman, and root to connect to remote SMTP servers.

This control is also adjustable in Tweak Settings.

The SMTP restriction is enabled.

参考:https://docs.cpanel.net/whm/security-center/smtp-restrictions/

用 Xidel 提取出目标网页的数据 然后通过 REST API 发布到 WordPress 站

需求:复制指定网页上某部分的文字,然后以文章的形式发布到wordpress站,采集。

尝试:xidel 这个软件很好地自动分析文件上标签,并导出数据。将导出的数据以参数递给 curl,通过 WordPress 的 REST API 发布文章。

如:

for i in $(seq -w 1000)
do
    caijiurl=https://liujia.anqun.org/index.php/archives/${i}/
    # curl $caijiurl | iconv -f gb2312 > out.html
    wget -O out.html $caijiurl
    title=$(xidel out.html -e "(css('h1'))")
    content=$(xidel out.html -e "(css('div.post-content'))")

    curl --user "admin:apppassword" -H "Accept: application/json" -H "Content-Type: application/json" -X POST -d '{"title":"'$title'","content":"'$content'","type":"post","status":"publish","categories":[25]}' https://wp.anqun.org/wp-json/wp/v2/posts
done

参考:

用 Clover 在 bios 机子上模拟 uefi 安装 Windows 2022 系统

继上一篇:《grub2 + 虚拟磁盘 或 grub2 + ntboot 启动 bios + gpt 上的 Windows 2022》,因为网友反馈用方案A和B的Windows系统安装关键更新失败,这里实验方案D:用 clover 在 bios 机上模拟 uefi,让Windows以为这就是uefi启动的。

过程:

  1. 将分好区的虚拟磁盘 win2022.vhd 挂到 debian 11 的虚拟机里,准备安装 clover
  2. 如下载到当前最新版本 Clover-5145-X64.iso.7z,解压后 Clover-5145-X64.iso
  3. mount -o loop Clover-5145-X64.iso /mnt/iso # 挂载iso文件
  4. dd if=/dev/sdb2 of=/tmp/origPBR bs=512 count=1 conv=notrunc # 假如 win2022.vhd 上的 esp 分区为 /dev/sdb2
  5. cp /mnt/iso/usr/standalone/i386/boot1f32 /tmp/newPBR
  6. dd if=/tmp/origPBR of=/tmp/newPBR skip=3 seek=3 bs=1 count=87 conv=notrunc
  7. dd if=/tmp/newPBR of=/dev/sdb2 bs=512 count=1 conv=notrunc
  8. dd if=/mnt/iso/usr/standalone/i386/boot0ss of=/dev/sdb bs=440 count=1 conv=notrunc
  9. mount /dev/sdb2 /mnt/1 # 将 esp 分区挂载到 /mnt/1
  10. cp -r /mnt/iso/efi /mnt/1/ # 复制efi目录到esp分区
  11. cp /mnt/iso/usr/standalone/i386/x64/boot6 /mnt/1/boot
  12. 如果仅启动Windows,可编辑配置文件 /mnt/1/EFI/clover/config.plist ,内容如下:

    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "https://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
     <key>Boot</key>
     <dict>
         <key>DefaultVolume</key>
         <string>EFI</string>
         <key>DefaultLoader</key>
         <string>\efi\Microsoft\Boot\bootmgfw.efi</string>
         <key>Fast</key>
         <true/>
     </dict>
     <key>GUI</key>
     <dict>
         <key>Custom</key>
         <dict>
             <key>Entries</key>
             <array>
                 <dict>
                     <key>Hidden</key>
                     <false/>
                     <key>Disabled</key>
                     <false/>
                     <key>Image</key>
                     <string>os_win</string>
                     <key>Volume</key>
                     <string>EFI</string>
                     <key>Path</key>
                     <string>\efi\Microsoft\Boot\bootmgfw.efi</string>
                     <key>Title</key>
                     <string>Windows 2022</string>
                     <key>Type</key>
                     <string>Windows</string>
                 </dict>
             </array>
         </dict>
     </dict>
    </dict>
    </plist>
  13. clover安装好后,释放Windows 2022,添加引导等操作和前边的方案A差不多
  14. 在VirtualBox里的bios虚拟机启动,可以正常安装Windows及进行更新。在系统信息中显示为UEFI类型

在一台线上超微atom C2750的机子上测试,失败,clover未能启动,报错:

X64 Exception type - 0000000000000000D !!!
RIP - 000000007D34F7C5, CS - 00000000000038, RFLAGS - 00000000010206
ExceptionData - 000000000000000

bios-gpt-5.png

bios-gpt-6.png

参考:

grub2 + 虚拟磁盘 或 grub2 + ntboot 启动 bios + gpt 上的 Windows 2022

感谢:wzy,wintoflash,minlearn

需求:主机商提供的产品存储超过2TB容量,且仅支持bios方式启动机子。Linux系统能在 bios + gpt 的环境中正常安装和运行,但 Windows 系统要求 bios + mbr 或 uefi + gpt 的组合,不支持 bios + gpt 的场景。

方案A:从网友 wzy 的博客来看,Windows的启动管理bootmgr.exe不认gpt分区,所以启动不了。解决方法是创建一个包含启动代码和文件的虚拟磁盘文件来启动Windows。缺点:无法Windows更新

方案B:从网友 minlearn 在无忧论坛里和 ntboot 作者 wintoflash 交流帖可知,通过 ntboot 是可以启动 bios + gpt 磁盘上已经安装的Windows系统(不支持Windows安装,会报“Windows安装程序 - 无法将 Window 配置为在此计算机的硬件上运行”的错误)。缺点:无法Windows更新

方案C:用grub4dos的ntloader来启动Windows。测试失败,用grub4dos的ntloader可以让gpt上的windows进入到桌面,但如计算机名、配置网卡静态IP地址等更改操作在重启系统后不生效。

这里记录一下实践的过程:

方案A:

  1. 创建一个vhd固定大小的虚拟磁盘,如 18 GB,名称为win2022.vhd
  2. 该vhd虚拟磁盘至少有三个分区,第一个是BIOS Partition,这个特别的分区是grub2必需的,可通过Linux系统里的cfdisk程序来创建。如下边的分区例子:

    Device                                Start                   End               Sectors               Size Type
    >>  /dev/sdb1                              2048                 32767                 30720                15M BIOS boot
    /dev/sdb2                             32768                647167                614400               300M EFI System
    /dev/sdb3                            647168                679935                 32768                16M Microsoft reserved
    /dev/sdb4                            679936              37746687              37066752              17.7G Microsoft basic data
  3. 创建第二个vhd固定大小的虚拟磁盘,本例的容量为64MB,名称为bootmgr.vhd。磁盘用MBR分区,创建一个主分区,且设置为活动分区
  4. 在Windows系统里附加两个vhd虚拟磁盘,假如本例中,第一个大的虚拟磁盘的NTFS分区盘符是M:,ESP分区盘符是L:;第二个虚拟磁盘的分区的分区盘符是B:
  5. 将已经安装好的Windows映像释放到NTFS分区中,如本例中的第4个分区M:,执行 bcdboot.exe M:\Windows /s L: /v /f uefi 将创建uefi相关的启动文件到 L: 分区 ;执行 bcdboot.exe M:\Windows /s B: /v /f bios 将创建bois相关的启动文件到 B: 分区;执行 bootsect /nt60 B: /mbr 将在B:上创建启动代码
  6. 分离第二个虚拟磁盘
  7. 将bootmgr.vhd的虚拟磁盘文件放到第一个vhd虚拟磁盘中的esp分区中L:
  8. 分离第一个虚拟磁盘
  9. 将win2022.vhd磁盘挂到一个debian系统的虚拟机里,挂载后,esp分区/dev/sdb2路径为/mnt/1,用grub-install将grub2安装到vhd磁盘。如例:grub-install --target=i386-pc /dev/sdb --boot-directory=/mnt/1;复制/usr/lib/syslinux/memdisk 文件 到esp分区/mnt/1
  10. 复制或创建一个grub的配置文件,放在grub目录里,配置文件需有bootmgr.vhd的启动项内容,如本例的部分内容:

     menuentry "bootmgr.vhd" {
    insmod part_msdos
    insmod part_gpt
    insmod fat
    insmod ntfs
    linux16 /memdisk raw
    initrd16 /bootmgr.vhd
    }

    11.正常的情况下,该包含有grub2,bootmgr.vhd和Windows的gpt vhd虚拟磁盘,能在VirtualBox的bios或efi虚拟机里启动

方案B:

  1. 下载ntboot的源码,通过grub-mkimage创建好grub2的core.img,再用grub-install安装到vhd磁盘。如例:grub-install --target=i386-pc /dev/sdb --boot-directory=/mnt/1 --directory=/home/liujia/grub/i386-pc/ 这例里,是将vhd磁盘挂到debian系统里安装grub2,/mnt/1路径是vhd的第2个分区,即esp分区 /home/liujia/grub/i386-pc/ 是ntboot源码的目录路径
  2. 将windows的安装光盘iso里的sources/boot.wim/1/Windows/Boot/PXE/bootmgr.exe文件提取出来,放到ESP分区中
  3. 复制或创建一个grub的配置文件,放在grub目录里,配置文件需有ntboot的启动项内容,如本例的部分内容:

    menuentry 'nbtoot' {
    insmod part_msdos
    insmod part_gpt
    insmod fat
    insmod ntfs
    set root='hd0,gpt2'
    ntboot --efi=/bootmgr.exe --win (hd0,gpt4);
    }
  4. 将已经安装好的Windows映像释放到NTFS分区中,如本例中的第4个分区,且Windows是从uefi环境中引导的(ESP中有Windows的相应目录和文件,如上边的步骤,执行 bcdboot.exe M:\Windows /s L: /v /f uefi
  5. 正常的情况下,该包含有grub2,ntboot和Windows的gpt vhd虚拟磁盘,能在VirtualBox的bios或efi虚拟机里启动

问题:因为Windows是已经安装的,所以如将这个win2022.vhd复制使用,Windows的SID、计算机名称等是一样的。微软建议用sysprep来生成新的SID,避免机子加域时遇到问题。

bios-gpt-2.png

参考:

在 iredmail 里批量添加邮箱用户

环境:debian11,iredmail-1.5.1。例子,创建user5@anqun.orguser6@anqun.org两个邮箱用户。

步骤:

  1. cd iRedMail-1.5.1/tools # 转到 iRedmail 安装目录中的tools子目录
  2. bash create_mail_user_SQL.sh user5@anqun.org 'mima881' >> user.sql
    bash create_mail_user_SQL.sh user6@anqun.org 'mima882' >> user.sql # 生成一个包含sql语句的文件。sql语句是创建user5和user6两个用户,且设置密码
  3. mysql -u root vmail < user.sql # 将此文件导入到vmail数据库中

参考:https://docs.iredmail.org/sql.create.mail.user.html