Git Product home page Git Product logo

mts's Introduction

What is this?

Simple, its a tool set for PHP. Currently comprised of two core components shell and browser.

This project strives to give developers the tools that let them automate processes that were designed for people.

My philosophy:

People should only do interesting work. If it can be automated it should be automated.

The Browser:

Browser Documentation.

The Shell:

Shell Documentation.

The Install:

Installation Documentation.

mts's People

Contributors

itsmemattchung avatar lucasinunas avatar merlinthemagic avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mts's Issues

License

Could you provide a license file for this code, so we know what it can/cannot be used for? I'm interested in possibly using this for a BSD related project, but everything must be explicitly licensed appropriately or else it cannot be included in the project.

Bash::shellStrExecute>> Read data timeout

After ensuring screen is installed, I get this when using code from example to connect to remote host.

PHP Fatal error:  Uncaught Exception: MTS\Common\Devices\Shells\Bash::shellStrExecute>> Read data timeout in /home/g9735/IdeaProjects/mts/MTS/Common/Devices/Shells/Bash.php:81
Stack trace:
#0 /home/g9735/IdeaProjects/mts/MTS/Common/Devices/Shells/Base.php(89): MTS\Common\Devices\Shells\Bash->shellStrExecute('\x03\r', '\\[bash\\.5bc1f68...', 10000)
#1 /home/g9735/IdeaProjects/mts/MTS/Common/Devices/Shells/Bash.php(252): MTS\Common\Devices\Shells\Base->exeCmd('\x03\r')
#2 /home/g9735/IdeaProjects/mts/MTS/Common/Devices/Shells/Base.php(105): MTS\Common\Devices\Shells\Bash->shellKillLastProcess()
#3 /home/g9735/IdeaProjects/mts/MTS/Common/Devices/Actions/Remote/Connections/Ssh.php(76): MTS\Common\Devices\Shells\Base->killLastProcess()
#4 /home/g9735/IdeaProjects/mts/MTS/Common/Devices/Actions/Remote/Connections/Ssh.php(47): MTS\Common\Devices\Actions\Remote\Connections\Ssh->connectByUsernameFromLinux(Object(MTS\Common\Devices\Shells\Bash), 'redacted', 'redacted', 'redacted', 22, 30000)
#5 /home/g9735/IdeaProjects/mts/MTS/Common/ in /home/g9735/IdeaProjects/mts/MTS/Common/Devices/Shells/Bash.php on line 81
PHP Fatal error:  Uncaught Exception: MTS\Common\Devices\Shells\Bash::shellStrExecute>> Read data timeout in /home/g9735/IdeaProjects/mts/MTS/Common/Devices/Shells/Bash.php:81
Stack trace:
#0 /home/g9735/IdeaProjects/mts/MTS/Common/Devices/Shells/Base.php(89): MTS\Common\Devices\Shells\Bash->shellStrExecute('\x03\r', '\\[bash\\.5bc1f68...', 10000)
#1 /home/g9735/IdeaProjects/mts/MTS/Common/Devices/Shells/Bash.php(252): MTS\Common\Devices\Shells\Base->exeCmd('\x03\r')
#2 /home/g9735/IdeaProjects/mts/MTS/Common/Devices/Shells/Base.php(105): MTS\Common\Devices\Shells\Bash->shellKillLastProcess()
#3 /home/g9735/IdeaProjects/mts/MTS/Common/Devices/Shells/Bash.php(223): MTS\Common\Devices\Shells\Base->killLastProcess()
#4 /home/g9735/IdeaProjects/mts/MTS/Common/Devices/Shells/Base.php(148): MTS\Common\Devices\Shells\Bash->shellTerminate()
#5 /home/g9735/IdeaProjects/mts/MTS/Common/Devices/Shells/Base.php(28): MTS\Common\Devices\Shells\Base->terminate()
#6 [internal function]: MTS\Common\Devices\Shells\Base->__destruct()
#7 {main}

Could not determine OS distribution

When launching the MtsSetup.php file in my website's public folder, when I set the correct path to the MTS library and click setup, I get the error at the end of this post. I'm running this on my LAMP setup on Amazon Linux AMI release 2016.09, here more info about my setup:

cat /etc/os-release
NAME="Amazon Linux AMI"
VERSION="2016.09"
ID="amzn"
ID_LIKE="rhel fedora"
VERSION_ID="2016.09"
PRETTY_NAME="Amazon Linux AMI 2016.09"
ANSI_COLOR="0;33"
CPE_NAME="cpe:/o:amazon:linux:2016.09:ga"
HOME_URL="http://aws.amazon.com/amazon-linux-ami/"

And here the error I get:

Fatal error: Uncaught exception 'Exception' with message 'MTS\Common\Devices\Actions\Local\Host\OperatingSystem::execute>> Could not determine OS distribution' in /var/www/library/MTS/Common/Devices/Actions/Local/Host/OperatingSystem.php:115 Stack trace: #0 /var/www/library/MTS/Common/Devices/Actions/Local/Host/OperatingSystem.php(11): MTS\Common\Devices\Actions\Local\Host\OperatingSystem->execute() #1 /var/www/library/MTS/EnableMTS.php(39): MTS\Common\Devices\Actions\Local\Host\OperatingSystem->getOsObj() #2 /var/www/library/MTS/EnableMTS.php(34): mtsEnvironmentalSetup() #3 /var/www/thegroomersspotlight/public/MtsSetup.php(80): require_once('/var/www/librar...') #4 {main} thrown in /var/www/library/MTS/Common/Devices/Actions/Local/Host/OperatingSystem.php on line 115

Clearing the text field

How can we clear the text field ? so i was trying to implement captcha solve by user, but if i save the window object and then enter the captcha , or corrected email by user , it actually appends to the text field , i assume this is because i serialized and saved the previous state of the page and hence it already contained the email i entered before; here is the image;

image

you can see in the email field , that emails are appended to the previous state email.

In short i need something like clear text field , then i will be able to clear the field and enter the posted email etc

Regarding Two way verification issue.

Hi merlinthemagic,,
Sorry for opening new issue. As I have already followed this thread.
Amazon daily deals page not loading completely
I have followed your thread and able to go beyond the first step of two step verification at amazon. But in second step I got an screen of insert code which is send to me via mobile number. How can I process this using MTS library. Please help me.

Why getElement() show different result?

target.html

<!doctype html>
<html>
<head>
<title>i'm title</title>
</head>
<body>
  <div>CONTENT</div>
</body>
</html>

mts.php

<?php
set_time_limit(120);
require('MTSpath/EnableMTS.php');
$windowObj = \MTS\Factories::getDevices()->getLocalHost()->getBrowser('phantomjs')->getNewWindow("http://localhost/target.html");
print_r($windowObj->getElement('title')); 
print_r($windowObj->getElement('div')); 
?>

i run same script in different machine:

  1. ubuntu 14 32bit
    MTS download: 2 weeks ago
Array
(
    [tagName] => TITLE
    [value] => 
    [type] => 
    [text] => i'm title
    [innerHTML] => i'm title
    [location] => Array
        (
            [top] => 0
            [bottom] => 0
            [right] => 0
            [left] => 0
        )

)
Array
(
    [tagName] => DIV
    [value] => 
    [type] => 
    [text] => 
    [innerHTML] => CONTENT
    [location] => Array
        (
            [top] => 8
            [bottom] => 27
            [right] => 1912
            [left] => 8
        )

)
  1. win 7 32bit
    MTS download: 2 days ago
Array
(
    [tagName] => TITLE
    [value] => 
    [type] => 
    [text] => i'm title
    [location] => Array
        (
            [top] => 0
            [bottom] => 0
            [right] => 0
            [left] => 0
        )

)
Array
(
    [tagName] => DIV
    [value] => 
    [type] => 
    [text] => 
    [location] => Array
        (
            [top] => 8
            [bottom] => 28
            [right] => 1912
            [left] => 8
        )

)

if i copy MTS from ubuntu to windows. My windows will have same result as my ubuntu.

  1. why i got different result?
  2. if i want to add array ['outerHTML'] or something else, how to do that? what file that i should edit?

Click on Element question

<a href="javascript:void(0);" class="bblcheck_button" record_id="6227260" rel="prettyPhoto[iframe]" id="check_bl" infovalue="Check">Check</a>
I want to click on id="check_bl", but there are so many record_id=[id number]. Can I click to all record_id??

How to set user agent?

Hello, thank you for perfect source !
I'm new for PHP. I don't know how to set user agent in your code.
My code:

setUserAgent($agentName); $windowObj = \MTS\Factories::getDevices()->getLocalHost()->getBrowser('phantomjs')->getNewWindow($myUrl); ?>

And I got error:

Notice: Undefined variable: windowObj in /var/www/html/master/test2.php on line 9

Fatal error: Uncaught Error: Call to a member function setUserAgent() on null in /var/www/html/master/test2.php:9 Stack trace: #0 {main} thrown in /var/www/html/master/test2.php on line 9

Please give me an idea. Thank you so much ~!

how to use mysql in code?

Hi, I inserted mysql connect in the top of page after <?php to use database :

define('db_host','localhost');
define('db_data','database');
define('db_user','root');
define('db_pass','password');
mysql_connect(db_host,db_user,db_pass) or die("Not the connect to database");
mysql_select_db(db_data) or die ("Not found database");

And error:

Fatal error: Uncaught Error: Call to undefined function mysql_connect() in /var/www/html/master/test.php:6 Stack trace: #0 {main} thrown in /var/www/html/master/test.php on line 6

Please help me. Thank you very much

Don't enforce connection via username:password

I'm using authentication via SSH keys instead of username/password. MTS does not support it, because it throws exception when missing username/password;

$shellObj = \MTS\Factories::getDevices()->getRemoteHost('redacted')->getShell();
PHP Fatal error:  Uncaught Exception: MTS\Common\Devices\Types\Remotehost::getShell>> Missing Connection details in /home/g9735/IdeaProjects/mts/MTS/Common/Devices/Types/Remotehost.php:80
Stack trace:
#0 /home/g9735/IdeaProjects/mts/index.php(5): MTS\Common\Devices\Types\Remotehost->getShell()
#1 {main}
  thrown in /home/g9735/IdeaProjects/mts/MTS/Common/Devices/Types/Remotehost.php on line 80

String cutting off with sendKeyPresses function using a variable

So , i am adding an address in a text field , the address is :

1181 S. Beech Dr. #204

When i pass this through a variable:
$windowObj->mouseEventOnElement("[id=address-ui-widgets-enterAddressLine1]", 'leftclick'); $windowObj->sendKeyPresses($_REQUEST['address1_pp']);
it shows as cut off #204 part:
image

but when i hardcode the string then it enters correctly;

$windowObj->mouseEventOnElement("[id=address-ui-widgets-enterAddressLine1]", 'leftclick');
$windowObj->sendKeyPresses('1181 S. Beech Dr. #204');

Bash not available on localHost

I get an error !
Fatal error: Uncaught exception 'Exception' with message 'MTS\Common\Devices\Actions\Local\Host\Shell::execute>> Bash not available on localHost

Formatting output

Thank you for providing this which is a great way to learn, and yes it has some security concerns that one has to address. I was wondering if there is a way to address output formatting, in a way that it might appear more organized. Since you have experience I thought maybe you had some ideas.
Thanks

Install Error

Hi! MTS returns error during install on Centos 7 x64. Installing manually with file downloaded here.
Already gave exec privileges (755) to the file but still same error:

`Warning: exec() has been disabled for security reasons in /home/hotsale/MTS/Common/Devices/Actions/Local/Base.php on line 11

Warning: implode(): Invalid arguments passed in /home/hotsale/MTS/Common/Devices/Actions/Local/Base.php on line 13

Fatal error: Uncaught Exception: MTS\Common\Devices\Actions\Local\Host\OperatingSystem::execute>> Could not determine OS distribution in /home/hotsale/MTS/Common/Devices/Actions/Local/Host/OperatingSystem.php:115 Stack trace: #0 /home/hotsale/MTS/Common/Devices/Actions/Local/Host/OperatingSystem.php(11): MTS\Common\Devices\Actions\Local\Host\OperatingSystem->execute() #1 /home/hotsale/MTS/EnableMTS.php(39): MTS\Common\Devices\Actions\Local\Host\OperatingSystem->getOsObj() #2 /home/hotsale/MTS/EnableMTS.php(34): mtsEnvironmentalSetup() #3 /home/hotsale/public_html/MtsSetup.php(80): require_once('/home/hotsale/M...') #4 {main} thrown in /home/hotsale/MTS/Common/Devices/Actions/Local/Host/OperatingSystem.php on line 115`

How to capture element to image

hi, you can add function to export element to image.
Ex:
<img src="url.png" alt="image" class="img" />
I want export element[class=img] to base64 data, can you help me?

How to install MTS manually without PHP automation install (MtsSetup.php) ?

hi bro,
after several weeks i use MTS, i use in my VPS ubuntu which is working awesome.

2 days ago, i try to install it in my laptop

  1. windows 7 SP1 32 bit (localhost)
  2. PHP 7.1 (XAMPP)
  3. python 3.6.3
  4. Powershell 6.0.0-rc-win-x86
  5. cygwin 2.9.0 (python 2.7)
  6. win 7 SP1 cmd

i try both browser and CLI (cmd, ps, cygwin) installation but i got error. I fix the MTS source but still didnt get right.

if i read the doc carefully, this issue #11 , and the source which have inconsistance $OsName for Windows (some script use Windows, some use windows. and some of them use comparison $OsName without case insensitive (strtolower). i get that MTS was not fully already for windows. CMIIW

But, since python, phantomJS which is core for MTS. i think MTS should can run in windows too.

So, now i want to know how to install MTS manually without MtsSetup.php.

  1. we skip using composer require merlinthemagic/MTS seems no other dependencies from other github there. so we can just download the source (zip) from github.
  2. PHP 5.3++ installed and make sure this allowed:
    a. exec()
    b. popen()
    c. pclose()
    d. proc_open()
  3. python 3.x.x installed
  4. phantomJS installed
  5. make sure php, python, phantomJS registered in System Path Environment

what's next?

problem:

  1. inconsistance in windows OsName: windows and Windows
  2. no linux screen alternative in windows. i can get this using cygwin but still fail to install MTS. and actually i dont know what screen usage and what screen did in MTS. so i really blank of this
  3. we cant use exec("where python") so easly using browser installation in windows. we must give much effort to make this run. really!! i take this part 6 hours

forgot the rest (so sleepy yesterday).

Note: i hope i can help pull something if i get correct information

Install breaks with Fatal Error: Call to member function setCnild() on null

root@ec0f866a369a:/var/www/html/vendor/merlinthemagic/mts# php MtsSetup.php
We do not know which user you intend to execute the scripts with
All example commands use '$userName' as the user, please replace with
the username you intent to use.
Fatal error: Uncaught Error: Call to a member function setChild() on null in /var/www/html/vendor/merlinthemagic/mts/MTS/Factories/Files.php:
19
Stack trace:
#0 /var/www/html/vendor/merlinthemagic/mts/MTS/Common/Devices/Actions/Local/Host/PhpEnvironment.php(52): MTS\Factories\Files->getFile('', '')
#1 /var/www/html/vendor/merlinthemagic/mts/MTS/Common/Devices/Actions/Local/Host/PhpEnvironment.php(16): MTS\Common\Devices\Actions\Local\Hos
t\PhpEnvironment->execute()
#2 /var/www/html/vendor/merlinthemagic/mts/MTS/Common/Devices/Actions/Local/Host/MtsSetup/SetupMTS.php(130): MTS\Common\Devices\Actions\Local
\Host\PhpEnvironment->getIniFile()
#3 /var/www/html/vendor/merlinthemagic/mts/MTS/Common/Devices/Actions/Local/Host/MtsSetup/SetupMTS.php(14): MTS\Common\Devices\Actions\Local\
Host\MtsSetup\SetupMTS->timezoneValid()
#4 /var/www/html/vendor/merlinthemagic/mts/MtsSetup.php(18): MTS\Common\Devices\Actions\Local\Host\MtsSetup\SetupMTS->getInstall()
#5 {main}
  thrown in /var/www/html/vendor/merlinthemagic/mts/MTS/Factories/Files.php on line 19

Call to a member function getPathAsString() on boolean

using your example code

$shellObj = \MTS\Factories::getDevices()->getRemoteHost('ip_address')->setConnectionDetail('username', 'password')->getShell();

results in

$ php index.php
PHP Fatal error:  Uncaught Error: Call to a member function getPathAsString() on boolean in /home/g9735/IdeaProjects/mts/MTS/Common/Devices/Actions/Local/Host/Shell.php:67
Stack trace:
#0 /home/g9735/IdeaProjects/mts/MTS/Common/Devices/Actions/Local/Host/Shell.php(16): MTS\Common\Devices\Actions\Local\Host\Shell->execute()
#1 /home/g9735/IdeaProjects/mts/MTS/Common/Devices/Types/Localhost.php(55): MTS\Common\Devices\Actions\Local\Host\Shell->getShell('bash', false, false, 1000, 1000)
#2 /home/g9735/IdeaProjects/mts/MTS/Common/Devices/Types/Remotehost.php(66): MTS\Common\Devices\Types\Localhost->getShell('bash', false)
#3 /home/g9735/IdeaProjects/mts/index.php(5): MTS\Common\Devices\Types\Remotehost->getShell()
#4 {main}
  thrown in /home/g9735/IdeaProjects/mts/MTS/Common/Devices/Actions/Local/Host/Shell.php on line 67

How to run function from target using MTS?

i have this script:

<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script>
function showtext()
{
    $.ajax({
        url: 'process.php',
        type: 'GET',
        data: {name: $('input').val()},
        success: function(d){
            $('#show').text(d);
        }
    })
}
</script>
<input type="text" value="John">
<button id="clickme" onclick="showtext()">click me</button>
<div id="show"></div>

i was able to done this using leftclick. But i want to know can we run showtext() directly?
i try callFunctionJs but not work
thanks.

Save the login state , so that do not have to log in again and again

So i am trying to save the login state , by getting the cookie and saving it ;

$cookieArray = $windowObj->getCookies(); file_put_contents(__DIR__ .'/tmp/cookies/cookies.ser', serialize($cookieArray));

image

and then on the next script run, load that cookie file again , loop over it , but the login page still shows , here is my code;

`//open the login page:
$myUrl = "https://www.amazon.com/gp/css/account/address/view.html?ie=UTF8&ref_=myab_view_new_address_form&viewID=newAddress";
$browserObj = \MTS\Factories::getDevices()->getLocalHost()->getBrowser('phantomjs');

$windowObj      = $browserObj->getNewWindow();
	
$agentName	= "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36 OPR/46.0.2597.57";
$windowObj->setUserAgent($agentName);
	
$windowObj->setUrl($myUrl);

//read array
$cookieArray = unserialize(file_get_contents(__DIR__ . '/tmp/cookies/cookies.ser'));

foreach($cookieArray as $key=>$value){
	
	/* echo "<pre>";
	var_dump($cookieArray[$key]);
	echo "</pre>"; */
	
	$name			= $cookieArray[$key]['name']; //String: mandetory cookie name.
	$value			= $cookieArray[$key]['value']; //String: mandetory cookie value.
	$domain			= $cookieArray[$key]['domain']; //String: defaults to current domain in window URL
	$path			= $cookieArray[$key]['path']; //String: defaults to "/";
	$expireTime		= $cookieArray[$key]['expiry']; //Int (epoch): default is 2147483647
	$serverOnly		= false; //Bool: default false; if true cookie cannot be read by client scripts.
	$secureOnly		= false; //Bool: default false; if true cookie can only be transmitted using secure (defined by the user agent, i.e. TLS) channel.

	$windowObj->setCookie($name, $value, $domain, $path, $expireTime, $serverOnly, $secureOnly);
	
}

//perform a screenshot:
$screenshotData	= $windowObj->screenshot();

//render it:
echo '<img src="data:image/png;base64,' . base64_encode($screenshotData) . '" />';`

How to enable the web driver?

How to enable the web driver, I check for availability on this service
https://intoli.com/blog/not-possible-to-block-chrome-headless/chrome-headless-test.html
When using MTS, it shows that it is disabled ...
How can I turn it on?

This my code
require(ROOT.'/vendor/autoload.php'); $browserObj=\MTS\Factories::getDevices()->getLocalHost()->getBrowser('phantomjs'); $browserObj->setKeepalive(true); $browserObj->setDefaultExecutionTime(60000); $windowObj=$browserObj->getNewWindow(); $windowObj->setUserAgent('Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:68.0) Gecko/20100101 Firefox/68.0'); $windowObj->setUrl('https://intoli.com/blog/not-possible-to-block-chrome-headless/chrome-headless-test.html'); $content=$windowObj->getDom(); $browserObj->terminate();

The ultimate goal is to make the request look like a real browser, and not be recognized as headless ...

Remote powershell doesn't return any data

Hello,

I know this project is no longer supported but I am taking a chance because we need help and this project is the most promising solution to meet our needs. We tried several different ways but it seems that when we execute the commands in command prompt, everything works perfectly but when we try the same commands in php, we don't get any data, not even an error message.

$cred = New-Object System.Management.Automation.PSCredential -ArgumentList @("*USER*",(ConvertTo-SecureString -String "*PASSWORD*" -AsPlainText -Force))

$session = New-PSSession -ComputerName "*SERVER*" -UseSSL -Credential $cred -Authentication CredSSP

Invoke-command -ComputerName "*SERVER*" -UseSSL -Credential $cred -Authentication CredSSP -ScriptBlock { Add-PSSnapin Microsoft.Exchange.Management.PowerShell.SnapIn; Get-Mailbox|select alias }

In my examples, I have obviously replaced the sensitive values but in my execution I use the right values.

Do you have any idea why the code doesn't run the same in both environments? We are on Windows and use WAMP Server.

Class 'MTS\Factories' not found

I have created a file and added this code <?php
$myUrl = "http://www.youtube.com";
$windowObj = \MTS\Factories::getDevices()->getLocalHost()->getBrowser('phantomjs')->getNewWindow($myUrl);

//now you can either retrive the DOM and parse it, like this:
$domData = $windowObj->getDom();

//this project also lets you manipulate the live page. Click, fill forms, submit etc.

?>

When I try to laujnch it, it get this error Class 'MTS\Factories' not found

Amazon daily deals page not loading completely

So here is the link for the daily deals amazon 1st page ( https://www.amazon.com/gp/goldbox ) . i am trying to load this with the php script. but it is loading only the first eight products , the rest 24 products are not loaded. After analyzing the daily deals page ,i realized the rest of products are loaded through ajax.

Anyway i can make the complete page load ? Here is the script i am using;

`ini_set('max_execution_time', 120);
require 'MTS/MTS/EnableMTS.php';

$windowObj = \MTS\Factories::getDevices()->getLocalHost()->getBrowser('phantomjs')->getNewWindow();

$agentName = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36 OPR/46.0.2597.57";
$windowObj->setUserAgent($agentName);

$myUrl = "https://www.amazon.com/gp/goldbox/";
$windowObj->setUrl($myUrl);

// tried to save page to see if all page is loaded or not , seems like did not load
//$domData = $windowObj->getDom();
//file_put_contents("daily_deals.html", $domData);

//perform a screenshot:
$screenshotData = $windowObj->screenshot();

//the image is just showing some portion of the screen, how can i capture complete page ?
echo <img src="data:image/png;base64,' . base64_encode($screenshotData) . '" />;

error excecuting command

Hi merlinthemagic,,
before all thanks for this great project!

when i send command with
$sent = $shellObj->exeCmd($daemon." sendfrom ".$faucetd." ".$wallet." ".$faucet);
it should get in to a coin daemon and excecute command but it doesnt get $faucet variable that it is 0.08, and when i excecute the code
i get error from coin daemon saying that i must use the command with sendfrom
as i can see it is not sending the last variable that is 0.08 and it says 0.08: command not found
if i go to shell and excecute that command i'm able to do that directly from coin daemoin

all vars where given by database i'm able to do
$sent = $shellObj->exeCmd($daemon." getbalance ".$wallet);
with no problems

so i think is an issue with MTS that is not sending all vars any help?

Custom headers

how to add custom header ?

this is custom header option:
http://phantomjs.org/api/webpage/property/custom-headers.html

but in where should i add this ? i itried to add in "PJCtrl.js" file , but then my php script kept on loading infinitely. I tried to add like this in "PJCtrl.js" file

`function configurePage(windowObj)
{
try {

	if (typeof windowObj.pjsPage == 'undefined') {
		windowObj.pjsPage			= webpage.create();
		
		windowObj.pjsPage.customHeaders = {
			"Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
			"Accept-Language:en-US,en;q=0.8",
			"Connection:keep-alive",
			"User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.124 Safari/537.36"
		};
		
	}`

Setup problem

Hello, What is the problem when I run setup

Fatal error: Uncaught exception 'Exception' with message 'MTS\Common\Devices\Actions\Local\Host\OperatingSystem::execute>> Not Handled for Request Type: getOsObj' in /var/www/html/vc/vc/MTS/Common/Devices/Actions/Local/Host/OperatingSystem.php:143 Stack trace: #0 /var/www/html/vc/vc/MTS/Common/Devices/Actions/Local/Host/OperatingSystem.php(11): MTS\Common\Devices\Actions\Local\Host\OperatingSystem->execute() #1 /var/www/html/vc/vc/MTS/EnableMTS.php(39): MTS\Common\Devices\Actions\Local\Host\OperatingSystem->getOsObj() #2 /var/www/html/vc/vc/MTS/EnableMTS.php(34): mtsEnvironmentalSetup() #3 /var/www/html/vc/vc/MtsSetup.php(80): require_once('/var/www/html/v...') #4 {main} thrown in /var/www/html/vc/vc/MTS/Common/Devices/Actions/Local/Host/OperatingSystem.php on line 143

Thank you!!

Powershell not available on localHost

$shellObj = \MTS\Factories::getDevices()->getLocalHost()->getShell('powershell');

Throw Exception

MTS\Common\Devices\Actions\Local\Host\Shell::execute>> Powershell not available on localHost

How to fix that?

Set cookie again

Hi Sir.
How can I , save cookies of a page I login to and then set that cookie again and use it again?
Actually how can I set cookie before request url ?
Thank You

How to handle download file using MTS?

Hi merlin XD
How to handle download file using MTS?

if i can get url, ofc i can handle that. But i cant get the url, so How to handle that

  1. open: "https://indoxxi.net/movie/wheelman-2017-a3fq/play"
  2. after video play: hit SUB button, or run $('#dlsub').click() in the console
<?php
ini_set('max_execution_time', 120);
require_once "/var/www/html/test/MTS/MTS/EnableMTS.php";
$url = "https://indoxxi.net/movie/wheelman-2017-a3fq/play";

$windowObj      = \MTS\Factories::getDevices()->getLocalHost()->getBrowser('phantomjs')->getNewWindow();
$windowObj->setUserAgent("Mozilla/5.0 (Windows NT 6.1; WOW64; rv:47.0) Gecko/20100101 Firefox/47.0");
$windowObj->setUrl($url);

if($windowObj->getSelectorExists('#dlsub'))
{
	echo "button exists". PHP_EOL;
	$windowObj->clickElement('#dlsub');
	echo "button clicked". PHP_EOL;
}
else
{
	echo "button not exists";
}

header

Request URL:https://sub.indoxxi.net/muvi/471014/id/prov/boker1.srt
Request Method:GET
Status Code:200  (from disk cache)
Remote Address:104.25.235.118:443
Referrer Policy:no-referrer-when-downgrade
Response Headers
accept-ranges:bytes
access-control-allow-origin:*
cf-ray:3b75669ffe176fea-SIN
content-encoding:gzip
content-length:24500
content-type:text/plain
date:Thu, 02 Nov 2017 07:32:36 GMT
etag:"04cfdc7e952d31:0"
last-modified:Wed, 01 Nov 2017 08:16:56 GMT
server:cloudflare-nginx
status:200
vary:Accept-Encoding
Request Headers
Provisional headers are shown
Accept:*/*
Origin:https://indoxxi.net
Referer:https://indoxxi.net/movie/wheelman-2017-a3fq/play
User-Agent:Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36

at this moment, i can handle this using phantomJS, casperJS. But how to handle this using MTS?

Error when connecting...

Hi, my goal is to connect to the first server, then tunnel to a second one, and get the last 300 lines of a log file.

both servers are RHEL and I can use putty to ssh to both w/out issues using username and pw.

Here is my code:

` require_once "c:\xampp\htdocs\tools\MTS\EnableMTS.php";

//first you get a shell on the first server:
$shellObj = \MTS\Factories::getDevices()->getRemoteHost('192.168.1.14')->setConnectionDetail('test', 'test')->getShell('bash', false);

//then build on that first shell, the following way.
\MTS\Factories::getDevices()->getRemoteHost('10.10.10.48')->setConnectionDetail('user', 'test')->getShell($shellObj);

//any command executed on the shell will run only on the second host you connected to.
$return1 = $shellObj->exeCmd("hostname");
echo $return1;//hostname of the second host you connected to`

when I run the above, I get the below error message:


( ! ) Fatal error: Uncaught Error: Call to a member function getActiveShell() on string in C:\xampp\htdocs\tools\MTS\Common\Devices\Actions\Remote\Connections\Ssh.php on line 31

1 | 0.2088 | 405480 | {main}( ) | ...\test.php:0
2 | 0.6057 | 506984 | MTS\Common\Devices\Types\Remotehost->getShell( ) | ...\test.php:24
3 | 0.6073 | 554888 | MTS\Common\Devices\Actions\Remote\Connections\Ssh->connectByUsername( ) | ...\Remotehost.php:73
4 | 0.6073 | 555264 | MTS\Common\Devices\Actions\Remote\Connections\Ssh->execute( ) | ...\Ssh.php:18


Install on localhost (windows)

I'm using Appserv and got an error when run mtsSetup.php:

Fatal error: Class 'MTS\Factories' not found in C:\AppServ\www\MTS\MTS\EnableMTS.php on line 34

What's problem?

Timeout error

So sometimes i get timeout PHP Fatal error when script keeps running for few seconds ( maybe due to slow internet sometimes i guess ) and then stops halfway with timeout error , even though i have set at top of script this ;

ini_set('max_execution_time', 900); ( 15 minutes --> 900 secs )

this is the error:

[17-Sep-2017 04:35:42 America/Denver] PHP Fatal error: Uncaught exception 'Exception' with message 'MTS\Common\Devices\Browsers\PhantomJS::getSelectorExists>> Got result code: 0, EMsg: timeout, ECode: 408' in /home/fankeyco/public_html/1chinadirect/testing/mts_library/MTS/MTS/Common/Devices/Browsers/PhantomJS.php:227
Stack trace:
#0 /home/fankeyco/public_html/1chinadirect/testing/mts_library/MTS/MTS/Common/Devices/Browsers/Window.php(150): MTS\Common\Devices\Browsers\PhantomJS->getSelectorExists(Object(MTS\Common\Devices\Browsers\Window), '[name=code]')
#1 /home/fankeyco/public_html/1chinadirect/testing/mts_library/mts_amazon_add_address.php(610): MTS\Common\Devices\Browsers\Window->getSelectorExists('[name=code]')
#2 {main}
thrown in /home/fankeyco/public_html/1chinadirect/testing/mts_library/MTS/MTS/Common/Devices/Browsers/PhantomJS.php on line 227

How to get dom element?

i try to learn this 4 hours
but im stuck in this random website.

how to get the video from this. (note: this website provide direct download link, so maybe its fine to use this website as example)

https://indoxxi.net/film-seri/stranger-things-season-2-2017-1fhos2/play

because, there is no way to get specific dom element except whole html. So i decide to use simple html dom parser.

after page loaded, i run several script on web console

$('video').attr('src');
undefined
$("[id='ep-1072070']").click()
[a#ep-1072070.btn-eps.active, prevObject: init(1), context: document, selector: "[id='ep-1072070']"]
$('video').attr('src');
"https://lh3.googleusercontent.com/wpbYsMBx7WHFrm_jSjZQrQVlPLusRF0njilMpyTlbg_YVNSffjfufAWht5_kvJu4BUDJRpWkeuw=m22"

from information above. we know that there is not any

ok. lets do this with MTS

==============
header.php

<?php
ini_set('max_execution_time', 120);
require_once "/var/www/html/test/MTS/MTS/EnableMTS.php";
require_once "advanced_html_dom.php"; //same as PHP Simple HTML DOM Parser http://simplehtmldom.sourceforge.net/manual.htm
$url = "https://indoxxi.net/film-seri/stranger-things-season-2-2017-1fhos2/play";

//MTS begin
$windowObj      = \MTS\Factories::getDevices()->getLocalHost()->getBrowser('phantomjs')->getNewWindow($url);
$windowObj->setUserAgent("Mozilla/5.0 (Windows NT 6.1; WOW64; rv:47.0) Gecko/20100101 Firefox/47.0");
$wait	= "function wait5() {
	setTimeout(function(){}, 5000);
	return 'wait 5sec';
}";
$windowObj->loadJS($wait);
$selector = "[id='ep-1072070']";
$exists		= $windowObj->getSelectorExists($selector);

test1.php

<?php
require('header.php');
if($exists)
{
	//using clickElement
	$windowObj->clickElement($selector);
	echo $windowObj->callJSFunction("wait5") ."<br>";
	sleep(5);
	$dom = $windowObj->getDom();
	$html = str_get_html($dom); //from simple dom html parser
	var_dump($html->find('video')->outertext); //still empty
	
}

test2.php

<?php
require('header.php');
if($exists)
{
	//using leftclick
	$windowObj->mouseEventOnElement($selector, 'leftclick');
	echo $windowObj->callJSFunction("wait5") ."<br>";
	sleep(5);
	$dom = $windowObj->getDom();
	$html = str_get_html($dom); //from simple dom html parser
	var_dump($html->find('video')->outertext); //still empty
	
}

test3.php

<?php
require('header.php');
if($exists)
{
	//using callJSFunction
	$scriptData	= "function myHelloWorld() {
		loadEpisode(0,1072070);
		return 'script loaded';
	}"; //we get loadEpisode() from onclick property in $selector
	$windowObj->loadJS($scriptData);
	echo $windowObj->callJSFunction("myHelloWorld") ."<br>";
	echo $windowObj->callJSFunction("wait5") ."<br>";
	sleep(5);
	$dom = $windowObj->getDom();
	$html = str_get_html($dom); //from simple dom html parser
	var_dump($html->find('video')->outertext); //still empty
	
}

but all i get is NULL. :(

how i can get that video src using MTS?

thanks .

sry for my long post. but i really struggle to know about this

PHP Session destroy not working

So i sometimes save the browser state in a session , and continue the automationtask from where i left by loading window obj etc from the session. But when i manually try to destroy the session , php does not destroy it. although i have noticed that when the actual folder from the work directory is destroyed ( eg ini_set('max_execution_time', 300); ) after for example 300 seconds , only then php lets me destroy the session
function logout(){
session_start();
session_unset();
session_destroy();
header("Location: mts_add_address.php");
exit;
}

if( isset($_REQUEST["logout"]) && $_REQUEST["logout"] == "yes" ){logout();}

eg saving in a PHP session, this will not get destroyed manually , only destroyed until the folder in work directory is destroyed ( this is what i have observed , i could be wrong ):
$saveWindowObj = serialize($windowObj);
$_SESSION["window_obj"] = $saveWindowObj;

If the folder is still present in the WorkDirectory , and i try to destroy my session and after destroying it when i print the session variable ,
var_dump($_SESSION);

all my set session variables are still there.

Fatal error: Uncaught Exception Could not determine OS version

I Caught the error while after run composer dump-autoload. I am running on Windows NT Desktop 6.0 build 6002 (Windows Server 2008 Enterprise Edition Service Pack 2) (I am aware of my server outdated :'( ). Please I need help, what am I supposed to do then ? Thanks in advance.

Fatal error: Uncaught Exception: MTS\Common\Devices\Actions\Local\Host\OperatingSystem::execute>> Could not determine OS version in C:\xampp\htdocs\myproject\vendor\merlinthemagic\mts\MTS\Common\Devices\Actions\Local\Host\OperatingSystem.php:117 Stack trace: #0 C:\xampp\htdocs\myproject\vendor\merlinthemagic\mts\MTS\Common\Devices\Actions\Local\Host\OperatingSystem.php(11): MTS\Common\Devices\Actions\Local\Host\OperatingSystem->execute() #1 C:\xampp\htdocs\myproject\vendor\merlinthemagic\mts\MTS\EnableMTS.php(39): MTS\Common\Devices\Actions\Local\Host\OperatingSystem->getOsObj() #2 C:\xampp\htdocs\myproject\vendor\merlinthemagic\mts\MTS\EnableMTS.php(34): mtsEnvironmentalSetup() #3 C:\xampp\htdocs\myproject\vendor\composer\autoload_real.php(69): require('C:\\xampp\\htdocs...') #4 C:\xampp\htdocs\myproject\vendor\composer\autoload_real.php(59): composerRequire981082f7a0b8008583433cb793079xxx('028ab563f39ac1e...', 'C:\\xampp\\htdocs...') #5 C:\xampp\htdocs\myproject\vendor\autoload.php(7): ComposerAutoloaderInit981082f7a0b80085xxx in C:\xampp\htdocs\myproject\vendor\merlinthemagic\mts\MTS\Common\Devices\Actions\Local\Host\OperatingSystem.php on line 117

WorkDirectory File time extend

sometimes when i save a window object;
$saveWindowObj = serialize($windowObj); $_SESSION['window_obj'] = $saveWindowObj;

and refresh to try to unserialize and use windowobject , after some time , error comes ,

"PHP Fatal error: Uncaught exception 'Exception' with message 'File does not exist: /home/fankeyco/public_html/1chinadirect/testing/mts_library/MTS/MTS/WorkDirectory/LHB_59b118a98e0ec/stdOut' in /home/fankeyco/public_html/1chinadirect/testing/mts_library/MTS/MTS/Common/Tools/FileSystems/Files.php:29 "

so in the "WorkDirectory" some folders are automatically deleted after few seconds , how can we extend the time ? so that they are not deleted quickly and hence i will be able to use the window object, which i saved in a session, for extended time period

select option and javascript

First of all, i would like to congratule you for this amazing project.

Second, i have a form like this:

<form name="formit"><select name="juite" onchange="changethis(this.value)"><option value="00" selected>Select option</option><option value="Option*01">Option 1</option><option value="Option*02">Option 2</option><option value="Option*03">Option 3</option><option value="Option*04">Option 4</option><option value="Option*05">Option 5</option></select><a href="javascript:Send('formoptionsnews');"><img src="images/sendform.png"></a></form>

How can i choose an option and finally send the form??

i tried this to choose an option:
$windowObj->mouseEventOnElement("[name=juite]", 'leftclick');
$windowObj->mouseEventOnElement("[value=Option*04]", 'leftclick');
but it doesnt work..

Thanks

simple issue

hi sir thanks for providing such nice code, i have a simple problem that what to do if phantomjs has been blocked by the website. Any way to fix this kind of problem.

Fatal error

Hi merlin,
i am using your great script to automate some task, but the script after a while stops and show me the attached error.
timeout

i think is timeout but, how can i fix it.

Execute Script Over SSH via a Jumpbox

Hi @merlinthemagic
Your repo looks fantastic just what I need, but I was after some help. (I wasn't sure if to post here or in MTM-SSH, sorry if it's wrong)

My problem, I need to run a script (Bash, Perl, etc) on a remote machine but I can only access it via a Jumpbox over SSH using Key authentication.
A <-> B <-> C

ServerA contains the script and the key to access ServerB, need to connect as nagios
ServerB contains the key to connect to server ServerC, need to connect as root

PHP is version 7.0, running on Ubuntu 16.04 LTS, OpenSSH_7.2p2 Ubuntu-4ubuntu2.1 (Sadly no -J support)

As of today, I'm limited to a one liner via SSH and quotes are always a problem, as mentioned I would ideally like to create a PHP script which reads the contents on the script file and is able to execute them directly on ServerC, capturing the output (and return code if possible) without the need for multiple SCP/temporary files.

ssh -q -o BatchMode=yes -o StrictHostKeyChecking=no -o ConnectTimeout=10 -t nagios@ServerB ssh -q -o BatchMode=yes -o StrictHostKeyChecking=no -o ConnectTimeout=5 root@ServerC 'command'

Thanks in advance.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.