1- const child_process = require ( " child_process" )
2- const debug = require ( " debug" ) ( " storefront-ica-generator:StoreFrontICAGenerator" )
3- const fs = require ( " fs-extra" )
1+ const child_process = require ( ' child_process' )
2+ const debug = require ( ' debug' ) ( ' storefront-ica-generator:StoreFrontICAGenerator' )
3+ const fs = require ( ' fs-extra' )
44const series = require ( 'async/series' )
5- const request = require ( " request" )
6- const bindAll = require ( " lodash/fp/bindAll" )
7- const find = require ( " lodash/fp/find" )
8- const get = require ( " lodash/fp/get" )
9- const join = require ( " lodash/fp/join" )
10- const replace = require ( " lodash/fp/replace" )
11- const opn = require ( " opn" )
12- const tmp = require ( " tmp" )
5+ const request = require ( ' request' )
6+ const bindAll = require ( ' lodash/fp/bindAll' )
7+ const find = require ( ' lodash/fp/find' )
8+ const get = require ( ' lodash/fp/get' )
9+ const join = require ( ' lodash/fp/join' )
10+ const replace = require ( ' lodash/fp/replace' )
11+ const opn = require ( ' opn' )
12+ const tmp = require ( ' tmp' )
1313
1414const { isJSON } = require ( './helpers' )
1515
@@ -23,7 +23,7 @@ class StoreFrontICAGenerator {
2323 if ( ! query ) throw new Error ( 'StoreFrontICAGenerator: requires query' )
2424 if ( ! username ) throw new Error ( 'StoreFrontICAGenerator: requires username' )
2525 if ( ! password ) throw new Error ( 'StoreFrontICAGenerator: requires password' )
26- debug ( { storeFrontUrl, query, domain, username, password } )
26+ debug ( JSON . stringify ( { storeFrontUrl, query, domain, username, password } , null , 2 ) )
2727 this . username = username
2828 this . password = password
2929 this . domain = domain
@@ -36,27 +36,27 @@ class StoreFrontICAGenerator {
3636 forever : true ,
3737 gzip : true ,
3838 agentOptions : {
39- rejectUnauthorized : false
40- }
39+ rejectUnauthorized : false ,
40+ } ,
4141 } )
4242 }
4343
4444 explicitLogin ( callback ) {
4545 this . setStoreFrontCookies ( )
4646 const csrfToken = this . getCookie ( 'CsrfToken' , 'value' )
4747 const options = {
48- uri : " ExplicitAuth/Login" ,
48+ uri : ' ExplicitAuth/Login' ,
4949 headers : {
50- ' Accept' : 'application/xml, text/xml, */*; q=0.01' ,
51- 'X-Citrix-IsUsingHTTPS' : " Yes" ,
50+ Accept : 'application/xml, text/xml, */*; q=0.01' ,
51+ 'X-Citrix-IsUsingHTTPS' : ' Yes' ,
5252 'Content-Length' : '0' ,
5353 'Csrf-Token' : csrfToken ,
54- }
54+ } ,
5555 }
56- debug ( 'explicitLogin' , options )
56+ debug ( 'explicitLogin' , JSON . stringify ( options , null , 2 ) )
5757 this . request . post ( options , ( error , response ) => {
5858 if ( error ) return callback ( error )
59- debug ( 'explicitLogin result' , response . statusCode , response . body )
59+ debug ( 'explicitLogin result' , response . statusCode , JSON . stringify ( response . body , null , 2 ) )
6060 if ( response . statusCode > 399 ) {
6161 return callback ( new Error ( `Unexpected status code (${ response . statusCode } ) when ExplicitAuth/Login` ) )
6262 }
@@ -67,36 +67,37 @@ class StoreFrontICAGenerator {
6767 explicitLoginAttempt ( callback ) {
6868 const csrfToken = this . getCookie ( 'CsrfToken' , 'value' )
6969 const options = {
70- uri : " ExplicitAuth/LoginAttempt" ,
70+ uri : ' ExplicitAuth/LoginAttempt' ,
7171 headers : {
72- ' Accept' : 'application/xml, text/xml, */*; q=0.01' ,
72+ Accept : 'application/xml, text/xml, */*; q=0.01' ,
7373 'Accept-Language' : 'en-US,en;q=0.8' ,
7474 'X-Requested-With' : 'XMLHttpRequest' ,
75- 'X-Citrix-IsUsingHTTPS' : " Yes" ,
75+ 'X-Citrix-IsUsingHTTPS' : ' Yes' ,
7676 'Csrf-Token' : csrfToken ,
77- ' Referer' : this . storeFrontUrl ,
77+ Referer : this . storeFrontUrl ,
7878 } ,
7979 form : {
8080 domain : this . domain ,
8181 password : this . password ,
8282 username : this . username ,
83- saveCredentials : " true" ,
83+ saveCredentials : ' true' ,
8484 loginBtn : 'Log On' ,
8585 StateContext : '' ,
86- }
86+ } ,
8787 }
88- debug ( 'explicitLoginAttempt' , options )
88+ debug ( 'explicitLoginAttempt' , JSON . stringify ( options , null , 2 ) )
8989 this . request . post ( options , ( error , response ) => {
9090 if ( error ) return callback ( error )
91- debug ( 'explicitLoginAttempt result' , response . statusCode , response . body , response . headers )
91+ debug ( 'explicitLoginAttempt result' , response . statusCode , JSON . stringify ( response . body , null , 2 ) , JSON . stringify ( response . headers , null , 2 ) )
9292 debug ( 'explicitLoginAttempt cookies' , this . getCookies ( ) )
9393 if ( response . statusCode > 399 ) {
94- return callback ( new Error ( `Unexpected status code (${ response . statusCode } ) when ExplicitAuth/LoginAttempt` ) )
94+ return callback ( new Error ( `Unexpected status cod (${ response . statusCode } ) when ExplicitAuth/LoginAttempt` ) )
9595 }
9696 callback ( )
9797 } )
9898 }
9999
100+
100101 generateAndLaunch ( callback ) {
101102 this . generateICAFile ( ( error , icaFilePath ) => {
102103 if ( error ) {
@@ -122,14 +123,14 @@ class StoreFrontICAGenerator {
122123 return callback ( error )
123124 }
124125 icaContents = this . modifyICA ( icaContents )
125- debug ( 'modified ica contents' , icaContents )
126+ debug ( 'modified ica contents' , JSON . stringify ( icaContents , null , 2 ) )
126127 callback ( null , icaContents )
127128 } )
128129 } )
129130 }
130131
131132 generateICAFile ( callback ) {
132- tmp . tmpName ( { postfix : " .ica" } , ( error , icaFilePath ) => {
133+ tmp . tmpName ( { postfix : ' .ica' } , ( error , icaFilePath ) => {
133134 if ( error ) return callback ( error )
134135 this . generateICA ( ( error , icaContents ) => {
135136 if ( error ) {
@@ -143,19 +144,19 @@ class StoreFrontICAGenerator {
143144 getAuthMethods ( callback ) {
144145 const csrfToken = this . getCookie ( 'CsrfToken' , 'value' )
145146 const options = {
146- uri : " Authentication/GetAuthMethods" ,
147+ uri : ' Authentication/GetAuthMethods' ,
147148 headers : {
148- ' Accept' : 'application/xml, text/xml, */*; q=0.01' ,
149- 'X-Citrix-IsUsingHTTPS' : " Yes" ,
149+ Accept : 'application/xml, text/xml, */*; q=0.01' ,
150+ 'X-Citrix-IsUsingHTTPS' : ' Yes' ,
150151 'Content-Length' : '0' ,
151152 'Csrf-Token' : csrfToken ,
152- ' Referer' : this . storeFrontUrl ,
153- }
153+ Referer : this . storeFrontUrl ,
154+ } ,
154155 }
155- debug ( 'getAuthMethods' , options )
156+ debug ( 'getAuthMethods' , JSON . stringify ( options , null , 2 ) )
156157 this . request . post ( options , ( error , response ) => {
157158 if ( error ) return callback ( error )
158- debug ( 'getAuthMethods result' , response . statusCode , response . body )
159+ debug ( 'getAuthMethods result' , response . statusCode , JSON . stringify ( response . body , null , 2 ) )
159160 if ( response . statusCode > 399 ) {
160161 return callback ( new Error ( `Unexpected status code (${ response . statusCode } ) when fetching Authentication/GetAuthMethods` ) )
161162 }
@@ -164,7 +165,7 @@ class StoreFrontICAGenerator {
164165 }
165166
166167 getCookies ( ) {
167- return this . jar . _jar . getCookiesSync ( this . storeFrontUrl , { allPaths :true } )
168+ return this . jar . _jar . getCookiesSync ( this . storeFrontUrl , { allPaths : true } )
168169 }
169170
170171 getCookie ( key , property ) {
@@ -176,7 +177,7 @@ class StoreFrontICAGenerator {
176177 }
177178
178179 getICAFileContents ( resource , callback ) {
179- debug ( 'getICAFileContents resource' , resource )
180+ debug ( 'getICAFileContents resource' , JSON . stringify ( resource , null , 2 ) )
180181 if ( ! resource . launchurl ) {
181182 return callback ( new Error ( 'Resource missing launchurl' ) )
182183 }
@@ -187,12 +188,12 @@ class StoreFrontICAGenerator {
187188 qs : {
188189 CsrfToken : csrfToken ,
189190 IsUsingHttps : 'Yes' ,
190- }
191+ } ,
191192 }
192- debug ( 'getICAFileContents' , options )
193+ debug ( 'getICAFileContents' , JSON . stringify ( options , null , 2 ) )
193194 this . request . get ( options , ( error , response , contents ) => {
194195 if ( error ) return callback ( error )
195- debug ( 'getICAFileContents result' , response . statusCode , response . body )
196+ debug ( 'getICAFileContents result' , response . statusCode , JSON . stringify ( response . body , null , 2 ) )
196197 if ( response . statusCode > 399 ) {
197198 return callback ( new Error ( `Unexpected status code (${ response . statusCode } ) when fetching ICA File` ) )
198199 }
@@ -230,24 +231,24 @@ class StoreFrontICAGenerator {
230231 listResources : this . listResources ,
231232 } , ( error , result ) => {
232233 if ( error ) return callback ( error )
233- debug ( 'getResources result' , result )
234+ debug ( 'getResources result' , JSON . stringify ( result , null , 2 ) )
234235 const { listResources } = result
235236 callback ( null , get ( 'resources' ) ( listResources ) )
236237 } )
237238 }
238239
239240 homeConfiguration ( callback ) {
240241 const options = {
241- uri : " Home/Configuration" ,
242+ uri : ' Home/Configuration' ,
242243 headers : {
243244 Accept : 'application/xml, text/xml, */*; q=0.01' ,
244245 'Content-Length' : 0 ,
245246 'X-Requested-With' : 'XMLHttpRequest' ,
246247 'X-Citrix-IsUsingHTTPS' : 'Yes' ,
247- ' Referer' : this . storeFrontUrl ,
248- }
248+ Referer : this . storeFrontUrl ,
249+ } ,
249250 }
250- debug ( 'homeConfiguration' , options )
251+ debug ( 'homeConfiguration' , JSON . stringify ( options , null , 2 ) )
251252 this . request . post ( options , ( error , response ) => {
252253 if ( error ) return callback ( error )
253254 debug ( 'homeConfiguration result' , response . statusCode , response . body )
@@ -282,20 +283,20 @@ class StoreFrontICAGenerator {
282283 listResources ( callback ) {
283284 const csrfToken = this . getCookie ( 'CsrfToken' , 'value' )
284285 const options = {
285- uri : " Resources/List" ,
286+ uri : ' Resources/List' ,
286287 headers : {
287- " Accept" : 'application/json, text/javascript, */*; q=0.01' ,
288- 'X-Citrix-IsUsingHTTPS' : " Yes" ,
288+ Accept : 'application/json, text/javascript, */*; q=0.01' ,
289+ 'X-Citrix-IsUsingHTTPS' : ' Yes' ,
289290 'X-Requested-With' : 'XMLHttpRequest' ,
290291 'Csrf-Token' : csrfToken ,
291- ' Referer' : this . storeFrontUrl ,
292+ Referer : this . storeFrontUrl ,
292293 } ,
293294 form : {
294295 format : 'json' ,
295296 resourceDetails : 'Full' ,
296- }
297+ } ,
297298 }
298- debug ( 'listResources' , options )
299+ debug ( 'listResources' , JSON . stringify ( options , null , 2 ) )
299300 this . request . post ( options , ( error , response , body ) => {
300301 if ( error ) return callback ( error )
301302 debug ( 'listResources result' , response . statusCode , response . body )
@@ -312,13 +313,13 @@ class StoreFrontICAGenerator {
312313
313314 loadMainPage ( callback ) {
314315 const options = {
315- uri : "/" ,
316+ uri : '/' ,
316317 headers : {
317318 Accept : 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8' ,
318319 'Upgrade-Insecure-Requests' : '1' ,
319- }
320+ } ,
320321 }
321- debug ( 'loadMainPage' , options )
322+ debug ( 'loadMainPage' , JSON . stringify ( options , null , 2 ) )
322323 this . request . get ( options , ( error , response ) => {
323324 if ( error ) return callback ( error )
324325 debug ( 'loadMainPage result' , response . statusCode )
@@ -330,15 +331,15 @@ class StoreFrontICAGenerator {
330331 }
331332
332333 modifyICA ( icaContents ) {
333- const enableTWIMode = replace ( 'TWIMode=Off' , join ( "\n" , [ 'TWIMode=On' , 'TWIIgnoreWorkArea=1' ] ) )
334+ const enableTWIMode = replace ( 'TWIMode=Off' , join ( '\n' , [ 'TWIMode=On' , 'TWIIgnoreWorkArea=1' ] ) )
334335 icaContents = this . addSectionToICA ( '[Thinwire 3.0]' , [ 'TWIFullScreenMode=1' ] , icaContents )
335336 icaContents = this . addSectionToICA ( '[WFClient]' , [ 'TWISeamlessFlag=1' ] , icaContents )
336337 return enableTWIMode ( icaContents )
337338 }
338339
339340 addSectionToICA ( title , settings , content ) {
340- const multiline = join ( "\n" )
341- if ( content . indexOf ( title ) < 0 ) {
341+ const multiline = join ( '\n' )
342+ if ( content . indexOf ( title ) < 0 ) {
342343 content = multiline ( [ content , title ] )
343344 }
344345 return replace ( title , multiline ( [ title , ...settings ] ) ) ( content )
@@ -354,7 +355,7 @@ class StoreFrontICAGenerator {
354355 setCookie ( key , value ) {
355356 const domain = this . getCookie ( 'CsrfToken' , 'domain' )
356357 const cookie = request . cookie ( `${ key } =${ value } ; Domain=${ domain } ` )
357- this . jar . setCookie ( cookie , this . storeFrontUrl , { ignoreError : true } )
358+ this . jar . setCookie ( cookie , this . storeFrontUrl , { ignoreError : true } )
358359 }
359360
360361 writeICAFileContents ( icaFilePath , icaContents , callback ) {
@@ -366,7 +367,6 @@ class StoreFrontICAGenerator {
366367 } )
367368 } )
368369 }
369-
370370}
371371
372372module . exports = StoreFrontICAGenerator
0 commit comments