易栈网-膘叔

浏览模式: 标准 | 列表 | 图文

叫卖fans123..com和fans123.net

这两个域名在我身边很久了,当初的一些想法最后都没有做。在征得团队成员的同意后,决定出售这两个域名。

有需要的可以在此留言,或者加我QQ或者MSN等 。。。
QQ:19129540
msn:goukixiao@hotmail.com,学学坏人,用全角,呵呵

Good and Bad PHP Code

Good and Bad PHP Code

by Kevin Yank

The following is republished from the Tech Times #165.

When interviewing a PHP developer candidate for a job at SitePoint, there is one question that I almost always ask, because their answer tells me so much about the kind of programmer they are. Here’s the question: “In your mind, what are the differences between good PHP code and bad PHP code?”

The reason I like this question is because it tests more than just a candidate’s encyclopedic knowledge of PHP’s functions. Zend’s PHP certification does a good job of that (as does the test that Yahoo! issues to applicants for its PHP developer jobs, apparently).

Rather, the answer to this question tells me whether a PHP developer has, for example, experienced the pain of working with poorly-written code inherited from a careless predecessor, and whether he or she will go the extra mile to save the rest of the team from that same pain.

I don’t have a set notion of the perfect answer to the question, but I do know the kinds of things I’m hoping to hear. Just off the top of my head:

Good PHP code should be structured. Long chunks of code can be broken up into functions or methods that achieve sub-tasks with simple code, while non-obvious snippets should be commented to make their meaning plain. As much as possible, you should separate frontend HTML/CSS/JavaScript code from the server-side logic of your applications. PHP’s object oriented programming features give you some especially powerful tools to break up your applications into sensible units.

Good PHP code should be consistent. Whether that means setting rules for the names of variables and functions, adopting standard approaches to recurring tasks like database access and error handling, or simply making sure all of your code is indented the same way, consistency makes your code easier for others to read.

Good PHP code should be portable. PHP has a number of features, such as magic quotes and short tags, that can break fragile code when they are switched on or off. If you know what you’re doing, however, you can write code that works by adapting to its environment.

Good PHP code should be secure. While PHP offers excellent performance and flexibility out of the box, it leaves important issues like security entirely in the hands of the developer. A deep understanding of potential security holes like Cross-Site Scripting (XSS), Cross-Site Request Forgeries (CSRF), code injection vulnerabilities, and character encoding loopholes is essential for a professional PHP developer these days.

Once a candidate has answered this question, I usually have a pretty good idea of whether they’ll be hired or not. Of course, there’s always the possibility that an interviewee simply isn’t able to articulate these types of things, so we also have our candidates sit a PHP developer exam.

Many of the questions in this exam seem straightforward on the surface, but they give candidates plenty of opportunity to show how much they care about the little details.

The following “bad” code is a highly simplified example of the sort of thing we might put in our PHP developer exam. The question might be something like “How would you rewrite this code to make it better?”

<?php
echo("<p>Search results for query: " .
$_GET['query'] . ".</p>");
?>

<?php
echo("<p>Search results for query: " . $_GET['query'] . ".</p>");
?>

The main problem in this code is that the user-submitted value ($_GET['query']) is output directly to the page, resulting in a Cross Site Scripting (XSS) vulnerability. But there are plenty of other ways in which it can be improved.

So, what sort of answer are we hoping for?

Good:

<?php
echo("<p>Search results for query: " .
htmlspecialchars($_GET['query']) . ".</p>");
?>


<?php
echo("<p>Search results for query: " .
htmlspecialchars($_GET['query']) . ".</p>");
?>

This is the least we expect. The XSS vulnerability has been remedied using htmlspecialchars to escape dangerous characters in the submitted value.

Better:

<?php
if (isset($_GET['query']))
{
echo '<p>Search results for query: ',
htmlspecialchars($_GET['query'], ENT_QUOTES), '.</p>';
}
?>


<?php
if (isset($_GET['query'])) {
echo '<p>Search results for query: ',
htmlspecialchars($_GET['query'], ENT_QUOTES), '.</p>';
}
?>

Now this looks like someone we might want to hire:

* The “short” opening PHP tag (<?) has been replaced with the more portable (and XML-friendly) <?php form.
* Before attempting to output the value of $_GET['query'], isset is used to verify that it actually has a value.
* The unnecessary brackets (()) around the value passed to echo have been removed.
* Strings are delimited by single quotes instead of double quotes to avoid the performance hit of PHP searching for variables to interpolate within the strings.
* Rather than using the string concatenation operator (.) to pass a single string to the echo statement, the strings to be output by echo are separated by commas for a tiny performance boost.
* Passing the ENT_QUOTES argument to htmlspecialchars to ensure that single quotes (') are also escaped isn’t strictly necessary in this case, but it’s a good habit to get into.

Somewhat distressingly, the number of PHP developers looking for work that are able to give a fully satisfactory answer to this sort of question—at least here in Melbourne—are few and far between. We spent a good three months interviewing for this latest position before we found someone with whom we were happy!

So, how would you do when asked a question like this one? Are there any factors that make PHP code good or bad that you feel I’ve left out? And what else would you look for in a PHP developer?

JavaScript---Web流程定义工具

JavaScript---Web流程定义工具

用javascript+vml来做工作流,确实是第一次看到,所以我在看到有这个新闻的时候,就觉得特别的吃惊。当年的TRS就是因为有一个activex版的工作流控件的CMS,导致他的价格非常的高,今天能够看到有javascript版的,惊讶是难免的。。。

只是并非所有的机器都支持VML,所以它的适用范围还是有限的,不过,话又说回来,activex也只支持IE,但仍然有那么多人在用。看来,只要是好东西,即使你不跨平台,照样有人用的起劲。

闲话不说了,附上原文网址和他的说明,原文:http://www.cssrain.cn/article.asp?id=1192

开发语言;javascript,html,vml,json,css
功能:
1.环节可用鼠标拖拽
鼠标选中环节后不释放,拖拽鼠标,环节将随鼠标移动,释放鼠标后,环节不再移动。
2.路径的两个端点可以通过鼠标拖拽,改变路径指向的环节
鼠标选中路径的端点后不释放,拖拽鼠标,路径被选中的端点将鼠标移动,在选中的环节释放鼠标后,路径被选中的端点将指向该选中的环节。
3.ctrl+a,全选。
4.按住ctrl,鼠标选中对象,可以多选。
5.delete,删除选中对象。
6.使用鼠标多选
鼠标点击空白处不释放,拖拽鼠标,会出现一个长方形虚框,虚框的范围随着鼠标移动而变化,虚框范围内的对象将被选中。
7.动态添加环节和路径的属性

55aaefff5b3293ce4a92b425e8c1fcc6

由于对这个东西很吃惊,所以,把图片和附件保存到了本地。需要的朋友可以点上面那个网址或者点本文的附件进行下载

(不好意思,刚发现附件有密码,我也不知道是什么密码,有破解软件的朋友只能辛苦一下了,或者去上面的cssrain.cn问站长去吧,我这里仅仅是作个备份)

下午突然不能访问

下午突然不能访问

下午四五点钟的时候,网站突然不能访问,很紧张,呵呵,PING了一下网址,不通,再PING IP地址仍然不通,不知道怎么回事,可能是机房那边出了问题吧。
看来,我真的是得了那种精神病了,对于网络的故障明显比其他人紧张的多。
不过也难怪,毕竟是自己在做的网站,虽然仅仅是博客,但也是自己的一番心血,总归是显得比别人担心的。。。

晚上回到家访问一下,正常了。oh yeah,很开心啊

PHP的XSS攻击过滤函数

PHP的XSS攻击过滤函数

XSS攻击在最近很是流行,往往在某段代码里一不小心就会被人放上XSS攻击的代码,看到国外有人写上了函数,咱也偷偷懒,悄悄的贴上来。。。
原文如下:
The goal of this function is to be a generic function that can be used to parse almost any input and render it XSS safe. For more information on actual XSS attacks, check out http://ha.ckers.org/xss.html. Another excellent site is the XSS Database which details each attack and how it works.

<?php
function RemoveXSS($val) {
// remove all non-printable characters. CR(0a) and LF(0b) and TAB(9) are allowed
// this prevents some character re-spacing such as <java\0script>
// note that you have to handle splits with \n, \r, and \t later since they *are* allowed in some inputs
$val = preg_replace('/([\x00-\x08,\x0b-\x0c,\x0e-\x19])/', '', $val);

// straight replacements, the user should never need these since they're normal characters
// this prevents like <IMG SRC=@avascript:alert('XSS')>
$search = 'abcdefghijklmnopqrstuvwxyz';
$search .= 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
$search .= '1234567890!@#$%^&*()';
$search .= '~`";:?+/={}[]-_|\'\\';
for ($i = 0; $i < strlen($search); $i++) {
// ;? matches the ;, which is optional
// 0{0,7} matches any padded zeros, which are optional and go up to 8 chars

// @ @ search for the hex values
$val = preg_replace('/(&#[xX]0{0,8}'.dechex(ord($search[$i])).';?)/i', $search[$i], $val); // with a ;
// @ @ 0{0,7} matches '0' zero to seven times
$val = preg_replace('/(&#0{0,8}'.ord($search[$i]).';?)/', $search[$i], $val); // with a ;
}

// now the only remaining whitespace attacks are \t, \n, and \r
$ra1 = Array('javascript', 'vbscript', 'expression', 'applet', 'meta', 'xml', 'blink', 'link', 'style', 'script', 'embed', 'object', 'iframe', 'frame', 'frameset', 'ilayer', 'layer', 'bgsound', 'title', 'base');
$ra2 = Array('onabort', 'onactivate', 'onafterprint', 'onafterupdate', 'onbeforeactivate', 'onbeforecopy', 'onbeforecut', 'onbeforedeactivate', 'onbeforeeditfocus', 'onbeforepaste', 'onbeforeprint', 'onbeforeunload', 'onbeforeupdate', 'onblur', 'onbounce', 'oncellchange', 'onchange', 'onclick', 'oncontextmenu', 'oncontrolselect', 'oncopy', 'oncut', 'ondataavailable', 'ondatasetchanged', 'ondatasetcomplete', 'ondblclick', 'ondeactivate', 'ondrag', 'ondragend', 'ondragenter', 'ondragleave', 'ondragover', 'ondragstart', 'ondrop', 'onerror', 'onerrorupdate', 'onfilterchange', 'onfinish', 'onfocus', 'onfocusin', 'onfocusout', 'onhelp', 'onkeydown', 'onkeypress', 'onkeyup', 'onlayoutcomplete', 'onload', 'onlosecapture', 'onmousedown', 'onmouseenter', 'onmouseleave', 'onmousemove', 'onmouseout', 'onmouseover', 'onmouseup', 'onmousewheel', 'onmove', 'onmoveend', 'onmovestart', 'onpaste', 'onpropertychange', 'onreadystatechange', 'onreset', 'onresize', 'onresizeend', 'onresizestart', 'onrowenter', 'onrowexit', 'onrowsdelete', 'onrowsinserted', 'onscroll', 'onselect', 'onselectionchange', 'onselectstart', 'onstart', 'onstop', 'onsubmit', 'onunload');
$ra = array_merge($ra1, $ra2);

$found = true; // keep replacing as long as the previous round replaced something
while ($found == true) {
$val_before = $val;
for ($i = 0; $i < sizeof($ra); $i++) {
$pattern = '/';
for ($j = 0; $j < strlen($ra[$i]); $j++) {
if ($j > 0) {
$pattern .= '(';
$pattern .= '(&#[xX]0{0,8}([9ab]);)';
$pattern .= '|';
$pattern .= '|(&#0{0,8}([9|10|13]);)';
$pattern .= ')*';
}
$pattern .= $ra[$i][$j];
}
$pattern .= '/i';
$replacement = substr($ra[$i], 0, 2).'<x>'.substr($ra[$i], 2); // add in <> to nerf the tag
$val = preg_replace($pattern, $replacement, $val); // filter out the hex tags
if ($val_before == $val) {
// no replacements were made, so exit the loop
$found = false;
}
}
}
return $val;
}

经过这样的过滤后,应该被攻击的机会会少上很多吧?试试看呢?

使用PHP得到所有的HTTP请求头

使用PHP得到所有的HTTP请求头

PHP中一般采用getallheaders来获取头部,但事实上,有些模式下是获取不到的(以前真没有注意过在fastcgi下这个函数不能用,当然我现在也没有测试。是老王说的)

他说:

在PHP里,想要得到所有的HTTP请求头,可以使用getallheaders方法,不过此方法并不是在任何环境下都存在,比如说,你使用fastcgi方式运行PHP的话,就没有这个方法,所以说我们还需要考虑别的方法,幸运的是$_SERVER里有我们想要的东西,它里面键名以HTTP_开头的就是HTTP请求头:

$headers = array();
foreach (
$_SERVER as $key => $value) {
if (
'HTTP_' == substr($key, 0, 5)) {
$headers[str_replace('_', '-', substr($key, 5))] = $value;
}
}


代码很简单,需要说明的是RFC里明确指出了信息头的名字是不区分大小写的。

不过并不是所有的HTTP请求头都是以HTTP_开头的的键的形式存在与$_SERVER里,比如说Authorization,Content-Length,Content-Type就不是这样,所以说为了取得所有的HTTP请求头,还需要加上下面这段代码:

if (isset($_SERVER['PHP_AUTH_DIGEST'])) {
$header['AUTHORIZATION'] = $_SERVER['PHP_AUTH_DIGEST']);
} elseif (isset(
$_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])) {
$header['AUTHORIZATION'] = base64_encode($_SERVER['PHP_AUTH_USER'] . ':' . $_SERVER['PHP_AUTH_PW']));
}
if (isset(
$_SERVER['CONTENT_LENGTH'])) {
$header['CONTENT-LENGTH'] = $_SERVER['CONTENT_LENGTH'];
}
if (isset(
$_SERVER['CONTENT_TYPE'])) {
$header['CONTENT-TYPE'] = $_SERVER['CONTENT_TYPE'];
}


搞定!

网址为:http://hi.baidu.com/thinkinginlamp/blog/item/c0bff01f3beb66f2e1fe0b7e.html

短信价格下来了

短信价格下来了

12月3日消息,据中国新闻网报道,工业和信息化部通知,长期被消费者和业界诟病的短信网间差别定价将被取消,在2009 年1月15日前基于就低不就高原则实行内外网间统一定价。届时起,移动、联通和电信三大运营商的6亿多手机用户间互发国内短信将享有统一的0.1元/条的 价格。

据工信部10月份通信统计月报数据显示,截至10月31日,中国手机用户总数为6.27亿户。目前,除了小灵通外,我国手机用户在同一家运营商的网 络内互发国内短信,费用是0.1元/条,而在不同运营商的网络间发送国内短信时,一般费用为 0.15元/条(移动神州行用户为:网内0.15元/条,网外0.2元/条),实行的是“异网异价”政策。


不过我还是觉得挺为电信惋惜的,刚刚把CDMA搞过来。就给他定下来价格一致了。连价格优势都被扼杀了。真可怜

Jadu: 将 PHP 编译成 .NET

新闻来源:itnews.com.au
内容管理公司 Jadu 最近发布了一个工具,可以让 PHP 和 .NET 这对冤家和平共处。他们开发了一个叫做 Phalanger PHP compiler 的工具,可以将 PHP 程序编译成本地 .NET 程序执行。他们还准备将这一工具开源。


据 Jadu CEO Suraj Kika 介绍,这个工具对 PHP 程序进行编译,编译成 .NET 框架下下的本地程序。比如,你想用 WordPress,但你属于微软阵营,你可以将 WordPress 编译成可执行文件,放到 .NET 中并在 Visual Studio 中针对这个编译过的 WordPress 做进一步开发。

这个工具将为 PHP 和 .NET 开发工程师带来职业上的便利,避免在各自对方的技术领域内再培训。Kika 表示,我们会看到大量 PHP 开发者在微软阵营找到客户群。

Kika 还表示,开源和商业软件之间向来泾渭分明,这一工具将让这两个阵营的开发者走到一起。

本文来源:http://www.itnews.com.au/News/90129,jadu-brings-php-and-net-closer-together.aspx
中文翻译:COMSHARP CMS
膘叔:好妖的功能呀,一直以为PHP要想在windows下独立运行,得使用php GTK的,结果现在居然有人编译成.net,真是心有多大,世界有多大呀

简述虚拟机下三种网络连接方式

简述虚拟机下三种网络连接方式

虚拟机常用的几种网络连接方式分别为Bridge模式、NAT模式、Host-Only模式

Bridge模式(桥模式)
这种模式是在新建虚拟机的时候默认选择的,是将虚拟主机的虚拟网卡桥接到一个Host主机的物理网卡上面,实际上是将Host主机的物理网卡设置为混杂模 式,从而达到侦听多个IP的能力。在这种模式下,虚拟主机的虚拟网卡直接与Host主机的物理网卡所在的网络相连,可以理解为虚拟机和Host主机处于对 等的地位,在网络关系上是平等的,没有谁主谁次、谁前谁后之分。

NAT模式
这种模式下Host主机的“网络连接”中会出现了一个虚拟的网卡VMnet8(默认情况下)。如果你做过2000/2003的NAT服务器的实验就会理 解:Host主机上的VMnet8虚拟网卡就相当于连接到内网的网卡,Host主机上的物理网卡就相当于连接到外网的网卡,而虚拟机本身则相当于运行在内 网上的计算机,虚拟机内的虚拟网卡则独立于Virtual Ethernet Switch(VMnet8)。在这种方式下,VMware自带的DHCP服务会默认地加载到Virtual Ethernet Switch(VMnet8)上,这样虚拟机就可以使用DHCP服务。更为重要的是,VMware自带了NAT服务,提供了从Host主机的VMnet8 虚拟网卡到外网的地址转换。所以这种情况是一个实实在在的NAT服务器在运行,只不过是供虚拟机用的NAT罢了。

Host-Only模式
这种模式是一种封闭的方式,适合在一个独立的环境中进行各种网络实验。这种方式下Host主机的“网络连接”中出现了一个虚拟的网卡VMnet1(默认情 况下)。和NAT唯一的不同的是:此种方式下,没有地址转换服务。因此这种情况下,虚拟机只能访问到主机,这也是Host-Only的名字的意义。默认情 况下该模式也会有一个DHCP服务加载到Virtual Ethernet Switch(VMnet1)上。这样连接到Virtual Ethernet Switch(VMnet1)上的虚拟机仍然可以设置成DHCP,主要是方便系统的配置。

如何优化VMware Server虚拟机系统[值得收藏]

如何优化VMware Server虚拟机系统[值得收藏]

原文来自:http://server.zdnet.com.cn/server/2008/0910/1117939.shtml

我也是在操作vmware server版的时候才找到的此文章,它给我带来了很多思路,比如把网卡改为其他型号的。原来这都是我没有想过的。

  在现实情况中,许多商业程序只能分别在Windows或Linux下运行。那么,如何在同一台主机上运行Windows和Linux两种系统, 以支持尽可能多的应用软件,就成了一个重要的课题。VMware Server虚拟机模拟软件的出现为解决这一问题提供了不错的方法,它可以同时运行Linux和Windows等其它操作系统,且每个操作系统在各自独立 的窗口里运行。

  不过,尽管可以在Windows主机下运行VMware Server,但不推荐这么做——Windows的蓝屏死机会让Windows主机和Linux虚拟机系统同时挂掉,所以我们选择在Linux下运行虚拟 软件。这种模拟能帮助Windows用户容易地过渡到Linux,它让用户在使用新的Linux应用程序时就像在使用熟悉的Windows应用一样,且用 户不需要关心它是运行在Linux下还是Windows下。

  当前,VMware主要有三个版本:VMware Server、VMware Workstation和VMware ACE。VMware Server是免费的,它给Linux提供了多操作系统功能。VMware Workstation和VMware ACE为程序开发人员提供额外功能,例如给一台虚拟机分配多个CPU,给虚拟机设置安全策略。

  主流x86多系统的选择

  虽然在Linux下运行Windows或其它操作系统应用有几种方法,但我觉得VMware Server是最符合我的要求的。当然,所有的模拟软件都会降低性能,并且消耗更多的内存。所以,我的测试系统配备的是Athlon3500+的 CPU,1GB DDR2的内存——VMware在Duron 1800、512M DRAM和3GB的虚拟内存(交换文件)下也能运行得不错;但如果同样是Duron 1800的CPU,只配置1GB的虚拟内存(交换文件),运行起来就不太流畅了。另外,如果有硬件虚拟化支持(如Intel VT和AMD-V)就更好了,但对VMware Server来说这并不是必需的。

  其他几种运行外部操作系统应用的方法及其特性与限制如下表所示:

  Vmware的系统优化

  在不同的Linux版本中安装VMware Server有细微的差别。注意,本文的重点不在于如何安装VMware Server软件,而是要告诉你如何优化系统,使VMware Server更有效地工作。

  首先,我们从http://www.vmware.com/download/server/下载VMware Server(下载时需要提供注册号码),从http://ftp.cvut.cz/VMware/VMware-any-any- update105.tar.gz可以下载各种补丁,包含一些支持VMware Server的内核模块。注意,当运行VMware的配置脚本时,会提示你输入VMware设备的目录名称,把/var/lib/VMware /Virtual Machines改成/var/lib/Virtual_Machines。因为如果有空格,在用命令行应用程序访问时会有很多麻烦。另外,当在虚拟机配 置向导里提示输入虚拟机名称时,也不要带空格,如要用Windows_98代替Windows 98。

  不论VMware虚拟机系统依赖什么配置,运行起来和在物理机器本地运行是一样的。比如,假设USB有问题,则在Windows控制面板里,找到系统、设备,就能看到跟物理机器安装时一样的错误图标。其它如音频、网络、视频以及各类驱动问题也是一样。

  如果你以前安装过VMware Server(你可能只是升级下主机系统或者换个Linux版本),只要把.vmx和.vmdk文件放到相应的地方,如/var/lib/VMware /Virtual_Machines/,然后改变文件的所有者属性和访问权限。从VMware Server控制台选择VM菜单,安装VMware Tools,能提高速度和稳定性,也能让你访问VMware音频和视频驱动。

  虚拟以太网卡的配置

  我们可以通过虚拟以太网卡在虚拟机和主机之间传输文件,系统默认提供的网卡是AMD PCNet PCI网卡,传输速率大约是400Kbps,换成Pro1000的网卡,能提高到3Mbps。VMware Server的虚拟以太网卡在vmx配置文件里就是一行文本,跟实际网卡一样,它也需要驱动程序。如果驱动程序位于C盘下的好几级目录中(如下图),那你 应该创建一个快捷方式放在C盘根目录下,这样安装驱动时就不用找来找去了。

  进入/var/lib/VMware/Virtual_Machine/Windows_98。用一个文本编辑工具打开.vmx文件,在 Ethernet那一节的第一行前插入:ethernet0.virtualDev = e1000。保存文件,退出。然后,启动虚拟机下的Windows系统,做如下操作:

  1. 从开始菜单的设置-系统-设备下删除AMD网络适配器。

  2. 重启虚拟机Windows系统。

  3. 当提示你为一个PCI以太网卡安装驱动时,点取消。

  4. 打开开始菜单-设置-系统-设备,找到那个有问题的网络设备。

  5. 右键单击该网络设备,选择安装驱动。

  6. 选择“从磁盘安装”。

  7. 到你刚刚创建的快捷方式,选择.inf驱动安装文件,点击OK,就会看到一个列表。

  8. 然后选择Intel Pro/1000 MT桌面连接,点OK。

  9. 当提示你要Pro/1000安装包时,选择C盘的快捷方式。当提示需要Windows安装盘时,插入光盘。

  10. 点击完成按钮。

  11. 重启。

  12. 改变网卡设置,选择开始菜单-设置-网络-Intel Pro/1000 MT 桌面连接-属性-高级-连接速度和双工,选择1000Mbps自动协商。

  通过Samba在主机系统和虚拟机系统间共享文件

  通过VMware Server安装虚拟机系统,最大的好处就是可以用传统的Windows应用程序和本地的Linux应用访问同一个文件。因此,在Linux主机系统和 Windows虚拟机系统之间共享文件是必需的。Samba是一组给Windows客户端提供文件和打印机共享服务的程序集合,可以让这些客户端象访问网 络磁盘一样访问Linux文件系统。下面我们给出出一些提示供参考。

  首先,保证系统已经安装Samba。通常是默认安装的,但最好查一查。在下面的Samba配置文件中,“Username”指你的用户 名,Linux主机系统下的用户ID要和Windows虚拟机系统下的一致。这个文件定义了Linux和Windows共享的基本配置。更多的信息,可以 运行如下命令查看Samba的帮助文件:$ man Samba。或者到Samba的网站查看相关文档。

  1)VMware Server的Samba配置

  用root用户打开一个Linux文本编辑工具,把下面的内容保存为文件:/etc/Samba/smb.conf (;表示注释行)

  [global]

  ;General server settings

  netbios name = FC6

  workgroup = workgroup

  wins server = 169.0.0.1

  server string = Samba Server

  printcap name = /etc/printcap

  cups options = raw

  log file = /var/log/Samba/%m.log

  max log size = 50

  socket options = SO_KEEPALIVE TCP_NODELAY IPTOS_LOWDELAY SO_RCVBUF=8192

  ; SO_SNDBUF=8192

  dns proxy = no

  guest ok = yes

  guest account = username

  security = user

  encrypt passwords = yes

  username map = /etc/Samba/smbusers

  smb passwd file = /etc/Samba/smbpasswd

  restrict anonymous = no

  domain master = yes

  preferred master = yes

  max protocol = NT

  acl compatibility = winnt

  ldap ssl = No

  server signing = Auto

  [win]

  path = /home/username/data/

  writeable = yes

  valid users = username

  comment = home

  admin users = username

  browseable = yes

  case sensitive = no

  配置文件中的“path”指你需要共享的Linux目录,也就是你允许Linux和Windows都能访问的文件空间。在Windows虚拟机 系统下访问时,你可以选择“映射到网络驱动器”。这时,你就能看到你在Linux和Windows共享的内容了。刚安装的Windows系统访问 Linux主机系统时,可能会因为Windows安装了防火墙而弹出一个提示框,如下图:

  如图所示(假设本地IP是196.x.x.x范围的),告诉你的防火墙允许NetBIOS访问那个IP:

  2)有用的SAMBA提示

  下面的提示可以帮助你更好的在Linux和Windows共享文件:

  · 在物理主机上运行Windows系统时,不用修改已经共享的目录名称。只把那些非Windows系统不能访问的文件放在Windows驱动器下。

  · 因为你不能在Linux系统下直接访问虚拟机系统下的文件,所以最好把数据文件保存在Linux空间下,然后通过Samba共享给Windows程序用。

  · 在Windows桌面上的快捷方式点击右键,把驱动盘符C改为E,这样你就可以继续使用这些快捷方法

  设置音频

  VMware Server下的虚拟机系统能够处理多媒体内容,并通过声卡播放声音。如果你的主机系统和虚拟机系统都是64位的,可以到Vmware官方网站上下载驱动 (http://download3.vmware.com/software/wkst/vmaudio-5.10.0.350)。下载之后,复制到 Windows文件系统下,安装时跟安装其它音频驱动一样。其它情况需要这样做:

  1. 打开控制面板-设置-系统-声音,安装Windows声音驱动。

  2. 删除所有的音频驱动。

  3. 安装驱动文件。

  4. 重启,在驱动文件里找到系统提示要的.cat文件(或其它配置文件),点击OK。

  5. 播放一个声音文件。

  6. 把KDE的声音管理设置改为“自动检测”,然后告诉它空闲2秒钟后释放资源。

  USB设备配置

  通过VMware Server下的Windows应用可以直接访问打印机、扫描仪或者其它USB设备。如在VMware Server控制台的菜单查找打印机:VM >Removable Devices >USB Controller >printer(如下图)。

  那么,如何在VMware里使用USB打印机呢?其步骤如下:

  1. 打开VMware Server。

  2. 点击Windows标签。

  3. 点击添加设备。

  4. 添加USB控制器。

  5. 启动Windows。

  6. 打开VM工具栏,VM >Removable Devices >USB Devices >[你的打印机名]。

  7. Windows会提示找到新设备,要求你选择一款打印机或者从磁盘安装驱动。插入你的打印机驱动光盘。

  8. 点击OK,能看到一个安装成功的提示窗口。

  9. 打开开始菜单-设置-打印机,就能看到你的打印机了。

  10. 右键打印机图标,选择属性。

  11. 点击“打印测试页”,看看打印机是否打印出来。

  同样,安装扫描仪和其它USB设备也可参考上述步骤。值得一提的是,VMware虚拟USB适配器可以同时使用两个USB设备。安装第二个USB设备时,只要按照上面的步骤到VMware工具栏那一步就可以了。

  另外,一个USB设备可以被Linux主机系统使用,也可以被Windows虚拟机系统使用,你必须确定是哪个系统在使用它。选择菜单VM >Removable Devices >printer在虚拟机Windows系统下禁用打印机,这样主机的Linux系统才能使用它。然后重新插拔一下打印机的USB线。打开打印机管 理器,先停用、再启用一下打印机。

  在主机系统和虚拟机系统之间切换USB打印机,你需要在VMware Server上关闭USB设备,甚至通过重新插拔一下来重启设备,然后打开Linux开始菜单-控制中心,点击外设-打印机,选择相应的打印机菜单,点击 下拉菜单的重启项,重启CUPS Linux打印系统。

  优化VMware Server虚拟机系统的小提示

  下面是我常用到的小提示:

  · 磁盘速度:大多数版本都有调整硬盘速率的选项,借此你可以让硬盘访问速度加倍。

  · 把虚拟硬盘文件(即VMware虚拟机系统的“硬盘”)分割成多个2GB的文件,我发现这样能显著提高访问速率。

  · 一些优化Windows系统的小技巧在虚拟机下也可以用,当然最好安装防火墙和反病毒软件。

  · 如果映射驱动器上的某个程序运行慢或者有问题,可以在Windows虚拟机系统下重新安装试试。我就重新安装过Eudora、MS Office、CorelDRAW和Paint Shop Pro。如果你本地安装的Windows系统在C:Program Files下有程序,也安装到虚拟机的虚拟硬盘上去,不要留在映射驱动器E:(也就是/home/username/win)上。

  最后,值得一提的是,分割虚拟硬盘文件不仅有利于提高访问速率也有利于备份。通过以下命令可以分割虚拟硬盘文件:# VMware-vdiskmanager -r sourceDisk.vmdk -t 3 destinationDisk.vmdk。完成之后,要修改一下访问权限:

  chown username:username *.vm*

  chmod 777 *

  打开原来的.vmx文件,保证里面的硬盘项是指向分割后的文件里的第一个。VMware相关的文件列在/etc/VMware/locations这个文本文件里。

  在Linux主机系统之上通过VMware Server运行Windows虚拟机系统,让用户可以同时使用两个系统。也就是,既可以享受Linux的稳定性和健壮性,又能享受Windows程序的 易用性和通用性。也为现代计算机系统的后续扩展提供了空间。随着Linux程序变得一样易用而功能强大,普通用户也能比较容易的使用Linux程序。