Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- declare(strict_types = 1);
- const USERNAME = '???';
- const PASSWORD = '???';
- header ( "content-type: text/plain;charset=utf8" );
- require_once ('hhb_.inc.php');
- $hc = new hhb_curl ( '', true );
- $html = $hc->exec ( 'https://app.cfe.gob.mx/Aplicaciones/CCFE/Recibos/Consulta/login.aspx' )->getStdOut ();
- $domd = @DOMDocument::loadHTML ( $html );
- $inputsRaw = getDOMDocumentFormInputs ( $domd, true ) ['aspnetForm'];
- $inputs = array ();
- foreach ( $inputsRaw as $tmp ) {
- $inputs [$tmp->getAttribute ( "name" )] = $tmp->getAttribute ( "value" );
- }
- assert ( isset ( $inputs ['__VIEWSTATE'], $inputs ['__EVENTVALIDATION'] ) );
- $inputs ['ctl00$PHContenidoPag$UCLogin2$LoginUsuario$UserName'] = USERNAME;
- $inputs ['ctl00$PHContenidoPag$UCLogin2$LoginUsuario$Password'] = PASSWORD;
- hhb_var_dump ( $inputs );
- $html = $hc->setopt_array ( array (
- CURLOPT_URL => 'https://app.cfe.gob.mx/Aplicaciones/CCFE/Recibos/Consulta/login.aspx',
- CURLOPT_POST => true,
- CURLOPT_POSTFIELDS => http_build_query ( $inputs )
- ) )->exec ()->getStdOut ();
- // hhb_var_dump($html) & die();
- $domd = @DOMDocument::loadHTML ( $html );
- $xp = new DOMXPath ( $domd );
- $loginErrors = $xp->query ( '//*[(contains(@style,"color:Red") or contains(@color,"Red")) and not(contains(@style,"hidden"))]' );
- foreach ( $loginErrors as $tmp ) {
- echo "login error!! ";
- var_dump ( $tmp->textContent );
- }
- if (0 === $loginErrors->length) {
- echo "login success!";
- }
- function getDOMDocumentFormInputs(DOMDocument $domd, bool $getOnlyFirstMatches = false): array {
- // :DOMNodeList?
- $forms = $domd->getElementsByTagName ( 'form' );
- $parsedForms = array ();
- $isDescendantOf = function (DOMNode $decendant, DOMNode $ele): bool {
- $parent = $decendant;
- while ( NULL !== ($parent = $parent->parentNode) ) {
- if ($parent === $ele) {
- return true;
- }
- }
- return false;
- };
- // i can't use array_merge on DOMNodeLists :(
- $merged = function () use (&$domd): array {
- $ret = array ();
- foreach ( $domd->getElementsByTagName ( "input" ) as $input ) {
- $ret [] = $input;
- }
- foreach ( $domd->getElementsByTagName ( "textarea" ) as $textarea ) {
- $ret [] = $textarea;
- }
- foreach ( $domd->getElementsByTagName ( "button" ) as $button ) {
- $ret [] = $button;
- }
- return $ret;
- };
- $merged = $merged ();
- foreach ( $forms as $form ) {
- $inputs = function () use (&$domd, &$form, &$isDescendantOf, &$merged): array {
- $ret = array ();
- foreach ( $merged as $input ) {
- // hhb_var_dump ( $input->getAttribute ( "name" ), $input->getAttribute ( "id" ) );
- if ($input->hasAttribute ( "disabled" )) {
- // ignore disabled elements?
- continue;
- }
- $name = $input->getAttribute ( "name" );
- if ($name === '') {
- // echo "inputs with no name are ignored when submitted by mainstream browsers (presumably because of specs)... follow suite?", PHP_EOL;
- continue;
- }
- if (! $isDescendantOf ( $input, $form ) && $form->getAttribute ( "id" ) !== '' && $input->getAttribute ( "form" ) !== $form->getAttribute ( "id" )) {
- // echo "this input does not belong to this form.", PHP_EOL;
- continue;
- }
- if (! array_key_exists ( $name, $ret )) {
- $ret [$name] = array (
- $input
- );
- } else {
- $ret [$name] [] = $input;
- }
- }
- return $ret;
- };
- $inputs = $inputs (); // sorry about that, Eclipse gets unstable on IIFE syntax.
- $hasName = true;
- $name = $form->getAttribute ( "id" );
- if ($name === '') {
- $name = $form->getAttribute ( "name" );
- if ($name === '') {
- $hasName = false;
- }
- }
- if (! $hasName) {
- $parsedForms [] = array (
- $inputs
- );
- } else {
- if (! array_key_exists ( $name, $parsedForms )) {
- $parsedForms [$name] = array (
- $inputs
- );
- } else {
- $parsedForms [$name] [] = $tmp;
- }
- }
- }
- unset ( $form, $tmp, $hasName, $name, $i, $input );
- if ($getOnlyFirstMatches) {
- foreach ( $parsedForms as $key => $val ) {
- $parsedForms [$key] = $val [0];
- }
- unset ( $key, $val );
- foreach ( $parsedForms as $key1 => $val1 ) {
- foreach ( $val1 as $key2 => $val2 ) {
- $parsedForms [$key1] [$key2] = $val2 [0];
- }
- }
- }
- return $parsedForms;
- }
Add Comment
Please, Sign In to add comment