-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathDebug.pl
executable file
·170 lines (134 loc) · 4.51 KB
/
Debug.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#!/usr/bin/env perl
#
# Debug.pl
#
# Copyright (c) 2009 Fletcher T. Penney
# <http://fletcherpenney.net/>
#
#
# This routine is designed to create a log file that I can use to try and help
# debug when SimplenoteSync isn't working.
# If we hit a point where we need it, I'll ask you to send me a copy of the
# log file from your home directory
#
# Of note, it will log the titles of files on your computer, but will not log
# your email address or password.
#
#
# So, do the following:
#
# First - make sure that you synchronize your iPhone app so it and web app
# are up to date
#
# Make sure there is at least one note on the iPhone that is also on the web
#
# Synchronize iphone again if necessary
#
# Make sure there is at least one text file in your local directory -
# remember that this file must have ".txt" as the file extension
#
# Make sure that you have the latest versions of this software from my web
# site
#
# Enable debug mode in SimplenoteSync.pl
#
# Run "SimplenoteSync.pl > ~/SimplenoteSyncDebug.txt"
#
# Run "Debug.pl"
#
# Open SimplenoteSyncDebug.txt and SimplenoteSyncLog.txt and make sure no
# confidential information is included
#
# Email me copies of those two files along with a description of the problem
# that you're having
#
use strict;
use warnings;
use File::Basename;
use File::Path;
use Cwd;
use Cwd 'abs_path';
use MIME::Base64;
use LWP::UserAgent;
my $ua = LWP::UserAgent->new;
use Time::Local;
use File::Copy;
# Configuration
#
# Create file in your home directory named ".simplenotesyncrc"
# First line is your email address
# Second line is your Simplenote password
# Third line is the directory to be used for text files
open (CONFIG, "<$ENV{HOME}/.simplenotesyncrc") or die "Unable to load config file $ENV{HOME}/.simplenotesyncrc.\n";
my $email = <CONFIG>;
my $password = <CONFIG>;
my $rc_directory = <CONFIG>;
my $sync_directory;
close CONFIG;
chomp ($email, $password, $rc_directory);
if ($rc_directory eq "") {
# If a valid directory isn't specified, then don't keep going
die "A directory was not specified.\n";
};
$rc_directory =~ s/\\ / /g;
if ($sync_directory = abs_path($rc_directory)) {
} else {
# If a valid directory isn't specified, then don't keep going
die "$rc_directory does not appear to be a valid directory.\n";
};
$sync_directory =~ s/ /\\ /g;
open (LOG, ">$ENV{HOME}/SimplenoteSyncLog.txt");
print LOG ".simplenotesyncrc:\n";
my $temp = $email;
$temp =~ s/[A-Za-z]/\#/g;
print LOG $temp . "\npassword redacted\n";
print LOG "$sync_directory\n\n";
my $url = 'https://simple-note.appspot.com/api/';
# Document Mac OS X version
my $mac_version = readpipe ("sw_vers");
print LOG "Mac OS X:\n$mac_version\n\n";
# Document token (proof of successful login to Simplenote)
my $token = getToken();
print LOG "Token:\n$token\n\n";
# Document contents of simplenote account (keys only - no private info)
getNoteIndex();
# Document list of ".txt" files in your specified directory, along with
# mod/create times
print LOG "Looking for .txt files in \"$sync_directory\"\n";
checkLocalDirectory();
# Do a list of all files in the directory, in case user is forgetting about
# .txt extension
my $filelist = readpipe("ls $sync_directory");
print LOG "Complete file listing:\n$filelist\n\n";
# append the contents of simplenotesync.db
print LOG "simplenotesync.db:\n";
close LOG;
system ("cat $sync_directory/simplenotesync.db >> $ENV{HOME}/SimplenoteSyncLog.txt");
1;
sub getToken {
# Connect to server and get a authentication token
my $content = encode_base64("email=$email&password=$password");
my $response = $ua->post($url . "login", Content => $content);
if ($response->content =~ /Invalid argument/) {
die "Problem connecting to web server.\nHave you installed Crypt:SSLeay as instructed?\n";
}
die "Error logging into Simplenote server:\n$response->content\n" unless $response->is_success;
return $response->content;
}
sub getNoteIndex {
# Get list of notes from simplenote server
my %note = ();
my $response = $ua->get($url . "index?auth=$token&email=$email");
my $index = $response->content;
print LOG "Index from Simplenote:\n$index\n\n";
}
sub checkLocalDirectory {
print LOG "Local Files:\n";
foreach my $filepath (glob("$sync_directory/*.txt")) {
print LOG "$filepath:\n";
my @d=gmtime ((stat("$filepath"))[9]);
printf LOG "\tmodify: %4d-%02d-%02d %02d:%02d:%02d\n", $d[5]+1900,$d[4]+1,$d[3],$d[2],$d[1],$d[0];
@d = gmtime (readpipe ("stat -f \"%B\" \"$filepath\""));
printf LOG "\tcreate: %4d-%02d-%02d %02d:%02d:%02d\n\n", $d[5]+1900,$d[4]+1,$d[3],$d[2],$d[1],$d[0];
}
}