分类 编程技巧 下的文章

"""
#
# 批量刷日志配置,config_log.py
#
# @author lk
# @copyright Copyright (c) 2023 lk team (http://www.uqn.cn)
# @license GNU General Public License 2.0
# @version 1.0.0(23.7.11)
#
"""

from netmiko import ConnectHandler
n = 0
cmds = ['info-center loghost 10.25.1.17 facility local6']  # 配置日志
with open('ip.txt') as f:       # 配套文件,每行一个IP
    for ips in f.readlines():
        ip = ips.strip()
        n = n + 1
        connection_info = {
                'device_type': 'huawei',
                'ip': ip,
                'username': 'h3cadmin',
                'password': '******',
        }
        with ConnectHandler(**connection_info) as conn:
            output = conn.send_config_set(cmds)
            # 以下命令为模拟用户保存
            saveput = conn.send_command(command_string='save',
expect_string=r'Are you sure?',strip_prompt=False,strip_command=False)
            saveput = conn.send_command(command_string='y',
expect_string=r'[flash:/startup.cfg]',strip_prompt=False,strip_command=False) 
            saveput = conn.send_command(command_string='startup.cfg',
expect_string=r'overwrite?',strip_prompt=False,strip_command=False)
            saveput = conn.send_command(command_string='y',
expect_string=r'>',strip_prompt=False,strip_command=False)
            print(f'{n} 已经成功登陆交换机 {ip},日志配置:{output} {saveput}')

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>文件查找</title>
</head>
<body>
    <form action="" method="post">
        <p>在XX目录查找XX文件</p>
        <p>目录:
        <input list="browsers" name="date">
            <datalist id="browsers">
                <option value="202001">
                <option value="202002">
                <option value="202003">
                <option value="202004">
            </datalist>
        </p>
        <p>文件:
        <input type="text" name="key" />
        </p>
        <p><input type="submit" name="sub" value=" 查 找 " /></p>
    </form>

<?php

$dir = "/data/ipcc/"; //操作系统目录
$root = "/ipcc/"; //http根目录

$date = $_POST['date']; //子目录名
$search = $_POST['key']; //文件名

if (is_dir($dir)) {

if ($dh = opendir($dir)){
    $num = 0;   //计数
    while (($dirname = readdir($dh)) !== false) {
        if (strstr($dirname,$date)) {   //按关键字搜索子目录名
            $dir2=$dir.$dirname."/";    //子目录绝对路径
            if ($dh2 = opendir($dir2)){
                while (($dirname2 = readdir($dh2)) !== false) {
                    if (strstr($dirname2,$search)) {    //按关键字搜索子目录下的文件
                        echo "<a href=$root$dirname/$dirname2>$dirname/$dirname2<a />

\n"; //显示文件的http全路径

                        $num = $num + 1;    //计数
                    }
                }
                closedir($dh2);
            }
        }
    }
    closedir($dh);
    echo "合计:$num";  //显示计数结果
}

}
?>

</body>

仅适用emlog,修改/content/templates/你的模板/module.php

一、最新评论:

找到:module.php里面的
//widget:最新评论

把函数function widget_newcomm($title)里面的

<\li><\img alt='' src='<?php echo getGravatar($value['mail']);?>'修改为:

<\li><\img alt='' src='
<?php
if ($value['name']=='博主昵称或admin')

echo BLOG_URL.'content/uploadfile/201212/logo.jpg'; 
//你的头像路径

else

echo getGravatar($value['mail']);

?>'

二、博客评论列表

找到:
//blog:博客评论列表

在函数function blog_comments($comments)里面
$comment = $comments[$cid];的后面加入一行:

$Poster = $comment['poster']; //下面会用到,判断是否为博主

再往后寻找<?php echo getGravatar($comment['mail']);?>,然后修改为:

<?php
if ($Poster=="博主昵称或admin" )

echo BLOG_URL.'content/uploadfile/201212/logo.jpg';
//你的头像路径

else

echo getGravatar($comment['mail']); 

?>

三、博客子评论列表

找到://blog:博客子评论列表

在函数function blog_comments_children($comments, $children)里面
$comment = $comments[$child];的后面加入一行:

$Poster = $comment['poster']; //下面会用到,判断是否为博主

再往后寻找<?php echo getGravatar($comment['mail']);?>,然后修改为:

<?php
if ($Poster=="博主昵称或admin" )

echo BLOG_URL.'content/uploadfile/201212/logo.jpg';
//你的头像路径

else

echo getGravatar($comment['mail']); 

?>

完毕!