This file is indexed.

/usr/bin/obm-moz is in obmenu 1.0-4.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#!/usr/bin/python -O
#########################################################################
#  Copyright 2005 Manuel Colmenero 
#
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
########################################################################
#
# a mozilla bookmarks to openbox menus translator
#

import obxml, sys, os
from HTMLParser import HTMLParser
from optparse import OptionParser

class MozParser(HTMLParser, obxml.ObMenu):
	
	def init(self):
		self.stack = [None]
		self.data = ""
		self.newPipe()
		self.href = ""
		self.root = ""
		self.started = False
		self.finished = False
		self.browser = "firefox"
		
	def openFile(self,filename):
		try:
			f = open(filename)
		except:
			mp.createItem(None, "Couldn't open file!", "Execute", "true")
			return
			
		mp.feed(f.read())
		f.close()	
		
	def handle_data(self, data):
		if self.finished: return
		
		d = data.strip()
		if d != "":
			self.data = unicode(d,"utf-8")
			
	def handle_starttag(self, tag, attrs):
		if self.finished: return
		
		if tag == "h3" or tag == "h1":
			if not self.started:
				if self.root == "" or self.data == self.root:
					for a in attrs:
						if a[0] == "id":
							self.stack.append(a[1])
					self.started = True
			else:
				for a in attrs:
					if a[0] == "id":
						self.stack.append(a[1])
			
		if self.started and tag == "a":
			for attr in attrs:
				if attr[0] == "href":
					self.href = attr[1]
			
	def handle_endtag(self, tag):
		if self.finished: return
		
		if self.started:
			if tag == "dl":
				self.stack.pop(-1)
				if len(self.stack) == 0:
					self.finished = True

			elif tag == "h3" :
				if len(self.stack) > 1:
					self.createMenu(self.stack[-2], self.data, self.stack[-1])

			if tag == "a":
				self.createItem(self.stack[-1], self.data, "Execute", "%s %s" % (self.browser, self.href))
	

def get_firefox_bm ():
	if os.path.isdir(home + "/.mozilla"):
		if os.path.isdir(home + "/.mozilla/firefox"):
			for f in os.listdir(home+"/.mozilla/firefox"):
				if ".default" in f:
					if os.path.isfile(home + "/.mozilla/firefox/" + f + "/bookmarks.html"):
						return home + "/.mozilla/firefox/" + f + "/bookmarks.html"
	return ""

def get_mozilla_bm ():
	if os.path.isdir(home + "/.mozilla/default"):
		l = os.listdir(home + "/.mozilla/default")
		if len(l) == 1:
			if os.path.isfile(home + "/.mozilla/default/" + l[0] + "/bookmarks.html"):
				return home + "/.mozilla/default/" + l[0] + "/bookmarks.html"
	return ""

def print_error(error):
	obm = obxml.ObMenu()
	obm.newPipe()
	for line in error.split("\n"):
		obm.createItem(None, line, "Execute", "true")
	obm.printXml()
			
if __name__ == "__main__":
	home = os.getenv("HOME")
	
	opt = OptionParser()
	opt.add_option("-f", "--firefox", action="store_const", const=1, dest="nav", help="Look for Firefox bookmarks")
	opt.add_option("-m", "--mozilla", action="store_const", const=2, dest="nav", help="Look for Mozilla Suite bookmarks")
	opt.add_option("-b", "--bookmarks", action="store", dest="filename", help="Especify the path to the bookmarks.html file")
	opt.add_option("-r", "--root", action="store", dest="root", help="Root folder of the bookmarks")
	opt.add_option("-n", "--navigator", action="store", dest="browser", help="Command to run the web browser.")
	(opts, args) = opt.parse_args()
	
	nav = 0
	if opts.nav:
		nav = opts.nav
	
	browser = ""
	if opts.browser:
		browser = opts.browser
	if browser == "":
		browser = "firefox"
	
	filename = ""
	if opts.filename:
		filename = opts.filename
	
	root = ""
	if opts.root:
		root = opts.root
		
	if filename != "":
		if not os.path.isfile(filename):
			print_error("ERROR: %s: not found" % (filename))
			sys.exit(1)
	else:
		if nav == 0:
			filename = get_firefox_bm()
			if filename == "":
				filename = get_mozilla_bm()
				if filename == "":
					print_error("ERROR: No bookmarks found, please especify location.")
					sys.exit(1)
		if nav == 1:
			filename = get_firefox_bm()
			if filename == "":
				print_error("ERROR: Firefox bookmarks not found, please especify location.")
				sys.exit(1)
								
		if nav == 2:			
			filename = get_mozilla_bm()
			if filename == "":
				print_error("ERROR: Mozilla suite bookmarks not found, please especify location.")
				sys.exit(1)
	
	cachefile = "%s/.obmmoz.xml" % (home)
	lastopts = "%s/.obmmoz.conf" % (home)
	
	if os.path.isfile(lastopts):
		f = open(lastopts)
		last = eval(f.read())
		f.close()
		if last == opts and os.path.isfile(cachefile) and os.path.getmtime(filename) < os.path.getmtime(cachefile):
			cache = open(cachefile)
			print cache.read()
			cache.close()
			sys.exit()
			
	mp = MozParser()
	mp.init()
	mp.root = root
	mp.browser = browser
	mp.openFile(filename)
	mp.saveMenu(cachefile)
	
	f = open(lastopts, "w")
	f.write(str(opts))
	f.close()
	
	mp.printXml()