How to prevent ducplicate tickets aqnd therads in osTicket - 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;

Related

Convert Query from Codeigniter to Laravel 8

How to write this query in laravel? this query was used in Codeigniter
$ci->db->query("SELECT ratings.rating_id," . $table . "." . $namefield . " as thenamefield,ROUND(AVG(ratings.rating_num),2) as rating
FROM ratings," . $table . " WHERE " . $table . "." . $idfield . " = ratings.rating_id GROUP BY rating_id
ORDER BY rating DESC LIMIT " . $limit . "");
try this
$select_part = $table . "." . $namefield;
DB::table('ratings')
->select('ratings.rating_id',DB::raw("{$select_part} as thenamefield"),DB::raw("ROUND(AVG(ratings.rating_num)2) as rating"))
->crossJoin($table)
->whereRaw("{$select_part} = ratings.rating_id")
->groupBy("rating_id")
->orderByRaw("rating DESC")
->limit($limit)
->get();

whereBetween not working with Carbon::parse()->subDay() & current day laravel

i want to query whereBetween two dates with time
here is code which is working fine
whereBetween('created_at', [now()->subDay()->format('Y-m-d') . ' ' . $tgame->start_time->format('H:i:s'), now()->format('Y-m-d') . ' ' . $tgame->end_time->format('H:i:s')]
but this code is not working
$date = Carbon::parse($request->date);
whereBetween('created_at', [$date->subDay()->format('Y-m-d') . ' ' . $tgame->start_time->format('H:i:s'), $date->format('Y-m-d') . ' ' . $tgame->end_time->format('H:i:s')]
please also explain thank you
Calling subDay() on the $date object will set the time in the Carbon object back 24 hours. So in the upper boundary for whereBetween, you are not using the request date, but the one 24 hours back.
To achieve what you want, you need to copy the object before changing it:
...->whereBetween('created_at', [$date->copy()->subDay()->format('Y-m-d') . ' ' . $tgame->start_time->format('H:i:s'), $date->format('Y-m-d') . ' ' . $tgame->end_time->format('H:i:s')]

How to filter {ITEM_TITLE} and {ITEM_DESCRIPTION} osclass keywords before using them in emails?

How to filter {ITEM_TITLE} and {ITEM_DESCRIPTION} osclass keywords before using them in emails?
I want to apply a function on the item_title and item_description before using them in emails.
Ex.
Title: Sell bmw_ x5__
To become
Sell bmw x5
without changing the database values
I have the function
removeunderline(argument) that works, I only need to know from where to call it or where to use it.
(Osclass forums are blocked for new users, that's why I ask here)
/oc-includes/osclass/emails.php
Put removeunderline() at {ITEM_TITLE} and {ITEM_DESCRIPTION} values.
Example:
$words = array();
$words[] = array(
'{ITEM_DESCRIPTION_ALL_LANGUAGES}',
'{ITEM_DESCRIPTION}',
'{ITEM_COUNTRY}',
'{ITEM_PRICE}',
'{ITEM_REGION}',
'{ITEM_CITY}',
'{ITEM_ID}',
'{USER_NAME}',
'{USER_EMAIL}',
'{ITEM_TITLE}',
'{ITEM_URL}',
'{ITEM_LINK}',
'{VALIDATION_LINK}',
'{VALIDATION_URL}',
'{EDIT_LINK}',
'{EDIT_URL}',
'{DELETE_LINK}',
'{DELETE_URL}'
);
$words[] = array(
$all,
removeunderline($item['s_description']), // here
$item['s_country'],
osc_format_price($item['i_price']),
$item['s_region'],
$item['s_city'],
$item['pk_i_id'],
$item['s_contact_name'],
$item['s_contact_email'],
removeunderline($item['s_title']), // here
$item_url,
$item_link,
'<a href="' . $validation_url . '" >' . $validation_url . '</a>',
$validation_url,
'' . $edit_url . '',
$edit_url,
'' . $delete_url . '',
$delete_url
);
Do the same for all {ITEM_TITLE} in this file (10 replacements).
Do the same for all {ITEM_DESCRIPTION} in this file (3 replacements).

preg_match(): No ending delimite

My website shows the following error when host updates the php version
Warning: preg_match(): No ending delimiter '^' found in
in the following code:
<?php
$mid_str = " and mid != '0' and ";
if($_REQUEST['search']){
mysql_select_db($database_myconn, $myconn);
$query_spages = "SELECT id, url, title, description, keywords, active, ip, catID, exp, pdate,
MATCH(title,description,keywords)
AGAINST ('$search_str' IN BOOLEAN MODE) AS score FROM pages
WHERE MATCH(title, description,keywords)
AGAINST ('$search_str' IN BOOLEAN MODE) " . $mid_str . " active = 'Yes' ORDER BY score DESC";
}else// not search fetch rand by catid
$query_spages = "SELECT * FROM pages where " . preg_match("^ and", "", $mid_str) . " active = 'Yes' and catID = '" . $_REQUEST['id'] . "' ORDER BY mid DESC";
mysql_select_db($database_myconn, $myconn);
$spages = mysql_query($query_spages, $myconn) or die(mysql_error());
//$row_spages = mysql_fetch_assoc($spages);
unset($settings);
$settings = mysql_fetch_assoc(mysql_query('select * from settings where id = 1',$myconn));
?>
preg_match expects a start and an end of the regular expression.
For example preg_match("/^ and/", "", $mid_str).
In your case, ^ is taken as start delimiter but the regex does not end with ^ so you get an error. Start and end delimiter can be anything, but most likely /is used to not clash with other specially treated characters.
Also, you probably mixed up preg_matchand preg_replace. I think you want to preg_replacehere, p.e.
$query_spages = "SELECT * FROM pages where " . preg_replace("/^ and/", "", $mid_str) . " active = 'Yes' and catID = '" . $_REQUEST['id'] . "' ORDER BY mid DESC";

How to create a signed url with Firebase/JWT?

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.

Resources