forked from jantman/misc-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdumpFirefoxSession.php
More file actions
executable file
·137 lines (117 loc) · 3.37 KB
/
dumpFirefoxSession.php
File metadata and controls
executable file
·137 lines (117 loc) · 3.37 KB
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
#!/usr/bin/env php
<?php
/**
* Script to dump all URLs from a Firefox3 sessionstore.js file as text or HTML.
* Copyright 2010 Jason Antman <http://www.jasonantman.com> <jason@jasonantman.com> all rights reserved.
* This script can be distributed, modified, used, etc. without limit provided that any
* modifications are sent back to me and this notice is kept intact, and the changelog is updated.
**********************************************
* Canonical URL to current version:
* <https://github.com/jantman/misc-scripts/blob/master/dumpFirefoxSession.php>
**********************************************
* Dependencies:
* PHP5 with JSON
**********************************************
* TESTED FOR:
* Firefox 3.5.7 on OpenSuSE 11.1 x86_64
*
**********************************************
* CHANGELOG:
*
* 2010-08-17 jantman:
* original version
*
**********************************************
* USAGE: dumpFirefoxSession.php [--text | --html] [sessionstore.js]
**********************************************
*/
array_shift($argv); // get rid of script name
if(isset($argv[0]) && ($argv[0] == "--help" || $argv[0] == "-h"))
{
usage();
exit(0);
}
$outputHTML = false;
$arg = array_shift($argv);
if($arg == "--html"){ $outputHTML = true; $arg = array_shift($argv); }
if($arg != NULL)
{
$filePath = $arg;
if(! file_exists($filePath)){ fwrite(STDERR, "File $filePath does not exist. Dieing.\n"); exit(1);}
}
else
{
if(file_exists("sessionstore.js"))
{
$filePath = "sessionstore.js";
fwrite(STDERR, "No sessionstore.js path specified, using ./sessionstore.js\n");
}
else
{
fwrite(STDERR, "No sessionstore.js path specified and ./sessionstore.js not present... exiting.\n");
usage();
exit(1);
}
}
// we have a file that exists
$contents = file_get_contents($filePath);
if(! $contents)
{
fwrite(STDERR, "ERROR: Could not get contents of file $filePath. Dieing.\n");
exit(1);
}
// begin hacks to parse sessionstore.js as valid JSON
$contents = trim($contents);
$contents = trim($contents, "()");
// end hacks
$decoded = json_decode($contents, true); // return as an assoc array
if($decoded == NULL)
{
fwrite(STDERR, "ERROR: json_decode failed on file contents.\n");
exit(1);
}
// we're only interested in open windows and tabs
$windows = $decoded['windows'];
foreach($windows as $name => $arr)
{
doWindow($name, $arr);
}
// FUNCTIONS
function doWindow($name, $arr)
{
global $outputHTML;
if($outputHTML)
{
echo "<h1>Window $name</h1>\n";
echo '<ol>'."\n";
}
else
{
echo "====WINDOW $name====\n";
}
$selected = $arr['selected'];
foreach($arr['tabs'] as $key => $val)
{
$foo = count($val['entries']);
$current = $val['entries'][$foo-1];
if($outputHTML)
{
echo '<li>';
if($key == $selected){ echo '<strong>SELECTED: </strong>';}
echo '<a href="'.$current['url'].'">'.$current['title'].'</a>';
echo '</li>'."\n";
}
else
{
if($key == $selected) { fwrite(STDOUT, "!!SELECTED!!");}
echo $current['url']."\n";
}
}
if($outputHTML){ echo '</ol>'."\n";}
}
function usage()
{
fwrite(STDERR, "dumpFirefoxSession.php by Jason Antman <http://www.jasonantman.com>\n");
fwrite(STDERR, "\tUSAGE: dumpFirefoxSession.php [--text | --html ] [path to sessionstore.js]\n");
}
?>