29 3 月 2014

Ebury 侵入 SSH 导致中毒

在 v2ex上看到的

侵入了 SSH 服务器,会开后门,偷走所有经过本机的 SSH 用户名密码、密钥等
在本机运行ipcs -m,如果发现666权限,超过3M的空间那就是中毒了
介绍里还有一句很重要:
The network of cPanel Inc.’s support department was compromised and machines used for connecting to customers’ servers were found to be infected with Ebury [3].

赶紧检查了一下自己的,显示如下:

1
2
3
~ ipcs -m
------ Shared Memory Segments --------
key shmid owner perms bytes nattch status

如果显示是空的,那么就没中招;大于26k 且666权限的基本就是中招了。

20 3 月 2014

jQuery动态改变图片显示大小

当我们要显示后台传过来若干个尺寸不一的图片时,为了保证图片大小的一致性及比例的协调,需要动态改变图片显示尺寸。通过搜索,我们可以从网上找到实现此功能的jQuery代码如下。这段代码可以使图片的大小保持在一定范围内,如果图片的原始尺寸都大于max*值,则显示出来的图片宽度都相等。

原始代码:

 

01 $(document).ready(function() {
02      $('.post img').each(function() {
03      var maxWidth = 100; // 图片最大宽度
04      var maxHeight = 100;    // 图片最大高度
05      var ratio = 0;  // 缩放比例
06      var width = $(this).width();    // 图片实际宽度
07      var height = $(this).height();  // 图片实际高度
08   
09      // 检查图片是否超宽
10      if(width > maxWidth){
11          ratio = maxWidth / width;   // 计算缩放比例
12          $(this).css("width", maxWidth); // 设定实际显示宽度
13          height = height * ratio;    // 计算等比例缩放后的高度
14          $(this).css("height", height);  // 设定等比例缩放后的高度
15      }
16   
17      // 检查图片是否超高
18      if(height > maxHeight){
19          ratio = maxHeight / height; // 计算缩放比例
20          $(this).css("height", maxHeight);   // 设定实际显示高度
21          width = width * ratio;    // 计算等比例缩放后的高度
22          $(this).css("width", width * ratio);    // 设定等比例缩放后的高度
23      }
24  });
25  });

 

在我的js代码中,也采取了这种写法。然而在不同的浏览器测试效果时,发现此种写法不能适应chrome浏览器(chrome版本号为10.0.648.204),会产生图片以原有尺寸显示出来的bug。后来把$(‘.post img’).each()的代码用$(window).load()方法包装起来,就解决了chrome浏览器显示不正确的问题。那么在chrome浏览器中为什么会产生bug,并且$(document).ready和$(window).load有什么区别呢?

 

原来document ready事件是在HTML文档载入即DOM准备好就开始执行了,即使图片资源还没有加载进来。而window load事件执行的稍晚一些,它是在整个页面包括frames, objects和images都加载完成后才开始执行的。从这种区别可以分析出chrome浏览器在对于图片不采用$(window).load()方法处理时,图片载入与动态改变图片的js代码执行顺序不确定。

关于上面的代码,放到我的页面中时获取图片高度时会报错,提示没有提供width方法:

 

1 var width = $(this).width();    // 图片实际宽度
2 var height = $(this).height();  // 图片实际高度

 

故修改代码如下:

 

01 jQuery(window).load(function () {
02             jQuery("div.product_info img").each(function () {
03                 DrawImage(this, 680, 1000);
04             });
05         });
06         function DrawImage(ImgD, FitWidth, FitHeight) {
07             var image = new Image();
08             image.src = ImgD.src;
09             if (image.width > 0 && image.height > 0) {
10                 if (image.width / image.height >= FitWidth / FitHeight) {
11                     if (image.width > FitWidth) {
12                         ImgD.width = FitWidth;
13                         ImgD.height = (image.height * FitWidth) / image.width;
14                     else {
15                         ImgD.width = image.width;
16                         ImgD.height = image.height;
17                     }
18                 else {
19                     if (image.height > FitHeight) {
20                         ImgD.height = FitHeight;
21                         ImgD.width = (image.width * FitHeight) / image.height;
22                     else {
23                         ImgD.width = image.width;
24                         ImgD.height = image.height;
25                     }
26                 }
27             }
28         } 
20 3 月 2014

Eclipse出现failed to create the java virtual machine

有时候重装系统之后会发现eclipse很意外的打不开,出现failed to create the java virtual machine的这种情况

 

“failed to create the java virtual machine”

对于这种情况的解决方法很简单,原因是计算机的内存不足。可以通过修改eclipse的配置文件来解决这种情况~

首先进入到eclipse的安装文件夹,打开 eclipse,ini 文件,找到–launcher.XXMaxPermSize  256M  将256M改成128M即可以正常打开eclipse了(注:一共有两处,两处都要修改!!)

 

修改后的文件如下所示:
-startup
plugins/org.eclipse.equinox.launcher_1.1.0.v20100507.jar
–launcher.library
plugins/org.eclipse.equinox.launcher.win32.win32.x86_1.1.0.v20100503
-product
org.eclipse.epp.package.jee.product
–launcher.defaultAction
openFile
–launcher.XXMaxPermSize
128M
-showsplash
org.eclipse.platform
–launcher.XXMaxPermSize
128m
–launcher.defaultAction
openFile
-vmargs
-Dosgi.requiredJavaVersion=1.5
-Xms40m
-Xmx512m

 

源文件如下:
-startup
plugins/org.eclipse.equinox.launcher_1.1.0.v20100507.jar
–launcher.library
plugins/org.eclipse.equinox.launcher.win32.win32.x86_1.1.0.v20100503
-product
org.eclipse.epp.package.jee.product
–launcher.defaultAction
openFile
–launcher.XXMaxPermSize
256M
-showsplash
org.eclipse.platform
–launcher.XXMaxPermSize
256m
–launcher.defaultAction
openFile
-vmargs
-Dosgi.requiredJavaVersion=1.5
-Xms40m
-Xmx512m

17 3 月 2014

debian32位小内存精简教程

很多好友买了3.99刀的小内存vps,下面介绍下~怎么最优化使用

系统只能安装debian32,因为这是最省资源的

 

下面上脚本

先在机器下载脚本

wget http://linux-bash.googlecode.com/files/debian-actgod-vps.sh

通过下面一键安装命令安装自己需要的功能:

bash debian-actgod-vps.sh system #优化系统,删除不需要组件,dropbear替代sshd
bash debian-actgod-vps.sh exim4 #更轻量级邮件系统
bash debian-actgod-vps.sh mysql #安装mysql
bash debian-actgod-vps.sh nginx #安装nginx,默认两个进程
bash debian-actgod-vps.sh php #安装php,默认两个php-cgi进程
bash debian-actgod-vps.sh all #安装上面所有,软件是debian官方的,版本较低但也很好
bash debian-actgod-vps.sh update #升级最新稳定版,如nginx是0.8.53版,不升级是0.6版
bash debian-actgod-vps.sh wordpress yourdomain #一键安装wordpress中文版。数据库自动配置好。
bash debian-actgod-vps.sh vhost yourdomain #一键安装虚拟主机。适合静态站和自行上传网站程序
bash debian-actgod-vps.sh typecho yourdomain #安装typecho,提供数据库名,密码等自主添加完成安装
bash debian-actgod-vps.sh wordpressen yourdomain # 一键安装wordpress英文版。数据库自动配置好。
bash debian-actgod-vps.sh phpmyadmin yourdomain #一键安装phpmyadmin 数据库管理软件
bash debian-actgod-vps.sh http port #生成一个http代理,port是端口号,大于1000小于65535
bash debian-actgod-vps.sh ssh 用户名 密码 #生成仅供ssh代理上网,不能登录shell进行vps操作的帐号
bash debian-actgod-vps.sh addnginx 3 #调整nginx进程数,3表示调整后的进程数,请根据vps配置更改
bash debian-actgod-vps.sh addphp 3 #调整php-cgi进程,这里3表示调整后的进程数,请根据vps配置更改

比如,你不需要其他功能,直接 bash debian-actgod-vps.sh system

友情提示:精简结束后,请重启(因为上述编译会带大了内存)

15 3 月 2014

wp评论邮件通知代码+漂亮的评论样式

先谢豆腐同学,豆腐君的博客

<?php
// 评论回应邮件通知
function comment_mail_notify($comment_id) {
$admin_notify = ‘1’; // admin 要不要收回复通知 ( ‘1’=要 ; ‘0’=不要 )
$admin_email = get_bloginfo (‘admin_email’); // $admin_email 可改为你指定的 e-mail.
$comment = get_comment($comment_id);
$comment_author_email = trim($comment->comment_author_email);
$parent_id = $comment->comment_parent ? $comment->comment_parent : ”;
global $wpdb;
if ($wpdb->query(“Describe {$wpdb->comments} comment_mail_notify”) == ”)
$wpdb->query(“ALTER TABLE {$wpdb->comments} ADD COLUMN comment_mail_notify TINYINT NOT NULL DEFAULT 0;”);
if (($comment_author_email != $admin_email && isset($_POST[‘comment_mail_notify’])) || ($comment_author_email == $admin_email && $admin_notify == ‘1’))
$wpdb->query(“UPDATE {$wpdb->comments} SET comment_mail_notify=’1′ WHERE comment_ID=’$comment_id'”);
$notify = $parent_id ? get_comment($parent_id)->comment_mail_notify : ‘0’;
$spam_confirmed = $comment->comment_approved;
if ($parent_id != ” && $spam_confirmed != ‘spam’ && $notify == ‘1’) {
$wp_email = ‘no-reply@’ . preg_replace(‘#^www.#’, ”, strtolower($_SERVER[‘SERVER_NAME’])); // e-mail 发出点, no-reply 可改为可用的 e-mail.
$to = trim(get_comment($parent_id)->comment_author_email);
$subject = ‘您在 [‘ . get_option(“blogname”) . ‘] 的留言有了新回复’;
$message = ‘
<div style=”background:#fff;zoom:1;position:relative;z-index:1;margin:50px auto;”><table width=”556″cellspacing=”0″cellpadding=”0″border=”0″align=”center”style=”margin: 0 auto; font: normal 12px/1 微软雅黑,Tahoma,Helvetica,Arial,sans-serif; background: #fff; line-height: 20px;”><tbody><tr><td height=”115″background=”http://aapple-code.qiniudn.com/header.jpg”><div style=”padding: 0 30px 40px;”><h2 style=”color:#fff;font-size:14px;font-weight:normal;padding:0;”><span style=”color: #ED5224″>&gt;&nbsp;</span>您在&nbsp;<a style=”text-decoration:none;color: #ED5224;”href=”‘ . get_option(‘home’) . ‘”title=”‘ . get_option(‘blogname’) . ‘”target=”_blank”>’ . get_option(‘blogname’) . ‘</a>&nbsp;中的留言有回复啦!</h2></div></td></tr><tr><td valign=”top”background=”http://aapple-code.qiniudn.com/body.jpg”style=”padding: 0 25px;”><table width=”100%”><tbody><tr><td><div style=”font-size:12px;color:#777;padding:0px 6px 1px;”>’ . trim(get_comment($parent_id)->comment_author) . ‘&nbsp;您曾在本站文章「&nbsp;’
. get_the_title($comment->comment_post_ID) . ‘&nbsp;」中发表留言:</p><p style=”color: #777;border: 1px solid #DDD;padding: 5px 8px 5px 8px;background-color: #FCFCFC;border-radius: 3px 3px 3px 3px;font-size: 12px;line-height: 22px;font-family: Consolas,Courier,minispace,Lucida Console;”>’ . nl2br(get_comment($parent_id)->comment_content) . ‘</p><p>「’ . trim($comment->comment_author) . ‘」&nbsp;給您的回复如下:</p><p style=”color: #777;border: 1px solid #DDD;padding: 5px 8px 5px 8px;background-color: #FCFCFC;border-radius: 3px 3px 3px 3px;font-size: 12px;line-height: 22px;font-family: Consolas,Courier,minispace,Lucida Console;”>’ . nl2br($comment->comment_content) . ‘</p><p>您可以点击「&nbsp;<a style=”text-decoration:none; color:#12addb”href=”‘ . htmlspecialchars(get_comment_link($parent_id)) . ‘”title=”单击查看回复的完整內容”target=”_blank”>&nbsp;查看回复的完整內容</a>」,欢迎再次光临&nbsp;「<a style=”text-decoration:none; color:#12addb”href=”‘ . get_option(‘home’) . ‘”title=”‘ . get_option(‘blogname’) . ‘”target=”_blank”>’ . get_option(‘blogname’) . ‘</a>」&nbsp;!</p></div></td></tr></tbody></table></td></tr><tr><td height=”15″background=”http://aapple-code.qiniudn.com/footer.jpg”></td></tr></tbody></table></div>’;
$from = “From: “” . get_option(‘blogname’) . “” <$wp_email>”;
$headers = “$fromnContent-Type: text/html; charset=” . get_option(‘blog_charset’) . “n”;
wp_mail( $to, $subject, $message, $headers );
//echo ‘mail to ‘, $to, ‘<br/> ‘ , $subject, $message; // for testing
}
}
add_action(‘comment_post’, ‘comment_mail_notify’);
// 自动勾选
function add_checkbox() {
echo ‘<input type=”checkbox” name=”comment_mail_notify” id=”comment_mail_notify” value=”comment_mail_notify” checked=”checked” style=”margin-left:0px;” /><label for=”comment_mail_notify”>有人回复时邮件通知我</label>’;
}
add_action(‘comment_form’, ‘add_checkbox’);
?>

这是豆腐的评论邮件样式.

使用方法:在主题的function.php中添加~(如果已经有这个类函数~请删除掉~)

 

这个样式超漂亮~如果谁有兴趣,去豆腐博客里评论下,他回复你~就可以看到啦~~~

14 3 月 2014

定时自动备份WordPress数据库的N种方法

1.WordPress Database Backup

这货是一个WordPress插件,插件下载地址:http://wordpress.org/plugins/wp-db-backup/,也可以直接在wp后台搜索WP-DB-Backup 安装

界面还算简单,可以立即备份或者定时备份,可以将备份定时发到邮箱,但是据说有时候这货会漏备份,博主在使用这款插件,有几天确实是没有备份。。。。

2.WP-DBManager

这货也是WordPress插件,但是功能不仅限于备份,它可以管理数据库、优化、修复、清空、甚至是执行sql语句,功能强大

2.5中文版下载:  http://pan.baidu.com/s/1gdDVrTx

2.65英文版下载:http://wordpress.org/plugins/wp-dbmanager/

3.WP2PCS

这也是WordPress插件。。。。但是可以备份网站文件+数据库到百度网盘,还可以把网站附件放到百度网盘~2TB这下不愁用不完了哈哈

官方项目地址:http://wp2pcs.duapp.com/

插件下载地址:http://wordpress.org/plugins/wp2pcs/

4.BACKWPUP

也是WP插件。。。。可以备份网站文件+数据库,可以将备份文件存储到本地文件夹、远程FTP、Amazon S3、RackSpaceClous以及通过电子邮件发送

插件下载地址:http://wordpress.org/plugins/backwpup/

5.多备份

这次终于不是插件了,多备份已经有很多博客介绍了,可以绑定百度盘等常用网盘,并且自己也提供512MB空间用于备份存储

可以通过FTP备份、通过php插件打包+连接MySQl备份、通过远程直接访问数据库备份

虽然网站看着有点不靠谱,但是备份了的文件是AES加密的,安全性值得信赖,做个备用的备份也好

官网地址:http://www.dbfen.com

6.小结

本站目前使用了七牛云存储存放附件,所以网站文件几乎是不需要备份了,不过博主偶尔还是会备份下的~

博主目前使用WordPress Database Backup每日备份并发送到邮箱并且同时使用多备份远程备份数据库到百度网盘,另外。。博主的主机商有每日两组离岸自动备份以及SAN离机备份,怎么样~

最后补上一句:数据无价,谨慎对待!

 

转自:http://www.geekzu.me/archives/auto-backup-wordpress.html