0

I would like to improve an ioncube cms with a hook.

I need an SQL query able to blank mysql content in a specic row in a table, but only if the content in question start with "Modified Product/Service - Username changed from to"

Just to clarify :

  • the cms in question record a log with the old / new user password when a password is changed for a product. I want to create a hook that will detect the line added in the logs, and then delete it. ...or better : a way to ask mysql to refuse to save something if it start with "Modified Product/Service..." (i assume this would have to be done in php, but that also, i cannot figure out how to do it)

What's the SQL request i need for this?

Thank you for you help on this :)

Carl
  • 1
  • 3
  • Something like `SELECT * FROM your_table WHERE your_column LIKE 'Modified Product/Service - Username changed from to%'` ? – Raptor May 08 '14 at 06:06

2 Answers2

0
DELETE FROM yourTable
WHERE content LIKE 'Modified Product/Service - Username changed from to %'

Does the sentence really say from to like that? It seems more likely it would say from OLDNAME to NEWNAME. If so, that part of the pattern should be from % to %.

In PHP, you can prevent inserting the row with something like:

if (!preg_match('#^Modified Product/Service - Username changed from to#', $content)) {
    // Code here to insert the row
}
Barmar
  • 741,623
  • 53
  • 500
  • 612
  • Is there any way i can ask mysql to just refuse to save those lines? – Carl May 08 '14 at 06:09
  • You can't prevent the insert in MySQL, see http://stackoverflow.com/questions/2538786/how-to-abort-insert-operation-in-mysql-trigger. So if that's what you want, you'll have to do it in PHP, as I showed in my answer. – Barmar May 08 '14 at 06:12
  • Well, you can make it blank the passwords with a trigger i believe? I suggest though that you look for a way to turn of this misfeature in your cms, because they really really should have a way to do so. – monocell May 08 '14 at 06:15
  • i tried with DELETE FROM logtable WHERE content LIKE 'Modified Product/Service - Username changed from to %' ...but it doesn't work. Why it may not work? – Carl May 08 '14 at 06:37
  • I don't know. Can you make a sqlfiddle with sample data? – Barmar May 08 '14 at 06:38
  • Hi Barmar. Thank you for your help on this. :) Here is a paste on sqlfiddle : http://sqlfiddle.com/#!2/a2bad the cms in question is whmcs. I want a quick way to whipe out specific lines in the logs, but leave other intacts. – Carl May 08 '14 at 06:45
  • Where is the data? The problem is probably that the pattern doesn't exactly match the log messages, so I can't tell what's wrong if you don't post some messages. – Barmar May 08 '14 at 06:46
  • it's in the description field. The pattern match (copied / pasted) – Carl May 08 '14 at 06:47
  • I mean you haven't put any data in the sqlfiddle, just the schema. I need to see the actual log messages, so I can make sure the pattern matches them correctly. – Barmar May 08 '14 at 06:49
  • logs are looking like this : (75430,'2011-11-21 17:46:32','Modified Product/Service - Password changed from to JTYGHG?%gh','username',28,'77.81.196.116') – Carl May 08 '14 at 06:50
  • my query : mysql_query("DELETE FROM tblactivitylog WHERE content LIKE 'Modified Product/Service - Password changed from to %'"); – Carl May 08 '14 at 06:51
  • That log message says `Password changed`. Your question says `Username changed`. – Barmar May 08 '14 at 06:56
  • ok. it's working now with "DELETE FROM tblactivitylog WHERE description LIKE 'Modified Product/Service - Password changed%" – Carl May 08 '14 at 06:59
0

If you want to restrict in PHP you can use something like

<?php 
$question = $_POST['question'];
if (strpos($question,'Modified Product/Service - Username changed from to') !== false){
  //redirect to some page or exit the control
}else{
  //execute the insert Query here
}
?>
Rizwan Abbas
  • 178
  • 2
  • 10