Skip to content
This repository has been archived by the owner on Mar 4, 2022. It is now read-only.

Commit

Permalink
兼容 Chrome/Firefox 历史浏览文件不存在的情况
Browse files Browse the repository at this point in the history
  • Loading branch information
jiacai2050 committed Jan 16, 2016
1 parent b4f1179 commit ce85c38
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 22 deletions.
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,17 +98,18 @@ Firefox 历史浏览文件保存在`places.sqlite`文件中,该文件在各大

修改完`config.json`后,就可以运行我们的服务了:
```
$ node app
node app
# 看到下面的输出,说明服务已经启动了
add router: /chrome
add router: /firefox
init chrome db successfully... visit http://localhost:5210/chrome
init firefox db successfully... visit http://localhost:5210/firefox
Listening on port 5210 ...
```
服务成功启动后,就可以打开浏览器访问了:
如果`config.json`中没有正确配置 Chrome/Firefox 历史浏览文件,会有相应的提示,比如:
```
chrome_history_file isn't set properly
```

- `http://localhost:5210/chrome`
- `http://localhost:5210/firefox`

### 4. 数据导出
当然,除了在线浏览,还可以把数据导出为 CSV 文件。直接在命令行执行下面的命令:
Expand Down
2 changes: 1 addition & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ app.get("/", function(req, res) {
});

var server = app.listen(config.port, function() {
console.log('Listening on port %d ...', server.address().port);
console.log('Listening on port %d...', server.address().port);
});
43 changes: 32 additions & 11 deletions lib/util.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
var moment = require('moment');
var fs = require("fs");
var sqlite3 = require("sqlite3");
var fs = require("fs");
var config = require("../config");

// https://digital-forensics.sans.org/blog/2010/01/21/google-chrome-forensics/
Expand Down Expand Up @@ -40,19 +41,39 @@ exports.saveCSVFile = function(f, data) {
}
});
}
var chromeDB = new sqlite3.Database(config["chrome_history_file"], sqlite3.OPEN_READONLY);
var firefoxDB = new sqlite3.Database(config["firefox_history_file"], sqlite3.OPEN_READONLY);
exports.executeSQL = function(dbType, sql, cb) {

var chromeDB = null;
if (fs.existsSync(config["chrome_history_file"])) {
console.log(`init chrome db successfully... visit http://localhost:${config.port}/chrome`);
chromeDB = new sqlite3.Database(config["chrome_history_file"], sqlite3.OPEN_READONLY);
} else {
console.log(`chrome_history_file isn't set properly`);
}
var firefoxDB = null;
if (fs.existsSync(config["firefox_history_file"])) {
console.log(`init firefox db successfully... visit http://localhost:${config.port}/firefox`);
firefoxDB = new sqlite3.Database(config["firefox_history_file"], sqlite3.OPEN_READONLY);
} else {
console.log(`firefox_history_file isn't set properly`);
}

exports.executeSQL = function(dbType, sql, cb) {
var db = {
"Chrome": chromeDB,
"Firefox": firefoxDB
}[dbType];
db.all(sql, function(err, rows) {
if (err) {
console.error(err)
cb([]);
} else {
cb(rows);
}
});
if (db) {
db.all(sql, function(err, rows) {
if (err) {
console.error(err)
cb([]);
} else {
cb(rows);
}
})
} else {
console.log(`${dbType} hisotry file isn't set.`)
cb([]);
}

}
12 changes: 9 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
{
"name": "chrome_history_stat",
"version": "2.0.0",
"version": "2.0.1",
"description": "统计 chrome/firefox 历史浏览记录",
"main": "app.js",
"author": "liujiacai.net",
"author": {
"name": "Jiacai Liu",
"email": "jiacai2050@gmail.con",
"url": "http://liujiacai.net"
},
"license": "MIT",
"bugs": {
"url": "https://github.com/jiacai2050/chrome-history-stat/issues"
},
"dependencies": {
"ejs": "^2.3.4",
"express": "^4.13.3",
Expand Down
2 changes: 1 addition & 1 deletion routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ _.map(files, function(file) {
if(/js$/.test(file) && ! /index/.test(file)) {
var file = path.join(__dirname, file),
router = "/" + path.basename(file, ".js");
console.log("add router: " + router);
//console.log("add router: " + router);
app.use(router, require(file));
}
});

0 comments on commit ce85c38

Please sign in to comment.