This file is indexed.

/usr/share/mediatomb/web/js/tools.js is in mediatomb-common 0.12.1-47-g7ab7616-1ubuntu2.

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

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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
/*MT*
    
    MediaTomb - http://www.mediatomb.cc/
    
    tools.js - this file is part of MediaTomb.
    
    Copyright (C) 2005 Gena Batyan <bgeradz@mediatomb.cc>,
                       Sergey 'Jin' Bostandzhyan <jin@mediatomb.cc>
    
    Copyright (C) 2006-2010 Gena Batyan <bgeradz@mediatomb.cc>,
                            Sergey 'Jin' Bostandzhyan <jin@mediatomb.cc>,
                            Leonhard Wimmer <leo@mediatomb.cc>
    
    MediaTomb is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License version 2
    as published by the Free Software Foundation.
    
    MediaTomb 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
    version 2 along with MediaTomb; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
    
    $Id$
*/

var INACTIVITY_TIMEOUT       = 5000;
var INACTIVITY_TIMEOUT_SHORT = 1000;

var use_inactivity_timeout_short = false;

/*
function genericCallback(ajaxRequest)
{
    var xml = ajaxRequest.responseXML;
    if (! errorCheck(xml))
        return;
    //last_update = new Date().getTime();
}
*/

function link(req_type, param, get_update_ids)
{
    var url = "content/interface?req_type="+ encodeURIComponent(req_type) +"&return_type=xml&sid="+ SID;
    var got_update_param = false;
    if (param)
        for (var key in param)
        {
            if (key == 'updates')
            {
                got_update_param = true;
                if (! isTypeDb() || ! dbStuff.treeShown)
                    continue;
            }
            url += "&" + encodeURIComponent(key) +"="+ encodeURIComponent(param[key]);
        }
    if (! got_update_param && get_update_ids && isTypeDb() && dbStuff.treeShown)
        url += "&updates=check";
    return url;
}

function isTypeDb()
{
    return (TYPE == "db");
}

function xmlGetElement(parent, name)
{
    var returnVal = parent.getElementsByTagName(name)
    
    if (!returnVal || !returnVal.length)
        return null;
    else
        return returnVal[0];
}

function xmlGetElementText(parent, name)
{
    var el = xmlGetElement(parent, name);
    return xmlGetText(el);
}
function xmlGetText(el)
{
    if (!el || el.childNodes.length != 1)
        return "";
    return el.firstChild.nodeValue;
}

function xmlGetAttribute(parent, name)
{
    var a = parent.attributes;
    if (! a)
        return null;
    for (var i = 0; i < a.length; i++)
    {
        if (a[i].name == name)
            return a[i].value;
    }
    return null;
}

function appendImgNode(document, node, alt, icon)
{
    var img = document.createElement("img");
    img.setAttribute("src", icon.src);
    img.setAttribute("alt", alt);
    if (showTooltips) {
        img.setAttribute("title", alt);
    }
    img.setAttribute("border", "0");
    img.setAttribute("width", icon.width);
    img.setAttribute("height", icon.height);
    node.appendChild(img);
}

var timer;

function errorCheck(xml, noredirect)
{
    if (!xml)
    {
        //alert ("could not fetch XML");
        return false;
    }
    var rootEl = xmlGetElement(xml, 'root');
    
    var errorEl = xmlGetElement(xml, 'error');
    var error = false;
    var redirect = false;
    var uiDisabled = false;
    if (errorEl)
    {
        var code = errorEl.getAttribute('code');
        var mainCode = Math.floor(code / 100);
        
        // 2xx - object not found
        // 3xx - login exception (not logged in or login error)
        // 4xx - session error (no valid session)
        // 5xx - storage exception
        // 8xx - general error (no more accurate code available (yet))
        // 900 - UI disabled
        
        if (mainCode == 4)
            redirect = '/';
        else if (mainCode == 9)
            uiDisabled = true;
        else if (mainCode != 2)
            error = xmlGetText(errorEl);
    }
    
    if (uiDisabled)
    {
        window.location = "/disabled.html";
        return false;
    }
    
    if (redirect)
    {
        var now = new Date();
        var expire = new Date();
        expire.setTime(now.getTime() - 3600000 * 24 * 360);
        setCookie('SID', null, expire);
        if (SID && ! noredirect)
        {
            SID = null;
            window.location = redirect;
        }
        return false;
    }
    
    // clears current task if no task element
    updateCurrentTask(xmlGetElement(xml, 'task'));
    
    var updateIDsEl = xmlGetElement(xml, 'update_ids');
    if (updateIDsEl)
        handleUIUpdates(updateIDsEl);
    
    if (error)
    {
        alert(error);
        return false;
    }
    return true;
}

function handleUIUpdates(updateIDsEl)
{
    if (updateIDsEl.getAttribute("pending") == '1')
    {
        setStatus("updates_pending");
        addUpdateTimer();
        last_update = new Date().getTime();
    }
    else if (updateIDsEl.getAttribute("updates") != '1')
    {
        setStatus("no_updates");
        clearUpdateTimer();
        last_update = new Date().getTime();
    }
    else
    {
        var updateIDStr = xmlGetText(updateIDsEl);
        var savedlastNodeDbID = lastNodeDb;
        var savedlastNodeDbIDParent;
        if (savedlastNodeDbID != 'd0')
            savedlastNodeDbIDParent = getTreeNode(savedlastNodeDbID).getParent().getID();
        //alert('before: lastid: ' + savedlastNodeDbID);
        //alert('before: node: ' + getTreeNode(savedlastNodeDbID));
        selectNodeIfVisible('d0');
        var updateAll = false;
        if (updateIDStr != 'all')
        {
            var updateIDsArr = updateIDStr.split(",");
            for (var i = 0; i < updateIDsArr.length; i++)
            {
                if (updateIDsArr[i] == 0)
                    updateAll = true;
            }
        }
        else
            updateAll = true;
        if (! updateAll)
        {
            for (var i = 0; i < updateIDsArr.length; i++)
            {
                var node = getTreeNode('d' + updateIDsArr[i]);
                if (node)
                {
                    var parNode = node.getParent();
                    if (parNode)
                    {
                        parNode.childrenHaveBeenFetched=false;
                        parNode.resetChildren();
                        fetchChildren(parNode, true);
                    }
                }
            }
        }
        else
        {
            var node = getTreeNode('d0');
            node.childrenHaveBeenFetched=false;
            node.resetChildren();
            fetchChildren(node, true);
        }
        var savedlastNodeDb = getTreeNode(savedlastNodeDbID);
        if (savedlastNodeDb)
            selectNodeIfVisible(savedlastNodeDbID);
        else if (savedlastNodeDbIDParent)
        {
            savedlastNodeDb = getTreeNode(savedlastNodeDbIDParent);
            if (savedlastNodeDb)
                selectNodeIfVisible(savedlastNodeDbIDParent);
        }
        setStatus("no_updates");
        if (timer)
        {
            window.clearTimeout(timer);
            timer = false;
        }
        last_update = new Date();
    }
}

function addBr(useDocument, element)
{
    var newBr = useDocument.createElement('br');
    element.appendChild(newBr);
}

function getTopOffset(el)
{
    var offset = 0;
    while (el != null)
    {
        offset += el.offsetTop;
        el = el.offsetParent;
    }
    return offset;
}

function ensureElementVisibility(win, doc, el, bottomAdd)
{
    var viewheight;
    if (win.innerHeight) // all except IE
    {
        viewheight = win.innerHeight;
    }
    else if (doc.documentElement && doc.documentElement.clientHeight)
        // IE 6 Strict Mode
    {
        viewheight = doc.documentElement.clientHeight;
    }
    else if (doc.body) // other IEs
    {
        viewheight = doc.body.clientHeight;
    }
    
    var scrollpos;
    var xoffset;
    if (win.pageYOffset) // all except IE
    {
        xoffset = win.pageXOffset;
        scrollpos = win.pageYOffset;
    }
    else if (doc.documentElement && doc.documentElement.scrollTop)
        // IE 6 Strict
    {
        xoffset = doc.documentElement.scrollLeft;
        scrollpos = doc.documentElement.scrollTop;
    }
    else if (document.body) // all other IEs
    {
        xoffset = doc.body.scrollLeft;
        scrollpos = doc.body.scrollTop;
    }
    
    var elpos = getTopOffset(el);
    
    if (elpos<scrollpos)
    {
        win.scrollTo(xoffset, elpos);
    }
    else if (elpos>scrollpos+viewheight-bottomAdd)
    {
        win.scrollTo(xoffset, elpos-viewheight+bottomAdd);
    }
}

function formToArray(form, args)
{
    for (var i = 0; i < form.length; ++i)
    {
        var element = form.elements[i];
        
        if (element.type && ((element.type != 'submit' && element.type != "radio" && element.type != "checkbox") || element.checked) && ! element.disabled)
            args[element.name] = element.value;
    }
}

var status_updates_pending = false;
var status_loading = false;

function setStatus(status)
{
    var topDocument = frames["topF"].document;
    
    if (status == "idle" && status_loading)
    {
        status_loading = false;
        Element.hide(topDocument.getElementById("statusWorking"));
        if (status_updates_pending)
            Element.show(topDocument.getElementById("statusUpdatesPending"));
        else
            Element.show(topDocument.getElementById("statusIdle"));
    }
    else if (status == "loading" && ! status_loading)
    {
        status_loading = true;
        if (status_updates_pending)
            Element.hide(topDocument.getElementById("statusUpdatesPending"));
        else
            Element.hide(topDocument.getElementById("statusIdle"));
        Element.show(topDocument.getElementById("statusWorking"));
    }
    else if (status == "updates_pending" && ! status_updates_pending)
    {
        status_updates_pending = true;
        if (! status_loading)
        {
            Element.hide(topDocument.getElementById("statusIdle"));
            Element.show(topDocument.getElementById("statusUpdatesPending"));
        }
    }
    else if (status == "no_updates" && status_updates_pending)
    {
        status_updates_pending = false;
        if (! status_loading)
        {
            Element.hide(topDocument.getElementById("statusUpdatesPending"));
            Element.show(topDocument.getElementById("statusIdle"));
        }
    }
}

function getUpdates(force)
{
    if (loggedIn)
    {
        var url = link('void', {updates: (force ? 'get' : 'check')});
        var myAjax = new Ajax.Request(
            url,
            {
                method: 'get',
                asynchronous: false,
                onComplete: getUpdatesCallback
            });
    }
}

function getUpdatesCallback(ajaxRequest)
{
    var xml = ajaxRequest.responseXML;
    if (! errorCheck(xml))
        return;
    last_update = new Date().getTime();
}

function userActivity(event)
{
    clearUpdateTimer();
    addUpdateTimer();
    return true;
}

var last_update = new Date().getTime();

function mouseDownHandler(event)
{
    userActivity();
    var now = new Date().getTime();
    if (last_update + 3000 < now)
    {
        getUpdates(false);
        last_update = now;
    }
}

function addUpdateTimer()
{
    if (! timer)
    {
        timer = window.setTimeout("getUpdates(true)", (use_inactivity_timeout_short ? INACTIVITY_TIMEOUT_SHORT : INACTIVITY_TIMEOUT));
        if (use_inactivity_timeout_short)
            use_inactivity_timeout_short = false;
    }
}

function clearUpdateTimer()
{
    if (timer)
    {
        window.clearTimeout(timer);
        timer = false;
    }
}

function action(action)
{
    var url = link('action', {action: action});
    
    var myAjax = new Ajax.Request(
        url,
        {
            method: 'get'
            //onComplete: 
        });
}