DB drivers not specified - sql

I have perl script which on running gives me this error.What could be the error ? because i just changed the host and DB connection setings. Earlier the script worked fine.
I get below error
"dbi:Oracle:host=localhost;sid=nms", 'user', 'password', no database driver specified and DBI_DSN env var not set at ./test.pl line 9..
And here's the code:
sub connect{
my $self = shift;
$logger->debug("Connecting to: " . $self->{config}->{connection}->{host});
$self->{db} = DBI->connect("$self->{config}->{connection}->{host}",
"$self->{config}->{login}->{user}",
"$self->{config}->{login}->{password}")
or ($logger->fatal("Connection Failed : " . $DBI::errstr . " : " . $self->{config}->{login}->{user} . ":" . $self->{config}->{login}->{password} )
and return 0);
return 1; }–

You're missing "dbi:Oracle:", and when connecting to Oracle you don't use host but refer to name from Tnsnames.ora, ie. ORA11 or using complete string instead:
$CFG->{TNS_NAME} = "(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = ORA11)
)
)";
# ..
$CFG->{TNS_NAME} = "ORA11";
my $DB = DBI->connect(
"dbi:Oracle:",
"$CFG->{USER}/$CFG->{PASSWORD}#". $CFG->{TNS_NAME},
"",
{
ChopBlanks => 1,
AutoCommit => 0,
RaiseError => 1,
},
);

Are you sure your dns var is correct ?
it should be formatted like that : "dbi:<driver>:<database>:<host>:<port>";
use DBI;
$database = 'your_db_name';
$host = 'test.com';
$port = '1521';
$user = 'your_user';
$password = 'your_password';
$dsn = 'dbi:Oracle:'.$database.':'.$host.':'.$port;
$db = DBI->connect($dsn, $user, $password, { 'RaiseError' => 1, 'PrintError' => 0, 'AutoCommit' => 0 })
or die "Unable to connect: $DBI::errstr";
You can also try to set your ORACLE_HOME and ORACLE_OWNER env variable before your DBI->connect():
$ENV{'ORACLE_HOME'} = '...' # path to your oracle lib
$ENV{'ORACLE_OWNER'} = 'oracle'; # Owner

Related

AES 256 GCM with php 5.6

I have taken reference of code from this post :
Trying to decrypt with aes-256-gcm with php
Code :
< ?php
$textToEncrypt = "demo text";
$password = '3sc3RLrpd17';
$key = substr(hash('sha256', $password, true), 0, 32);
$cipher = 'aes-256-gcm';
$iv_len = openssl_cipher_iv_length($cipher);
$tag_length = 16;
$iv = openssl_random_pseudo_bytes($iv_len);
$ciphertext = openssl_encrypt($textToEncrypt, $cipher, $key, OPENSSL_RAW_DATA, $iv);
$encrypted = base64_encode($iv.$ciphertext);
$textToDecrypt = $encrypted;
$encrypted = base64_decode($textToDecrypt);
$password = '3sc3RLrpd17';
$key = substr(hash('sha256', $password, true), 0, 32);
$cipher = 'aes-256-gcm';
$iv_len = openssl_cipher_iv_length($cipher);
$iv = substr($encrypted, 0, $iv_len);
$ciphertext = substr($encrypted, $iv_len);
$decrypted = openssl_decrypt($ciphertext, $cipher, $key, OPENSSL_RAW_DATA, $iv);
var_dump (openssl_error_string());
var_dump($decrypted);
echo $decrypted;
?>
Running this code on PHP 5.6
Now the issue is I am always getting false as decrypted text.
What is wrong?

How can I bind correctly my variables to my tokens?

I can't figure out what causes this error, I'm burned out already. I can't figure out how to solve this.
Warning: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter
number: number of bound variables does not match number of tokens in C:\wamp64\www\myproject-dev\public\viajes\orden_mantenimiento\controller.php on line 77
This happens when I try to execute my create method so heres the whole method:
if ($type == 'create') {
$Records = $request->models;
foreach ($Records as $rec) {
if (isset($request->pky)) {
$fky = $request->fky;
$rec->$fky = $request->pky;
}
$aError = Validate($rec);
$statement = $conn->prepare('INSERT INTO order (id, idVehiculo, idTipo, fecha, kilometraje, horaIn, horaSal, proyecto, jefeProy, aprobadoPor, descripcion)
VALUES (:id, :idVehiculo, idTipo, :fecha, :kilometraje, :horaIn, :horaSal, :proyecto, :jefeProy, :aprobadoPor, descripcion)');
$statement->bindValue(':id', $rec->id);
$statement->bindValue(':idVehiculo', $rec->idVehiculo);
$statement->bindValue(':idTipo', $rec->idTipo);
$statement->bindValue(':fecha', $rec->fecha);
$statement->bindValue(':kilometraje', $rec->kilometraje);
$statement->bindvalue(':horaIn', $rec->horaIn);
$statement->bindvalue(':horaSal', $rec->horaSal);
$statement->bindValue(':proyecto', $rec->proyecto);
$statement->bindValue(':jefeProy', $rec->jefeProy);
$statement->bindValue(':aprobadoPor', $rec->aprobadoPor);
$statement->bindValue(':descripcion', $rec->descripcion);
if (!$statement->execute()) { // **========================== THIS IS LINE 77 ===================**
$aErrInfo = $statement->errorInfo();
$aError = array();
$aError[] = array('success' => false);
$aError[] = array('msg' => $aErrInfo[1]);
$aError[] = array('error' => $aErrInfo[2]);
$respuesta["errors"] = $aError;
echo "statement error".$respuesta;
} else {
$rec->id = $conn->lastInsertId();
$respuesta["data"] = $rec;
echo "Data bound.";
}
} else {
$respuesta["errors"] = $aError;
echo "ERROR";
}
}
}
Thanks a lot in advance.

WHMCS License Addon not working

I have just authored a WHMCS addon module that works great on my server; however, others that have tried to use it are not having success. There are 2 issues...
1) I use the WHMCS License Addon; however, it does not appear that their remote machines are making a successful connection to my machine to validate the license. I use the WHMCS supplied code to handle the connection and validation. No idea on what else to check... Any ideas?
2) I have a database that my script checks to see if the user has the most current version of the script. Access to the database works great from my local machine and RemoteSQL is enabled with a % wildcard so anyone should be able to connect but yet the remote machines do not seem to be able to connect. Here is my info...
$link = mysql_connect('gjinternetsolutions.com', 'gj_Guest', 'Password1');
mysql_select_db("gj_Software", $link);
$query = "SELECT * FROM `VersionCheck` where `Software`='RedemptionFee'";
... additional code to display the results
Is anyone able to successfully make a remote connection to the above database?
=========== UPDATE ===========
The second issue above has been resolved. We are still having an issue with the licensing code.... Here is what we have....
# Values obtained from our database...
$localkey=$row['LocalKey'];
$licensekey=$vars['License'];
$results = RedemptionFee_check_gj_license($licensekey,$localkey);
function RedemptionFee_check_gj_license($licensekey,$localkey="")
{
$whmcsurl = "http://gjinternetsolutions.com/home/";
$licensing_secret_key = "####-VALUE REMOVED FOR THIS POST-####"; # Unique value, should match what is set in the product configuration for MD5 Hash Verification
$check_token = time().md5(mt_rand(1000000000,9999999999).$licensekey);
$checkdate = date("Ymd"); # Current date
$usersip = isset($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR'] : $_SERVER['LOCAL_ADDR'];
$localkeydays = 1; # How long the local key is valid for in between remote checks
$allowcheckfaildays = 5; # How many days to allow after local key expiry before blocking access if connection cannot be made
$localkeyvalid = false;
if ($localkey) {
$localkey = str_replace("\n",'',$localkey); # Remove the line breaks
$localdata = substr($localkey,0,strlen($localkey)-32); # Extract License Data
$md5hash = substr($localkey,strlen($localkey)-32); # Extract MD5 Hash
if ($md5hash==md5($localdata.$licensing_secret_key)) {
$localdata = strrev($localdata); # Reverse the string
$md5hash = substr($localdata,0,32); # Extract MD5 Hash
$localdata = substr($localdata,32); # Extract License Data
$localdata = base64_decode($localdata);
$localkeyresults = unserialize($localdata);
$originalcheckdate = $localkeyresults["checkdate"];
if ($md5hash==md5($originalcheckdate.$licensing_secret_key)) {
$localexpiry = date("Ymd",mktime(0,0,0,date("m"),date("d")-$localkeydays,date("Y")));
if ($originalcheckdate>$localexpiry) {
$localkeyvalid = true;
$results = $localkeyresults;
$validdomains = explode(",",$results["validdomain"]);
if (!in_array($_SERVER['SERVER_NAME'], $validdomains)) {
$localkeyvalid = false;
$localkeyresults["status"] = "Invalid";
$results = array();
}
$validips = explode(",",$results["validip"]);
if (!in_array($usersip, $validips)) {
$localkeyvalid = false;
$localkeyresults["status"] = "Invalid";
$results = array();
}
if ($results["validdirectory"]!=dirname(__FILE__)) {
$localkeyvalid = false;
$localkeyresults["status"] = "Invalid";
$results = array();
}
}
}
}
}
if (!$localkeyvalid) {
$postfields["licensekey"] = $licensekey;
$postfields["domain"] = $_SERVER['SERVER_NAME'];
$postfields["ip"] = $usersip;
$postfields["dir"] = dirname(__FILE__);
if ($check_token) $postfields["check_token"] = $check_token;
if (function_exists("curl_exec")) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $whmcsurl."modules/servers/licensing/verify.php");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($ch);
curl_close($ch);
} else {
$fp = fsockopen($whmcsurl, 80, $errno, $errstr, 5);
if ($fp) {
$querystring = "";
foreach ($postfields AS $k=>$v) {
$querystring .= "$k=".urlencode($v)."&";
}
$header="POST ".$whmcsurl."modules/servers/licensing/verify.php HTTP/1.0\r\n";
$header.="Host: ".$whmcsurl."\r\n";
$header.="Content-type: application/x-www-form-urlencoded\r\n";
$header.="Content-length: ".#strlen($querystring)."\r\n";
$header.="Connection: close\r\n\r\n";
$header.=$querystring;
$data="";
#stream_set_timeout($fp, 20);
#fputs($fp, $header);
$status = #socket_get_status($fp);
while (!#feof($fp)&&$status) {
$data .= #fgets($fp, 1024);
$status = #socket_get_status($fp);
}
#fclose ($fp);
}
}
if (!$data) {
$localexpiry = date("Ymd",mktime(0,0,0,date("m"),date("d")-($localkeydays+$allowcheckfaildays),date("Y")));
if ($originalcheckdate>$localexpiry) {
$results = $localkeyresults;
} else {
$results["status"] = "Invalid";
$results["description"] = "Remote Check Failed";
return $results;
}
} else {
preg_match_all('/<(.*?)>([^<]+)<\/\\1>/i', $data, $matches);
$results = array();
foreach ($matches[1] AS $k=>$v) {
$results[$v] = $matches[2][$k];
}
}
if ($results["md5hash"]) {
if ($results["md5hash"]!=md5($licensing_secret_key.$check_token)) {
$results["status"] = "Invalid";
$results["description"] = "MD5 Checksum Verification Failed";
return $results;
}
}
if ($results["status"]=="Active") {
$results["checkdate"] = $checkdate;
$data_encoded = serialize($results);
$data_encoded = base64_encode($data_encoded);
$data_encoded = md5($checkdate.$licensing_secret_key).$data_encoded;
$data_encoded = strrev($data_encoded);
$data_encoded = $data_encoded.md5($data_encoded.$licensing_secret_key);
$data_encoded = wordwrap($data_encoded,80,"\n",true);
$results["localkey"] = $data_encoded;
}
$results["remotecheck"] = true;
}
unset($postfields,$data,$matches,$whmcsurl,$licensing_secret_key,$checkdate,$usersip,$localkeydays,$allowcheckfaildays,$md5hash);
return $results;
}
Yes, I can connect using the details above.
Query run:
SELECT * FROM `gj_Software`.`VersionCheck` where `Software`='RedemptionFee'
Result:
# Software, Version, URL
'RedemptionFee', '1.0', 'http://GJinternetSolutions.com/home/upgrade.php?type=package&id=660'
Hope this helps.
Ash

can't delete subscriber aweber api php wrapper

As expected on documentation for delete subscriber but its not working
require_once('aweber_api/aweber_api.php');
$consumerKey = '***'; # put your credentials here
$consumerSecret = '***'; # put your credentials here
$accessKey = '***'; # put your credentials here
$accessSecret = '***'; # put your credentials here
$account_id = '***'; # put the Account ID here
$list_id = '***'; # put the List ID here
$aweber = new AWeberAPI($consumerKey, $consumerSecret);
try {
$account = $aweber->getAccount($accessKey, $accessSecret);
$listURL = "/accounts/{$account_id}/lists/{$list_id}";
$list = $account->loadFromUrl($listURL);
# subscriber to delete
$params = array(
'email' => 'johndoe#example.com'
);
$subscribers = $list->subscribers;
$new_subscriber = $subscribers->delete($params);
# success!
print "Subscriber was deleted!";
} catch(AWeberAPIException $exc) {
print "<h3>AWeberAPIException:</h3>";
print " <li> Type: $exc->type <br>";
print " <li> Msg : $exc->message <br>";
print " <li> Docs: $exc->documentation_url <br>";
print "<hr>";
exit(1);
}
My reference https://labs.aweber.com/snippets/subscribers#del
Try this code. Its working for me
require_once('aweber_api/aweber_api.php');
$consumerKey = '###';
$consumerSecret = '###';
$accessKey = '###';
$accessSecret = '###';
$account_id = '###';
$list_id = '###';
$aweber = new AWeberAPI($consumerKey, $consumerSecret);
try {
$account = $aweber->getAccount($accessKey, $accessSecret);
$listURL = "/accounts/{$account_id}/lists/{$list_id}";
$list = $account->loadFromUrl($listURL);
$params = array(
'email' => 'info#examples.com'
);
$subscribers = $list->subscribers;
$found_subscribers = $subscribers->find($params);
foreach ($found_subscribers as $subscriber) {
$subscriber->delete();
}
print "Subscriber was deleted!";
} catch(AWeberAPIException $exc) {
print "AWeberAPIException:";
print "Type: $exc->type";
print "Msg : $exc->message";
print "Docs: $exc->documentation_url";
exit(1);
}

Joomla auto login

How can I auto-login a user in Joomla 1.5. I am using this code:
global $mainframe;
$db =& JFactory::getDBO();
$query = ‘SELECT `id`, `password`, `gid`’. ‘ FROM `#__users`’. ‘ WHERE username=’ . $db->Quote( JRequest::getVar(‘username’, null) ). ‘ AND password=’ . `enter code here` $db->Quote( JRequest::getVar(‘passw’, null) );
$db->setQuery( $query );
$result = $db->loadObject();
if($result) {
JPluginHelper::importPlugin(‘user’);
$response->username = JRequest::getVar(‘username’, null);
$result = $mainframe->triggerEvent(‘onLoginUser’, array((array)$response, $options));
}
$mainframe->redirect(‘XXXXXXXXXXXX’);
Where did I go wrong?
add this top of the code, it will solve the issue
jimport(‘joomla.user.helper’);
// Auto Login customization by Akram abbasi
$mainframe = JFactory::getApplication();
$credentials = array();
$credentials['username'] = $app->input->get('username', '', 'string');
$credentials['password'] = $app->input->get('password', '', 'raw');
$mainframe->login($credentials);
//$mainframe->redirect(JRoute::_('index.php', false));