2018-11-01 11:33:22    2018-11-01 11:33:22   

python django 邮件
阅读 71 评论 0 收藏 0
阅读 71
评论 0
收藏 0

   2018-10-29 23:59:04    2018-10-29 23:59:04   

贪吃蛇 easyx c语言
安装easyx,文件保存为cpp后缀 ```C #include <graphics.h> #include <conio.h> #include <time.h> #include <stdio.h> #include <math.h> #include <windows.h> #define KEYDOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0) void init(void);//初始化 void gamebegin(void);//游戏开始 void gameplay(void);//开始游戏 void gameend(void);//游戏借宿 void drawsnake(void);//绘制小蛇 void drawfood(void);//绘制食物 //定义坐标struct struct Point{ int x,y; }; struct Point aps[3871]; //定义界面所有点坐标数组 struct Point snake[3871];//定义蛇身的各个位置的坐标数组 struct Point food[100];//定义食物的各个位置的坐标数组 int apsindex=0; //定义界面所有点坐标数组索引 int snakeindex=0; //定义蛇身的各个位置的坐标数组索引 int foodindex=0; //定义食物的各个位置的坐标数组索引 struct Point snakehead={300,250};//定义蛇头的位置 int snakedirect; //1为上,2为下,3为左,4为右 int snakespeed=1; //设置蛇的速度 int snakelength=3; //初始化蛇的长度 int gamestop=0; //游戏是否结束 int stoptype; //游戏结束原因,值为1,则是撞墙,值为2则为碰到身子 int gamescore=0; //游戏分数 int gamelevel=1; //游戏等级 void main(void){ init(); gamebegin(); gameplay(); gameend(); } //初始化函数 void init(void){ initgraph(1100,600); } //绘制分数 void drawscore(int score){ char s[50]; sprintf(s,"分数:%4d",score); settextstyle(18, 0, _T("黑体")); settextcolor(RGB(255,255,0)); outtextxy(950, 60, s); } //绘制等级 void drawlevel(int level){ char s[50]; sprintf(s,"等级:%4d",level); settextstyle(18, 0, _T("黑体")); settextcolor(RGB(255,255,0)); outtextxy(950, 80, s); } //绘制蛇 void drawsnake(){ setlinecolor(RGB(255,255,255)); setlinestyle(PS_SOLID, 1); for(int i=0;i<snakeindex;i++){ if(i==0){ setfillcolor(RGB(255,0,0)); }else{ setfillcolor(RGB(128,128,0)); } fillrectangle(snake[i].x-5,snake[i].y-5,snake[i].x+5,snake[i].y+5); } } //擦除蛇尾 void earsesnaketail(){ //setlinestyle(PS_SOLID, 0); setlinecolor(RGB(0,128,0)); setfillcolor(RGB(0,128,0)); fillrectangle(snake[snakeindex-1].x-5,snake[snakeindex-1].y-5,snake[snakeindex-1].x+5,snake[snakeindex-1].y+5); } //绘制食物 void drawfood(Point p1){ setlinestyle(PS_SOLID, 1); setfillcolor(RGB(255,255,0)); fillrectangle(p1.x-5,p1.y-5,p1.x+5,p1.y+5); } //生成食物 void genfood(int index=-1){ //生产随机数0~3871 int r=rand()%3872; //判断随机点aps[r]是否和蛇身所在位置是否重合 for(int j=0;j<snakeindex;j++){ if(aps[r].x==snake[j].x&&aps[r].y==snake[j].y){ //如果发生重合,j减一,重新循环一次 j--; //重新生成随机数 r=rand()%3872; } } if(index!=-1){ food[index]=aps[r]; }else{ food[foodindex]=aps[r]; foodindex++; } } //游戏开始 void gamebegin(){ //1 绘制游戏界面 //1.1 设置游戏框 setfillcolor(RGB(0,128,0)); setlinestyle(PS_SOLID, 10); fillrectangle(100,50,900,550); //绘制分数 drawscore(gamescore); //绘制等级 drawlevel(gamelevel); //初始化所有点的坐标 for(int i=110;i<=890;i+=10){ for(int j=60;j<=540;j+=10){ aps[apsindex].x=i; aps[apsindex].y=j; apsindex++; printf("%d,%d ",i,j); } } //初始化小蛇身体数组 for(i=0;i<snakelength;i++){ snake[i].x=snakehead.x-10*i; snake[i].y=snakehead.y; snakeindex++; } //初始化食物的数组 //初始化随机数种子 srand((unsigned)time(NULL)); //绘制小蛇 drawsnake(); //绘制食物 //随机5个食物 for(i=0;i<10;i++){ genfood(); } //画出食物 for(i=0;i<foodindex;i++){ drawfood(food[i]); } //drawfood(); } //方向函数 void toward(struct Point temp){ //判断是否撞墙 if(temp.x<110||temp.x>890||temp.y<60||temp.y>540){ gamestop=1; stoptype=1; } //判断是否蛇头碰到身子 for(int i=0;i<snakeindex;i++){ if(temp.x==snake[i].x&&temp.y==snake[i].y){ gamestop=1; stoptype=2; } } //定义蛇是否迟到食物变量iseat bool iseat=0; //判断是否吃到食物 for(i=0;i<foodindex;i++){ if(food[i].x==temp.x&&food[i].y==temp.y){ iseat=1; //计算游戏分数 gamescore=gamescore+(snakeindex-snakelength+1)*2; if(gamescore>400){ gamelevel=6; }else if(gamescore>300){ gamelevel=5; }else if(gamescore>200){ gamelevel=4; }else if(gamescore>100){ gamelevel=3; }else if(gamescore>10){ gamelevel=2; } genfood(i); drawfood(food[i]); } } Sleep(10); if(iseat){ for(int i=snakeindex;i>0;i--){ snake[i]=snake[i-1]; } snakeindex++; snake[0]=temp; }else{ earsesnaketail(); for(int i=snakeindex;i>0;i--){ snake[i]=snake[i-1]; } snake[0]=temp; } drawsnake(); } //向上 void towardsUp(){ struct Point newhead={snake[0].x,snake[0].y-10}; toward(newhead); } //向下 void towardsDown(){ struct Point newhead={snake[0].x,snake[0].y+10}; toward(newhead); } //向左 void towardsLeft(){ struct Point newhead={snake[0].x-10,snake[0].y}; toward(newhead); } //向右 void towardsRight(){ struct Point newhead={snake[0].x+10,snake[0].y}; toward(newhead); } void gameplay(){ //判断方向键,绘制蛇头的方块的方向,同时在蛇尾去掉方块 //判断方块是否和墙面接触,如果是则游戏结束,否则,继续往最后一次按键方向绘制方块 int dr=0; while(gamestop!=1){ //判断方向键是否为上 if(KEYDOWN(VK_UP)&&dr!=2){ dr=1; } //判断方向键是否为下 if(KEYDOWN(VK_DOWN)&&dr!=1){ dr=2; } //判断方向键是否为左 if(KEYDOWN(VK_LEFT)&&dr!=4){ dr=3; } //判断方向键是否为右 if(KEYDOWN(VK_RIGHT)&&dr!=3){ dr=4; } switch(dr){ case 1: towardsUp(); break; case 2: towardsDown(); break; case 3: towardsLeft(); break; case 4: towardsRight(); break; } //绘制分数 drawscore(gamescore); //绘制等级 drawlevel(gamelevel); switch(gamelevel){ case 1: Sleep(80); break; case 2: Sleep(70); break; case 3: Sleep(60); break; case 4: Sleep(50); break; case 5: Sleep(40); break; case 6: Sleep(20); break; } } } void gameend(){ //绘制结束框 setfillcolor(RGB(255,0,0)); setlinestyle(PS_SOLID, 10); fillrectangle(300,200,700,300); char s[200]; if(stoptype==1){ sprintf(s,"你撞墙了,游戏结束!"); }else if(stoptype==2){ sprintf(s,"你咬到自己了,游戏结束!"); }else{ sprintf(s,"游戏结束!"); } settextstyle(18, 0, _T("黑体")); settextcolor(RGB(255,255,0)); RECT r = {300,200,700,300}; setbkmode(TRANSPARENT); drawtext(s, &r, DT_CENTER | DT_VCENTER | DT_SINGLELINE); while(1){ Sleep(10000); }; getch(); closegraph(); } ``` ![](https://image.ynotes.cn/18-10-30/5567999.jpg) `下载链接`[贪吃蛇下载](https://image.ynotes.cn/%E8%B4%AA%E5%90%83%E8%9B%87.exe)
阅读 1151 评论 0 收藏 0
阅读 1151
评论 0
收藏 0

   2018-10-18 21:20:29    2018-10-18 21:20:29   

图片解码 base64
### 获取到.jpg文件,windows打开显示已损坏 #### 查看文件的类型 ```bash $ file test.jpg ``` ``` test.jpg: ASCII text, with very long lines, with no line terminators ``` #### 显示文件为ASCII编码,进一步查看文件内容 ```bash $ cat test.jpg ``` ``` /43/DgABpGSUZAAQEBAABgAGAAD/vQA0AHBQUGBQQHBgUGCAcHCAoBGwoJCQoFHwAcARgVGhkYFRgXGx4XISsdFS0XGBIuIiUoKSssKyoQLyM... ``` #### 猜测应该是应用了base64编码,通过base64解码 ```bash $ cat test.jpg|base64 -d >test2.jpg ``` #### 再次查看文件的类型 ```bash $ file test2.jpg ``` ``` test2.jpg: data ``` 文件base64解码之后还不是jpeg格式 #### 查看文件的十六进制编码 ```bash $ cat test2.jpg|xxd |more ``` ```bash 0000000: ff8d ff0e 0001 a464 9464 0010 1010 0006 .......d.d...... 0000010: 0006 0000 ffbd 0034 0070 5050 6050 4070 .......4.pPP`P@p 0000020: 6050 6080 7070 80a0 11b0 a090 90a0 51f0 `P`.pp........Q. 0000030: 01c0 1181 51a1 9181 5181 71b1 e172 12b1 ....Q...Q.q..r.. 0000040: d152 d171 8122 e222 5282 92b2 c2b2 a102 .R.q."."R....... 0000050: f233 f2a2 2372 a2b2 a2ff bd00 3410 7080 .3..#r......4.p. 0000060: 80a0 90a0 41b0 b041 a2c1 81c1 a2a2 a2a2 ....A..A........ 0000070: a2a2 a2a2 a2a2 a2a2 a2a2 a2a2 a2a2 a2a2 ................ 0000080: a2a2 a2a2 a2a2 a2a2 a2a2 a2a2 a2a2 a2a2 ................ 0000090: a2a2 a2a2 a2a2 a2a2 a2a2 a2a2 a2a2 ff0c ................ 00000a0: 0011 8010 0e20 0830 1022 0020 1110 3011 ..... .0.". ..0. 00000b0: 10ff 4c00 f100 0010 5010 1010 1010 1000 ..L.....P....... 00000c0: 0000 0000 0000 0010 2030 4050 6070 8090 ........ 0@P`p.. 00000d0: a0b0 ff4c 005b 0100 2010 3030 2040 3050 ...L.[.. .00 @0P 00000e0: 5040 4000 0010 d710 2030 0040 1150 2112 P@@..... 0.@.P!. 00000f0: 1314 6031 1516 7022 1741 2318 191a 8032 ..`1..p".A#....2 ``` #### 通过谷歌搜索ff8dff0e字符串显示 ![](https://image.ynotes.cn/ff8dff0e.png) 结果显示文件内容中的每一个字节,高4位和低4位调转了位置 #### 编辑python脚本实现转换 ```bash $ vim conv_jpg.py ``` ```python from __future__ import print_function import struct import ntpath import sys import os import base64 src_file=sys.argv[1] dest_dir=sys.argv[2] src_filename=ntpath.basename(src_file) desc_full_path=os.path.join(dest_dir,src_filename) f=open(src_file,'rb') f2=open(desc_full_path,'wb+') for bit in base64.b64decode(f.read()): #for bit in f.read(): c=ord(bit) c1=(c & 0xf0)>>4 c2=(c & 0x0f)<<4 c_n=c1|c2 b_c=struct.pack('B',c_n) f2.write(b_c) f.close() f2.close() ``` ```bash $ python conv_jpg.py test.jpg test_new.jpg ``` #### 再次查看文件的内容,显示文件格式为JPEG,说明解码成功! ```bash $ file test_new.jpg ``` ``` test_new.jpg: JPEG image data, JFIF standard 1.01 ```
阅读 105 评论 0 收藏 0
阅读 105
评论 0
收藏 0

   2018-08-20 15:16:35    2018-08-20 15:16:35   

postfix 邮件服务器 Roundcube Roundcubemail
## 这里介绍两种加密方法:Roundcubemail自带的PGP插件加密和第三方插件Mailvelope加密 ### 一、Roundcubemail自带的PGP插件加密 #### 配置发件人的签名信息 ![](https://image.ynotes.cn/18-8-20/52424548.jpg)    #### 配置PGP密钥对 ![](https://image.ynotes.cn/18-8-20/12310155.jpg)    #### 设置PGP私钥密码 ![](https://image.ynotes.cn/18-8-20/51664035.jpg)    #### 生成了密钥对 ![](https://image.ynotes.cn/18-8-20/56071063.jpg)    #### 设置加密选项 ![](https://image.ynotes.cn/18-8-20/88918582.jpg)    #### 发送公钥给test01 ![](https://image.ynotes.cn/18-8-20/92981185.jpg) ![](https://image.ynotes.cn/18-8-20/41683578.jpg)    #### test01收到公钥并添加到公钥(test01的密钥对的生成跟前面的test02操作一样) ![](https://image.ynotes.cn/18-8-20/13807193.jpg)    #### test02\@unotes.co的公钥已经添加成功 ![](https://image.ynotes.cn/18-8-20/97274363.jpg)    #### test01使用test02的公钥加密发送邮件给test02(只有拥有该公钥所对应的私钥的用户才能解密) ![](https://image.ynotes.cn/18-8-20/88244155.jpg) ![](https://image.ynotes.cn/18-8-20/64025748.jpg)    #### test01需输入密码,对该邮件进行签名 ![](https://image.ynotes.cn/18-8-20/55239850.jpg)    #### test02收到了test01的加密邮件 ![](https://image.ynotes.cn/18-8-20/89570053.jpg) #### 如果test02使用了没有私钥的客户端foxmail打开,是看不到加密邮件的真实内容 ![](https://image.ynotes.cn/18-8-20/75606557.jpg)    ### 二、第三方插件Mailvelope加密 浏览器需要安装Mailvelope扩展插件 ![](https://image.ynotes.cn/18-8-20/22598679.jpg) **firefox:** `https://download.mailvelope.com/releases/latest/mailvelope.firefox.xpi` **chrome:** `https://chrome.google.com/webstore/detail/kajibbejlbohfaggdiogboambcijhkke`       #### 安装扩展完成,之后浏览器上会有个小锁图标 ![](https://image.ynotes.cn/18-8-20/71417391.jpg)      #### 这里测试chrome登录test01的邮箱,火狐登录test02的邮箱 #### 激活当前域名的开启Mailvelope ![](https://image.ynotes.cn/18-8-20/68133310.jpg) ![](https://image.ynotes.cn/18-8-20/61285170.jpg)    #### 添加成功后,发送邮件页面会多一个加密图标 ![](https://image.ynotes.cn/18-8-20/83700494.jpg)    #### 导入双方的公私钥 #### chrome的Mailvelope导入test01的私钥以及test02的公钥 ![](https://image.ynotes.cn/18-8-20/92526057.jpg) ![](https://image.ynotes.cn/18-8-20/61774999.jpg)    #### firefox的Mailvelope导入test02的私钥以及test01的公钥 ![](https://image.ynotes.cn/18-8-20/64105510.jpg)    #### 测试test01给test02发送一份通过Mailvelope加密的邮件 ![](https://image.ynotes.cn/18-8-20/954079.jpg)    #### test02收到加密的邮件,通过私钥自动解密 ![](https://image.ynotes.cn/18-8-20/12330240.jpg)    #### 如果test02使用了没有私钥的客户端foxmail打开,是看不到加密邮件的真实内容 ![](https://image.ynotes.cn/18-8-20/19852859.jpg)
阅读 127 评论 0 收藏 0
阅读 127
评论 0
收藏 0

   2018-08-19 19:17:36    2018-08-19 19:17:36   

postfix 邮件服务器 Roundcube Roundcubemail
### Roundcubemail介绍   *RoundCube Webmail是一个基于浏览器,支持多国语言的IMAP客户端,操作界面看起像一个桌面应用程序   它提供一个e-mail客户端应该具备的所有功能包括MIME支持,地址薄,文件夹操作,信息搜索和拼写检查。RoundCube Webmail采用PHP+Ajax开发并且需要MySQL数据库来存储数据。 用户界面采用XHTML+CSS2设计。*    ### 安装LAMP 参考[邮件服务器之postfix+dovecot+postfixadmin+TLS](https://ynotes.cn/blog/article_detail/143)中的`LAMP`部分          ### 安装Roundcubemail(1.3.7版本) 下载地址: `https://roundcube.net/` ```bash $ wget https://github.com/roundcube/roundcubemail/releases/download/1.3.7/roundcubemail-1.3.7-complete.tar.gz $ tar -xf roundcubemail-1.3.7-complete.tar.gz -C /var/www/html/ $ cd /var/www/html/ $ mv roundcubemail-1.3.7 webmail ``` ### 浏览器访问`http://roundcube_server_ip/webmail/installer/` ![](https://image.ynotes.cn/18-8-19/59318596.jpg) ![](https://image.ynotes.cn/18-8-19/30786452.jpg) 上面提示时区没有配置 ```bash $ vim /etc/php.ini ``` ``` date.timezone = Asia/Shanghai ``` ![](https://image.ynotes.cn/18-8-19/95449628.jpg) ![](https://image.ynotes.cn/18-8-19/52171862.jpg) ![](https://image.ynotes.cn/18-8-19/72514419.jpg) ![](https://image.ynotes.cn/18-8-19/35096279.jpg) ![](https://image.ynotes.cn/18-8-19/39801531.jpg) ![](https://image.ynotes.cn/18-8-19/35432756.jpg) ![](https://image.ynotes.cn/19-2-23/12425125.jpg)          ### 配置插件 ```bash $ vim /var/www/html/webmail/config/config.inc.php ``` ``` $config['smtp_user'] = '%u'; $config['smtp_pass'] = '%p'; $config['product_name'] = 'unotes.co Webmail'; $config['plugins'] = array('attachment_reminder', 'autologon', 'emoticons', 'enigma', 'filesystem_attachments', 'markasjunk', 'newmail_notifier', 'password', 'show_additional_headers', 'userinfo', 'virtuser_file','virtuser_query', 'zipdownload'); $config['password_dovecotpw'] = '/usr/bin/doveadm pw'; $config['password_dovecotpw_method'] = 'CRAM-MD5'; $config['password_dovecotpw_with_method'] = false; $config['password_force_new_user'] = true; $config['password_driver'] = 'sql'; //下面配置postfix库的访问账号 $config['password_db_dsn'] = 'mysql://username:password@localhost/postfix'; ```    ### 添加automatic_addressbook插件(自动补全已发送过的邮件地址) #### 安装插件 ```bash $ cd /var/www/html/webmail/plugins $ wget https://github.com/sblaisot/automatic_addressbook/archive/master.zip $ tar xvf master.zip $ rm master.zip $ mv automatic_addressbook-master automatic_addressbook $ chown -R apache.apache automatic_addressbook ``` #### 添加插件相关的表 ```bash mysql>use roundcubemail; mysql>source automatic_addressbook/SQL/mysql.initial.sql; ``` #### 修改config配置 ```bash $ vim /var/www/html/webmail/config/config.inc.php ``` ``` $config['plugins'] = array('attachment_reminder', 'autologon', 'emoticons', 'enigma', 'automatic_addressbook', 'filesystem_attachments', 'markasjunk', 'newmail_notifier', 'password', 'show_additional_headers', 'userinfo', 'virtuser_file','virtuser_query', 'zipdownload'); ``` #### 重启服务 ```bash $ /etc/init.d/httpd restart ```    ### 登录webmail `http://mail.unotes.co/webmail` ![](https://image.ynotes.cn/18-8-19/78965000.jpg)    ### 配置SSL 增加ssl.conf ```bash /etc/httpd/conf.d/ssl.conf ``` ``` <VirtualHost *:80> ServerName mail.unotes.co RewriteEngine on RewriteCond %{SERVER_PORT} !^443$ RewriteRule ^/?(.*)$ https://%{SERVER_NAME}/$1 [L,R] </VirtualHost> ``` ``` LoadModule ssl_module modules/mod_ssl.so Listen 443 SSLPassPhraseDialog builtin SSLSessionCache shmcb:/var/cache/mod_ssl/scache(512000) SSLSessionCacheTimeout 300 SSLMutex default SSLRandomSeed startup file:/dev/urandom 256 SSLRandomSeed connect builtin SSLCryptoDevice builtin <VirtualHost _default_:443> DocumentRoot "/var/www/html" ServerName mail.unotes.co SSLEngine on SSLCertificateFile /etc/httpd/conf/ssl/mail.unotes.co.crt SSLCertificateKeyFile /etc/httpd/conf/ssl/mail.unotes.co.key SSLCertificateChainFile /etc/httpd/conf/ssl/ca.crt ErrorLog logs/ssl_error_log TransferLog logs/ssl_access_log LogLevel warn SSLProtocol all -SSLv2 SSLCipherSuite DEFAULT:!EXP:!SSLv2:!DES:!IDEA:!SEED:+3DES <Files ~ "\.(cgi|shtml|phtml|php3?)$"> SSLOptions +StdEnvVars </Files> <Directory "/var/www/cgi-bin"> SSLOptions +StdEnvVars </Directory> SetEnvIf User-Agent ".*MSIE.*" \ nokeepalive ssl-unclean-shutdown \ downgrade-1.0 force-response-1.0 CustomLog logs/ssl_request_log \ "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b" </VirtualHost> ``` 重定向80->443 ```bash $ vim /etc/httpd/conf/httpd.conf ``` 拷贝证书到/etc/httpd/conf/ssl ```bash $ cp /etc/postfix/ssl/* /etc/httpd/conf/ssl ``` 重启服务 ```bash $ /etc/init.d/httpd restart ``` 访问 `https://mail.unotes.co/webmail/` ![](https://image.ynotes.cn/18-8-19/74998541.jpg)
阅读 198 评论 0 收藏 0
阅读 198
评论 0
收藏 0

   2018-08-19 18:07:50    2018-08-19 18:07:50   

postfix 邮件服务器
### 邮件服务器(mail.unotes.co)收到 test01\@unotes.co 发送给 test.redhat\@gmail.com 邮件的日志 ```bash $ tail -f /var/log/maillog ``` **`收到客户端x.x.196.255的连接请求`** ```bash Aug 19 05:49:42 mail postfix/smtps/smtpd[10057]: connect from unknown[x.x.196.255] ``` **`用户test01@unotes.co通过sasl认证登录成功`** ```bash Aug 19 05:49:43 mail postfix/smtps/smtpd[10057]: EA8FF222F6: client=unknown[x.x.196.255], sasl_method=LOGIN, sasl_username=test01@unotes.co ``` **`postfix cleanup清理邮件,处理好的邮件,会被传入收件队列(Incoming Queue)`** ```bash Aug 19 05:49:44 mail postfix/cleanup[10064]: EA8FF222F6: message-id=<2018081917494313210561@unotes.co> ``` **`opendkim会检查发送邮件的DKIM签名是否通过`** ```bash Aug 19 05:49:44 mail opendkim[10046]: EA8FF222F6: DKIM-Signature field added (s=default, d=unotes.co) ``` **`qmgr把邮件放入active队列`** ```bash Aug 19 05:49:44 mail postfix/qmgr[7739]: EA8FF222F6: from=<test01@unotes.co>, size=1725, nrcpt=1 (queue active) ``` **`邮件服务器和gmail的smtp发起建立TLS的连接的请求`** ```bash Aug 19 05:49:44 mail postfix/smtp[10065]: setting up TLS connection to gmail-smtp-in.l.google.com[74.125.197.26]:25 ``` **`邮件服务器和gmail的smtp的TLS连接建立成功`** ```bash Aug 19 05:49:44 mail postfix/smtp[10065]: Trusted TLS connection established to gmail-smtp-in.l.google.com[74.125.197.26]:25: TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits) ``` **`邮件服务器发送邮件给gmail的smtp服务器`** ```bash Aug 19 05:49:45 mail postfix/smtp[10065]: EA8FF222F6: to=<test.redhat@gmail.com>, relay=gmail-smtp-in.l.google.com[74.125.197.26]:25, delay=1.8, delays=0.74/0.03/0.19/0.82, dsn=2.0.0, status=sent (250 2.0.0 OK 1534672190 g10-v6si7304311pfd.86 - gsmtp) ``` **`qmgr把邮件移除`** ```bash Aug 19 05:49:45 mail postfix/qmgr[7739]: EA8FF222F6: removed ``` **`客户端x.x.196.255断开连接`** ```bash Aug 19 05:49:49 mail postfix/smtps/smtpd[10057]: disconnect from unknown[x.x.196.255] ``` ### 邮件服务器(mail.unotes.co)收到 test.redhat\@gmail.com 发送给 test01\@unotes.co 邮件的日志 **`gmail客户端请求连接邮件服务器`** ```bash Aug 19 06:09:14 mail postfix/smtpd[10077]: connect from mail-wr1-f42.google.com[209.85.221.42] ``` **`postgrey灰名单校验通过,客户端在whitelist中`** ```bash Aug 19 06:09:15 mail postgrey[9433]: action=pass, reason=client whitelist, client_name=mail-wr1-f42.google.com, client_address=209.85.221.42, sender=test.redhat@gmail.com, recipient=test01@unotes.co Aug 19 06:09:15 mail postgrey[9433]: cleaning up old logs... Aug 19 06:09:15 mail postgrey[9433]: cleaning up old entries... Aug 19 06:09:15 mail postgrey[9433]: cleaning main database finished. before: 4, after: 4 Aug 19 06:09:15 mail postgrey[9433]: cleaning clients database finished. before: 4, after: 4 ``` **`postfix cleanup清理邮件`** ```bash Aug 19 06:09:15 mail postfix/smtpd[10077]: 974C6222F6: client=mail-wr1-f42.google.com[209.85.221.42] Aug 19 06:09:15 mail postfix/cleanup[10083]: 974C6222F6: message-id=<CAOmnsz0oWbDCvGsjo3Q2sLoyCWeFPqsyZFdin1thTvC2NmWA5w@mail.gmail.com> ``` **`opendkim检查客户端的smtp服务器的DKIM签名成功`** ```bash Aug 19 06:09:15 mail opendkim[10046]: 974C6222F6: mail-wr1-f42.google.com [209.85.221.42] not internal Aug 19 06:09:15 mail opendkim[10046]: 974C6222F6: not authenticated Aug 19 06:09:15 mail opendkim[10046]: 974C6222F6: DKIM verification successful ``` **`qmgr把邮件放入active队列`** ```bash Aug 19 06:09:15 mail postfix/qmgr[7739]: 974C6222F6: from=<test.redhat@gmail.com>, size=9907, nrcpt=1 (queue active) Aug 19 06:09:16 mail postfix/smtpd[10077]: disconnect from mail-wr1-f42.google.com[209.85.221.42] Aug 19 06:09:16 mail postfix/smtpd[10088]: connect from unknown[127.0.0.1] Aug 19 06:09:17 mail postfix/smtpd[10088]: 01373222F7: client=unknown[127.0.0.1] Aug 19 06:09:17 mail postfix/cleanup[10083]: 01373222F7: message-id=<CAOmnsz0oWbDCvGsjo3Q2sLoyCWeFPqsyZFdin1thTvC2NmWA5w@mail.gmail.com> ``` **`opendkim检查客户端的发件人的DKIM签名不匹配(正常,因为我们没有把test.redhat@gmail.com添加到/etc/opendkim/SigningTable),smtp服务器的DKIM签名成功`** ```bash Aug 19 06:09:17 mail opendkim[10046]: 01373222F7: no signing table match for 'test.redhat@gmail.com' Aug 19 06:09:17 mail opendkim[10046]: 01373222F7: DKIM verification successful ``` **`qmgr再次把邮件放入active队列`** ```bash Aug 19 06:09:17 mail postfix/qmgr[7739]: 01373222F7: from=<test.redhat@gmail.com>, size=10498, nrcpt=1 (queue active) ``` **`amavis检测通过`** ```bash Aug 19 06:09:17 mail amavis[9854]: (09854-01) Passed CLEAN {RelayedInbound}, [209.85.221.42] [209.85.221.42] <test.redhat@gmail.com> -> <test01@codemax.cn>, Message-ID: <CAOmnsz0oWbDCvGsjo3Q2sLoyCWeFPqsyZFdin1thTvC2NmWA5w@mail.gmail.com>, mail_id: rLrGCzYXUKtd, Hits: -0.099, size: 10066, queued_as: 01373222F7, dkim_sd=20161025:gmail.com, 1077 ms ``` **`smtp把邮件发送给amavis`** ```bash Aug 19 06:09:17 mail postfix/smtp[10084]: 974C6222F6: to=<test01@codemax.cn>, relay=127.0.0.1[127.0.0.1]:10024, delay=1.5, delays=0.42/0.04/0.02/1.1, dsn=2.0.0, status=sent (250 2.0.0 from MTA(smtp:[127.0.0.1]:10025): 250 2.0.0 Ok: queued as 01373222F7) ``` **`qmgr把邮件移除`** ```bash Aug 19 06:09:17 mail postfix/qmgr[7739]: 974C6222F6: removed ``` **`把邮件中继给dovecot`** ```bash Aug 19 06:09:17 mail postfix/pipe[10090]: 01373222F7: to=<test01@codemax.cn>, relay=dovecot, delay=0.32, delays=0.06/0.01/0/0.25, dsn=2.0.0, status=sent (delivered via dovecot service) ``` **`qmgr把邮件移除`** ```bash Aug 19 06:09:17 mail postfix/qmgr[7739]: 01373222F7: removed ```
阅读 515 评论 0 收藏 0
阅读 515
评论 0
收藏 0

   2018-08-18 23:45:14    2019-06-17 09:28:37   

clamav spamassassin 反垃圾 病毒检测 amavisd-new
### 准备工作 添加postgrey的yum仓库 ```bash $ wget http://packages.psychotic.ninja/6/base/x86_64/RPMS/psychotic-release-1.0.0-1.el6.psychotic.noarch.rpm $ rpm -Uvh psychotic-release-1.0.0-1.el6.psychotic.noarch.rpm ```    ### 安装 `反垃圾过滤` `病毒检测` `灰名单` 等相关软件包 ```bash $ yum --enablerepo=psychotic-testing --enablerepo=epel install spamassassin amavisd-new clamav clamd pyzor perl-Mail-SPF perl-Mail-DKIM postgrey tmpwatch lzop -y ```    ### 配置postfix Amavisd-new集成到postfix,从postfix的queue队列中接收未过滤的邮件,需要添加下面的参数 添加`-o content_filter=smtp-amavis:[127.0.0.1]:10024`到/etc/postfix/master.cf的`smtp inet n - n - - smtpd`这行下面 ```bash $ vim /etc/postfix/master.cf ``` ``` smtp inet n - n - - smtpd -o content_filter=smtp-amavis:[127.0.0.1]:10024 ``` 上面的配置会把邮件发送给amavisd-new。需要amavisd-new把邮件返回给postfix,添加下面的配置 ```bash $ vim /etc/postfix/master.cf ``` ``` # amavisd-new deamon smtp-amavis unix - - - - 2 smtp -o smtp_data_done_timeout=1200 -o disable_dns_lookups=yes # smtpd deamon for amavisd-new to send mails back to postfix 127.0.0.1:10025 inet n - - - - smtpd -o content_filter= -o strict_rfc821_envelopes=yes ``` amavisd-new 将会发送警告消息,配置别名让这些消息发送给root或者其他收件人,编辑/etc/aliases添加下面一行 ```bash $ vim /etc/aliases ``` ``` virusalert: root ``` ```bash $ newaliases ``` Postgrey需要集成到postfix,Postgrey叫做策略服务器.postfix使用策略服务器去决定接受还是拒绝这些邮件。添加`check_policy_service unix:/var/spool/postfix/postgrey/socket`到smtpd_recipient_restrictions中,内容如下 ```bash $ vim /etc/postfix/main.cf ``` ``` smtpd_recipient_restrictions = reject_unauth_pipelining, reject_non_fqdn_recipient, reject_unknown_recipient_domain, permit_mynetworks, permit_sasl_authenticated, check_policy_service unix:/var/spool/postfix/postgrey/socket reject_unauth_destination, permit ```       ### 配置postgrey Postgrey是一个灰名单策略服务器,后面是一个简单的灰名单。它包含了一些垃圾邮件服务器.Postgrey将会第一次拒绝这些服务器的邮件并且返回临时错误代码。用于识别客户端ip/发件人/收件人。当发件人多次重试去发送邮件。Postgrey会接收它。 Centos配置Postgrey,打开/etc/sysconfig/postgrey文件,添加下面的内容(`delay选项将会延迟60秒转发邮件,max-age选项定义了多久时间内,将会直接转发那些成功邮件的后续邮件`) ```bash $ vim /etc/sysconfig/postgrey ``` ``` POSTGREY_OPTS="--inet=127.0.0.1:10023 --max-age=365 --delay=60 --unix=/var/spool/postfix/postgrey/socket" ```    ### 配置Amavisd-New Amavisd-New的配置文件下面的参数需要修改 ```bash $ vim /etc/amavisd/amavisd.conf ``` ``` $mydomain = 'unotes.co'; #配置你的域名 @mynetworks = qw( 127.0.0.0/8 [::1] ); $sa_spam_subject_tag = '[Spam] '; $allowed_added_header_fields{lc('Received')} = 0; #禁掉 "Received"头添加到邮件头 ['ClamAV-clamd', \&ask_daemon, ["CONTSCAN {}\n", "/var/run/clamav/clamd.sock"], qr/\bOK$/m, qr/\bFOUND$/m, qr/^.*?: (?!Infected Archive)(.*) FOUND$/m ], $sa_tag_level_deflt = -999; ```    ### 配置Spamassassin ```bash $ mkdir /etc/mail/bayes $ vim /etc/mail/spamassassin/local.cf ``` ``` # The score from which an email will be considered spam required_hits 5.0 # Subject prefix if spam is detected rewrite_header Subject [SPAM] # Disable encapsulate spam in an attachment report_safe 0 # Configure the Bayes system use_bayes 1 bayes_auto_learn 0 bayes_path /etc/mail/bayes/bayes bayes_file_mode 0666 # Enable or disable network checks skip_rbl_checks 0 # pyzor configuration use_pyzor 1 pyzor_options --homedir /etc/mail/spamassassin pyzor_timeout 5 ```    ### 安装Pyzor 用root运行下面的命令 ```bash $ pyzor --homedir /etc/mail/spamassassin/ discover ``` ### 重启服务 ```bash $ /etc/init.d/clamd restart $ /etc/init.d/spamassassin restart $ /etc/init.d/amavisd restart $ /etc/init.d/postgrey restart $ /etc/init.d/postfix restart $ chkconfig spamassassin on $ chkconfig amavisd on $ chkconfig clamd on $ chkconfig postgrey on ``` 翻译: https://blog.tinned-software.net/setup-amavisd-new-with-spamassassin-and-clamav-with-postfix/
阅读 147 评论 1 收藏 0
阅读 147
评论 1
收藏 0

   2018-08-18 21:33:33    2018-08-18 21:33:33   

反垃圾 dkim SPF PTR 反向解析
### SPF认证 域名解析添加SPF的TXT记录 ``` @ IN TXT "v=spf1 mx mx:mail.unotes.co ip4:95.163.201.189 ~all" ```    ### DKIM认证 ```bash $ yum install epel-release -y $ yum --enablerepo=epel install opendkim ``` ```bash $ vim /etc/opendkim.conf ``` 添加下面的文本 ``` AutoRestart Yes AutoRestartRate 10/1h LogWhy Yes Syslog Yes SyslogSuccess Yes Mode sv Canonicalization relaxed/simple ExternalIgnoreList refile:/etc/opendkim/TrustedHosts InternalHosts refile:/etc/opendkim/TrustedHosts KeyTable refile:/etc/opendkim/KeyTable SigningTable refile:/etc/opendkim/SigningTable SignatureAlgorithm rsa-sha256 Socket inet:8891@localhost PidFile /var/run/opendkim/opendkim.pid UMask 022 UserID opendkim:opendkim TemporaryDirectory /var/tmp ``` 生成key ```bash $ mkdir /etc/opendkim/keys/unotes.co #新建域名目录 $ opendkim-genkey -D /etc/opendkim/keys/unotes.co/ -d unotes.co -s default #生成随机密钥 ``` ```bash $ /etc/opendkim/KeyTable #添加下面内容 ``` ``` default._domainkey.unotes.co unotes.co:default:/etc/opendkim/keys/unotes.co/default.private ``` ```bash $ vim /etc/opendkim/SigningTable #添加下面内容 ``` ``` *@unotes.co default._domainkey.unotes.co ``` ```bash $ vim /etc/opendkim/TrustedHosts #添加下面内容 ``` ``` 127.0.0.1 unotes.co ``` 域名解析添加DKIM的TXT记录,文件`/etc/opendkim/keys/unotes.co/default.txt`的内容,记得去掉内容中的空格和引号 ``` default._domainkey IN TXT v=DKIM1;k=rsa;p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCw/S6dg+kqpr7WIykX+e53bI3qg8qbCyWGfH/rU8UsDk8xZjpgWBiPv94SIJI0FYv4i2sJfVlD/4N2XfblPX/Vvu9LU1c66SvEyl/5cnVj/Bppyg4d3wggn+ROChBi9vWXrmUEGUbLOrWBDee3ZcSBaqK3DXFg7iSQlMATVtSnyQIDAQAB ``` DKIM检测是否配置正确 网站:`https://dkimcore.org/c/keycheck` ![](https://image.ynotes.cn/18-8-18/43984887.jpg) postfix添加dkim认证: ```bash $ vim /etc/postfix/main.cf #添加下面内容 ``` ``` smtpd_milters = inet:127.0.0.1:8891 non_smtpd_milters = $smtpd_milters milter_default_action = accept milter_protocol = 2 ``` 启动opendkim,重启postfix ```bash $ /etc/init.d/opendkim start $ /etc/init.d/postfix restart ``` ### DMARC认证 域名解析添加DMARC的TXT记录 ``` _dmarc IN TXT “v=DMARC1; p=quarantine; fo=1; ruf=mailto:dmarc_report@unotes.co; rua=mailto:dmarc_report@unotes.co” ``` 检测SPF和DMARC配置 `https://mxtoolbox.com/` ![](https://image.ynotes.cn/18-9-7/55228303.jpg) ### PTR反向解析 到主机运营商(**`注意:阿里云、腾讯云禁止25端口使用SMTP发送邮件`**)添加PTR解析,我用的是搬瓦工 地址:https://bandwagonhost.com/aff.php?aff=35573 ![](https://image.ynotes.cn/18-8-18/85327047.jpg) 测试结果:qq邮箱、163邮箱、gmail邮箱均收发正常,邮件未进入垃圾邮箱
阅读 429 评论 1 收藏 0
阅读 429
评论 1
收藏 0

第 2 页 / 共 4 页
 
第 2 页 / 共 4 页