-
Notifications
You must be signed in to change notification settings - Fork 0
/
DomainSearcher.js
144 lines (124 loc) · 3.74 KB
/
DomainSearcher.js
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
var godaddyPostUrl = "http://www.godaddy.com/domains/actions/dodomainbulksearch.aspx?source=%2fbulk-domain-search.aspx&isc=cjc695tnw";
var allTLDs = new Array('undefined','com','co','info','net','org','me','mobi','us','biz','ca','com.au','net.au','org.au','mx','ws','asia','bz','com.co','net.co','nom.co','eu','in','com.mx','nl','se','xxx','cz','la');
var allGoodTLDs = new Array('com','co','info','net','org','me','mobi','biz','ca','mx','ws','asia','bz','eu','in','nl','se','xxx','cz','la');
var topTLDs = new Array('com','co','info','net','org');
var dotComOnly = new Array('com');
var limit = 50;
// prfane????? titscent.us
var wordFusionQuery = " SELECT CONCAT(rand1.word, rand2.word) as word" +
" FROM " +
" ( " +
" SELECT word, @ai1 := @ai1 + 1 as rowNum " +
" FROM ( SELECT word FROM monosyllabic ORDER BY RAND() ) r, (SELECT @ai1 := 0) selRow " +
" LIMIT " + limit + " " +
" ) as rand1 " +
" JOIN " +
" ( " +
" SELECT word, @ai2 := @ai2 + 1 as rowNum " +
" FROM ( SELECT word FROM monosyllabic ORDER BY RAND() ) r, (SELECT @ai2 := 0) selRow " +
" LIMIT " + limit + " " +
" ) as rand2 " +
" ON rand1.rowNum = rand2.rowNum ";
DomainSearcher = function(){};
require('./mysql_connect');
var cheerio = require('cheerio');
var request = require('request');
function trim(string){
return string.replace(/\s+/g, '');
}
dbConn = new DbConn();
function sendGoDaddyRequest(names, tlds, callback){
var tldString = tlds.join(",");
var nameString = names.join(",");
console.log(tldString);
console.log(nameString);
//clear cookies
var j = request.jar();
request.post(
godaddyPostUrl,
{
form: {
dotTypes: tldString,
extrnl: 1,
bulk: 1,
domainNames: nameString
},
jar: j,
followAllRedirects: true,
timeout: 1000 * 360
},
function (error, response, body) {
var domainList = Array();
if (!error && response.statusCode == 200) {
$daddy = cheerio.load(body);
// $('#dppBulkSearch input:checkbox')
$daddy('.prevDomain').each(function(i, elem){
var domain = $daddy(this).val();
domainList.push(domain);
});
console.log("Daddy Came Back!");
console.log(domainList);
callback(domainList);
}else
{
console.log("No Daddy Error!");
console.log(error);
}
}
);
}
function halfRandomWords(word, callback){
word = dbConn.mysql.escape(word);
var query = "" +
" SELECT IF(" +
" ROUND( RAND())," +
" CONCAT(word, " + word + ")," +
" CONCAT(" + word + ", word)" +
" ) as word" +
" FROM monosyllabic" +
" ORDER BY RAND() "+
" LIMIT " + limit +
"";
console.log(query);
dbConn.query(query, function(rows){
callback(rows);
} );
}
function randomWords(callback){
dbConn.query(wordFusionQuery, function(rows){
callback(rows);
} );
}
DomainSearcher.prototype.generateAndTestWords = function(callback, suggestion){
var domainSearchfunc = function(results){
var queryWords = Array();
if(results==="undefined")
callback({});
for(var i=0; i<results.length;i++)
queryWords.push(results[i].word);
sendGoDaddyRequest(queryWords, dotComOnly, callback);
};
if(suggestion !== undefined){
suggestion = trim(suggestion);
console.log("--"+suggestion+"--");
if(suggestion !== "")
halfRandomWords(suggestion, domainSearchfunc);
else
randomWords(domainSearchfunc);
}
else
randomWords(domainSearchfunc);
};
DomainSearcher.prototype.testConnection = function(){
dbConn.query("SELECT NOW()", function(rows){
console.log(rows);
} );
};
DomainSearcher.prototype.allWords = function(limit, callback){
var sql = "SELECT * FROM monosyllabic LIMIT " + dbConn.mysql.escape(limit);
console.log(sql);
dbConn.query(sql, function(rows){
callback(rows);
} );
};
exports = DomainSearcher;