• jquery应用:鼠标移动到表格tr变色

    /*
    *@param tabID 表格名称
    *@param oveClass 鼠标进入时的样式
    *@param outClass 鼠标离开时的样式(为样式名称)
    */
    function altrow(tabID,oveClass,outClass) {
    var rowObj = $(“#” + tabID).find(“tr”);
    $.each(rowObj, function (i, obj) {
    var tr = $(obj);
    tr.mousemove(function () {
    tr.addClass(oveClass);
    });
    tr.mouseout(function () {
    tr.removeClass(oveClass);
    tr.addClass(outClass);
    });
    });
    }
    网页加载
    $(document).ready(function(){
    altrow(传入参数);
    });
  • Js压缩加密工具 (PHP版)

    下载地址:
    http://www.codebit.cn/packer/packer.php-1.0.zip

  • get_magic_quotes_gpc() get_magic_quotes_runtime()

    GPC 过滤Get Post Cookie 而 RUNTIME 是过滤对数据库执行查询时的过滤。
    作用:检测php.ini中的magic_quotes_runtime的值
    magic_quotes_gpc 设置是否自动为GPC(get,post,cookie)传来的数据中的\’\”\\加上反斜
    线。
    set_magic_quotes_runtime(0)
  • debian专题

    LAMP安装  http://www.silentstreet.net/archives/2218.html

    debian开发环境安装 http://blogold.chinaunix.net/u/20581/showart_1098627.html

  • Amavisd参数

    前言
    amavisd-new为一新的amavis perl module,它具有高效能、检查信件内容(SpamAssasin)、VirusScanners(可结合28种之多的扫毒程式)。它是由perl所写成的,所以效能有大幅的成长。它可与MTA使用SMTP、LMTP协定来沟通。
    postfix+amavisd-new的流程:
    (1)信件由Internet(smtpd)或是由Local(pickup)接收要传送的信件
    (2)信件传送至cleanup
    (3)信件传送至qmgr
    (4)因content_filter的设定,会将信件传送至smtp-amavis
    (5)amavisd-new执行content file及scanvirus的动作
    (6)amavisd-new将信件传送至smtpd 10025(127.0.0.1:10025)
    (7)信件传送至cleanup
    (8)信件传送至qmgr
    (9)信件传送至Internet(smtp)或是Local(local)
    ———————————————————————————————————————
    版本
    系统为debian/linux 4.0,amavisd-new 2.4.2-5
    配置文件
    Amavisd-new的主要配置文档在/etc/amavis/conf.d/目录中;
    还有些变量需在amavisd-new的可执行脚步中查看,为/usr/sbin/amavisd-new。
    1./etc/amavis/conf.d/配置文档
    在/etc/amavis/conf.d/目录中,主要配置文件有:
    /etc/amavis/conf.d/15-content_filter_mode
    /etc/amavis/conf.d/20-debian_defaults
    ⑴在15-content_filter_mode中:
    查杀病毒功能块,把下面代码前的“#”去掉便可。
    #@bypass_virus_checks_maps = (
    # \%bypass_virus_checks, \@bypass_virus_checks_acl, \$bypass_virus_checks_re);
    垃圾邮件功能块:
    @bypass_spam_checks_maps = (                 #让amavisd-new启动spamassassin
    \%bypass_spam_checks, \@bypass_spam_checks_acl, \$bypass_spam_checks_re);
    1;  # insure a defined return
    ⑵在20-debian_defaults中(此文件相当于其他版本中的amavisd.conf):
    use strict;
    #将$QUARANTINEDIR设定为刚刚建立的病毒隔离目录
    $QUARANTINEDIR = “$MYHOME/virusmails”;
    $log_recip_templ = undef;    # disable by-recipient level-0 log entries
    $DO_SYSLOG = 1;              # log via syslogd (preferred)
    $syslog_ident = ‘amavis’;    # syslog ident tag, prepended to all messages
    $syslog_facility = ‘mail’;     # Syslog facility as a string
    $syslog_priority = ‘debug’;  # switch to info to drop debug output, etc
    $enable_db = 1;              # enable use of BerkeleyDB/libdb (SNMP and nanny)
    $enable_global_cache = 1;    # enable use of libdb-based cache if $enable_db=1
    $inet_socket_port = 10024;   # 默认amavisd-new监听端口t
    #设定评分规则
    #变量以$sa开头的均为spamassassin中的,在这进行设置后,在 /etc/spamassassin/local.cf 所#设定的將失去效用
    $sa_spam_subject_tag = ‘***SPAM*** ‘;  # 对垃圾邮件主题添加’***SPAM*** ‘
    $sa_tag_level_deflt  = -10;  # 超过这个分数标准者,才视为垃圾邮件打分数。
    $sa_tag2_level_deflt = 20; # 超过这个分数标准者,才允许在邮件标题加入Spam 信息。加入#X-Spam-Flag:YES 及改写主题
    $sa_kill_level_deflt = 6.31;  # 超过这个分数标准者,就直接將信件备份后删除
    $sa_dsn_cutoff_level = 10;   # 超过这个分数标准者,將不会送出 DSN 信息
    $sa_mail_body_size_limit = 200*1024; # 超过某个特定大小的邮件就不经过SpamAssassin 的扫#描,此大小不包括附件大小。
    #让sa可以和外部连线
    $sa_local_tests_only = 0;    # only tests which do not require internet access?
    $sa_auto_whitelist = 1;  # 启用自动学习白名单 White List
    #启用 SpamAssassin 的 Debug。在正式上线时请记得去掉
    # Turn on SpamAssassin debugging (output to STDERR, use with ‘amavisd debug’)
    $sa_debug = 1;            # defaults to false
    # 设定 White List
    # 注意:在 /etc/spamassassin/local.cf 所设定的將失去效用!
    @whitelist_sender_maps = ( [“.cc17121.com”] );#添加白名单,对大附件仍然进行解压缩,但不打分
    #map { $whitelist_sender{lc($_)}=1 } (qw(    #同上功能
    #  *@cc17121.com
    #  *@*.edu.tw
    #));
    # 或指定为某个档案。注意:这些档案必须存在,否则Amavisd-new 將无法启动!
    read_hash(\%whitelist_sender, ‘/var/amavis/whitelist’);
    #指定黑名单
    read_hash(\%blacklist_sender, ‘/var/amavis/blacklist’);
    #若收件人名列其中,则不进行垃圾邮件检测
    read_hash(\%spam_lovers, ‘/var/amavis/spam_lovers’);
    ###以下几个变量在执行脚本/usr/sbin/amavisd-new中均可找到######################
    # Quota limits to avoid bombs (like 42.zip)
    $MAXLEVELS = 1;    #扫描压缩包时,解压几层
    $MAXFILES = 150;     #最多扫描压缩包内1500个文件
    $MIN_EXPANSION_QUOTA = 100*1024;  # 单位bytes,最小邮件限额,包括附件
    $MAX_EXPANSION_QUOTA = 200*1024*1024;  # bytes , 最大邮件大小,为200K
    $MIN_EXPANSION_FACTOR =   1;  #可扫描邮件大小的最小倍数
    $MAX_EXPANSION_FACTOR =   500; #可扫描邮件大小的最大倍数#
    #最大扫描压缩包大小为($MAX_EXPANSION_QUOTA)×($MAX_EXPANSION_FACTOR),#当解压缩后的文件达到此值时,系统会结束解压缩进程。
    #
    #
    #########################################################
    $undecipherable_subject_tag = ‘ ‘;   #取消对未检查的信件主题添加“UNCHECK”,也可以在
    #执行脚本/usr/sbin/amavisd-new中修改”UNCHECK”
    # Use D_DISCARD  邮件不传送给发件人及收件人。
    #Use D_BOUNCE  不传送给收件人。除了定义在 $viruses_that_fake_sender_re 病毒名称#  #                #外的信件,amavisd-new 皆会传送 DSN 讯息给发件人。
    # Use D_REJECT   不传送给收件人,发件人会收到拒绝传送的信息。
    # Use D_PASS   不做任何处理,直接传送给收件人。
    $final_virus_destiny = D_DISCARD;
    $final_banned_destiny = D_PASS;
    $final_spam_destiny = D_DISCARD;
    $final_bad_header_destiny = D_PASS;
    $MAX_EXPANSION_FACTOR测试结果:
    a.        附件为257M,$MAX_EXPANSION_FACTOR为500倍,先添加好附件:
    点击发送:11:16:00     发送页面完成:11:19:20         耗时:3m 20s
    Bzip进程开始时间:11:23:45   结束时间:11:28:00       耗时:4m 15s   (bzip为解压缩进程)
    发送完成时间:11:30:40                             共耗时:14m40s
    b.        附件为257M,$MAX_EXPANSION_FACTOR为1倍,先添加好附件:
    点击发送:12:31:30     发送页面完成:12:34:40         耗时:3m 10s
    Bzip进程开始时间:12:39:05   结束时间:12:39:55       耗时:50s   (bzip为解压缩进程)
    发送完成时间:12:42:30                             共耗时:11m00s
    2./usr/sbin/amavisd-new 执行文件
    $MIN_EXPANSION_FACTOR =   1;  # times original mail size
    $MAX_EXPANSION_FACTOR =   500;  # times original mail size
    $spam_lover           #发送垃圾邮箱至
    # timeout for our processing:  超出设置时间后会断开连接
    $child_timeout = 8*60; # abort child if it does not complete a task in n sec
    # $child_timeout的值則須小於/etc/postfix/main.cf裡smtp_data_dome_timeout的值
    # Net::Server pre-forking settings – defaults, overruled by amavisd.conf
    $max_servers  = 2;   # number of pre-forked children
    $max_requests = 10;  # retire a child after that many accepts
    # serves only as a quick default for other configuration settings
    $MYHOME   = ‘/var/amavis’;
    $mydomain = ‘!change-mydomain-variable!.example.com’;#intentionally bad default
    $virus_admin = “administrator\@$mydomain”;
    $spam_admin = “administrator\@$mydomain”;
    $mailfrom_notify_admin     = “administrator\@$mydomain”;
    $mailfrom_notify_recip     = “administrator\@$mydomain”;
    $mailfrom_notify_spamadmin = “administrator\@$mydomain”;
  • 邮件服务器安装完毕,安装反垃圾邮件,和反病毒

    apt-get install amavisd-new
    apt-get install spamassassin
    apt-get install clamav
    apt-get install clamav-daemon
    apt-get install clamtk
    apt-get install libnet-dns-perl
    apt-get install libmail-spf-query-perl
    apt-get install libnet-ph-perl
    apt-get install libnet-snpp-perl
    apt-get install libnet-telnet-perl
    apt-get install pyzor razor
    apt-get install arj
    apt-get install bzip2
    apt-get install cabextract
    apt-get install cpio
    apt-get install nomarch
    apt-get install pax
    apt-get install unzip
    apt-get install zip
    apt-get install zoo
    apt-get install lzop
    apt-get install arc
    系统已经有的
    apt-get install file
    apt-get install gzip
    apt-get install lha
    安装源里没有的
    apt-get install zop 没有
    apt-get install rar 没有
    apt-get install unrar 没有
    安装完以后的一些服务
    testServer:/var/spool# netstat -tap
    Active Internet connections (servers and established)
    Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
    tcp        0      0 localhost.localdo:10024 *:*                     LISTEN      28665/amavisd (mast
    tcp        0      0 localhost.localdo:10025 *:*                     LISTEN      30507/master
    tcp        0      0 localhost.localdoma:745 *:*                     LISTEN      22193/famd
    tcp        0      0 *:mysql                 *:*                     LISTEN      1466/mysqld
    tcp        0      0 *:11211                 *:*                     LISTEN      2235/memcached
    tcp        0      0 localhost.localdo:spamd *:*                     LISTEN      30522/spamd.pid
    tcp        0      0 *:sunrpc                *:*                     LISTEN      1622/portmap
    tcp        0      0 *:ssmtp                 *:*                     LISTEN      30507/master
    tcp        0      0 *:ftp                   *:*                     LISTEN      874/vsftpd
    tcp        0      0 59.108.38.221:domain    *:*                     LISTEN      8346/named
    tcp        0      0 postfixserver.do:domain *:*                     LISTEN      8346/named
    tcp        0      0 localhost.locald:domain *:*                     LISTEN      8346/named
    tcp        0      0 *:ssh                   *:*                     LISTEN      25579/sshd
    tcp        0      0 localhost.localdom:8888 *:*                     LISTEN      18342/dispatch.fcgi
    tcp        0      0 *:smtp                  *:*                     LISTEN      30507/master
    tcp        0      0 localhost.localdoma:953 *:*                     LISTEN      8346/named
    tcp        0    248 postfixserver.domai:ssh localhost:nessus        ESTABLISHED 19023/sshd: kangjin
    tcp        0      0 localhost.localdo:mysql localhost.localdo:42555 ESTABLISHED 1466/mysqld
    tcp        0      0 localhost.localdo:mysql localhost.localdo:42584 ESTABLISHED 1466/mysqld
    tcp        0      0 postfixserver.domai:ssh localhost:msnp          ESTABLISHED 23562/sshd: kangjin
    tcp        0      0 localhost.localdo:mysql localhost.localdo:42552 ESTABLISHED 1466/mysqld
    tcp        0      0 localhost.localdo:42619 localhost.localdo:mysql ESTABLISHED 28487/authdaemond
    tcp        0      0 localhost.localdo:mysql localhost.localdo:42576 ESTABLISHED 1466/mysqld
    tcp        0      0 localhost.localdo:42556 localhost.localdo:mysql ESTABLISHED 30528/smtpd
    tcp        0      0 localhost.localdo:42578 localhost.localdo:mysql ESTABLISHED 30553/virtual
    tcp        0      0 localhost.localdo:42325 localhost.localdo:spamd TIME_WAIT   –
    tcp        0      0 localhost.localdo:42552 localhost.localdo:mysql ESTABLISHED 28484/authdaemond
    tcp        0      0 localhost.localdo:42563 localhost.localdo:mysql ESTABLISHED 28482/authdaemond
    tcp        0      0 localhost.localdo:39194 localhost.localdo:10025 ESTABLISHED 29398/amavisd (ch3-
    tcp        0      0 localhost.localdo:mysql localhost.localdo:42556 ESTABLISHED 1466/mysqld
    tcp        0      0 localhost.localdo:mysql localhost.localdo:42563 ESTABLISHED 1466/mysqld
    tcp        0      0 localhost.localdo:42576 localhost.localdo:mysql ESTABLISHED 30552/trivial-rewri
    tcp        0      0 localhost.localdo:mysql localhost.localdo:42577 ESTABLISHED 1466/mysqld
    tcp        0      0 localhost.localdo:mysql localhost.localdo:42560 ESTABLISHED 1466/mysqld
    tcp        0      0 localhost.localdo:42575 localhost.localdo:mysql ESTABLISHED 30552/trivial-rewri
    tcp        0      0 localhost.localdo:42577 localhost.localdo:mysql ESTABLISHED 30533/cleanup
    tcp        0      0 localhost.localdo:42584 localhost.localdo:mysql ESTABLISHED 28485/authdaemond
    tcp        0      0 localhost.localdo:10025 localhost.localdo:39194 ESTABLISHED 30561/smtpd
    tcp        0      0 localhost.localdo:mysql localhost.localdo:42578 ESTABLISHED 1466/mysqld
    tcp        0      0 localhost.localdo:42560 localhost.localdo:mysql ESTABLISHED 28476/authdaemond
    tcp        0      0 localhost.localdo:10025 localhost.localdo:39234 TIME_WAIT   –
    tcp        0      0 localhost.localdo:42555 localhost.localdo:mysql ESTABLISHED 30528/smtpd
    tcp        0      0 localhost.localdo:mysql localhost.localdo:42575 ESTABLISHED 1466/mysqld
    tcp        0      0 localhost.localdo:mysql localhost.localdo:42619 ESTABLISHED 1466/mysqld
    tcp6       0      0 [::]:imaps              [::]:*                  LISTEN      28516/couriertcpd
    tcp6       0      0 [::]:pop3s              [::]:*                  LISTEN      28544/couriertcpd
    tcp6       0      0 [::]:svn                [::]:*                  LISTEN      9603/svnserve
    tcp6       0      0 [::]:pop3               [::]:*                  LISTEN      28527/couriertcpd
    tcp6       0      0 [::]:imap2              [::]:*                  LISTEN      28499/couriertcpd
    tcp6       0      0 [::]:www                [::]:*                  LISTEN      28140/apache2
    tcp6       0      0 [::]:domain             [::]:*                  LISTEN      8346/named
    tcp6       0      0 [::]:ssh                [::]:*                  LISTEN      25579/sshd
    tcp6       0      0 localhost:953           [::]:*                  LISTEN      8346/named
    tcp6       0      0 [::]:https              [::]:*                  LISTEN      28140/apache2
  • Cyrus SASL Libary

    (1) 什么是SASL和Cyrus SASL

    SASL (Simple Authentication Security Layer) is an Internet standards-track method for remote computers to authenticate. The Cyrus SASL library makes supporting various SASL mechanisms easy for both client and server writers.

    The Cyrus project is the implementation of an enterprise mail system by the Carnegie Mellon University Computing Services Department. We are interested in scalable, easy to administer systems.

    (2) Cyrus SASL组成部分

    SASL是一个胶合(glue)库,通过这个库把应用层  形式多样的认证系统整合在一起。这有点类似于 PAM,但是后者是认证方式,决定什么人可以访问什么服务而SASL是认证过程,侧重于信任建立过程,这个过程可以调用PAM来建立信任关系。

    应用层

    应用层是SASL库的使用者既可以是客户应用程序,也可以是服务应用程序,或者两者都是(在代理的情况下)。应用层负责SASL认证协商的连线和传达,具体的认证交给SASL库应用层的例子有Cyrus IMAPd,OpenLDAP,Sendmail,Mutt,sieveshell,cyradm等

    SASL胶合层(Glue Layer)

    负责如下的工作:
    加载插件;
    从应用层获取必要的认证属性,以选择适当的认证机制(或者限制可用的认证机制);
    给应用层列出可用的插件;
    为特定的认证请求选择最好的认证机制;
    在应用层和被选的认证机制间路由认证数据;
    为应用层提供SASL协商信息,比如认证的用户,请求的认证ID,安全层的强度等。

    SASL还提供一些别的服务给应用层和插件,一些是常用的工具,比如MIME Base64编码解码,随机数生成;还有一些是和认证相关的,比如口令验证服务。

    最后,SASL还允许应用层和认证机制层访问两种特殊类型的插件:Auxiliary Property或者 auxprop插件,它提供了简单的数据库接口,可返回用户属性,比如口令,home目录,邮件地址等;Username Canoicalization,提供了一个站点相关的用户正名服务(使用户名称规范化),或者其他的任务.

    SASL认证机制(SASL Mechanisms)

    有三种类型的机制:
    Password Verification Mechanisms – 接收远程的口令,传递给SASL胶合层,由口令验证器验证,这种机制的例子有PLAIN
    Shared Secret Mechanisms – 不是直接传递口令明文,而是服务方发起一个认证,客户证明自己知道这个口令,这需要服务方和客户方都保存有口令.这种机制的例子有CRAM-MD5,DIGEST-MD5以及SRP
    Kerberos Mechanisms – 使用信任的第三方来验证客户。

    Auxiliary Property(auxprop)

    为胶合层提供数据库服务,Cyrus SASL支持两种auxprop插件:SASLdb和SQL。auxprop通常用于共享密码机制。

    Username Canonicalization

    不是很常用,一般用于为应用层提供用户的规范名称。

    口令验证服务

    根据用户名和口令的明文,判断是否验证正确。口令验证服务器通过SASL选项pwcheck_method来选择,有两类主要的口令验证器:
    auxprop – 使用auxprop插件获取口令,比较和用户提供的口令是否相符;
    saslauthd – 呼叫saslauthd服务进程,验证用户。saslauthd支持很多识别方式,比如PAM,LDAP,Kerberos数据库等

    (3) SASL 术语

    认证ID(Authentication identifier)和授权ID(Authorization identifier)

    userid(user id, authorization id) – 用户ID,授权ID,说明执行操作的授权个体。
    authid(authentication id) – 认证ID,证明某人确系某人。

    比如小王休假,小李暂时接替他的工作。那么为了有小王的权限,小李认证时使用自己的帐号,即authid,执行具体的操作时需要有小王的user id,这样才能做他的工作。

    一般userid和authid是相同的。

    Realms

    A realm is an abstract set of users and certain mechanisms authenticate users in a certain realm.

    最简单的情况是单服务单机器的情况,realm就是FQDN(Full-qualified domain name),如果应用层没有提供,则很多SASL机制采用默认的。

    如果要多机共享口令,则通常选择域名,比如CMU.EDU。单个站点也可以支持多个不同的realms。为了把不同realm的用户加入sasldb,可以在saslpasswd2命令中用u选项,SQL插件通过宏’%r’在查询串中加入realm。

    (4) SASL工作流程

    PLAIN机制,sasl_checkpass(),以及明文口令

    auxprop – 根据auxiliary property插件提供的userPassword属性验证用户,数据库通常保存在/etc/sasldb2;
    saslauthd通过saslauthd验证用户,-a选项指示saslauthd的具体机制,-n指示saslauthd的线程数;
    Courier-IMAP – 通过Courier-IMAP的authdaemond检查口令,类似于saslauthd;
    pwcheck – 使用独立辅助服务进程来验证
    write your own – 自己写一个验证方式。

    共享密码机制

    CRAM-MD5和DIGEST-MD5使用这种机制,注意,这些方式不能使用saslauthd。如果不想用这些方式,可从插件目录移走这些插件,或者用mech_list禁用它们。

    为了简单起见,SASL库把口令的明文形式保存在/etc/sasldb2中。

    Kerberos mechanisms

    The Cyrus SASL library also comes with two mechanisms that make use of Kerberos: KERBEROS_V4, which should be able to use any Kerberos v4 implementation, and GSSAPI (tested against MIT Kerberos 5, Heimdal Kerberos 5 and CyberSafe Kerberos 5). These mechanisms make use of the kerberos infrastructure and thus have no password database.
    Applications that wish to use a kerberos mechanism will need access to a service key, stored either in a “srvtab” file (Kerberos 4) or a “keytab” file (Kerberos 5). Currently, the keytab file location is not configurable and defaults to the system default (probably /etc/krb5.keytab).

    The Kerberos 4 srvtab file location is configurable; by default it is /etc/srvtab, but this is modifiable by the “srvtab” option. Different SASL applications can use different srvtab files.

    A SASL application must be able to read its srvtab or keytab file.

    OTP机制和基于OPIE的OTP

    The Cyrus SASL library also supports the One-Time-Password (OTP) mechanism. This mechanism is similar to CRAM-MD5 and DIGEST-MD5 in that is uses a shared secret and a challenge/response exchange. However, OTP is more secure than the other shared secret mechanisms in that the secret is used to generate a sequence of one-time (single use) passwords which prevents reply attacks, and that secret need not be stored on the system. These one-time passwords are stored in the /etc/sasldb2 database. See the Shared secrets mechanisms section for a discussion of the /etc/sasldb2 database.

    For sites with an existing OTP infrastructure using OPIE, Cyrus SASL can be configured to use OPIE v2.4 instead of using its own database and server-side routines. OPIE should be configured with the –disable-user-locking option if the SASL server application will not be running as “root”.
    OPIE uses its own “opiekeys” database for storing the data necessary for generating the server challenges. The location of the opiekeys file is configurable in SASL; by default it is /etc/opiekeys, but this is modifiable by the “opiekeys” option.

    A SASL server application must be able to read and write the opiekeys file.

    (5) 如何配置选项

    缺省配置文件保存在/usr/lib/sasl2/App.conf里,这里App.conf为应用层名字,比如Sendmail为/usr/lib/sasl2/Sendmail.conf

    标准的Cyrus SASL配置文件类似于:

    srvtab: /var/app/srvtag
    pwcheck_method: saslauthd

    应用层可重新定义SASL库的选项,这因应用层而异,比如Cyrus imapd保存配置文件为/etc/imapd.conf。

    (6) Cyrus SASL 测试

    Cyrus SASL库带了两个测试程序:sasl2-sample-server和sasl2-samle-client,分别对应着服务程序和客户程序,可对SASL的配置进行测试。两个程序都带了三个参数:

    -p TCP监听或者连接的端口号,缺省为12345
    -s 服务名称,缺省为rcmd
    -m 认证的机制

    此外sasl2-sample-client还要求有一个服务程序主机名称或者IP地址的参数。

    首先我们给测试服务程序提供一个配置文件,sample.conf,保存在/usr/lib/sasl2目录下,内容如下:

    pwcheck_method: auxprop
    auxprop_plugin: sasldb
    mech_list: plain login ntlm cram-md5 digest-md5

    然后我们给sasl2db(在/etc/sasldb2)添加测试帐号,比如marchday:

    [root@research sasl2]# saslpasswd2 -c marchday
    Password: 
    Again (for verification):

    然后我们启动服务程序:

    $ sasl2-sample-server -p 9000

    打开另一个终端窗口,进行测试:

    $ sasl2-sample-client -p 9000 -m PLAIN localhost

    如果没别的问题,应该可以看到successful authentication。^_^

    你还可以测试别的Mechanisms,这里就不再举例了。

    参考资料:
    http://www.sendmail.org/~ca/email/cyrus/sysadmin.html

    http://asg.web.cmu.edu/sasl/
    Cyrus SASL Library Documatation

    以Sendmail为例:

    应用程序——>SASL 为客户服务的配置/usr/lib/sasl2/Sendmail.conf
           pwcheck_method:pam
           pam—->/etc/pam.d/smtp.sendmail
                         —->

                          #%PAM-1.0
               auth       required     pam_stack.so service=system-auth
               account    required     pam_stack.so service=system-auth
     为APP提供选择具体的认证方法的机会,认证中介、认证代理….

  • vi命令

    进入vi的命令
    vi filename :打开或新建文件,并将光标置于第一行首
    vi +n filename :打开文件,并将光标置于第n行首
    vi + filename :打开文件,并将光标置于最后一行首
    vi +/pattern filename:打开文件,并将光标置于第一个与pattern匹配的串处
    vi -r filename :在上次正用vi编辑时发生系统崩溃,恢复filename
    vi filename….filename :打开多个文件,依次进行编辑

    移动光标类命令
    h :光标左移一个字符
    l :光标右移一个字符
    space:光标右移一个字符
    Backspace:光标左移一个字符
    k或Ctrl+p:光标上移一行
    j或Ctrl+n :光标下移一行
    Enter :光标下移一行
    w或W :光标右移一个字至字首
    b或B :光标左移一个字至字首
    e或E :光标右移一个字至字尾
    ) :光标移至句尾
    ( :光标移至句首
    }:光标移至段落开头
    {:光标移至段落结尾
    nG:光标移至第n行首
    n+:光标下移n行
    n-:光标上移n行
    n$:光标移至第n行尾
    H :光标移至屏幕顶行
    M :光标移至屏幕中间行
    L :光标移至屏幕最后行
    0:(注意是数字零)光标移至当前行首
    $:光标移至当前行尾

    屏幕翻滚类命令
    Ctrl+u:向文件首翻半屏
    Ctrl+d:向文件尾翻半屏
    Ctrl+f:向文件尾翻一屏
    Ctrl+b;向文件首翻一屏
    nz:将第n行滚至屏幕顶部,不指定n时将当前行滚至屏幕顶部。

    插入文本类命令
    i :在光标前
    I :在当前行首
    a:光标后
    A:在当前行尾
    o:在当前行之下新开一行
    O:在当前行之上新开一行
    r:替换当前字符
    R:替换当前字符及其后的字符,直至按ESC键
    s:从当前光标位置处开始,以输入的文本替代指定数目的字符
    S:删除指定数目的行,并以所输入文本代替之
    ncw或nCW:修改指定数目的字
    nCC:修改指定数目的行

    删除命令
    ndw或ndW:删除光标处开始及其后的n-1个字
    do:删至行首
    d$:删至行尾
    ndd:删除当前行及其后n-1行
    x或X:删除一个字符,x删除光标后的,而X删除光标前的
    Ctrl+u:删除输入方式下所输入的文本

    搜索及替换命令
    /pattern:从光标开始处向文件尾搜索pattern
    ?pattern:从光标开始处向文件首搜索pattern
    n:在同一方向重复上一次搜索命令
    N:在反方向上重复上一次搜索命令
    :s/p1/p2/g:将当前行中所有p1均用p2替代
    :n1,n2s/p1/p2/g:将第n1至n2行中所有p1均用p2替代
    :g/p1/s//p2/g:将文件中所有p1均用p2替换

    选项设置
    all:列出所有选项设置情况
    term:设置终端类型
    ignorance:在搜索中忽略大小写
    list:显示制表位(Ctrl+I)和行尾标志($)
    number:显示行号
    report:显示由面向行的命令修改过的数目
    terse:显示简短的警告信息
    warn:在转到别的文件时若没保存当前文件则显示NO write信息
    nomagic:允许在搜索模式中,使用前面不带“\”的特殊字符
    nowrapscan:禁止vi在搜索到达文件两端时,又从另一端开始
    mesg:允许vi显示其他用户用write写到自己终端上的信息

    最后行方式命令
    :n1,n2 co n3:将n1行到n2行之间的内容拷贝到第n3行下
    :n1,n2 m n3:将n1行到n2行之间的内容移至到第n3行下
    :n1,n2 d :将n1行到n2行之间的内容删除
    :w :保存当前文件
    :e filename:打开文件filename进行编辑
    :x:保存当前文件并退出
    :q:退出vi
    :q!:不保存文件并退出vi
    :!command:执行shell命令command
    :n1,n2 w!command:将文件中n1行至n2行的内容作为command的输入并执行之,若不指定n1,n2,则表示将整个文件内容作为command的输入
    :r!command:将命令command的输出结果放到当前行

    寄存器操作
    “?nyy:将当前行及其下n行的内容保存到寄存器?中,其中?为一个字母,n为一个数字
    “?nyw:将当前行及其下n个字保存到寄存器?中,其中?为一个字母,n为一个数字
    “?nyl:将当前行及其下n个字符保存到寄存器?中,其中?为一个字母,n为一个数字
    “?p:取出寄存器?中的内容并将其放到光标位置处。这里?可以是一个字母,也可以是一个数字
    ndd:将当前行及其下共n行文本删除,并将所删内容放到1号删除寄存器中

    删除全部内容

    :1,$ 转到最后一行

    :1,.d 删除这行以上全部内容

  • ubuntu下架构extmail邮件服务器

    参考
    文库关键词:构建Postfix邮件服务器
    http://blog.thematice.com/html/y2010/03/17/1060/%E6%9E%84%E5%BB%BApostfix%E9%82%AE%E4%BB%B6%E6%9C%8D%E5%8A%A1%E5%99%A8%E4%B8%80lamp%E5%B9%B3%E5%8F%B0%E7%9A%84%E5%AE%89%E8%A3%85.html
    http://man.chinaunix.net/tech/Postfix_I.html
    1.首先,消灭一些专业词汇
    SMTP  (Simple Mail Transfer Protocol)   简单邮件传输协议
    IMAP  (Internet Mail Access Protocol)   交互式邮件存取协议
    POP3  (Post Office Protocol 3)          邮局协议的第3个版本
    MTA(Mail Transfer Agent)邮件传送代理 将来自MUA的信件转发给指定的用户的程序 从客户端软件收信,发信给目的地的其他的MTA
    //邮件服务器软件:eg:Postfix
    MUA(Mail User Agent) 邮件用户代理 用于收发Mail的程序
    //客户端软件:eg:OutLook Express
    MDA(MAIL DELIVERY AGENT)邮件投递代理 从MTA取得邮件并传送至邮件接受者的邮箱 它还可以具有邮件过滤(filtering)与其他相关功能
    //服务器软件:eg:maildrop(支持过滤,自动回复等强大功能)
    2.模拟一下工作流程
    简单图示:邮件服务器-MTA-MDA-MUA
    简单说明:服务器-邮件传输代理-邮件投递代理-客户端接收发送邮件
    简单理解:仓库-DHL快递公司-快递员-客户
    3.下面进行实操
    软件环境:
    操作系统(OS) ubuntu/debian 开源系统
    邮件传输代理(MTA) Postfix 使用最新版本2.5.1
    邮件投递代理(MDA) maildrop 支持过滤和强大功能
    数据库/目录服务 MySQL (可选openLDAP或NetScape LDAP)本文以MySQL为蓝本
    POP3 服务器 Courier-IMAP 只使用pop3部分,对于大部分企业而言完全足够 ( 也可用Cyrus-IMAP做 POP3/IMAP4服务器)
    SMTP认证库 Cyrus SASL 标准的SASL实现库,可以支持Courier authlib(通过Cyrus-SASL对存储在MySQL数据库中的用户进行验证和授权)
    其他数据认证库 Courier Authlib authlib是maildrop, courier-imap等服务的关键部件
    WebMail 系统 ExtMail 支持多语言、全部模板化,功能基本齐全
    ExtMan 帐户管理后台 ExtMan 支持无限域名、无限用户
    防病毒软件 Anti-Virus ClamAV 最热门的开源杀毒软件
    SMTP阶段反垃圾邮件工具 Spam Locker 基于SMTP行为识别的Antispam软件,大量可选插件
    内容过滤器 Amavisd-new Content-Filter软件,支持与clamav/sa的挂接
    内容级别的反垃圾邮件工具 SpamAssassin 著名的SA,可以支持大量规则,但速度慢
    日志分析及显示 mailgraph_ext 在ExtMan中已经包含了
    安装Courier-Authlib
    ape-get install courier-authdaemon courier-authlib-mysql
    配置文件在 /etc/courier/
    启动文件在 /etc/init.d/
    安装Maildrop
    apt-get install maildrop
    gedit /etc/maildropmysql.config //创建一个文件
    问题 Extmail1.1.0 显示:Unix::Syslog not found,
    apt-get install libunix-syslog-perl
    问题 系统信息 显示No such file or directory
    就是没有启动cmdserver造成的, 方法就启动 /var/www/extsuite/extman/daemon/cmdserver -d
    apt-get install
    postfix
    postfix-mysql  //mysql 存储数据
    postfix-doc
    mysql-client
    mysql-server
    courier-authdaemon
    courier-authlib-mysql  SASL2的认证方式就主要是靠courier-authlib来完成
    courier-pop
    courier-pop-ssl
    courier-imap
    courier-imap-ssl
    libsasl2-modules
    libsasl2-modules-sql
    sasl2-bin
    libpam-mysql
    openssl
    phpmyadmin
    apache2
    libapache2-mod-fastcgi
    libfcgi-perl
    libapache2-mod-php5
    php5
    php5-mysql
    build-essential
    libtool
    libnet-server-perl
    libnet-cidr-perl
    libberkeleydb-perl
    arc
    zoo
    lzop
    liblzo1
    libstdc++5
    libgd-gd2-perl
    libfile-tail-perl
    libdigest-sha1-perl
    libdigest-HMAC-perl
    libnet-ip-perl
    libnet-dns-perl
    libhtml-tagset-perl
    libhtml-parser-perl
    libio-stringy-perl
    libio-multiplex-perl
    libio-socket-ssl-perl
    libio-zlib-perl
    libnet-ssleay-perl
    libunix-syslog-perl
    libtimedate-perl
    libmailtools-perl
    libconvert-binhex-perl
    libconvert-tnef-perl
    libconvert-uulib-perl
    libcompress-zlib-perl
    libarchive-zip-perl
    perl-suid
    apache2-suexec
    安装apache fcgilib
    apt-get install apache2-mod-fastcgi libfcgi-perl
    安装posfix
    apt-get purge postfix postfix-mysql postfix-doc
    安装courier-authlib
    apt-get install courier-authdaemon courier-authlib-mysql courier-pop courier-pop-ssl courier-imap courier-imap-ssl
    修改authdaemon socket目录权限
    如果该目录权限不正确修改,maildrop及postfix等将无法正确获取用户的信息及密码认证:
    chmod 755 /var/spool/authdaemon
    重启
    /etc/init.d/apache2 restart
    /etc/init.d/postfix restart
    /etc/init.d/courier-authdaemon restart
    /etc/init.d/courier-imap restart
    /etc/init.d/courier-imap-ssl restart
    /etc/init.d/courier-pop restart
    /etc/init.d/courier-pop-ssl restart
    遇到的问题
    1.不能收信
    日志:Jan  9 12:10:21 testServer postfix/pipe[24667]: D75A442C079: to=<admin@hlg.cc>, relay=maildrop, delay=0.02, delays=0.01/0/0/0.01, dsn=5.1.1, status=bounced (user unknown. Command output: ERR: authdaemon: s_connect() failed: Permission denied Invalid user specified. )
    没有权限去读authdomain的socket文件,修改一下权限
    改变 authdaemon的权限为755   /var/run/courier/authdaemon/
    2.extman后台创建域
    /home/vmail 内没有创建该域目录
    解决办法:权限问题,/var/www/extsuite/extman/webman.cf 中把SYS_DEFAULT_UID = 1000 SYS_DEFAULT_GID = 1000 注释掉
    或者在apache的conf文件中把用户权限加上
    3.smtp 验证不成功
    修改 /etc/postfix/sasl/smtpd.conf

    pwcheck_method: authdaemond
    log_level: 3
    mech_list: PLAIN LOGIN
    authdaemond_path:/var/run/courier/authdaemon/socket

  • Ubuntu上安装 MongoDB,并与php 的链接测试

    MongoDB是一个可扩展、高性能的下一代数据库。MongoDB中的数据以文档形式存储,这样就能在单个数据对象中表示复杂的关系。文档可能由 以下几 部分组成:独立的基本类型属性、“内嵌文档”或文档数组。

    这样的灵活性让开发者能以一种易于管理且灵活的方式来对大量的问题进行建模,不必将数据打散到不同的数据表中。在数据不宜被构造成单独文档的情况 下,MongoDB有“DBRef”的概念,这是从文档的一个属性指向另一个文档的指针。

    从MongoDB数据库中获取和查询数据是十分灵活的——可以基于主文档、文档中的任意属性、任意内嵌文档、数组中的任意文档来动态地查询文档。可 以通过 “点”符号来访问内嵌文档。

    由于Ubuntu 10.04 已经带了MongoDB 1.2.2的源,因此可以直接使用apt-get安装:

    sudo apt-get install mongodb

    在安装MongoDB的时候,系统会安装MongoDB的很多依赖包,安装完成之后,运行MongoDB,会提示:

    mongod: error while loading shared libraries: libmozjs.so: cannot open shared object file: No such file or directory

    解决方法是:

    sudo apt-get install xulrunner-dev

    找到libmozjs.so文件:

    find /usr/lib | grep libmozjs

    可以看到:

    /usr/lib/xulrunner-devel-1.9.2.8/sdk/lib/libmozjs.so

    /usr/lib/xulrunner-1.9.2.8/libmozjs.so

    /usr/lib/firefox-3.6.8/libmozjs.so

    给库做个链接:

    sudo ln -s /usr/lib/xulrunner-1.9.2.8/libmozjs.so /usr/lib

    重启mongodb的服务:

    sudo service mongodb start

    可以确认一下服务是否启动:

    ps aux | grep mongod

    pymongo安装

    由于pymongo采用的是easy_install的模式进行安装的,所以需要先安装setuptools:

    sudo apt-get install python-setuptools

    安装好之后,可以执行安装:

    sudo easy_install pymongo

    注意事项:

    只要 sudo apt-get install mongodb 应该就会装好。

    但是安装得朋友一定都会发现,装起来无法启动无法使用。

    在查找了一些资料后发现:

    这主要的问题在于少了 /usr/lib/libmozjs.so 这个软件库的文件。

    只要你有装 Firefox 或是 另外安装 xulrunner 就应该会有,不过路径是错得。

    所以就要这样:sudo apt-get install xulrunner-1.9.2

    安装好了以后,建立连结。

    ln -s /usr/lib/xulrunner-1.9.2.6/libmozjs.so /usr/lib/libmozjs.so

    然后重新启动 mongodb 试试看,应该就会看到 mongodb 正确启动。

    安装php连接mongo的驱动


    可以到这个链接下载驱动http://github.com/mongodb/mongo-php-driver/downloads

    注意php的版本匹配问题,否则启动apache报错。

    mongoDB 服务端的默认连接端口是 27017

    <?php
    //多个服务器
    $conn = new Mongo(“mongodb://localhost:27017”);
    //选择数据库blog
    $db = $conn->blog;
    //制定结果集(表名:users)
    $collection = $db->users;
    //列出数据库列表
    $dbs = $conn->listDBs();
    echo “<pre>”;
    print_r($dbs);
    echo “</pre>”;
    //新增
    $user = array(‘name’ => ‘caleng’, ’email’ => ‘admin@admin.com’);
    $collection->insert($user);
    //修改
    $newdata = array(‘$set’ => array(“email” => “test@test.com”));
    $collection->update(array(“name” => “caleng”), $newdata);
    //查找
    $cursor = $collection->find();
    echo “<pre>”;
    print_r($cursor);
    echo “</pre>”;
    //查找一条
    $user = $collection->findOne(array(‘name’ => ‘caleng’), array(’email’));
    echo “<pre>”;
    print_r($user);
    echo “</pre>”;
    //删除
    $collection->remove(array(‘name’=>’caleng’), array(“justOne” => true));
    ?>