Compare commits
	
		
			4 commits
		
	
	
		
			23d0b7ae9e
			...
			91c93f1fe8
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
							 | 
						91c93f1fe8 | ||
| 
							 | 
						aff1643bb3 | ||
| 
							 | 
						affdd5bee9 | ||
| 
							 | 
						7dd3987bd8 | 
					 4 changed files with 31 additions and 11 deletions
				
			
		| 
						 | 
					@ -16,5 +16,5 @@ if ($_SERVER['argc'] < 2) {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
$serverHost = '127.0.0.1';
 | 
					$serverHost = '127.0.0.1';
 | 
				
			||||||
$serverPort = 4444;
 | 
					$serverPort = 4444;
 | 
				
			||||||
$main = new ScriptedBrowser\Main($serverHost, $serverPort, 6, $_SERVER['argc'] > 2 ? $_SERVER['argv'][2] : null);
 | 
					$main = new ScriptedBrowser\Main($serverHost, $serverPort, 6);
 | 
				
			||||||
$main->run($_SERVER['argv'][1]);
 | 
					$main->run($_SERVER['argv'][1]);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -110,7 +110,7 @@ function mousemoverel($main, $control, $options)
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
function sleep($main, $control, $options) : bool
 | 
					function sleep($main, $control, $options) : bool
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    usleep(intval($options['parameter']) * 1000000);
 | 
					    usleep(floatval($options['parameter']) * 1000000);
 | 
				
			||||||
    return true;
 | 
					    return true;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -121,7 +121,6 @@ class Control
 | 
				
			||||||
        curl_close($ch);
 | 
					        curl_close($ch);
 | 
				
			||||||
        $respJson = json_decode($resp, true);
 | 
					        $respJson = json_decode($resp, true);
 | 
				
			||||||
        if (!is_array($respJson)) {
 | 
					        if (!is_array($respJson)) {
 | 
				
			||||||
            echo "resp: '$resp'\n";
 | 
					 | 
				
			||||||
            return [];
 | 
					            return [];
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        if (array_key_exists('value', $respJson)) {
 | 
					        if (array_key_exists('value', $respJson)) {
 | 
				
			||||||
| 
						 | 
					@ -171,7 +170,8 @@ class Control
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public function getURL() : string
 | 
					    public function getURL() : string
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        return $this->execute('GET', 'url');
 | 
					        $url = $this->execute('GET', 'url');
 | 
				
			||||||
 | 
					        return (!is_array($url)) ? $url : '';
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
| 
						 | 
					@ -222,16 +222,21 @@ class Control
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $openSession = true;
 | 
					        $openSession = true;
 | 
				
			||||||
        if ($session !== null) {
 | 
					        if ($session !== null) {
 | 
				
			||||||
            // todo validate session
 | 
					 | 
				
			||||||
            $openSession = false;
 | 
					 | 
				
			||||||
            $this->session = $session;
 | 
					            $this->session = $session;
 | 
				
			||||||
 | 
					            // get current URL to see if the session is valid
 | 
				
			||||||
 | 
					            $url = $this->getURL();
 | 
				
			||||||
 | 
					            if ($url !== '') {
 | 
				
			||||||
 | 
					                $openSession = false;
 | 
				
			||||||
 | 
					            } else {
 | 
				
			||||||
 | 
					                $this->session = '';
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if ($openSession) {
 | 
					        if ($openSession) {
 | 
				
			||||||
            $sessionData = $this->execute('POST', "session", '{"capabilities" :  {"alwaysMatch": {"moz:firefoxOptions":{"prefs":{"browser.display.os-zoom-behavior": 0,"layout.css.prefers-color-scheme.content-override": 1}}}, "firstMatch": [{"browserName": "firefox"}]}}');
 | 
					            $sessionData = $this->execute('POST', "session", '{"capabilities" :  {"alwaysMatch": {"acceptInsecureCerts": true, "moz:firefoxOptions":{"prefs":{"browser.display.os-zoom-behavior": 0,"layout.css.prefers-color-scheme.content-override": 1}}}, "firstMatch": [{"browserName": "firefox"}]}}');
 | 
				
			||||||
            $this->session = $sessionData['sessionId'];
 | 
					            $this->session = $sessionData['sessionId'];
 | 
				
			||||||
            echo 'Session: '. $this->session. "\n";
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					        return $this->session;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -105,9 +105,8 @@ class Main
 | 
				
			||||||
     * @param string $serverHost server host name
 | 
					     * @param string $serverHost server host name
 | 
				
			||||||
     * @param int $serverPort server port
 | 
					     * @param int $serverPort server port
 | 
				
			||||||
     * @param int $display VNC display id
 | 
					     * @param int $display VNC display id
 | 
				
			||||||
     * @param string $session existing session id from geckodriver
 | 
					 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public function __construct($serverHost, $serverPort, $display = 6, $session = null)
 | 
					    public function __construct($serverHost, $serverPort, $display = 6)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        require 'commands/base.php';
 | 
					        require 'commands/base.php';
 | 
				
			||||||
        $this->display = $display;
 | 
					        $this->display = $display;
 | 
				
			||||||
| 
						 | 
					@ -117,7 +116,21 @@ class Main
 | 
				
			||||||
        // open xdotool
 | 
					        // open xdotool
 | 
				
			||||||
        $this->control->openInput();
 | 
					        $this->control->openInput();
 | 
				
			||||||
        // open/connect to browser
 | 
					        // open/connect to browser
 | 
				
			||||||
        $this->control->openGeckoDriver($session);
 | 
					        $sessionFile = @fopen('.session', 'r');
 | 
				
			||||||
 | 
					        $session = null;
 | 
				
			||||||
 | 
					        if ($sessionFile !== false) {
 | 
				
			||||||
 | 
					            $session = trim(fgets($sessionFile));
 | 
				
			||||||
 | 
					            fclose($sessionFile);
 | 
				
			||||||
 | 
					            if ($session == '') {
 | 
				
			||||||
 | 
					                $session = null;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        $newSession = $this->control->openGeckoDriver($session);
 | 
				
			||||||
 | 
					        if ($newSession !== $session) {
 | 
				
			||||||
 | 
					            $sessionFile = fopen('.session', 'w');
 | 
				
			||||||
 | 
					            fwrite($sessionFile, $newSession."\n");
 | 
				
			||||||
 | 
					            fclose($sessionFile);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
        $this->control->mousemove(959, 499);
 | 
					        $this->control->mousemove(959, 499);
 | 
				
			||||||
        $windowpos = $this->control->fullscreen();
 | 
					        $windowpos = $this->control->fullscreen();
 | 
				
			||||||
        $this->control->mousemove(960, 500);
 | 
					        $this->control->mousemove(960, 500);
 | 
				
			||||||
| 
						 | 
					@ -192,6 +205,8 @@ class Main
 | 
				
			||||||
        $this->control->mousemove(960, 500);
 | 
					        $this->control->mousemove(960, 500);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $steps = file_get_contents($instructions);
 | 
					        $steps = file_get_contents($instructions);
 | 
				
			||||||
 | 
					        $steps = preg_replace('/[\r\n]/', '', $steps);
 | 
				
			||||||
 | 
					        $steps = preg_replace('!/\*.*\*/!', '', $steps);
 | 
				
			||||||
        $plans = json_decode($steps, true);
 | 
					        $plans = json_decode($steps, true);
 | 
				
			||||||
        if ($plans === null) {
 | 
					        if ($plans === null) {
 | 
				
			||||||
            echo "error reading config\n";
 | 
					            echo "error reading config\n";
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue