-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathopen-submitter.coffee
More file actions
393 lines (371 loc) · 12.2 KB
/
open-submitter.coffee
File metadata and controls
393 lines (371 loc) · 12.2 KB
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
fs = require('fs')
system = require('system')
consolex = require('./app/console-xtra')
imports = require('./app/imports')
spinner = require('./app/spinner')
page = require('webpage').create()
casper = require('casper').create(
pageSettings: webSecurityEnabled: false
viewportSize: {width: 800, height: 600}
timeout: 3600000 # 1 hour general timeout
stepTimeout: 300000 # 5 min default step timeout
waitTimeout: 60000 # 1 min default wait timeout
verbose: true
onError: (self, msg) ->
consolex.log 'red', 'FATAL:' + msg
self.exit()
return
onTimeout: (self, msg) ->
@.capture('./capture/timeout.png')
consolex.log 'red', 'general timeout error: ' + msg
return
onStepTimeout: (self, msg) ->
@.capture('./capture/timeout.png')
consolex.log 'red', 'step timeout error: step ' + msg
return
onWaitTimeout: (self, msg) ->
@.capture ('./capture/timeout.png')
consolex.log 'red','wait timeout error: ' + msg
return
)
casper.userAgent 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 ' +
'(KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36'
fileAccounts = './accounts/' + casper.cli.get(0) + '.csv'
fileArticles = './articles/' + casper.cli.get(1) + '.txt'
fileBacklinks = './backlinks/' + casper.cli.get(2) + '.txt'
numPosts = casper.cli.get(3)
console.log '\n'
consolex.log 'cyan', '---------------- Submission Details --------------------'
consolex.log 'cyan', 'Accounts file: ' + fileAccounts
consolex.log 'cyan', 'Articles file: ' + fileArticles
consolex.log 'cyan', 'Backlinks saved to file: ' + fileBacklinks
consolex.log 'cyan', 'Number of Submissions: ' + numPosts
currentService = 0
currentStep = 0
submitArticle =
title: ''
body: ''
keywords: ''
# Import settings
services = imports.services('./settings/services.txt')
indexerDetails = imports.indexers('./settings/indexers.txt')
# Load services
numLoops = 0
service = []
currentService = 0
for i in [0...services.length]
if services[i].status.toLowerCase() == 'ok'
service[currentService] = require('./services/' + services[i].name)
numLoops += service[currentService].steps.length
++currentService
numLoops *= numPosts
# Load indexer
numIndexerLoops = 0
indexers = []
indexersLogin = []
currentIndexer = 0
for i in [0...indexerDetails.length]
if indexerDetails[i].status.toLowerCase() == 'ok'
indexers[currentIndexer] = require('./indexers/' + indexerDetails[i].name)
indexersLogin[currentIndexer] = indexerDetails[i]
numIndexerLoops += indexers[currentIndexer].steps.length
++currentIndexer
# ---------------- Import Files ------------------------
console.log ('------------------- Import Files -------------------------')
accounts = imports.accounts(fileAccounts)
articles = imports.articles(fileArticles)
# ------------------ Utils ------------------------
currentStep = 0
randomAccount =
username: ''
password: ''
site: ''
submitArticle =
title: ''
body: ''
keywords: ''
backlinksList = ''
skipService = ->
console.log 'Skipping ' + service[currentService].name
++currentService
currentStep = 0
errorMsg = ->
console.log 'Failed step ' + currentStep
console.log 'Check error.png file'
skipService()
# ------------------------ Step Commands ------------------------------
currentSubmission = 0
currentService = 0
currentIndexer = 0
currentIndexerStep = 0
casper.doStep = (objStep, serviceName) ->
@echo 'Step: ' + currentStep
# -------------------------- Create -------------------------------------
if objStep.command == 'create'
@echo 'Creating article...'
submitArticle = spinner.getArticle(articles, objStep.micro,objStep.noHTML)
randomAccount = spinner.getAccount(accounts, serviceName)
str = '-------------- Submit to ' + serviceName+' ----------------'
consolex.log 'yellow', str
# -------------------------- Open ---------------------------------------
else if objStep.command == 'open'
@echo 'Opening url '+objStep.url+'...'
@open(objStep.url).then ->
@capture('./capture/capture' + currentStep + '.png')
if objStep.confirm
@waitForSelector objStep.confirm,
->
@echo 'Opened url'
->
errorMsg()
@capture('./capture/error.png')
else if objStep.confirmtxt
@waitForText objStep.confirmtxt,
->
@echo 'Opened url'
->
errorMsg()
@capture('./capture/error.png')
# -------------------------- Open Site -----------------------------------
else if objStep.command == 'open-site'
tempURL = objStep.begin + randomAccount.site + objStep.end
@echo 'Opening url ' + tempURL + '...'
@open(tempURL).then ->
@capture('./capture/capture' + currentStep + '.png')
if objStep.confirm
@waitForSelector objStep.confirm,
->
@echo 'Opened url'
->
errorMsg()
@capture('./capture/error.png')
else if objStep.confirmtxt
@waitForText objStep.confirmtxt,
->
@echo 'Opened url'
->
errorMsg()
@capture('./capture/error.png')
# -------------------------- Login ----------------------------------------
else if objStep.command == 'login'
if randomAccount.username == 'no accounts'
@echo 'No '+ serviceName + ' accounts!'
skipService()
else
@echo 'Logging in: ' + randomAccount.username + '...'
# Login to WordPress with random account
tempObj =
formElem: objStep.form
nameElem: objStep.username
pwdElem: objStep.password
name: randomAccount.username
pwd: randomAccount.password
submit: objStep.submit
@evaluate ((s) ->
document.querySelector(s.nameElem).value = s.name
document.querySelector(s.pwdElem).value = s.pwd
if s.submit
document.querySelector(s.formElem).submit()
return
), tempObj
@capture('./capture/capture' + currentStep + '.png')
@echo 'Waiting for login confirmation...'
if objStep.submit
@waitForSelector objStep.confirm,
->
@echo 'Login success.'
->
errorMsg()
@capture('./capture/error.png')
else if objStep.confirmtxt
@waitForText objStep.confirmtxt,
->
@echo 'Login success.'
->
errorMsg()
@capture('./capture/error.png')
# -------------------------- Login-Indexer -----------------------------------
else if objStep.command == 'login-indexer'
@capture('./capture/indexer0.png')
if indexersLogin.length == 0
@echo 'No indexer accounts set up!'
else
@echo 'Logging in: ' +
indexersLogin[currentIndexer].username + '...'
# Login to Indexer
tempObj =
formElem: objStep.form
nameElem: objStep.username
pwdElem: objStep.password
name: indexersLogin[currentIndexer].username
pwd: indexersLogin[currentIndexer].password
submit: objStep.submit
@evaluate ((s) ->
document.querySelector(s.nameElem).value = s.name
document.querySelector(s.pwdElem).value = s.pwd
if s.submit
document.querySelector(s.formElem).submit()
return
), tempObj
@capture('./capture/indexer1.png')
@echo 'Waiting for login confirmation...'
if objStep.confirm
@waitForSelector objStep.confirm,
->
@echo 'Login success.'
->
@capture('./capture/error.png')
errorMsg()
else if objStep.confirmtxt
@waitForText objStep.confirmtxt,
->
@echo 'Login success.'
->
@capture('./capture/error.png')
errorMsg()
# --------------------------- Click ---------------------------------------
if objStep.command == 'click'
if objStep.selector
tempObj = objStep.selector
else if objStep.xpath
tempObj = {
type: 'xpath',
path: objStep.xpath
}
if @exists(tempObj)
@click tempObj
@echo 'Clicked on DOM selector'
if objStep.confirm
@waitForSelector objStep.confirm,
->
@echo 'Found confirm selector.'
->
@echo 'Confirm DOM selector not found', 'ERROR'
errorMsg()
@capture('./capture/error.png')
if objStep.confirmtxt
@waitForText objStep.confirmtxt,
->
@echo 'Found confirm text: ' + objStep.confirmtxt
->
@echo 'Confirm text' + objStep.confirmtxt + 'not found', 'ERROR'
errorMsg()
@capture('./capture/error.png')
else
@echo 'DOM selector not found', 'ERROR'
errorMsg()
# --------------------------- Wait ---------------------------------------
if objStep.command == 'wait'
@echo 'Waiting for ' + objStep.value + ' ms'
@wait objStep.value, ->
@echo 'Finished wait time.'
return
# --------------------------- Title ---------------------------------------
if objStep.command == 'title'
if objStep.selector
tempObj = objStep.selector
else if objStep.xpath
tempObj = {
type: 'xpath',
path: objStep.xpath
}
if @exists(tempObj)
@sendKeys(tempObj, submitArticle.title)
@echo 'Entered title'
else
@echo 'Input field not found', 'ERROR'
errorMsg()
# --------------------------- Title ---------------------------------------
if objStep.command == 'backlinks'
if objStep.selector
tempObj = objStep.selector
else if objStep.xpath
tempObj = {
type: 'xpath',
path: objStep.xpath
}
if @exists(tempObj)
@sendKeys(tempObj, backlinksList)
@echo 'Entered backlinks list'
else
@echo 'Input field not found', 'ERROR'
errorMsg()
# --------------------------- Body ---------------------------------------
if objStep.command == 'body'
if objStep.selector
tempObj = objStep.selector
else if objStep.xpath
tempObj = {
type: 'xpath',
path: objStep.xpath
}
if @exists(tempObj)
@sendKeys(tempObj, submitArticle.body)
@echo 'Entered body'
else
@echo 'Input field not found', 'ERROR'
errorMsg()
# --------------------------- Save-href -----------------------------------
if objStep.command == 'save-href'
if objStep.selector
tempObj = objStep.selector
else if objStep.xpath
tempObj = {
type: 'xpath',
path: objStep.xpath
}
if @exists(tempObj)
submitURL = @getElementAttribute tempObj, 'href'
backlinksList += submitURL + '\n'
consolex.log 'cyan', 'Submitted post to URL: ' + submitURL
# Save backlinks.txt
try
fs.write fileBacklinks, submitURL, 'a'
fs.write fileBacklinks, '\n', 'a'
catch e
@echo e
@echo 'Saved backlink to ' + fileBacklinks
else
@echo 'DOM selector not found' +tempObj, 'ERROR'
errorMsg()
# ------------------ Submit to Services ------------------------
casper.start()
casper.repeat numLoops, ->
@then ->
if currentService >= service.length
++currentSubmission
currentService = 0
currentStep = 0
if currentSubmission < numPosts
serviceName = service[currentService].name
objStep = service[currentService].steps[currentStep]
@.doStep(objStep, serviceName)
@then ->
@capture('./capture/capture' + currentStep + '.png')
++currentStep
if currentStep == service[currentService].steps.length
serviceName = service[currentService].name
consolex.log 'green', 'Completed submit to '+serviceName + '\n'
++currentService
currentStep = 0
return
return
casper.then ->
consolex.log 'blue', 'Submitting links to indexeing services'
casper.repeat numIndexerLoops, ->
@then ->
if currentIndexer < indexers.length
serviceName = indexers[currentIndexer].name
objStep = indexers[currentIndexer].steps[currentIndexerStep]
@.doStep(objStep, serviceName)
++currentIndexerStep
if currentIndexerStep == indexers[currentIndexer].steps.length
++currentIndexer
currentIndexerStep = 0
casper.run ->
consolex.log 'green', 'Finished all submissions.'
@echo 'Press ctrl C to exit'
@exit(0)
@bypass(1)
return
#