Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated UI, added date search, search queries and datestamps #1

Open
wants to merge 44 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
f0ea50b
added gitignore
clayshieh Dec 9, 2017
b2be7f1
added sensitive directories to gitignore
clayshieh Dec 10, 2017
1f8415b
removed settings.py from gitignore
clayshieh Dec 10, 2017
0b36803
added date filtering functionality
clayshieh Dec 11, 2017
8954a28
refactored filtering message functionality
clayshieh Dec 11, 2017
b2c435e
cleaned up messages views
clayshieh Dec 11, 2017
9211d9e
removed extra url endpoint
clayshieh Dec 11, 2017
5c8ba0e
updated style to ios9 ish and removed UiUIKit
clayshieh Dec 11, 2017
36fc62c
removed test html on home page
clayshieh Dec 11, 2017
f1fa116
updated README, updated readme, and created empty db folder for less …
clayshieh Dec 11, 2017
4dfcd22
added a better screenshot
clayshieh Dec 11, 2017
19c2b28
added instructions to home page
clayshieh Dec 11, 2017
4ed345b
updated home page
clayshieh Dec 11, 2017
d62ffc1
added datestamps
clayshieh Dec 11, 2017
d7f8f89
fixed css
clayshieh Dec 11, 2017
8b5f88b
added search functionality
clayshieh Dec 12, 2017
4267f2f
added search html
clayshieh Dec 12, 2017
fc1f834
updated homepage with search instructions
clayshieh Dec 12, 2017
073178e
fixed logic error in search filter
clayshieh Dec 12, 2017
e28ce4e
added new goals to README
clayshieh Dec 12, 2017
2606ac9
added styling for images and added additional gitignore for db stuff
clayshieh Dec 12, 2017
ec24d82
fixed datestamp bug
clayshieh Dec 12, 2017
83048aa
changed date filter to range
clayshieh Dec 13, 2017
b4247a5
added message counter
clayshieh Dec 13, 2017
aab9b52
added chat counter
clayshieh Dec 13, 2017
d48598e
added previous query to input
clayshieh Dec 19, 2017
f384158
forgot quotation marks
clayshieh Dec 19, 2017
dfeb89a
made settings.py read db filename from a config file
clayshieh Dec 19, 2017
a719008
setup basic workflow to change db name, not hot reload
clayshieh Dec 20, 2017
d903238
added comment code for future
clayshieh Dec 22, 2017
94ad11a
refactored code, added export function, added more comentary to datab…
clayshieh Dec 26, 2017
ce0cb3b
fixed some database selection logic errors and added modal for choosi…
clayshieh Dec 28, 2017
150f866
Merge pull request #1 from clayshieh/export
clayshieh Dec 28, 2017
bfbffb5
used django's hot reloading on code change to implement resync of dat…
clayshieh Dec 28, 2017
3db1268
updated the homepage instructions
clayshieh Dec 28, 2017
eab1314
updated README and home page
clayshieh Dec 28, 2017
b2a20b7
changed README instruction, syncdb no longer needed
clayshieh Dec 29, 2017
2cc508f
added requirements.txt
clayshieh Jan 31, 2018
08d4f97
added fix to handle OSX High Sierra changes to iMessage db
clayshieh Mar 10, 2018
1dc7b3c
updated screenshot
clayshieh Mar 28, 2018
3bc6335
updated screenshot (removed shadow)
clayshieh Mar 28, 2018
500a537
fixed location in README
clayshieh Mar 29, 2018
b58cdfe
updated README location errors
clayshieh Mar 29, 2018
8f6407f
push added update log and Dockerfile with instructions
clayshieh Sep 23, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
env/*
sms/db
.Python
bin/
include/
lib/
pip-selfcheck.json

sms/db/*.db
*.db-shm
*.db-wal

*.pyc
*.swp

7 changes: 7 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM python:2.7-buster

COPY sms /sms
COPY requirements.txt /
RUN pip install --no-cache-dir -r requirements.txt

ENTRYPOINT ["python", "/sms/manage.py", "runserver", "0.0.0.0:8000"]
83 changes: 65 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,43 +1,90 @@
iMessage SMS database browsing web app
======================================
This is a fork of jsok's repo [here](https://github.com/jsok/django-imessage). I have refactored some of the code, added functionalities and will continue to added functionalities to it as it seems to be a useful tool that elegantly solves a widely researched and discussed topic, how to read and search Apple's iMessages.

The readme below is a modified version of jsok's to reflect the changes I've made.

What?
-----
iOS stores all your SMS/Messages in a sqlite database. This gets downloaded to your computer each time you backup/sync your phone via iTunes.
iOS and OSX store all your iMessages/SMS texts in a sqlite database. This gets downloaded to your computer each time you backup/sync your phone via iTunes.

This is a django app which allows you to drop your SMS database into it, fire it up and have all your messages in a nice browseable web app.
This is a django app which allows you to drop your iMessage/SMS database(s) into it, fire it up and have all your messages and databases in a nice browseable web app. In addition to just viewing your messages, you can also filter by date and/or query search terms.

Why?
----
Why not? iOS will only show the most recent 100 or so messages on the screen, to view older ones you need to hit "Load Earlier Messages" and wait. Too bad if you want to see messages from last month, or even last year! With this app you can see them all and search them.
Why not? iOS and OSX will only show the most recent 100 or so messages on the screen, to view older ones you need to hit "Load Earlier Messages" and wait. Too bad if you want to see messages from last month, or even last year! With this app you can see them all, go to a specific date for a conversation and/or search them.

How?
----
The SMS database has been analysed by many and its schema is well known. I've taken some of this info and used it to convince django's ORM into reading it.
The iMessage/SMS database has been analysed by many and its schema is well known. I've taken some of this info and used it to convince django's ORM into reading it.

**For iOS:**

If you have a jailbroken device:

* SSH into your device
* Navigate to `/var/mobile/Library/SMS/`
* scp sms.db to your computer

If you do not have a jailbroken device or you do not want to use ssh:

* Backup your iphone locally on your computer
* Navigate to `~/Library/Application Support/Mobile Sync/Backup/<device id>/3d0d7e5fb2ce288813306e4d4636395e047a3d28`
* Copy the db file somewhere

**For OSX**

You can find the database in your iOS backup:
`~/Library/Application Support/Mobile Sync/Backup/<device id>/3d0d7e5fb2ce288813306e4d4636395e047a3d28`
* Open terminal.app
* Navigate to `~/Library/Messages/`
* Copy chat.db somewhere

As of OSX 10.15 and with iCloud message sync on it seems like users cannot access the `~/Library/Messages/` directory (I cannot confirm when or what caused this) so do the following steps instead:

1. Open terminal.app
2. `open ~/Library/Messages/`
3. Copy `chat.db` to the cloned github directory

Screenshot
----------
![Screenshot](https://raw.github.com/jsok/django-imessage/master/screenshot.png)
![Screenshot](https://raw.github.com/clayshieh/django-imessage/master/messages_screenshot.png)

Setup
-----
Requirements are:
- django 1.4
- pytz (for timezone info)
- [UiUIKit 2.1](http://code.google.com/p/iphone-universal/)
- pytz

1. edit `core/settings.py` and set your TIME_ZONE (list of timezones [here](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones))
2. Then drop your iMessage/SMS database(s) in `sms/db/`
3. run `python manage.py runserver`
4. Navigate to `http://localhost:8000/databases/` and select the database you wish to view

Navigate to `http://localhost:8000` for instructions in general

Docker Setup
------------
1. [Install Docker](https://docs.docker.com/get-docker/)
2. Run the container with the following command:
`docker run -it -p 8000:8000 -v <path to chat.db or sms.db>:/sms/db/sms.db clayshieh/django-imessage:latest`
3. Navigate to `http://localhost:8000`

Updates
-------
9/22/2020

1. edit `core/settings.py` and set your TIME_ZONE.
2. Then drop your SMS database in `db/sms.db` (rename it).
3. Unzip UiUIKit into `static/UiUIKit`
4. run `manage.py syncdb`
5. `manage.py runserver`
6. Point your browser at `http://localhost:8000/messages`, where you can browse your messages.
- Dockerized the app and updated instructions for OSX
- I have not worked on or updated this app in quite a while. There have been a lot of changes in both iOS and OSX so if you have any issues while using the app please let me know
- I did not realize that issues cannot be opened on forked repos, I will be moving all the code to a new repo and leaving this repo as a pointer once I either get permission from [jsok](https://github.com/jsok) and refactor the code

Future TODO
-----------
- Messages.app style timestamps (supressed timestamps when messages are received within a given time delta)
- Some way of searching your messages
- Group chat isn't yet supported
- ~~Messages.app style timestamps (supressed timestamps when messages are received within a given time delta)~~
- ~~Some way of searching your messages~~
- Update to Django 1.11
- Add support attachments if it is a OSX database
- Add contact import support to associate numbers with canonical names
- Add support for group chats
- Convert message data to REST endpoints so UI doesn't hang when loading
- Make setup process user friendly in terms of uploading user db, uploading attachments directory, etc.
- ~~Support multiple database selection~~
- ~~Add exporting functionality~~
Binary file added messages_screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Django==1.4
pytz==2017.3
Binary file removed screenshot.png
Binary file not shown.
1 change: 1 addition & 0 deletions sms/core/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#sms.db
5 changes: 2 additions & 3 deletions sms/core/settings.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Django settings for sms project.
import os
from os.path import join
import django

PROJECT_ROOT = os.path.dirname(os.path.realpath(__file__)) + '/..'
CORE_APP_ROOT = os.path.dirname(os.path.realpath(__file__))
Expand All @@ -16,7 +15,7 @@
MANAGERS = ADMINS

DATABASE_ENGINE = 'sqlite3'
DATABASE_NAME = 'sms.db'
DATABASE_NAME = open(join(join(PROJECT_ROOT, 'db'), "db.conf"), "r").read().strip()
DATABASE_PATH = join(join(PROJECT_ROOT, 'db'), DATABASE_NAME)
DATABASES = {
'default': {
Expand All @@ -33,7 +32,7 @@
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems.
# In a Windows environment this must be set to your system time zone.
TIME_ZONE = 'Australia/Sydney'
TIME_ZONE = 'America/Los_Angeles'

# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
Expand Down
4 changes: 4 additions & 0 deletions sms/core/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
from django.contrib import admin
admin.autodiscover()

from . import views

urlpatterns = patterns('',
url(r'^$', views.index),
url(r'^databases/', views.databases),
url(r'^messages/', include('messages.urls')),
url(r'^admin/', include(admin.site.urls)),
)
43 changes: 43 additions & 0 deletions sms/core/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from django.shortcuts import render
from django.conf import settings
from os.path import join
from os import listdir


def index(request):
return render(request, 'home.html', {})


def databases(request):
changed = False
files = listdir(join(join(settings.PROJECT_ROOT, 'db')))
dbs = []
for file in files:
if file.endswith(".db"):
dbs.append(file)
selected_db = settings.DATABASE_NAME
config_db = open(join(join(settings.PROJECT_ROOT, 'db'), "db.conf"), "r").read().strip()

if "select" in request.GET and request.GET["select"]:
select = request.GET["select"].strip()
if select != config_db:
with open(join(join(settings.PROJECT_ROOT, 'db'), "db.conf"), "w") as f:
f.write(select)

# Jank way of implementing the syncdb functionality below. Works because django hot reloads.
# from django.core.management import execute_from_command_line
# execute_from_command_line("syncdb")
with open(join(settings.CORE_APP_ROOT, "__init__.py"), "w") as f:
f.write("#" + select)

selected_db = select
config_db = select
changed = True

context = {
"databases": dbs,
"selected": selected_db,
"config_db": config_db,
"changed": changed
}
return render(request, 'db.html', context)
1 change: 1 addition & 0 deletions sms/db/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
!.gitignore
1 change: 1 addition & 0 deletions sms/db/db.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sms.db
7 changes: 6 additions & 1 deletion sms/messages/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,15 @@ def db_type(self, connection):

def to_python(self, value):
super(IMessageTimeStampField, self)

try:
app_tz = timezone(settings.TIME_ZONE)
return datetime.fromtimestamp(value+self.IMESSAGE_DELTA).replace(tzinfo=app_tz)
except:
except ValueError:
# to handle new version of databases (OSX 10.13)
app_tz = timezone(settings.TIME_ZONE)
return datetime.fromtimestamp(value/1000000000 + self.IMESSAGE_DELTA).replace(tzinfo=app_tz)
except Exception:
return value


Expand Down
2 changes: 1 addition & 1 deletion sms/messages/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

urlpatterns = patterns('messages.views',
url(r'^$', 'index'),
url(r'^(?P<handle_id>\d+)/$', 'messages'),
url(r'^(?P<handle_id>\d+)/$', 'messages'),
)
Loading