PHP文件上传时关于open_basedir的报错解决

Standard

PHP Upload files to the virtual host errors:
Warning: move_uploaded_file() [function.move-uploaded-file]: open_basedir restriction in effect. File(/tmp/phpEIjcGh) is not within the allowed path(s): (/usr/local/apache/htdocs/) in /usr/local/apache/htdocs/xxxsite/upload.htm on line 21

Because web users to operate without permission belong to the “root” directory /tmp/

Solution:
Apache virtual server configuration file to add add the follow info:
<Directory “/usr/local/apache/htdocs/xxxsite”>
php_admin_value open_basedir /usr/local/apache/htdocs/xxxsite/:/tmp/
</Directory>

ASP.NET调用DLL范例

Standard
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
'---------------------------------------------
'数据库链接DLL www.yemaosheng.com
'---------------------------------------------
Imports System.Data
Imports System.Data.OleDb
Public Class Conn
    Dim myConnection As OleDbConnection
    Dim myCommand As OleDbCommand
    Dim myDataadapter As SqlDataAdapter
    Dim myDatareader As OleDbDataReader
    Dim myDataset As DataSet
    '连接数据库
    Public Function Conection(ByVal strConn)
        myConnection = New OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA Source=" & strConn)
        myConnection.Open()
    End Function
 
    '执行Select将结果放入DataSet并返回
    Public Function ExecuteToDataAdapter(ByVal strSql, ByVal tb) As DataSet
        myCommand = New SqlCommand(strSql, myConnection)
        myDataadapter = New SqlDataAdapter(myCommand)
        myDataset = New DataSet
        myDataadapter.Fill(myDataset, tb)
        Return myDataset
    End Function
 
    '执行Select语句
    Public Function ExecuteQuery(ByVal strSql) As OleDbDataReader
        myCommand = New OleDbCommand(strSql, myConnection)
        myDatareader = myCommand.ExecuteReader()
        Return myDatareader
    End Function
 
    '执行Update和Insert语句
    Public Function ExecuteUpdate(ByVal strSql)
        myCommand = New OleDbCommand(strSql, myConnection)
        myCommand.ExecuteNonQuery()
    End Function
 
    '关闭数据库连接
    Public Function Close()
        myDatareader.Close()
        myConnection.Close()
        myConnection.Dispose()
    End Function
 
    '判断数据库中的字段是否为空
    Public Function DbLen(ByVal Field As Object) As Integer
        Dim len As Integer
        Dim NewVar As String = ""
        Dim ObjType As Type = Field.GetType()
        If ObjType.FullName = "System.DBNull" Then
            NewVar = Field.Value.ToString
        Else
            NewVar = Field
        End If
        Return NewVar.Length
    End Function
End Class
 
'---------------------------------------------
'aspx调用 www.yemaosheng.com
'---------------------------------------------
<%@ Page Language="VB" Debug="true" %>
<%@ Import Namespace="DBConn" %>
<%@ Import Namespace="System.Data.OleDb" %>
<%@ Import Namespace="System.Data" %>
 
<%
Dim conn As New Conn()
Dim dtr As OleDbDataReader
Dim sql As String
conn.Conection(Request.ServerVariables("APPL_PHYSICAL_PATH") & "common\survey.mdb")
If request.Form("radio_survey")<>"" Then
  sql="UPDATE tb_surveyitem SET surveyitem_item" & request.Form("radio_survey") & "=surveyitem_item" & request.Form("radio_survey") & "+1 WHERE surveyitem_survey=" & request.Form("hidden_surveyid")
  conn.ExecuteUpdate(sql)
End If
dtr=conn.ExecuteQuery("select * from tb_survey,tb_surveyitem where survey_id=surveyitem_survey and survey_id=" & request.Form("hidden_surveyid"))
dtr.Read()
%>
 
  <table width="500" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#333333">
  <tr>
    <td><table width="500" border="0" cellspacing="1" cellpadding"0">
      <tr align="center">
        <td colspan="2" bgcolor="#006699" class="title_text1"><strong><%=dtr("survey_title")%></strong></td>
      </tr>
  <%
    Dim I As Integer
    For I = 1 To 6
      If conn.DbLen(dtr("survey_item" & I & "title")) > 0 then
  %>
      <tr>
        <td width="100" bgcolor="#006699" class="title_text1"><%=dtr("survey_item" & I & "title")%></td>
        <td width="400" bgcolor="#ECF9FF" valign=middle>
        <img src='images/left-line.gif' width='<%=dtr("surveyitem_item" & I)*10%>' height=10>
        </td>
      </tr>
  <%
      End If
    Next
  %>
    </table></td>
  </tr>
</table>
<%
dtr.Close()
conn.Close()
%>
'---------------------------------------------
<TABLE cellSpacing=2 cellPadding=2 width=600 bgColor=#ffffff>
  <TBODY>
    <TR class="content_text1">
      <TD bgColor=#bfd5e3 colSpan=6>招聘信息</TD>
    </TR>
    <%
    Dim conn As New Conn()
    Dim dtr As OleDbDataReader
    conn.Conection(Request.ServerVariables("APPL_PHYSICAL_PATH") & "common\hr.mdb")
    dtr=conn.ExecuteQuery("select * from tb_hr where hr_state=1")
    While dtr.Read()
    %>
          <TR class="content_text1">
            <TD width=10% bgColor=#e9e9e9>职位名称:</TD>
            <TD width=50%><%=dtr("hr_job")%></TD>
            <TD width=10% bgcolor="#E9E9E9">性别要求:</TD>
            <TD width=10%><%=dtr("hr_gender")%></TD>
            <TD width=10% bgcolor="#E9E9E9">招聘人数:</TD>
            <TD width=10%><%=dtr("hr_num")%></TD>
          </TR>
          <TR class="content_text1">
            <TD width=10% valign="top" bgColor=#e9e9e9>职位描述:</TD>
            <TD colspan="5"><%=Replace(dtr("hr_desc"),vbCrLf,"<br>")%></TD>
          </TR>
          <TR class="content_text1">
            <TD bgColor=#bfd5e3 colspan="6"> </TD>
          </TR>
    <%
    End While
    dtr.Close()
    conn.Close()
    %>
  </TBODY>
</TABLE>
'---------------------------------------------
Dim conn As New Conn()
Dim ds As DataSet
Dim dr As DataRow
ds = conn.ExecuteToDataAdapter("select * from tb_board","board")
For Each dr In ds.Tables("board").Rows
    response.write(dr("board_id"))
Next

Awstats日志分析工具的安装配置

Standard

首先将Apache日志设为按天来生成,需用到cronolog.
使用rpm -qa | grep “cronolog”查看当前系统是否已经安装了cronolog,没安装的话就用键入yum install cronolog 进行安装.

然后修改apache虚拟主机中关于日志的配置,将配置文件中的日志格式改为
CustomLog “|/usr/sbin/cronolog /var/log/httpd/xxx.com-access_log.%Y%m%d” combined

重启apache后生效.

下载awstats的rpm包,运行rpm -ivh awstats.rpm进行安装.

运行 perl /usr/local/awstats/tools/awstats_config.pl 按照提示为所要统计的网站进行配置

在/var/lib下面新建awstats目录

在 /etc/cron.daily/ 下面写一个用来每天自动运行并生成静态日志报告的shell,如下:

#!/bin/sh
# Filename : awstats
/usr/local/awstats/tools/awstats_buildstaticpages.pl -update -c.xxx.com -lang=cn -dir=/usr/local/awstats/wwwroot/xxx -awstatsprog=/usr/lib/cgi-bin/awstats.pl

基本完成可以使用

安装GeoIP插件

相关文件下载地址
IP地址对照数据文件( http://www.maxmind.com/download/geoip/database/ )

Geo-IP C-API ( http://www.maxmind.com/download/geoip/api/c/ )
Geo-IP Perl-API ( http://www.maxmind.com/download/geoip/api/perl/ )

安装:
Geo-IP C-API:
#tar xzvf geo-ip-c.tar.gz
#./configure
#make
#make install

Geo-IP Perl-API:
#tar xzvf geo-ip-per.tar.gz
#perl MakeFile.PL
#make
#make install

注:网上的教程有一点都没有写明
我试下来编译完上面那两个库后还需要再用 yum install GeoIP 来安装一下才能正常使用

awstats配置文件修改
LoadPlugin=”tooltips”
LoadPlugin=”decodeutfkeys”
LoadPlugin=”geoip GEOIP_STANDARD /path/GeoIP.dat”
LoadPlugin=”geoip_city_maxmind GEOIP_STANDARD /path/GeoLiteCity.dat”

完成

Linux网卡配置

Standard

1.手动设置
#ifconfig etn0 192.168.1.2,设置网卡IP地址
或直接运行ifconfig,这时候要注意了,在网络接口中有一个lo接口,也就是网络回环(loopback).
再使用ping命令
#ping 192.168.1.2 -c 3
测试3次,看能否正常响应.

2.文件设置
在文件设置里,我们会用到的文件其实只有/etc/sysconfig/network-scrips/ifcfg-ent0,如果连同网关,主机名也一同设置,还会用到/etc/sysconfig/network.
1.设置/etc/sysconfig/network
可以设置主机名称与网关.某些版本无法设置Gateway.
vi /etc/sysconfig/network
NETWORK=yes <===是否启动网络
HOSTNAME=xwg999 <===要确定主机的名称,可以随时修改
2.设置网卡参数/etc/sysconfig/network-scrips/ifcfg-ent0
vi /etc/sysconfig/network-scrips/ifcfg-ent0
DEVICE=eth0 <===设置设备名称,这要跟文件名对应
NOBOOT=yes <===是否在开机的时候启动网卡
BOOTPROTO=static <===启动取得IP的方式这里是固定的,如果是Cable,要改成dhcp
IPADDR=192.168.1.2 <===就是网卡的IP
NETMASK=255.255.255.0 <===子网掩码
NETWORK=192.168.1.0 <===网络所在的网段
BROADCAST=192.168.1.255 <===网段的广播地址
GATEWAY=192.168.1.2 <===网卡的网关
#GATEWAYDEV=eth0 <===网卡的网关的另一种写法
GATEWAY设置的是整个Linux系统的default Gateway, 而不是这块网卡的Gateway.如果系统中有多个网卡,就就是有ifcfg-ent0,ifcfg-ent1,ifcfg-ent2等多个文件,只要在其中之一的文件中设置GATEWAY 就可以了.不用每个文件都设置.如果都设置,可能或发生一些故障与问题.如果您不是使用固定IP做为Gateway,而是使用网络设备做为 Gateway,那可以使用GATEWAYDEV来设置网关设备.

3.启动与关闭网卡
/etc/rc.d/init.d/network restart <===重新启动网络
ifup eth0 <===启动eth0网卡
ifdown eth0 <===关闭eth0网卡

4.检查网卡是否启动
ifconfig eth0
注意:如果先以ifup eth0的方式启动网卡,再以ifconfig修改IP,那么网卡的启动关闭就得使用ifconfig,不能够使用ifdown eth0来关闭,否则回显示找不到网卡的错误信息.
大原则是:先以文件的方式ifcfg-ent0来设置你的网络参数,如果想暂时更改网络参数,可以使用ifconfig进行修改,将来重新开机后,还会以ifcfg-ent0的设置为准.

Linux ACL访问控制表

Standard

setfacl -m <rules> <files>
rules的格式如下,多条规则间可用逗号分隔。
u:uid:perms #为用户设置ACL,perms为r、w、x的组合
g:gid:perms #为组设置ACL
o:perms #为其它组设置ACL
m:perms #设置有效权限屏蔽

[root@local ~]# cd /home/
[root@local home]# mkdir test
[root@local home]# ll
total 12
drwxr-xr-x 2 root root 4096 2007-11-20 10:20 test

此时userman用户操作
[userman@local ~]$ cd /home/ (有权限进入)

[root@local home]# chmod 700 ./test/
[root@local home]# ll
total 12
drwx—— 2 root root 4096 2007-11-20 10:20 test

此时userman用户操作
[userman@local home]$ cd test/
-bash: cd: test/: Permission denied (无权限进入)

[root@local home]# getfacl test/ (查看当前test目录访问权限)
# file: test
# owner: root
# group: root
user::rwx
group::—
other::—
[root@local home]# setfacl -m u:userman:rwx test/ (root为test目录新增userman的读写访问权限)
[root@local home]# getfacl test/ (查看当前test目录访问权限,下面多了一条userman的权限)
# file: test
# owner: root
# group: root
user::rwx
user:userman:rwx
group::—
mask::rwx
other::—

此时userman用户操作
[userman@local ~]$ cd /home/ (有权限进入)

Linux Iptables使用说明

Standard

Iptables [-t TABLE] ACTION [PATTERN] [-j TARGET]

TABLE:
有filter,nat,mangle;若无指定,预设为filter table.

ACTION:
-L Chain 显示Chain中的所有规则
-A Chain 对Chain新增一条规则
-D Chain 删除Chain中的一条规则
-I Chain 在Chain中插入一条规则
-R Chain 替换Chain中的某一条规则
-P Chain 对Chain设定的预设的Policy
-F Chain 清除Chain中的所有规则
-N Chain 自订一个Chain
-X 清除所有的自订Chain

Chain:
Iptables 有五条默认的Chains(规则链),如下表:
PREROUTING 数据包进入本机后,进入Route Table前
INPUT 数据包通过Route Table后,目地为本机
OUTPUT 由本机发出,进入Route Table前
FORWARD 通过Route Table后,目地不是本机时
POSTROUTING 通过Route Table后,送到网卡前

PATTERN(设定条件部份):
-p Protocol 通讯协议,如tcp,udp,icmp,all等。。。
-s Address 指定的Source Address为Address
-d Address 指定的Destination Address为Address
-I Interface 指定数据包进入的网卡
-o Interface 指定数据包输出的网卡
-m Match 指定高级选项,如mac,state,multiport等。。

TARGET(常用的动作):
ACCEPT 让这个数据包通过
DROP 丢弃数据包
RETURN 不作对比直接返回
QUEUE 传给User-Space的应用软件处理这个数据包
SNAT nat专用:转译来源地址
DNAT nat专用:转译目地地址
MASQUERADE nat专用:转译来源地址成为NIC的MAC
REDIRECT nat专用:转送到本机的某个PORT

用/etc/rc.d/init.d/iptables save可在/etc/sysconfig/中产生一iptables文件,大家可以看到,它有三个*号开始的行,其每一个以*号开始的行对应一个table,以COMMIT表示此table 的结束。可将要定的规则加入到对应的table中,如下:
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
COMMIT

linux调整系统时间和时区的方法

Standard

linux调整系统时间和时区的方法

1) 找到相应的时区文件 /usr/share/zoneinfo/Asia/Shanghai

用这个文件替换当前的/etc/localtime文件。

2) 修改/etc/sysconfig/clock文件,修改为:
Z O N E=”Asia/Shanghai”
UTC=false
ARC=false

3)
时间设定成2007年11月13日的命令如下:
#date -s 11/13/2007

将系统时间设定成下午6点38分0秒的命令如下。
#date -s 18:38:00

4)
同步BIOS时钟,强制把系统时间写入CMOS,命令如下:
#clock -w

5)重启。

PS:
把时间及时区调整完后samba service突然莫明奇妙的出问题了,config文件说是被异常关闭过了,害得我又要重新配一次-_-

Winxp上配Apache Mysql PHP及Linux上一些问题的备注

Standard

1.如果PHP5按网上的教程还认不出Mysql Module的话就在Apache的httpd.conf头上加一句”loadfile c:/php/libmysql.dll”

2.如果Apache mod_rewrite.so注释去掉重启后还没能认出网站目录下.htaccess文件的话,记得看一下目录配置中是否为”AllowOverride All”及”Options Indexes FollowSymLinks”

3.如果Mysql开了远程连接用户还连不上的话,记得确认一下是不是自己IP地址打错了,呵呵:)

4.解决PHP Warning: Cannot modify header information – headers already sent by ……打开 php.ini 然后把 output_buffering 设为 on .重起appache,OK.

5.fedora装好后鼠标箭头找不着可以修改/etc/X11/xorg.conf文件,在Section Device 中最后部分 添加Option “HWCursor” “false”后重新启动

6.samba服务配好后在window中可以看到主机及目录但不到登录时就检查SELinux配置

公司考勤系统的数据结构及SQL

Standard

CREATE TABLE IF NOT EXISTS tb_timecard (
timecard_id bigint(20) unsigned NOT NULL auto_increment,
timecard_user int(10) unsigned NOT NULL DEFAULT ” ,
timecard_ip varchar(16) NOT NULL DEFAULT ” ,
timecard_onduty datetime NOT NULL DEFAULT ” ,
timecard_offduty datetime NOT NULL DEFAULT ” ,
timecard_overtime datetime NOT NULL DEFAULT ” ,
timecard_memo tinytext ,
timecard_state tinyint(3) unsigned NOT NULL DEFAULT ‘0’ ,
PRIMARY KEY (timecard_id),
UNIQUE KEY timecard_id (timecard_id),
KEY timecard_id_2 (timecard_id),
KEY idx_datetime (timecard_offduty,timecard_onduty,timecard_overtime),
KEY idx_user (timecard_user)
);
<?php
$sql=”SELECT user_name,timecard_memo,timecard_ip,”;
$sql.=”CASE WHEN DATE_FORMAT(timecard_offduty,’%k:%i’)=’0:00′ “;
$sql.=”THEN “;
$sql.=”IF(DATE_FORMAT(timecard_overtime,’%k:%i’)<>’0:00′,TIME_FORMAT(TIMEDIFF(timecard_overtime,timecard_onduty),’%H:%i’),’00:00′) “;
$sql.=”ELSE TIME_FORMAT(TIMEDIFF(timecard_offduty,timecard_onduty),’%H:%i’) “;
$sql.=”END as t_worktime,”;
$sql.=”DATE_FORMAT(timecard_onduty,’%k:%i’) as t_onduty,”;
$sql.=”IF(DATE_FORMAT(timecard_offduty,’%k:%i’)<>’0:00′,DATE_FORMAT(timecard_offduty,’%k:%i’),”) as t_offduty,”;
$sql.=”IF(DATE_FORMAT(timecard_overtime,’%k:%i’)<>’0:00′,DATE_FORMAT(timecard_overtime,’%k:%i’),”) as t_overtime,”;
$sql.=”IF(DATE_FORMAT(timecard_overtime,’%k:%i’)<>’0:00′,TIME_FORMAT(TIMEDIFF(timecard_overtime,CONCAT(DATE_FORMAT(timecard_onduty,’%Y-%c-%d’),’ 18:00:00′)),’%H:%i’),”) as t_overtimeworktime,”;
$sql.=”DATE_FORMAT(timecard_onduty,’%Y-%m-%d %W’) as t_dateweek “;
$sql.=”FROM tb_timecard “;
$sql.=”INNER JOIN tb_user ON user_id=timecard_user “;
$sql.=”WHERE YEAR(NOW())=YEAR(timecard_onduty) and MONTH(timecard_onduty)=”.$_POST[‘select_month’].” and timecard_user=”.$_POST[‘select_user’].” “;
$sql.=”GROUP BY date_format(timecard_onduty,’%Y-%m-%d’) order by timecard_onduty”;
$result=mysql_query($sql);
while($row=mysql_fetch_array($result))
{
echo “总工作时间:”.$row[‘t_worktime’];
echo “上班考勤时间:”.$row[‘t_onduty’];
echo “下班考勤时间:”.$row[‘t_offduty’];
echo “加班时间:”.$row[‘t_overtimeworktime’];
}
?>

VB.NET更改域用户身份复制文件到域中的共享目录

Standard
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
Imports System.Management
Imports System.Security.Principal
 
Module modTemp
 
  Dim WITH_PROFILE As Integer = 5
  Dim LOGON32_PROVIDER_DEFAULT As Integer = 0
  Dim LOGON32_LOGON_INTERACTIVE As Integer = 2
  Const LOGON32_LOGON_NETWORK As Long = 3
 
  Dim impersonationContext As WindowsImpersonationContext
 
  Declare Function LogonUserA Lib "advapi32.dll" (ByVal lpszUsername As String, _
              ByVal lpszDomain As String, _
              ByVal lpszPassword As String, _
              ByVal dwLogonType As Integer, _
              ByVal dwLogonProvider As Integer, _
              ByRef phToken As IntPtr) As Integer
 
  Declare Auto Function DuplicateToken Lib "advapi32.dll" ( _
              ByVal ExistingTokenHandle As IntPtr, _
              ByVal ImpersonationLevel As Integer, _
              ByRef DuplicateTokenHandle As IntPtr) As Integer
 
  Declare Auto Function RevertToSelf Lib "advapi32.dll" () As Long
  Declare Auto Function CloseHandle Lib "kernel32.dll" (ByVal handle As IntPtr) As Long
 
  Public Function impersonateValidUser(ByVal userName As String, ByVal domain As String, _
  ByVal password As String) As Boolean
 
    Dim tempWindowsIdentity As WindowsIdentity
    Dim token As IntPtr = IntPtr.Zero
    Dim tokenDuplicate As IntPtr = IntPtr.Zero
    impersonateValidUse* = **lse
 
    If RevertToSelf() Then
      If LogonUserA(userName, domain, password, LOGON32_LOGON_INTERACTIVE, _
        LOGON32_PROVIDER_DEFAULT, token) &lt;&gt; 0 Then
        If DuplicateToken(token, 2, tokenDuplicate) &lt;&gt; 0 Then
          tempWindowsIdentity = New WindowsIdentity(tokenDuplicate)
          impersonationContext = tempWindowsIdentity.Impersonate()
          If Not impersonationContext Is Nothing Then
            impersonateValidUser = True
          End If
        End If
      End If
    End If
    If Not tokenDuplicate.Equals(IntPtr.Zero) Then
      CloseHandle(tokenDuplicate)
    End If
    If Not token.Equals(IntPtr.Zero) Then
      CloseHandle(token)
    End If
  End Function
 
  Public Sub undoImpersonation()
    impersonationContext.Undo()
  End Sub
 
End Module
 
  'www.yemaosheng.com
 
  Private Sub btnCopy_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCopy.Click
    If impersonateValidUser("username", "domainname", "password") Then
      Call ToCopyFile()
    Else
      MsgBox("Impersonation failed")
    End If
  End Sub
 
  Private Sub ToCopyFile()
    Try
      Dim strSource As String
      strSource = "C:\Documents and Settings\yemaosheng\桌面\test.txt"
 
      Dim strTarget As String
      strTarget = "\\domain-svr\temp\test_ye.txt"
 
      System.IO.File.Copy(strSource, strTarget, True)
 
    Catch ex A* **ception
      MsgBox(ex.Message.ToString, , "提示")
    End Try
  End Sub