php5中如何编程实现修改 .conf这样的配置文件,并且执行一些FREEBSD下面的命令!

b2sun 2008-07-10 12:17:13
(1)操作系统FREEBSD7.0-RELEASE
(2)WEB SERVER :APACHE22
(3)PHP5
(4)inetd.conf 是系统网络服务的一项配置文件

目标:想对它的内容进行修改.然后执行一些如重新启动这个服务inetd命令的办法.请各位大英雄多多指点.
这个文件的格式是这样的: 有#的表示注释,如果把#去掉,就表示这个服务开启.当然开启要重新启动它的命令.请问如何操作.
----孙立龙敬上----2008年07月
# $FreeBSD: src/etc/inetd.conf,v 1.73 2007/07/05 09:46:53 delphij Exp $
#
# Internet server configuration database
#
# Define *both* IPv4 and IPv6 entries for dual-stack support.
# To disable a service, comment it out by prefixing the line with '#'.
# To enable a service, remove the '#' at the beginning of the line.
#
ftp stream tcp nowait root /usr/libexec/ftpd ftpd -l
ftp stream tcp6 nowait root /usr/libexec/ftpd ftpd -l
#ftp stream tcp nowait root /usr/libexec/lukemftpd ftpd -l -r
#ftp stream tcp6 nowait root /usr/libexec/lukemftpd ftpd -l -r
#ssh stream tcp nowait root /usr/sbin/sshd sshd -i -4
#ssh stream tcp6 nowait root /usr/sbin/sshd sshd -i -6
telnet stream tcp nowait root /usr/libexec/telnetd telnetd
telnet stream tcp6 nowait root /usr/libexec/telnetd telnetd
#shell stream tcp nowait root /usr/libexec/rshd rshd
#shell stream tcp6 nowait root /usr/libexec/rshd rshd
#login stream tcp nowait root /usr/libexec/rlogind rlogind
#login stream tcp6 nowait root /usr/libexec/rlogind rlogind
#finger stream tcp nowait/3/10 nobody /usr/libexec/fingerd fingerd -s
#finger stream tcp6 nowait/3/10 nobody /usr/libexec/fingerd fingerd -s
#
# run comsat as root to be able to print partial mailbox contents w/ biff,
# or use the safer tty:tty to just print that new mail has been received.
#comsat dgram udp wait tty:tty /usr/libexec/comsat comsat
#
# ntalk is required for the 'talk' utility to work correctly
#ntalk dgram udp wait tty:tty /usr/libexec/ntalkd ntalkd
#tftp dgram udp wait root /usr/libexec/tftpd tftpd -l -s /tftpboot
#tftp dgram udp6 wait root /usr/libexec/tftpd tftpd -l -s /tftpboot
#bootps dgram udp wait root /usr/libexec/bootpd bootpd
#
# "Small servers" -- used to be standard on, but we're more conservative
# about things due to Internet security concerns. Only turn on what you
# need.
#
#daytime stream tcp nowait root internal
#daytime stream tcp6 nowait root internal
#daytime dgram udp wait root internal
#daytime dgram udp6 wait root internal
#time stream tcp nowait root internal
#time stream tcp6 nowait root internal
#time dgram udp wait root internal
#time dgram udp6 wait root internal
#echo stream tcp nowait root internal
#echo stream tcp6 nowait root internal
#echo dgram udp wait root internal
#echo dgram udp6 wait root internal
#discard stream tcp nowait root internal
#discard stream tcp6 nowait root internal
#discard dgram udp wait root internal
#discard dgram udp6 wait root internal
#chargen stream tcp nowait root internal
#chargen stream tcp6 nowait root internal
#chargen dgram udp wait root internal
#chargen dgram udp6 wait root internal
#
# CVS servers - for master CVS repositories only! You must set the
# --allow-root path correctly or you open a trivial to exploit but
# deadly security hole.
#
#cvspserver stream tcp nowait root /usr/bin/cvs cvs --allow-root=/your/cvsroot/here pserver
#cvspserver stream tcp nowait root /usr/bin/cvs cvs --allow-root=/your/cvsroot/here kserver
#
# RPC based services (you MUST have rpcbind running to use these)
#
#rstatd/1-3 dgram rpc/udp wait root /usr/libexec/rpc.rstatd rpc.rstatd
#rusersd/1-2 dgram rpc/udp wait root /usr/libexec/rpc.rusersd rpc.rusersd
#walld/1 dgram rpc/udp wait root /usr/libexec/rpc.rwalld rpc.rwalld
#pcnfsd/1-2 dgram rpc/udp wait root /usr/local/libexec/rpc.pcnfsd rpc.pcnfsd
#rquotad/1 dgram rpc/udp wait root /usr/libexec/rpc.rquotad rpc.rquotad
#sprayd/1 dgram rpc/udp wait root /usr/libexec/rpc.sprayd rpc.sprayd
#
# example entry for the optional pop3 server
#
#pop3 stream tcp nowait root /usr/local/libexec/popper popper
#
# example entry for the optional imap4 server
#
#imap4 stream tcp nowait root /usr/local/libexec/imapd imapd
#
# example entry for the optional nntp server
#
#nntp stream tcp nowait news /usr/local/libexec/nntpd nntpd
#
# example entry for the optional uucpd server
#
#uucpd stream tcp nowait root /usr/local/libexec/uucpd uucpd
#
# Return error for all "ident" requests
#
#auth stream tcp nowait root internal
#auth stream tcp6 nowait root internal
#
# Provide internally a real "ident" service which provides ~/.fakeid support,
# provides ~/.noident support, reports UNKNOWN as the operating system type
# and times out after 30 seconds.
#
#auth stream tcp nowait root internal auth -r -f -n -o UNKNOWN -t 30
#auth stream tcp6 nowait root internal auth -r -f -n -o UNKNOWN -t 30
#
# Example entry for an external ident server
#
#auth stream tcp wait root /usr/local/sbin/identd identd -w -t120
#
# Example entry for the optional qmail MTA
# NOTE: This is no longer the correct way to handle incoming SMTP
# connections for qmail. Use tcpserver (http://cr.yp.to/ucspi-tcp.html)
# instead.
#
#smtp stream tcp nowait qmaild /var/qmail/bin/tcp-env tcp-env /var/qmail/bin/qmail-smtpd
#
# Enable the following two entries to enable samba startup from inetd
# (from the Samba documentation). Enable the third entry to enable the swat
# samba configuration tool.
#
#netbios-ssn stream tcp nowait root /usr/local/sbin/smbd smbd
#netbios-ns dgram udp wait root /usr/local/sbin/nmbd nmbd
#swat stream tcp nowait/400 root /usr/local/sbin/swat swat
...全文
303 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
b2sun 2008-08-28
  • 打赏
  • 举报
回复
真是越看越生气。没人会吗???
会的不理我??唔。。。。救命呀???、
b2sun 2008-08-06
  • 打赏
  • 举报
回复
大哥你说的不错,按这个思路就对了,请问可否, 给一些细节实现办法。?
1。php要有权限修改inetd.conf 文件。
文件所属组和apache设置是否一样。默认都是 nobody吧
php是否安全模式运行,能否跨目录操作等。inetd.conf不会在网站目录下把
2。文件内容修改,就是读取后处理字符串,再保存。具体
$word=file('文件路径');foreach($word as $val){
//这样循环出来是文件的一行行内容,看你想怎么改一改,再组合成字符串,最后保存 file_put_contents('文件路径','文件内容');
}
3。php要能执行系统命令。exec(' 重启某服务的 freebsd命令 ');
b2sun 2008-08-06
  • 打赏
  • 举报
回复
楼上各位大哥,我确实是想做一个WEB页面,去修改一个配置文件如inetd.conf然后执行一些命令去启动服务之类,这里不是特指去实现INETD服务。
望大家给我一个实例,用PHP做个页面
去改CONF文件的内容。特定的行及内容。多些了。如果非常详细,我愿意给现金做为回报。如何???
ten789 2008-07-13
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 ten789 的回复:]
LZ想要通过PHP配置虚拟主机?
不如用APACHE的自动虚拟主机
VirtualDocumentRoot "/usr/local/apache/%2+/%1/html"
www.123.com会解析到 /usr/local/apache/123.com/www/html
俺的习惯是这样 呵呵 大部分习惯应该是
VirtualDocumentRoot "/usr/local/apache/%1+/html"
www.123.com /usr/local/apache/www.123.com/html

开通一个虚拟主机 要做的仅仅是建立文件夹 开通FTP帐号 建立MYSQL数据库

对于不存在的目录…
[/Quote]
如果用于开放主机 切忌不能这么干 有跨站攻击风险甚至root帐号泄漏风险

ten789 2008-07-13
  • 打赏
  • 举报
回复
LZ想要通过PHP配置虚拟主机?
不如用APACHE的自动虚拟主机
VirtualDocumentRoot "/usr/local/apache/%2+/%1/html"
www.123.com会解析到 /usr/local/apache/123.com/www/html
俺的习惯是这样 呵呵 大部分习惯应该是
VirtualDocumentRoot "/usr/local/apache/%1+/html"
www.123.com /usr/local/apache/www.123.com/html

开通一个虚拟主机 要做的仅仅是建立文件夹 开通FTP帐号 建立MYSQL数据库

对于不存在的目录会返回404 可以自定义404页面达到要求
b2sun 2008-07-13
  • 打赏
  • 举报
回复
# testoktest 老大,你在吗?
请您 多多指点。就是关于PHP是否有权限修改文件,它是跨目录的,怎么处理呢?从哪设定,望多多指点。
好吗?
b2sun 2008-07-12
  • 打赏
  • 举报
回复
望大哥给向行代码提醒一下吧
b2sun 2008-07-12
  • 打赏
  • 举报
回复
我刚刚进来这里不太知道分是什么意思。如果你要我都给你也可以
比如。CONF中有这样的一行内容
servername www.b2sun.com 80
这时我可以做个页面然后提交这个www.b2sun.com或者是改一下这个地址为:www.csdn.net之类。然后OK确定就重启一下服务(当然不是APACHE服务了),这个服务的方法是:#kldload ftpd 或者是其它的命令。
如果没有这行,我也会追加上去,望楼主大哥多多指点。

羊城绅士敬上
b2sun 2008-07-10
  • 打赏
  • 举报
回复
我是想在网页上做一个能够给用户录入的地方
如:有个[______________]用户可在这里写入IP地址
本机IP:[192.168.111.111]
[确定] [修改] [缺省]这样的按扭.然后点了这些按扭后,就可
执行一些命令,并加载这些配置.如:
#./usr/local/etc/apache22/apachectl restart
执行这这个以后APACHE的配置就可以重新加载并生效.
请大侠们多多关照.给个实际例子
b2sun 2008-07-10
  • 打赏
  • 举报
回复
请问哪位大侠给些实际例子,其实只是操作文件而矣.望多多指教.
在此表示感谢
testoktest 2008-07-10
  • 打赏
  • 举报
回复
分也太少点,总之把
1。php要有权限修改inetd.conf 文件。
文件所属组和apache设置是否一样。默认都是 nobody吧
php是否安全模式运行,能否跨目录操作等。inetd.conf不会在网站目录下把
2。文件内容修改,就是读取后处理字符串,再保存。具体
$word=file('文件路径');foreach($word as $val){
//这样循环出来是文件的一行行内容,看你想怎么改一改,再组合成字符串,最后保存 file_put_contents('文件路径','文件内容');
}
3。php要能执行系统命令。exec(' 重启某服务的 freebsd命令 ');
ten789 2008-07-10
  • 打赏
  • 举报
回复
.conf 就是普通的txt文件 如果做FreeBSD配置文件 慢慢想吧 呵呵 俺也不知道

通过exec system 函数就能执行shell命令了 想干什么干什么 但重启apache失败了怎么办?

LZ想要的东西 WebMin 呵呵 很成熟的Unix WEB管理软件 FreeBSD的ports里有安装

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧