-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathcloudflash.coffee
More file actions
309 lines (267 loc) · 10.1 KB
/
cloudflash.coffee
File metadata and controls
309 lines (267 loc) · 10.1 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
{@app} = require('zappajs') 5000, ->
@configure =>
@use 'bodyParser', 'methodOverride', @app.router, 'static'
@set 'basepath': '/v1.0'
@configure
development: => @use errorHandler: {dumpExceptions: on, showStack: on}
production: => @use 'errorHandler'
@enable 'serve jquery', 'minify'
@include 'services'
@include 'personality'
@include 'openvpn'
# @include 'openvpnlog'
# @include 'firewall'
@get '/test': ->
@render index: {title: 'cloudflash', layout: no}
@on 'set nickname': ->
@client.nickname = @data.nickname
@on serviceadded: ->
@broadcast said: {nickname: @client.nickname, text: @data.text}
@emit said: {nickname: @client.nickname, text: @data.text}
@on servicedeleted: ->
@broadcast said: {nickname: @client.nickname, text: @data.text}
@emit said: {nickname: @client.nickname, text: @data.text}
@on openvpnadded: ->
@broadcast said: {nickname: @client.nickname, text: @data.text}
@emit said: {nickname: @client.nickname, text: @data.text}
@on firewalladded: ->
@broadcast said: {nickname: @client.nickname, text: @data.text}
@emit said: {nickname: @client.nickname, text: @data.text}
@client '/index.js': ->
@connect()
@on serviceadded: ->
$('#panel').append "<p>#{@data} and #{@text}</p>"
$ =>
# @emit 'set nickname': {nickname: prompt 'Pick a nickname!'}
$('#box').focus()
$('button').click (e) ->
$form = $(this).closest('form')
sid = $form.find('input[name="id"]').val()
#console.log $form.attr('id')
switch $form.attr('id')
when 'create'
type = "POST"
url = '/services'
data = $form.serializeFormJSON()
when 'action'
type = "POST"
url = "/services/#{sid}/action"
data = { 'command': $form.find('option:selected').val() }
when 'delete'
type = "DELETE"
url = "/services/#{sid}"
when 'personality'
type = "POST"
url = "/personality"
data = { 'personality': [ $form.serializeFormJSON() ] }
json = JSON.stringify(data) if data
# alert 'about to issue POST to: '+url+' with: '+json
$.ajax
type: type
url: url
data: json
contentType: "application/json; charset=utf-8"
success: (data) =>
@emit serviceevent: { text: data }
e.preventDefault()
#Have to implement encoded and decoding
#work in progress..
#after recieving the encoded base64 do the decode appropriate
@client '/openvpn.js': ->
@connect()
@on openvpnadded: ->
$('#panel').append "<p>#{@data.services.openvpn} said: #{@data.service.id}</p>"
$ =>
$('#box').focus()
$('button').click (e) =>
json = $("#configdata").val()
id = $("#id").val()
unless id is " " and id is "undefined"
$.ajax
type: "POST"
url: '/services/'+id+'/openvpn'
data: json
contentType: "application/json; charset=utf-8"
success: (data) =>
@emit openvpnadded: { text: $('#box').val() }
e.preventDefault()
@client '/firewall.js': ->
@connect()
@on firewalladded: ->
$('#panel').append "<p>#{@data.services.firewall} said: #{@data.service.id}</p>"
$ =>
$('#box').focus()
$('button').click (e) =>
json = $("#configdata").val()
id = $("#id").val()
unless id is " " and id is "undefined"
$.ajax
type: "POST"
url: '/services/'+id+'/firewall'
data: json
contentType: "application/json; charset=utf-8"
success: (data) =>
@emit firewalladded: { text: $('#box').val() }
e.preventDefault()
@view index: ->
doctype 5
html ->
head ->
title 'CloudFlash Test Application!'
script src: '/socket.io/socket.io.js'
script src: '/zappa/jquery.js'
script src: '/zappa/zappa.js'
script src: '/jquery-json.js'
script src: '/index.js'
body ->
div id: 'panel'
div ->
p 'Create a new Service'
form '#create', ->
input
type: 'hidden'
name: 'version'
value: '1.0'
p ->
span 'Service Name: '
input '#name'
type: 'text'
name: 'name'
value: 'at'
p ->
span 'Service Type: '
input '#family',
type: 'text'
name: 'family'
value: 'remote-access'
p ->
span 'Package URL: '
input '#pkgurl',
type: 'text'
name: 'pkgurl'
value: 'http://10.1.10.145/vpnrac-0.0.1.deb'
button 'Send'
div ->
p 'Send an action to Service'
form '#action', ->
p ->
span 'Service ID: '
input
type: 'text'
name: 'id'
value: ''
p ->
span 'Action: '
select name: 'action', ->
option value: 'start', 'Start'
option value: 'stop', 'Stop'
option value: 'restart', 'Restart'
option value: 'sync', 'Sync'
button 'Send'
div ->
p 'Delete a Service'
form '#delete', ->
p ->
span 'Service ID: '
input '#id'
type: 'text'
name: 'id'
value: 'service id'
button 'Send'
div ->
p 'Post a Personality'
form '#personality', ->
p ->
span 'Path: '
input '#path'
type: 'text'
name: 'path'
value: ''
p ->
span 'Contents: '
textarea '#contents'
name: 'contents'
value: ''
# p ->
# span 'Postxfer: '
# input '#postxfer'
# type: 'text'
# name: 'postxfer'
# value: ''
button 'Send'
@view openvpn: ->
doctype 5
html ->
head ->
title 'CloudFlash Test Application!'
script src: '/socket.io/socket.io.js'
script src: '/zappa/jquery.js'
script src: '/zappa/zappa.js'
script src: '/jquery-json.js'
script src: '/openvpn.js'
body ->
div id: 'panel'
form '#services', ->
p ->
span 'Service Name: '
input '#name'
type: 'text'
name: 'name'
value: 'openvpn'
p ->
span 'Service Type: '
input '#type',
type: 'text'
name: 'type'
value: 'vpn'
p ->
span 'Service id: '
input '#id'
type: 'text'
name: 'guid'
value: 'openvpn guid'
p ->
span 'Openvpn Config: '
input '#configdata'
type: 'text'
name: 'openvpnpostdata'
value: ''
button 'Send'
@view firewall: ->
doctype 5
html ->
head ->
title 'CloudFlash Test Application!'
script src: '/socket.io/socket.io.js'
script src: '/zappa/jquery.js'
script src: '/zappa/zappa.js'
script src: '/jquery-json.js'
script src: '/firewall.js'
body ->
div id: 'panel'
form '#services', ->
p ->
span 'Service Name: '
input '#name'
type: 'text'
name: 'name'
value: 'firewall'
p ->
span 'Service Type: '
input '#type',
type: 'text'
name: 'type'
value: 'iptables'
p ->
span 'Service id: '
input '#id'
type: 'text'
name: 'guid'
value: 'firewall guid'
p ->
span 'Firewall Config: '
input '#configdata'
type: 'text'
name: 'firewallpostdata'
value: ''
button 'Send'