Skip to content

Commit

Permalink
feature/check-db-file-readability (#4)
Browse files Browse the repository at this point in the history
feature/check-db-file-readability
  • Loading branch information
squatto authored Feb 2, 2020
2 parents 5cef180 + 8424e1e commit e65a8b5
Showing 1 changed file with 73 additions and 31 deletions.
104 changes: 73 additions & 31 deletions find-messages.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,78 @@

$dbPath = $_SERVER['HOME'] . '/Library/Messages/chat.db';

$db = new PDO('sqlite:' . $dbPath);
$query = $db->query("
select
message.rowid,
ifnull(handle.uncanonicalized_id, chat.chat_identifier) AS sender,
message.service,
datetime(message.date / 1000000000 + 978307200, 'unixepoch', 'localtime') AS message_date,
message.text
from
message
left join chat_message_join
on chat_message_join.message_id = message.ROWID
left join chat
on chat.ROWID = chat_message_join.chat_id
left join handle
on message.handle_id = handle.ROWID
where
is_from_me = 0
and text is not null
and length(text) > 0
and (
text glob '*[0-9][0-9][0-9][0-9][0-9]*'
or text glob '*[0-9][0-9][0-9][0-9][0-9][0-9]*'
or text glob '*[0-9][0-9][0-9][0-9][0-9][0-9][0-9]*'
or text glob '*[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]*'
)
order by
message.date desc
limit 100
");
if (! is_readable($dbPath)) {
$workflow->result()
->title('ERROR: Unable to Access Your Messages')
->subtitle('We were unable to access the file that contains your text messages')
->arg('')
->valid(true);
echo $workflow->output();
exit;
}

try {
$db = new PDO('sqlite:' . $dbPath);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
$workflow->result()
->title('ERROR: Unable to Access Your Messages')
->subtitle('We were unable to access the file that contains your text messages')
->arg('')
->valid(true);
$workflow->result()
->title('Error Message:')
->subtitle($e->getMessage())
->arg('')
->valid(true);
echo $workflow->output();
exit;
}

try {
$query = $db->query("
select
message.rowid,
ifnull(handle.uncanonicalized_id, chat.chat_identifier) AS sender,
message.service,
datetime(message.date / 1000000000 + 978307200, 'unixepoch', 'localtime') AS message_date,
message.text
from
message
left join chat_message_join
on chat_message_join.message_id = message.ROWID
left join chat
on chat.ROWID = chat_message_join.chat_id
left join handle
on message.handle_id = handle.ROWID
where
is_from_me = 0
and text is not null
and length(text) > 0
and (
text glob '*[0-9][0-9][0-9][0-9][0-9]*'
or text glob '*[0-9][0-9][0-9][0-9][0-9][0-9]*'
or text glob '*[0-9][0-9][0-9][0-9][0-9][0-9][0-9]*'
or text glob '*[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]*'
)
order by
message.date desc
limit 100
");
} catch (PDOException $e) {
$workflow->result()
->title('ERROR: Unable to Query Your Messages')
->subtitle('We were unable to run the query that reads your text messages')
->arg('')
->valid(true);
$workflow->result()
->title('Error Message:')
->subtitle($e->getMessage())
->arg('')
->valid(true);
echo $workflow->output();
exit;
}

$found = 0;
$max = 8;
Expand Down Expand Up @@ -65,7 +107,7 @@
if (! $found) {
$workflow->result()
->title('No 2FA Codes Found')
->subtitle('No two-factor authentication codes were found in your recent iMessage messages')
->subtitle('No two-factor authentication codes were found in your recent text messages')
->arg('')
->valid(true);
}
Expand Down

0 comments on commit e65a8b5

Please sign in to comment.