-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathdomain.js
More file actions
53 lines (32 loc) · 751 Bytes
/
domain.js
File metadata and controls
53 lines (32 loc) · 751 Bytes
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
"use strict";
import fs from 'fs'
import path from 'path'
import crypto from 'crypto'
let mod = {
getDomainName: function(){
let cert = "";
try {
const files = fs.readdirSync("./data");
for(let fileName of files){
let ext = path.extname(fileName);
if(ext != ".db" && ext != ".json"){
let content = fs.readFileSync("./data/" + fileName, 'utf8');
if(content.includes("BEGIN CERTIFICATE")){
cert = content;
}
}
}
} catch (err) {
console.log("read directory fail");
console.log(err);
}
if(cert){
let extract = new crypto.X509Certificate(cert).subject;
let res = extract.match(/CN=([^ ]+)/);
return res[1] || "";
}else{
return "";
}
}
}
export default mod;