Emlog IIS7.5伪静态


<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="OrgPage" stopProcessing="true">
<match url="^(.*)$" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTP_HOST}" pattern="^(.*)$" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="index.php/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>

golnag根据ip地址的子网掩码获取最大和最小的ip地址


//根据ip地址的子网掩码获取最大ip和最小ip
func getCidrIpRange(cidr string) (string, string) {
    ip := strings.Split(cidr, "/")[0]
    ipSegs := strings.Split(ip, ".")
    maskLen, _ := strconv.Atoi(strings.Split(cidr, "/")[1])
    seg3MinIp, seg3MaxIp := getIpSeg3Range(ipSegs, maskLen)
    seg4MinIp, seg4MaxIp := getIpSeg4Range(ipSegs, maskLen)
    ipPrefix := ipSegs[0] + "." + ipSegs[1] + "."

    return ipPrefix + strconv.Itoa(seg3MinIp) + "." + strconv.Itoa(seg4MinIp),
        ipPrefix + strconv.Itoa(seg3MaxIp) + "." + strconv.Itoa(seg4MaxIp)
}

//计算得到CIDR地址范围内可拥有的主机数量
func getCidrHostNum(maskLen int) uint {
    cidrIpNum := uint(0)
    var i uint = uint(32 - maskLen - 1)
    for ; i >= 1; i-- {
        cidrIpNum += 1 << i
    }
    return cidrIpNum
}

//获取Cidr的掩码
func getCidrIpMask(maskLen int) string {
    // ^uint32(0)二进制为32个比特1,通过向左位移,得到CIDR掩码的二进制
    cidrMask := ^uint32(0) << uint(32-maskLen)
    fmt.Println(fmt.Sprintf("%b \n", cidrMask))
    //计算CIDR掩码的四个片段,将想要得到的片段移动到内存最低8位后,将其强转为8位整型,从而得到
    cidrMaskSeg1 := uint8(cidrMask >> 24)
    cidrMaskSeg2 := uint8(cidrMask >> 16)
    cidrMaskSeg3 := uint8(cidrMask >> 8)
    cidrMaskSeg4 := uint8(cidrMask & uint32(255))

    return fmt.Sprint(cidrMaskSeg1) + "." + fmt.Sprint(cidrMaskSeg2) + "." + fmt.Sprint(cidrMaskSeg3) + "." + fmt.Sprint(cidrMaskSeg4)
}

//得到第三段IP的区间(第一片段.第二片段.第三片段.第四片段)
func getIpSeg3Range(ipSegs []string, maskLen int) (int, int) {
    if maskLen > 24 {
        segIp, _ := strconv.Atoi(ipSegs[2])
        return segIp, segIp
    }
    ipSeg, _ := strconv.Atoi(ipSegs[2])
    return getIpSegRange(uint8(ipSeg), uint8(24-maskLen))
}

//得到第四段IP的区间(第一片段.第二片段.第三片段.第四片段)
func getIpSeg4Range(ipSegs []string, maskLen int) (int, int) {
    ipSeg, _ := strconv.Atoi(ipSegs[3])
    segMinIp, segMaxIp := getIpSegRange(uint8(ipSeg), uint8(32-maskLen))
    return segMinIp + 1, segMaxIp
}

//根据用户输入的基础IP地址和CIDR掩码计算一个IP片段的区间
func getIpSegRange(userSegIp, offset uint8) (int, int) {
    var ipSegMax uint8 = 255
    netSegIp := ipSegMax << offset
    segMinIp := netSegIp & userSegIp
    segMaxIp := userSegIp&(255<<offset) | ^(255 << offset)
    return int(segMinIp), int(segMaxIp)
}

golang获取一个ip段所有地址


//getIpAll 获取ip段
//最小IP: 223.255.0.1  最大IP: 223.255.127.255
func getIpAll(minIp, maxIp string) []string {
    ipArr := make([]string, 0)
    minIpaddress := net.ParseIP(minIp)
    maxIpaddress := net.ParseIP(maxIp)
    if minIpaddress == nil || maxIpaddress == nil {
        fmt.Println("ip地址格式不正确")
    } else {
        minIpSplitArr := strings.Split(minIp, ".")
        maxIpSplitArr := strings.Split(maxIp, ".")

        minIP1, _ := strconv.Atoi(minIpSplitArr[0])
        minIP2, _ := strconv.Atoi(minIpSplitArr[1])
        minIP3, _ := strconv.Atoi(minIpSplitArr[2])
        minIP4, _ := strconv.Atoi(minIpSplitArr[3])

        maxIP1, _ := strconv.Atoi(maxIpSplitArr[0])
        maxIP2, _ := strconv.Atoi(maxIpSplitArr[1])
        maxIP3, _ := strconv.Atoi(maxIpSplitArr[2])
        maxIP4, _ := strconv.Atoi(maxIpSplitArr[3])

        if minIP1 <= maxIP1 {
            for i1 := minIP1; i1 <= maxIP1; i1++ {
                minIP1 = i1
                var i2 int
                var maxi2 int
                if minIP1 == maxIP1 { //如果第一个数相等
                    i2 = minIP2
                    maxi2 = maxIP2
                } else {
                    i2 = 0
                    maxi2 = 255
                }
                for ii2 := i2; ii2 <= maxi2; ii2++ {
                    minIP2 = ii2
                    var i3 int
                    var maxi3 int
                    if minIP1 == maxIP1 && minIP2 == maxIP2 { //如果第一个数相等 并且 第二个数相等
                        i3 = minIP3
                        maxi3 = maxIP3
                    } else {
                        i3 = 0
                        maxi3 = 255
                    }
                    for ii3 := i3; ii3 <= maxi3; ii3++ {
                        minIP3 = ii3
                        var i4 int
                        var maxi4 int
                        if minIP1 == maxIP1 && minIP2 == maxIP2 && minIP3 == maxIP3 { //如果第一个数相等 并且 第二个数相等 并且 第三个数相等
                            i4 = minIP4
                            maxi4 = maxIP4
                        } else {
                            i4 = minIP4
                            maxi4 = 255
                        }
                        for ii4 := i4; ii4 <= maxi4; ii4++ {
                            minIP4 = ii4
                            newIP := fmt.Sprintf("%v.%v.%v.%v", minIP1, minIP2, minIP3, minIP4)
                            ipArr = append(ipArr, newIP)

                        }
                        minIP4 = 0

                    }
                    minIP3 = 0

                }
                minIP2 = 0

            }
        }
    }
    return ipArr
}

golang复制文件夹和文件



// File copies a single file from src to dst
func File(src, dst string) error {
    var err error
    var srcfd *os.File
    var dstfd *os.File
    var srcinfo os.FileInfo

    if srcfd, err = os.Open(src); err != nil {
        return err
    }
    defer srcfd.Close()

    if dstfd, err = os.Create(dst); err != nil {
        return err
    }
    defer dstfd.Close()

    if _, err = io.Copy(dstfd, srcfd); err != nil {
        return err
    }
    if srcinfo, err = os.Stat(src); err != nil {
        return err
    }
    return os.Chmod(dst, srcinfo.Mode())
}

// CopyDir copies a whole directory recursively
func CopyDir(src string, dst string) error {
    var err error
    var fds []os.FileInfo
    var srcinfo os.FileInfo

    if srcinfo, err = os.Stat(src); err != nil {
        return err
    }

    if err = os.MkdirAll(dst, srcinfo.Mode()); err != nil {
        return err
    }

    if fds, err = ioutil.ReadDir(src); err != nil {
        return err
    }
    for _, fd := range fds {
        srcfp := path.Join(src, fd.Name())
        dstfp := path.Join(dst, fd.Name())

        if fd.IsDir() {
            if err = CopyDir(srcfp, dstfp); err != nil {
                fmt.Println(err)
            }
        } else {
            if err = File(srcfp, dstfp); err != nil {
                fmt.Println(err)
            }
        }
    }
    return nil
}


golang给图片添加图片水印



//一个图片添加水印
func SetSY(logo, tp string) {
    //原始图片是sam.jpg
    imgb, err := os.Open(tp)
    if err != nil {
        fmt.Println("打开图片失败")
        return
    }
    img, format1, err := image.Decode(imgb)
    if err != nil {
        fmt.Println("解码图片失败-", format1, err.Error())
        return
    }
    defer imgb.Close()

    wmb, err := os.Open(logo)
    if err != nil {
        fmt.Println("打开Logo失败")
        return
    }
    watermark, format2, err := image.Decode(wmb)
    if err != nil {
        fmt.Println("解码Logo失败-", format2, err.Error())
        return
    }

    defer wmb.Close()

    //把水印写到右下角,并向0坐标各偏移10个像素
    offset := image.Pt(img.Bounds().Dx()-watermark.Bounds().Dx()-10, img.Bounds().Dy()-watermark.Bounds().Dy()-10)
    b := img.Bounds()
    m := image.NewNRGBA(b)

    draw.Draw(m, b, img, image.ZP, draw.Src)
    draw.Draw(m, watermark.Bounds().Add(offset), watermark, image.ZP, draw.Over)

    //生成新图片new.jpg,并设置图片质量..
    imgw, _ := os.Create(tp)
    jpeg.Encode(imgw, m, &jpeg.Options{100})

    defer imgw.Close()

    fmt.Println("添加水印成功...")
}

windows创建文件夹时不能包含一些特殊符号


QQ图片20200922181733.png

Go中使用字符串替换即可

//文件夹不能包含 \ / : * ? " < > |
dirName = strings.Replace(dirName, "\\", "", -1)
dirName = strings.Replace(dirName, "/", "", -1)
dirName = strings.Replace(dirName, ":", "", -1)
dirName = strings.Replace(dirName, "*", "", -1)
dirName = strings.Replace(dirName, "?", "", -1)
dirName = strings.Replace(dirName, "\"", "", -1)
dirName = strings.Replace(dirName, "<", "", -1)
dirName = strings.Replace(dirName, ">", "", -1)
dirName = strings.Replace(dirName, "|", "", -1)

typecho附件中的图片批量插入到编辑器


修改文件

admin/file-upload.php
111111.png
<li><button type="button" onclick="addImgAll()">批量插入图片</button></li>
<script>
    function addImgAll(){
        $("li[data-image='1']").each(function(index, element) {
            let imgUrl = $(element).attr("data-url")
            let title = $("#title").val()
            $("#text").val($("#text").val()+`<img alt="${title}" src="${imgUrl}">\n`)
        });
    }
</script>

效果图

lz222.gif

上传图片后 需要刷新一下网页!!!