Advertisement
globiws

gf_pf_auth_replace

Aug 12th, 2020
2,273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.38 KB | None | 0 0
  1. // GF PF token replace
  2. // replaces all ProcFu auth tokens in all GlobiFlow flows
  3.  
  4. input "auth token to search for" search_auth
  5. input "auth token to replace with" replace_auth
  6. input "enter 1 to replace or 0 to simulate" confirm_replace
  7.  
  8. flows = gf_get_flows_list()
  9. replaced = 0
  10.  
  11. // iterate through all flows
  12. foreach ( flows as flow ) {
  13.     flow_id = flow.pkFlows
  14.     print "fetching flow "+flow_id+" ("+flow.flowName+")"
  15.    
  16.     raw = gf_get_flow(flow_id, 0)
  17.     changed = false
  18.    
  19.     // iterate through each flow step
  20.     foreach ( raw.steps as i => fstep ) {
  21.         if ( fstep.stepFunction <> "remotePost" ) continue
  22.        
  23.         ispf = stristr(fstep.stepDetails.values.url, "procfu")
  24.         if ( not(ispf) ) continue
  25.        
  26.         hashead = stristr(fstep.stepDetails.values.headers, search_auth)
  27.         if ( not(hashead) ) continue
  28.        
  29.         // HIT - we have a remote post step to PF with our auth token
  30.         new_headers = str_replace(search_auth, replace_auth, raw.steps[i].stepDetails.values.headers)
  31.         raw.steps[i]['stepDetails'].values.headers = new_headers
  32.         changed = true
  33.         replaced = replaced + 1
  34.         print fstep
  35.     }
  36.    
  37.     // if we changed the flow - re-save it
  38.     if ( changed ) {
  39.         if ( confirm_replace ) {
  40.             print "flow has changed - re-saving"
  41.             gf_save_flow(raw)
  42.         } else {
  43.             print "skipping save - here's what would have been saved"
  44.             print raw
  45.         }
  46.     }
  47. }
  48.  
  49. print "DONE"
  50. print "Replaced "+replaced+" tokens"
  51.  
  52.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement