使用新主题了,大家给个意见哈

setsebool

九 20th, 2010

设置一个selinux的布尔值。

 一些常见项:

===ftp===
//If you want to share files anonymously
chcon -R -t public_content_t /var/ftp
//If you want to setup a directory where you can upload files
chcon -t public_content_rw_t /var/ftp/incoming
You must also turn on the boolean allow_ftpd_anon_write
setsebool -P allow_ftpd_anon_write=1
//If you are setting up this machine as a ftpd server and wish to allow users to access their home directorories
setsebool -P ftp_home_dir 1
//If you want to run ftpd as a daemon
setsebool -P ftpd_is_daemon 1
//You can disable SELinux protection for the ftpd daemon
setsebool -P ftpd_disable_trans 1

===httpd===
//If you want a particular domain to write to the public_content_rw_t domain
setsebool -P allow_httpd_anon_write=1
or
setsebool -P allow_httpd_sys_script_anon_write=1
//httpd can be setup to allow cgi scripts to be executed
setsebool -P httpd_enable_cgi 1
//If you want to allow access to users home directories
setsebool -P httpd_enable_homedirs 1
chcon -R -t httpd_sys_content_t ~user/public_html
//httpd is allowed access to the controling terminal
setsebool -P httpd_tty_comm 1
//such that one httpd service can not interfere with another
setsebool -P httpd_unified 0
//loadable modules run under the same context as httpd
setsebool -P httpd_builtin_scripting 0
//httpd scripts are allowed to connect out to the network
setsebool -P httpd_can_network_connect 1
// You can disable suexec transition
setsebool -P httpd_suexec_disable_trans 1
//You can disable SELinux protection for the httpd daemon by executing
setsebool -P httpd_disable_trans 1
service httpd restart

===named===
//If you want to have named update the master zone files
setsebool -P named_write_master_zones 1
//You can disable SELinux protection for the named daemon by executing
setsebool -P named_disable_trans 1
service named restart

===nfs===
//If you want to setup this machine to share nfs partitions read only
setsebool -P nfs_export_all_ro 1
//If you want to share files read/write
setsebool -P nfs_export_all_rw 1
//If you want to use a remote NFS server for the home directories on this machine
setsebool -P use_nfs_home_dirs 1

===samba===
//If you want to share files other than home directorie
chcon -t samba_share_t /directory
//If you want to share files with multiple domains
setsebool -P allow_smbd_anon_write=1
//If you are setting up this machine as a Samba server and wish to share the home directories
setsebool -P samba_enable_home_dirs 1
//If you want to use a remote Samba server for the home directories on this machine
setsebool -P use_samba_home_dirs 1
//You can disable SELinux protection for the samba daemon by executing
setsebool -P smbd_disable_trans 1
service smb restart

===rsync===
//If you want to share files using the rsync daemon
chcon -t public_content_t /directories
//If you want to share files with multiple domains
setsebool -P allow_rsync_anon_write=1
//You can disable SELinux protection for the rsync daemon by executing
setsebool -P rsync_disable_trans 1

===kerberos===
//allow your system to work properly in a Kerberos environment
setsebool -P allow_kerberos 1
//If you are running Kerberos daemons kadmind or krb5kdc
setsebool -P krb5kdc_disable_trans 1
service krb5kdc restart
setsebool -P kadmind_disable_trans 1
service kadmind restart

===nis===
Allow your system to work properly in a NIS environment
setsebool -P allow_ypbind 1

标签:

和web开发相关的几个rfc文档

七 28th, 2010

RFC1867 Form-based File Upload in HTML

RFC1942 HTML Tables

RFC2616 Hypertext Transfer Protocol

RFC2617 HTTP Authentication: Basic and Digest Access Authentication

RFC4229 HTTP Header Field Registrations

标签:

ssh默认用户更改

七 12th, 2010

经常有这样的经历: 在使用ssh连接远程服务器时,如果ssh serverhost会以当前用户去连接,远程的默认登录帐号变成本地的当前用户,修改~/.ssh/config 文件,里面加上

user root

可以更改默认登录帐号为root,省去了必需指定用户登录方式(root@serverhost)的麻烦

标签:

linux下lftp工具使用

六 29th, 2010

有时候需要在linux下批量上传一些文件或整个目录到远程FTP,由于ftp本身不支持整个目录的上传,因此可以使用lftp
用法如下
lftp ftp://username:password@somehost
登录后进入lftp提示符下
常见系统命令ls rm mkdir等都可在这使用
上传目录可用
mirror -R [remote] [local]
批量下载可用mget
批量上传可用mput
具体用法及其它指令可用help查看

标签:

mysql中使用外键约束(constraint)或触发器(trigger)来进行级联更新、删除

六 9th, 2010

今天在帮同事解决一个关联更新问题时,阅读了下手册,整理下外键约束及trigger的知识,备用=)

我们通常有这样的需求:删除表Table 1中记录,需要同时删除其它表中与Table 1有关的若干记录。

举个例子:
现有2个实体- 学生、课程,1种联系- 成绩
分别创建 学生表 students, 课程表course,成绩表score

--创建 学生表 students
CREATE TABLE IF NOT EXISTS `students` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(32) DEFAULT '',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB;
 
--插入若干记录
INSERT INTO `students` (`id`, `name`) VALUES
(1, 'john'),
(2, 'lucy'),
(4, 'jack');
 
--创建课程表
CREATE TABLE IF NOT EXISTS `course` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(32) DEFAULT '',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB;
 
-- 插入数据若干
INSERT INTO `course` (`id`, `name`) VALUES
(1, 'english'),
(2, 'chinese'),
(3, 'math');
 
--创建成绩表
--sid 学生id
--cid 课程id
CREATE TABLE IF NOT EXISTS `score` (
  `sid` int(11) DEFAULT '0',
  `cid` int(11) DEFAULT '0',
  `score` float(6,2) DEFAULT '0.00',
  KEY `sid` (`sid`),
  KEY `cid` (`cid`)
) ENGINE=InnoDB;
 
--插入若干数据
INSERT INTO `score` (`sid`, `cid`, `score`) VALUES
(1, 2, 95.00),
(1, 3, 65.00),
(2, 1, 77.00),
(2, 2, 68.50),
(2, 3, 89.00);

现在,我希望:
删除students表记录的同时,自动删除成绩表中该同学的记录
删除course表记录的同时,自动删除成绩表中该课程的记录

我想到的做法有二:

一,使用innodb表的外键约束

ALTER TABLE `score`
ADD CONSTRAINT `student_ibfk1`
FOREIGN KEY `sid`(`sid`) REFERENCES `students` (`id`)
ON DELETE CASCADE ON UPDATE CASCADE;

这里CASCADE作用就是在父表记录更新或删除时,子表更新或删除相应的记录
外键约束的动作除了CASCADE,还有RESTRICT(限制删除)SET NULL(设为空值,字段如果允许为空的话)等
外键约束文档详见:http://dev.mysql.com/doc/refman/5.0/en/innodb-foreign-key-constraints.html

二,使用触发器trigger进行操作

由于外键约束只能用于Innodb型表,因些对于MyIsam型表还得用trigger来进行更新

--以下触发器在删除students后同时删除表score中相关记录
DROP TRIGGER IF EXISTS `deleteScore`//
CREATE TRIGGER `deleteScore` AFTER DELETE ON `students`
 FOR EACH ROW BEGIN
DELETE FROM score WHERE sid=OLD.`id`;
END
//

触发器比较好理解,其中AFTER是事件发生后,有的需求可能用BEFORE;事件类型有INSERT,REPLACE,UPDATE,DELETE等
这里的”//”是delimiter,用来标记触发器开始与结束
trigger参考文档详见http://dev.mysql.com/doc/refman/5.0/en/create-trigger.html

标签:

mysql table status 如:取最近更新时间

四 8th, 2010

$conn = mysql_connect();
$sql = “SHOW TABLE STATUS FROM `DATABASE` WHERE `Name` = ‘TABLE”;
$rs = mysql_query($sql,$conn);
while($row = mysql_fetch_object($rs)) $updatetime = $row->Update_time;
print_r($updatetime);

标签:

查看apache安装了哪些模块

三 24th, 2010

apache支持-t -D参数查看所安装的模块
apachectl -t -D DUMP_MODULES

core_module (static)
authn_file_module (static)
authn_default_module (static)
authz_host_module (static)
authz_groupfile_module (static)
authz_user_module (static)
authz_default_module (static)
auth_basic_module (static)
include_module (static)
filter_module (static)
log_config_module (static)
env_module (static)
expires_module (static)
setenvif_module (static)
proxy_module (static)
……

标签:

恶搞版《楼市春晚》视频

三 3rd, 2010

标签:

linux下批量正则查找替换文本文件内容

三 2nd, 2010
find -name '*.html' | xargs perl -pi -e 's|href="(.*\.html)"|href="/html/$1"|g'

如上所示为我在所有形如xxx.html前加上/html/
正则查找,非常灵活方便。留帖备忘

标签: ,

支持ie6 ie7 ie8 firefox的javascript添加至收藏夹代码

三 2nd, 2010
function addfavor(url,title) {
    if(confirm('确定添加收藏?')){
        var ua = navigator.userAgent.toLowerCase();
        if(ua.indexOf("msie 8")>-1){
            external.AddToFavoritesBar(url,title,'slice');//IE8
        }else{
            try {
                window.external.addFavorite(url, title);
            } catch(e) {
                try {
                    window.sidebar.addPanel(title, url, "");//firefox
                } catch(e) {
                    alert("加入收藏失败,请使用Ctrl+D进行添加");
                }
            }
        }
    }
    return false;
}
标签: