designatedvictim
Red Shirt
- Joined
- Sep 16, 2024
- Posts
- 104
Part 2
PHP:
/******************************************************************************
Support functions in the class named 'site'
******************************************************************************/
/******************************************************************************
Logs into the site and stores the authenticated and sessionid cookie values
in the local cookiejar file
RETURNS: VOID
******************************************************************************/
function doLogin() {
log_message( 'trace', __METHOD__ . ' ' . __LINE__ );
$login_url = $this->config->item('leLogin_url');
$referer = $this->config->item('leReferer');
$username = $this->config->item('leUsername');
$password = $this->config->item('lePassword');
$credentials = $this->config->item('leCcredentials');
$cookiejarFile = $this->config->item('cookiejarFile');
$ch = curl_init( $login_url );
curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, 'POST' );
$payload = '{"login":"' . $username . '","password":"' . $password . '"}';
// Really ought to used the encoded $credentials with CURLOPT_USERPWD, this was faster to get working
curl_setopt( $ch, CURLOPT_POSTFIELDS, $payload );
curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json') );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
// curl_setopt( $ch, CURLOPT_USERPWD, $credentials );
curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, false );
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false );
curl_setopt( $ch, CURLOPT_COOKIEJAR, $cookiejarFile );
curl_setopt( $ch, CURLOPT_COOKIEFILE, $cookiejarFile );
curl_setopt( $ch, CURLOPT_REFERER, $referer );
// curl_setopt( $ch, CURLOPT_CAINFO, getcwd() . '\cacert.pem' );
// curl_setopt($ch, CURLOPT_VERBOSE, 1);
$content = curl_exec( $ch );
log_message( 'trace', __METHOD__ . ' ' . __LINE__ . " content [$content]" );
$thisData = curl_exec( $ch );
$thisError = curl_errno( $ch );
$thisErrorMsg = curl_error( $ch ) ;
$thisHeader = curl_getinfo( $ch );
if ( curl_errno( $ch ) ) {
// echo 'Error:' . curl_error( $ch );
log_message( 'trace', __METHOD__ . ' ' . __LINE__ . " Error: $thisError" );
log_message( 'trace', __METHOD__ . ' ' . __LINE__ . " Error Msg: $thisErrorMsg" );
log_message( 'trace', __METHOD__ . ' ' . __LINE__ . " Error Header:\n" . print_r( $thisHeader, TRUE ) );
} else {
$thisSize = 0;
if ( !empty( $thisData ) ) { $thisSize = strlen( $thisData ); }
log_message( 'trace', __METHOD__ . ' ' . __LINE__ . " Data Size: $thisSize" );
}
curl_close( $ch );
}
/******************************************************************************
Connect to the site, passing the authenticated and sessionid cookie values
through the local cookiejar file, adds the auth_token cookie value
RETURNS: VOID
******************************************************************************/
function getToken() {
log_message( 'trace', __METHOD__ . ' ' . __LINE__ );
$referer = $this->config->item('leReferer');
$tokenURL = $this->config->item('leTokenURL');
$cookiejarFile = $this->config->item('cookiejarFile');
$tokenURL .= time();
$ch = curl_init( $tokenURL );
curl_setopt( $ch, CURLOPT_HTTPHEADER, array('accept: application/json') );
curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, 'GET' );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, false );
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false );
curl_setopt( $ch, CURLOPT_COOKIEJAR, $cookiejarFile );
curl_setopt( $ch, CURLOPT_COOKIEFILE, $cookiejarFile );
curl_setopt( $ch, CURLOPT_REFERER, $referer );
// curl_setopt( $ch, CURLOPT_CAINFO, getcwd() . '\cacert.pem' );
// curl_setopt($ch, CURLOPT_VERBOSE, 1);
$thisData = curl_exec( $ch );
$thisError = curl_errno( $ch );
$thisErrorMsg = curl_error( $ch ) ;
$thisHeader = curl_getinfo( $ch );
if ( curl_errno( $ch ) ) {
// echo 'Error:' . curl_error( $ch );
log_message( 'trace', __METHOD__ . ' ' . __LINE__ . " Error: $thisError" );
log_message( 'trace', __METHOD__ . ' ' . __LINE__ . " Error Msg: $thisErrorMsg" );
log_message( 'trace', __METHOD__ . ' ' . __LINE__ . " Error Header:\n" . print_r( $thisHeader, TRUE ) );
} else {
$thisSize = 0;
if ( !empty( $thisData ) ) { $thisSize = strlen( $thisData ); }
log_message( 'trace', __METHOD__ . ' ' . __LINE__ . " Data Size: $thisSize" );
}
curl_close( $ch );
}
/******************************************************************************
Connect to the site, passing the authenticated, sessionid, and auth_token
cookie values through the local cookiejar file
RETURNS: STRING (CSV data)
******************************************************************************/
function getStoryStats() {
log_message( 'trace', __METHOD__ . ' ' . __LINE__ );
$referer = $this->config->item('leReferer');
$endpoint = $this->config->item('leEndpoint');
$cookiejarFile = $this->config->item('cookiejarFile');
log_message( 'trace', __METHOD__ . ' ' . __LINE__ . " referer: $referer" );
log_message( 'trace', __METHOD__ . ' ' . __LINE__ . " endpoint: $endpoint" );
$ch = curl_init( $endpoint );
curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, 'GET' );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, false );
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false );
curl_setopt( $ch, CURLOPT_COOKIEJAR, $cookiejarFile );
curl_setopt( $ch, CURLOPT_COOKIEFILE, $cookiejarFile );
curl_setopt( $ch, CURLOPT_REFERER, $referer );
// curl_setopt( $ch, CURLOPT_CAINFO, getcwd() . '\cacert.pem' );
// curl_setopt($ch, CURLOPT_VERBOSE, 1);
$thisData = curl_exec( $ch );
$thisError = curl_errno( $ch );
$thisErrorMsg = curl_error( $ch ) ;
$thisHeader = curl_getinfo( $ch );
if ( curl_errno( $ch ) ) {
// echo 'Error:' . curl_error( $ch );
log_message( 'trace', __METHOD__ . ' ' . __LINE__ . " Error: $thisError" );
log_message( 'trace', __METHOD__ . ' ' . __LINE__ . " Error Msg: $thisErrorMsg" );
log_message( 'trace', __METHOD__ . ' ' . __LINE__ . " Error Header:\n" . print_r( $thisHeader, TRUE ) );
} else {
$thisSize = 0;
if ( !empty( $thisData ) ) { $thisSize = strlen( $thisData ); }
log_message( 'trace', __METHOD__ . ' ' . __LINE__ . " Data Size: $thisSize" );
}
curl_close( $ch );
return ( $thisData );
}
Last edited: