How to create a signed url with Firebase/JWT? - google-api

In the new version of Googles PHP-API-Cient the Google_Signer_P12 class was removed and now you should create signed urls via Firebase JWT (see https://github.com/google/google-api-php-client/blob/master/UPGRADING.md).
Unfortunately this doesn't work for me (I am trying to generate signed urls for cloud storage downloads). My previous (working) code looked like this:
$signer = new \Google_Signer_P12( 'privatekey.p12' , 'notasecret' );
$stringToSign = 'GET' . "\n" . "\n" . "\n" . $expires . "\n". '/' . $bucketName . '/' . $fileName;
$signature = $signer->sign( utf8_encode( $stringToSign ) );
$finalSignature = \Google_Utils::urlSafeB64Encode( $signature );
I tried to replace this with:
$stringToSign = 'GET' . "\n" . "\n" . "\n" . $expires . "\n". '/' . $bucketName . '/' . $fileName;
$finalSignature = \JWT::encode(
$stringToSign,
'privateKey.p12'
);
but I receive a "SignatureDoesNotMatch" error. Unfortunately I couldn't find anything in the docs on how to upgrade this part of the code.

Related

How to get file name in Laravel without a path file

I'm trying to upload an image file to the database. But, when it posted, it shows a full path of the image file (I use the getClientOriginalName() to get the filename).
DSController.php
public function createDS2(Request $request)
{
//dd($request->all());
$imgName1 = $request->file('opsi_a')->getClientOriginalName() . '-' . time() . '.' . $request->file('opsi_a')->extension();
$imgName2 = $request->file('opsi_b')->getClientOriginalName() . '-' . time() . '.' . $request->file('opsi_b')->extension();
$imgName3 = $request->file('opsi_c')->getClientOriginalName() . '-' . time() . '.' . $request->file('opsi_c')->extension();
$imgName4 = $request->file('opsi_d')->getClientOriginalName() . '-' . time() . '.' . $request->file('opsi_d')->extension();
$data = new DS2;
$data->pertanyaan = $request->input('pertanyaan');
$data->opsi_a = $request->file('opsi_a')->move(public_path('image'), $imgName1);
$data->opsi_d = $request->file('opsi_b')->move(public_path('image'), $imgName2);
$data->opsi_b = $request->file('opsi_c')->move(public_path('image'), $imgName3);
$data->opsi_c = $request->file('opsi_d')->move(public_path('image'), $imgName4);
$data->kunci = $request->input('kunci');
$data->save();
return redirect('ds2');
}
the image file in the database will show something like this :
C:\xampp\htdocs\admin_kuis\public\image\hiu_press.png-1614165665.png
how I can just save the hiu_press.png-1614165665.png in my database?
The same way as #zia-yamin but different syntax.
$imgName1 = $request->file('opsi_a')->getClientOriginalName() . '-' . time() . '.' . $request->file('opsi_a')->extension();
$imgName2 = $request->file('opsi_b')->getClientOriginalName() . '-' . time() . '.' . $request->file('opsi_b')->extension();
$imgName3 = $request->file('opsi_c')->getClientOriginalName() . '-' . time() . '.' . $request->file('opsi_c')->extension();
$imgName4 = $request->file('opsi_d')->getClientOriginalName() . '-' . time() . '.' . $request->file('opsi_d')->extension();
$request->file('opsi_a')->move(public_path('image'), $imgName1);
$request->file('opsi_b')->move(public_path('image'), $imgName2);
$request->file('opsi_c')->move(public_path('image'), $imgName3);
$request->file('opsi_d')->move(public_path('image'), $imgName4);
$data = new DS2;
$data->pertanyaan = $request->input('pertanyaan');
$data->opsi_a = pathinfo($imgName1, PATHINFO_BASENAME);
$data->opsi_b = pathinfo($imgName2, PATHINFO_BASENAME);
$data->opsi_c = pathinfo($imgName3, PATHINFO_BASENAME);
$data->opsi_d = pathinfo($imgName4, PATHINFO_BASENAME);
$data->kunci = $request->input('kunci');
$data->save();
return redirect('ds2');
Use This Code:
if ($request->hasFile('file_name')) {
$file_name = $request->file('file_name');
$file_name = time() . $file_name->getClientOriginalName();
}
store your file full path in $stored_file variable and then use this one:
$data->opsi_d = $request->file('opsi_b')->move(public_path('image'), pathinfo($imgName2)['basename']);
Also, you can use:
$file = Input::file('image');
$fileName = $file->move(public_path('image'), $imgName1->getOriginalFileName());
$fileName->image = $fileName ->getRealPath();

Excel file with Multiple Sheets in Laravel-Excel 3.1 -> Import Original and Store + Store Individual sheets after cell validations

Thanks for the reaching out to my question, but i have got a problem, I'm trying to Import an excel file with multiple sheets.
Find sheets by some cell-value validation, like if on cell E7, i have a value, store this sheet as separate file. I'm doing mapping() for cell values, and then trying to use Excel::store to save each individual sheet separately. Can't receive any data for individual sheets
Also store the original file. This works!
The issue is, i can't receive any data for storing individual-sheets as excel files, i can create the individual excel files, but no data is being received, or maybe i'm not using the right data-format mentioned on documentation.
Please also check the code. Any help would be appreciated.
public function mapping(): array
{
return [
'altafit_id' => 'E7',
'year' => 'B3',
'initial_month' => 'B4',
'final_month' => 'B5',
];
}
public function model(array $row)
{
// dd($row);
$name = $row['altafit_id'];
$year = $row['year'];
$initial_month = $row['initial_month'];
$final_month = $row['final_month'];
$file_type = 'club';
// dd(collect((object) $row));
Excel::store(collect((object) $row), 'P&L_' . $name . '_' . $year . '_' . $initial_month . '_06' . ',clubs' . ',' . $initial_month . ',' . $final_month . '.' . 'xls', 'public');
return new Files([
//'user_id' => $row['user_id'],
'file_name' => 'P&L_' . $name . '_' . $year . '_' . $initial_month . '_06' . ',clubs' . ',' . $initial_month . ',' . $final_month . '.' . 'xls',
'file_type' => $file_type
]);
}
Already check the documentation, but doesn't work for me.
https://docs.laravel-excel.com/3.1/getting-started/

laravel deserialize/decode job raw body

i'm experiencing one problem here. Sample will speak for it self.
Queue::after(function (JobProcessed $event) {
$job_details = json_decode($event->job->getRawBody(), true);
)});
This is how $job_details looks like:
'displayName' => 'App\\Jobs\\CommandJob',
'job' => 'Illuminate\\Queue\\CallQueuedHandler#call',
'maxTries' => 10,
'timeout' => NULL,
'data' =>
array (
'commandName' => 'App\\Jobs\\CommandJob',
'command' => 'O:19:"App\\Jobs\\CommandJob":9:{s:32:"' . "\0" . 'App\\Jobs\\CommandJob' . "\0" . 'commandName";N;s:30:"' . "\0" . 'App\\Jobs\\CommandJob' . "\0" . 'arguments";N;s:28:"' . "\0" . 'App\\Jobs\\CommandJob' . "\0" . 'command";s:20:"google:get-campaigns";s:5:"tries";i:10;s:32:"' . "\0" . 'App\\Jobs\\CommandJob' . "\0" . 'nextCommand";a:1:{i:0;s:19:"google:get-adgroups";}s:6:"' . "\0" . '*' . "\0" . 'job";N;s:10:"connection";N;s:5:"queue";s:11:"update_data";s:5:"delay";N;}',
I would like to get some params from $job_details['data']['command'].
Is there some simple way to do this , or i need some home made soultion ?
$event->job->getRawBody returns a string so you can't write $job_details['data']['command'] and you will end up with Illegal string offset error.
I am using Laravel 5.4 and i have managed to retrieve my Job instance using $event->job->payload() then applying the unserialize method according to the documentation.
So what i did is :
$payload = $event->job->payload();
$myJob = unserialize($payload['data']['command']);
$myJob->getMyProperty();
//... Just work with $myJob as if it were your job class
The $job_details["data"]["command"] is a string generated from serialize($value). You can unserialize($str) it to create the job object represented by your string. You will then have access to the properties according to the usual visibility rules.
$job = unserialize($job_details["data"]["command"]);
dump($job->queue;) // "update_data"
I was having error with an email that contained some space in it. To fix the problem and send it, I had to decode the payload of the failed jobs and remove the space in the email.
To do so, in php artisan tinker
// take some specific failed jobs
$failed_job = DB::table('failed_jobs')->where('id', $your_job_id)->first();
$payload = json_decode($failed_job->payload);
$obj = unserialize($payload->data->command);
// here I have the user content, I can see the wrong email
$user = $obj->notifiables;
//update email and save
$user->email = "newemail#something"
$user->update()
As the last step, push again the jobs into the queue.

How to prevent ducplicate tickets aqnd therads in osTicket

Since around March of this year our osTicket system started posting duplicate tickets and duplicate threads.
I've tried everything method I know of to troubleshoot and identity where and why this is occurring. I've even implemented a catch condition to check the db tables prior to inserting tickets and threads to see if the contents of the $vars[]'s match what is already in the DB tables.
No success to solve this problem whatsoever.
I've Googled it and see where this issue has been in existence and dates back a number of years.
Does any one have a solution on how to stop osTicket from consistently creating ducpliate tickets and threads?
I tried the following from piecing together suggestions others have made out there in the various osTicket up through v1.10. Here is the code I tried. It actually worked for 2-days straight, then began to fail again yesterday.
Inserted around line 2498 in ./include/class.ticket.php right before if($errors) return 0;.
/**
* J.Doe added to intercept duplicate ticket entries.
* Updated: 2017-06-12
* #author John Doe <jd#example.com>
*/
$sql1='
SELECT ticketID FROM ost_ticket
WHERE
source = "' . $vars['source'] . '"
AND topic_id = "' . $vars['topicId'] . '"
AND url = "' . $vars['url'] . '"
AND priority_id = "' . $vars['priorityId'] . '"
AND duedate = "' . date( 'Y-m-d H:i:s', strtotime( $vars['duedate'] . ' ' . $vars['time'] ) ) . '"
AND team_id = "' . $vars['assignId'] . '"
AND subject = "' . $vars['subject'] . '"
AND dept_id = "' . $vars['deptId'] . '"
AND email = "' . $vars['email'] . '"
AND name = "' . $vars['name'] . '"
';
$sql2='
SELECT id FROM ost_ticket_thread
WHERE
staff_id = "' . $vars['assignId'] . '"
AND poster = "' . $vars['name'] . '"
AND title = "' . $vars['subject'] . '"
AND body = "' . $vars['message'] . '"
';
$res1=db_query($sql1);
$res2=db_query($sql2);
if( ( $res1 && db_num_rows( $res1 ) ) || ( $res2 && db_num_rows( $res2 ) ) ) {
header( 'Location: http://example.com/workorders/' );
exit;
}
//Any error above is fatal.
if($errors) return 0;

Get latitude and longitude given name and address

I have a CSV file with name,area,city fieds and I'm expecting that CSV with following fields name,area,city,latitude,longitude
Can any one suggest which API is best for these,
I already tried
Google API's
Textsearch: this is giving overall city wise. Not particular
eg: kfc, in jp nagar 1st phase, bangalore it throws all over bangalore kfc list
I want exactly
echo $url = "https://maps.googleapis.com/maps/api/geocode/json?address=" . $name1 . "+" . $area1 . "+" . $city . "&key=" . $api_key;
Which API will fulfill my requirement?
I tried this also
$url = "https://maps.googleapis.com/maps/api/place/textsearch/json?query=". $name1 . "+" . $area1 . "+" . $city . "&key=" . $api_key;

Resources