WebPagetest Forums
Using REST API to run server based script file - Printable Version

+- WebPagetest Forums (https://www.webpagetest.org/forums)
+-- Forum: WebPagetest (/forumdisplay.php?fid=7)
+--- Forum: Private Instances (/forumdisplay.php?fid=12)
+--- Thread: Using REST API to run server based script file (/showthread.php?tid=13199)



Using REST API to run server based script file - sonicdivx - 08-27-2014 01:31 AM

I am wondering if the REST API can be used to load and run a script file hosted on the private instance?

I would like to be able to submit a request from an application of our and passing the script via a post is less than ideal (login info would need to be passed).

Thanks


RE: Using REST API to run server based script file - pmeenan - 08-30-2014 01:48 AM

No, it can't pull pre-defined scripts (currently anyway).


RE: Using REST API to run server based script file - sonicdivx - 08-30-2014 04:40 AM

(08-30-2014 01:48 AM)pmeenan Wrote:  No, it can't pull pre-defined scripts (currently anyway).

Thanks, good to know. Maybe if I have time I'll search the code see what is involved in do that (maybe hardcode path and just send filename to minimize security risk)


RE: Using REST API to run server based script file - pmeenan - 08-30-2014 04:54 AM

Shouldn't be too hard. Somewhere around here: https://github.com/WPO-Foundation/webpagetest/blob/master/www/runtest.php#L76

Add a new parameter that identifies pre-defined scripts (say "runscript") and if that parameter is set go load the script into $test['script']. It will get treated as if it was passed in from that point on (do it after $test['script'] is initially set or it will be overwritten). You need to be a bit careful about server attacks so don't pass in the actual file name unless you do some regex scrubbing.

Another option (maybe cleaner) would be to define script replacement strings and in ValidateScript ( https://github.com/WPO-Foundation/webpagetest/blob/master/www/runtest.php#L1105 ) you could do the string replacement like we do for the built-in %URL% and %HOST% placeholders.


RE: Using REST API to run server based script file - sonicdivx - 08-30-2014 05:16 AM

Ahh cool. Thanks for the info, the cleaner is a good idea.