2012年8月9日木曜日

login

★express:http://hideyukisaito.github.com/expressjs-doc_ja/guide/
★node-メソッドの変更:http://dameninngenn.sblo.jp/article/43982874.html
★POSTの問題:http://havelog.ayumusato.com/develop/javascript/e214-express_post_params.html
=>ぶっちゃけ、app.useとかの定義をPOSTのやつより先に書いて(移動して)やったら普通に動いた。
★res.session:http://memo.yomukaku.net/entries/280

(☆動画アップロード:http://blog.fukaoi.org/2012/02/01/node-video-upload)
(★すクリーピングhttp://shimz.me/blog/?p=19)



connection.query('SELECT * FROM login',function(err,results,fields){
        if (err) throw err;
        console.log('Query result:',results);
        console.log('なんでも:',results[0].id);
        console.log('test1:',results[0].password);
});
この
resultsは全件持ってる。
results[0].idで、0件目のidに関して取ってくる。

また、変数の代入は
var id = results[0].id
と、”=”でいける。


----
ー「amidn追加時」
md5
https://github.com/pvorb/node-md5

【インストール】
npm install MD5
*Enderは謎。(ender build MD5)
【使い方】(公式に書いてるまんま)

var md5 = require('MD5');

console.log(md5("message"));

 This will print:
78e731027d8fd50ed642340b7c9a63b3


-----------------------------------------------------
Error: listen EADDRINUSE
ー別プロセスで、同じものが走ってる。


node+mysql


/**
 * Mysql
 * 公式(mysql@2.0.0-alpha3)
 */
var mysql = require('mysql');
var connection = mysql.createConnection({
        host:'localhost',
        user:'root',
        password:'',
        database:'node'
});
connection.connect();

connection.query('SELECT * FROM login',function(err,results,fields){
        if (err) throw err;
        console.log('Query result:',results);
});
//connection.end();
--------------------------------------------------------------------
公式だと、https://github.com/felixge/node-mysql/

var mysql      = require('mysql');
var connection = mysql.createConnection({
  host     : 'localhost',
  user     : 'me',
  password : 'secret',
});

connection.connect();

connection.query('SELECT 1', function(err, rows, fields) {
  if (err) throw err;

  console.log('Query result: ', rows);
});

connection.end();

だけど、使うDBをvar connectioの中に書いてやって、クエリの発行connection.queryのSELECT 1に使いたいクエリの発行、(ここではSELECT * FROM login)をかいてヤル。


ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー

/*ブログあたり(mysqlのvesion不明。)*versionあげたら動かなくなった:"has no method 'createClient'"
var mysqlConfig = {'host':'localhost','user':'root','password':'','database':'node'};
var mysqlClient = mysql.createClient(mysqlConfig);
global['mysqlClient'] = mysqlClient;

var Client = mysql.createClient({user:'root', password:''});
Client.query('use node');

Client.query('select * from node',function myCallback(err,result,fields){
        console.log(result);
});
*/

TABLE


DROP TABLE login;

SHOW TABLES;

CREATE TABLE login(
id VARCHAR(50) NOT NULL,
password VARCHAR(20) NOT NULL
);


SHOW TABLES;

DESC login;

INSERT INTO login(id,password)
VALUES ('jk','junichi');

謎のメール


mysql> :q
    -> \q
Bye
新しいメールが /var/spool/mail/root にあります
[root@host1 app1]# cat /var/spool/mail/root                              
From root@host1.localdomain  Wed Aug  1 17:43:05 2012
Return-Path: <root@host1.localdomain>
X-Original-To: root
Delivered-To: root@host1.localdomain
Received: by host1.localdomain (Postfix, from userid 0)
        id 74A0611D0; Wed,  1 Aug 2012 17:43:05 +0900 (JST)
Date: Wed, 01 Aug 2012 17:43:04 +0900
To: root@host1.localdomain
Subject: YUM:host1:2012-08-01
User-Agent: Heirloom mailx 12.4 7/29/08
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Message-Id: <20120801084305.74A0611D0@host1.localdomain>
From: root@host1.localdomain (root)

 --------------------
 YUM - security
 --------------------
Error: Cannot retrieve repository metadata (repomd.xml) for repository: sl. Please verify its path and try again


From root@host1.localdomain  Mon Aug  6 11:13:52 2012
Return-Path: <root@host1.localdomain>
X-Original-To: root
Delivered-To: root@host1.localdomain
Received: by host1.localdomain (Postfix, from userid 0)
        id 8325E2BE2; Mon,  6 Aug 2012 11:13:52 +0900 (JST)
Date: Mon, 06 Aug 2012 11:13:52 +0900
To: root@host1.localdomain
Subject: YUM:host1:2012-08-06
User-Agent: Heirloom mailx 12.4 7/29/08
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Message-Id: <20120806021352.8325E2BE2@host1.localdomain>
From: root@host1.localdomain (root)

 --------------------
 YUM - security
 --------------------

================================================================================
 Package         Arch       Version                       Repository       Size
================================================================================
Updating:
 dhclient        x86_64     12:4.1.1-31.P1.el6_3.1        sl-security     316 k
 dhcp-common     x86_64     12:4.1.1-31.P1.el6_3.1        sl-security     139 k

Transaction Summary
================================================================================
Upgrade       2 Package(s)

Total download size: 455 k

Updated:
  dhclient.x86_64 12:4.1.1-31.P1.el6_3.1                                      
  dhcp-common.x86_64 12:4.1.1-31.P1.el6_3.1                                    



From root@host1.localdomain  Thu Aug  9 10:18:45 2012
Return-Path: <root@host1.localdomain>
X-Original-To: root
Delivered-To: root@host1.localdomain
Received: by host1.localdomain (Postfix, from userid 0)
        id 500E02BDF; Thu,  9 Aug 2012 10:18:45 +0900 (JST)
Date: Thu, 09 Aug 2012 10:18:44 +0900
To: root@host1.localdomain
Subject: YUM:host1:2012-08-09
User-Agent: Heirloom mailx 12.4 7/29/08
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Message-Id: <20120809011845.500E02BDF@host1.localdomain>
From: root@host1.localdomain (root)

 --------------------
 YUM - security
 --------------------

================================================================================
 Package        Arch         Version                    Repository         Size
================================================================================
Updating:
 openldap       x86_64       2.4.23-26.el6_3.2          sl-security       261 k

Transaction Summary
================================================================================
Upgrade       1 Package(s)

Total download size: 261 k

Updated:
  openldap.x86_64 0:2.4.23-26.el6_3.2                                          



[root@host1 app1]# ^C  

2012年8月8日水曜日

mail


//モジュールロード
var nodemailer = require("nodemailer");
//埋め込み画像のファイル名に使用
//var cid = Date.now()+".image.png";

//SMTPサーバーの設定
nodemailer.SMTP = {
        host: "mail.c",
port:587,
//      ssl:true,
        use_authentication:true,
       user:"kawamoto_junichi@c",  
     pass:""
};

//メール情報の作成
var message = {      
sender:'kawamoto_junichi@c',
       to:'',
       subject:'【必ず読んでください】WindowsログインID変更のお知らせ!!!',    
  body:"Hello to myself",  
    html:"各位<br>8/11(土)WinodwsIDを社員番号へ変更を致し>ます。<br>■注意意!<br>WindowsID変更後は、必ず再起動を行ってください。",
debug:true
};

//メール送信のコールバック関数
var callback = function(error, success){      
if(error){              
 console.log("Error occured");  
             console.log(error.message);  
            return;  
     }      
 if(success){  
            console.log("Message sent successfully");
        }else{
                console.log("Message failed,reschedule!");        }
};

//メール送信
var mail;
try{
        mail = nodemailer.send_mail(message, callback);
}catch(e){
        console.log("Caught Exception", e);
}



mysqlが立たない


120808 18:06:29 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
120808 18:09:17 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
120808 18:09:17  InnoDB: Initializing buffer pool, size = 2.0G
120808 18:09:17  InnoDB: Completed initialization of buffer pool
InnoDB: Error: auto-extending data file ./ibdata1 is of a different size
InnoDB: 640 pages (rounded down to MB) than specified in the .cnf file:
InnoDB: initial 65536 pages, max 0 (relevant if non-zero) pages!
InnoDB: Could not open or create data files.
InnoDB: If you tried to add new data files, and it failed here,
InnoDB: you should now edit innodb_data_file_path in my.cnf back
InnoDB: to what it was, and remove the new ibdata files InnoDB created
InnoDB: in this failed attempt. InnoDB only wrote those files full of
InnoDB: zeros, but did not yet use them in any way. But be careful: do not
InnoDB: remove old data files which contain your precious data!
120808 18:09:17 [ERROR] Plugin 'InnoDB' init function returned error.
120808 18:09:17 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
120808 18:09:17 [ERROR] Unknown/unsupported table type: innodb
120808 18:09:17 [ERROR] Aborting

120808 18:09:17 [Note] /usr/libexec/mysqld: Shutdown complete