This file is indexed.

/usr/share/backintime/common/backintime.py is in backintime-common 1.0.34-0.1.

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
#    Back In Time
#    Copyright (C) 2008-2009 Oprea Dan, Bart de Koning, Richard Bailey
#
#    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.,
#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

#print into file like it is done in Python3
from __future__ import print_function
import os
import os.path
import stat
import sys
import gettext

import config
import logger
import snapshots
import tools
import sshtools
import mount
import password
import encfstools
import cli

_=gettext.gettext


def take_snapshot_now_async( cfg ):
    cmd = ''
    if cfg.is_run_ionice_from_user_enabled():
        cmd += 'ionice -c2 -n7 '
    cmd += 'backintime '
    if '1' != cfg.get_current_profile():
        cmd += '--profile-id %s ' % cfg.get_current_profile()
    if not cfg._LOCAL_CONFIG_PATH is cfg._DEFAULT_CONFIG_PATH:
        cmd += '--config %s ' % cfg._LOCAL_CONFIG_PATH
    cmd += '--backup &'

    os.system( cmd )


def take_snapshot( cfg, force = True ):
    logger.openlog()
    tools.load_env(cfg)
    snapshots.Snapshots( cfg ).take_snapshot( force )
    logger.closelog()

def _mount(cfg):
    try:
        hash_id = mount.Mount(cfg = cfg).mount()
    except mount.MountException as ex:
        logger.error(str(ex))
        sys.exit(1)
    else:
        cfg.set_current_hash_id(hash_id)

def _umount(cfg):
    try:
        mount.Mount(cfg = cfg).umount(cfg.current_hash_id)
    except mount.MountException as ex:
        logger.error(str(ex))


def print_version( cfg, app_name ):
    print('')
    print('Back In Time')
    print('Version: ' + cfg.VERSION)
    print('')
    print('Back In Time comes with ABSOLUTELY NO WARRANTY.')
    print('This is free software, and you are welcome to redistribute it')
    print("under certain conditions; type `%s --license\' for details." % app_name)
    print('')


def print_help( cfg ):
    print('OPTIONS (use these before other actions):')
    print('--profile <profile name>')
    print('\tSelect profile by name')
    print('--profile-id <profile id>')
    print('\tSelect profile by id')
    print('--keep-mount')
    print('\tDon\'t unmount on exit. Only valid with')
    print('\t--snapshots-list-path and --last-snapshot-path.')
    print('--quiet')
    print('\tBe quiet. Suppress messages on stdout.')
    print('--config PATH')
    print('\tread config from PATH.')
    print('--checksum')
    print('\tforce to use checksum for checking if files have been changed.')
    print('')
    print('ACTIONS:')
    print('-b | --backup')
    print('\tTake a snapshot (and exit)')
    print('--backup-job')
    print('\tUsed for cron job: take a snapshot (and exit)')
    print('--snapshots-path')
    print('\tShow the path where is saves the snapshots (and exit)')
    print('--snapshots-list')
    print('\tShow the list of snapshots IDs (and exit)')
    print('--snapshots-list-path')
    print('\tShow the paths to snapshots (and exit)')
    print('--last-snapshot')
    print('\tShow the ID of the last snapshot (and exit)')
    print('--last-snapshot-path')
    print('\tShow the path to the last snapshot (and exit)')
    print('--unmount')
    print('\tUnmount the profile.')
    print('--benchmark-cipher [file-size]')
    print('\tShow a benchmark of all ciphers for ssh transfer (and exit)')
    print('--pw-cache [start|stop|restart|reload|status]')
    print('\tControl Password Cache for non-interactive cronjobs')
    print('--decode [encoded_PATH]')
    print('\tDecode PATH. If no PATH is specified on command line')
    print('\ta list of filenames will be read from stdin.')
    print('--restore [WHAT [WHERE [SNAPSHOT_ID]]]')
    print('\tRestore file WHAT to path WHERE from snapshot SNAPSHOT_ID.')
    print('\tIf arguments are missing they will be prompted.')
    print('-v | --version')
    print('\tShow version (and exit)')
    print('--license')
    print('\tShow license (and exit)')
    print('-h | --help')
    print('\tShow this help (and exit)')
    print('')


def start_app( app_name = 'backintime', extra_args = [] ):
    force_stdout = sys.stdout
    if '--quiet' in sys.argv:
        f = open(os.devnull, 'w')
        sys.stdout = f

    config_path = None
    if '--config' in sys.argv:
        i = sys.argv.index('--config')
        try:
            path = sys.argv[i + 1]
            if os.path.isfile(path):
                config_path = path
        except IndexError:
            pass

    cfg = config.Config(config_path)
    print_version( cfg, app_name )

    skip = False
    index = 0
    keep_mount = False
    
    for arg in sys.argv[ 1 : ]:
        index = index + 1

        if skip:
            skip = False
            continue

        if arg == '--profile':
            if not cfg.set_current_profile_by_name( sys.argv[index + 1] ):
                print("Profile not found: %s" % sys.argv[index + 1], file=sys.stderr)
                sys.exit(0)
            skip = True
            continue

        if arg == '--profile-id':
            if not cfg.set_current_profile( sys.argv[index + 1] ):
                print("Profile id not found: %s" % sys.argv[index + 1], file=sys.stderr)
                sys.exit(0)
            skip = True
            continue

        if arg == '--backup' or arg == '-b':
            take_snapshot( cfg, True )
            sys.exit(0)

        if arg == '--backup-job':
            take_snapshot( cfg, False )
            sys.exit(0)

        if arg == '--version' or arg == '-v':
            sys.exit(0)

        if arg == '--license':
            print(cfg.get_license())
            sys.exit(0)

        if arg == '--help' or arg == '-h':
            print_help( cfg )
            sys.exit(0)

        if arg == '--snapshots-path':
            if not cfg.is_configured():
                print("The application is not configured !", file=sys.stderr)
            else:
                print("SnapshotsPath: %s" % cfg.get_snapshots_full_path(), file=force_stdout)
            sys.exit(0)

        if arg == '--snapshots-list':
            if not cfg.is_configured():
                print("The application is not configured !", file=sys.stderr)
            else:
                _mount(cfg)
                _list = snapshots.Snapshots( cfg ).get_snapshots_list()
                if len( _list ) <= 0:
                    print("There are no snapshots", file=sys.stderr)
                else:
                    for snapshot_id in _list:
                        print("SnapshotID: %s" % snapshot_id, file=force_stdout)
                _umount(cfg)
            sys.exit(0)

        if arg == '--snapshots-list-path':
            if not cfg.is_configured():
                print("The application is not configured !", file=sys.stderr)
            else:
                _mount(cfg)
                s = snapshots.Snapshots( cfg )
                _list = s.get_snapshots_list()
                if len( _list ) <= 0:
                    print("There are no snapshots", file=sys.stderr)
                else:
                    for snapshot_id in _list:
                        print("SnapshotPath: %s" % s.get_snapshot_path( snapshot_id ), file=force_stdout)
                if not keep_mount:
                    _umount(cfg)
            sys.exit(0)

        if arg == '--last-snapshot':
            if not cfg.is_configured():
                print("The application is not configured !", file=sys.stderr)
            else:
                _mount(cfg)
                _list = snapshots.Snapshots( cfg ).get_snapshots_list()
                if len( _list ) <= 0:
                    print("There are no snapshots", file=sys.stderr)
                else:
                    print("SnapshotID: %s" % _list[0], file=force_stdout)
                _umount(cfg)
            sys.exit(0)

        if arg == '--last-snapshot-path':
            if not cfg.is_configured():
                print("The application is not configured !", file=sys.stderr)
            else:
                _mount(cfg)
                s = snapshots.Snapshots( cfg )
                _list = s.get_snapshots_list()
                if len( _list ) <= 0:
                    print("There are no snapshots", file=sys.stderr)
                else:
                    print("SnapshotPath: %s" % s.get_snapshot_path( _list[0] ), file=force_stdout)
                if not keep_mount:
                    _umount(cfg)
            sys.exit(0)
            
        if arg == '--keep-mount':
            keep_mount = True
            continue
            
        if arg == '--unmount':
            _mount(cfg)
            _umount(cfg)
            sys.exit(0)

        if arg == '--benchmark-cipher':
            if not cfg.is_configured():
                print("The application is not configured !", file=sys.stderr)
            else:
                try:
                    size = sys.argv[index + 1]
                except IndexError:
                    size = '40'
                if cfg.get_snapshots_mode() in ['ssh', 'ssh_encfs']:
                    ssh = sshtools.SSH(cfg=cfg)
                    ssh.benchmark_cipher(size)
                else:
                    print('ssh is not configured !', file=sys.stderr)
            sys.exit(0)

        if arg == '--pw-cache':
            if not cfg.is_configured():
                print("The application is not configured !", file=sys.stderr)
                sys.exit(0)
            else:
                logger.openlog()
                daemon = password.Password_Cache(cfg)
                try:
                    if sys.argv[index + 1].startswith('-'):
                        daemon.run()
                    elif 'start' == sys.argv[index + 1]:
                        daemon.start()
                    elif 'stop' == sys.argv[index + 1]:
                        daemon.stop()
                    elif 'restart' == sys.argv[index + 1]:
                        daemon.restart()
                    elif 'reload' == sys.argv[index + 1]:
                        daemon.reload()
                    elif 'status' == sys.argv[index + 1]:
                        print('Backintime Password Cache:', end=' ', file=force_stdout)
                        if daemon.status():
                            print('running', file=force_stdout)
                        else:
                            print('not running', file=force_stdout)
                    else:
                        print("Unknown command")
                        print("usage: %s %s start|stop|restart|reload|status" % (sys.argv[0], sys.argv[index]))
                        sys.exit(2)
                except IndexError:
                    daemon.run()
                logger.closelog()
                sys.exit(0)

        if arg == '--decode':
            if not cfg.is_configured():
                print("The application is not configured !", file=sys.stderr)
                sys.exit(0)
            else:
                mode = cfg.get_snapshots_mode()
                if not mode in ['local_encfs', 'ssh_encfs']:
                    print('Profile \'%s\' is not encrypted.' % cfg.get_profile_name(), file=sys.stderr)
                path = ''
                _list = []
                try:
                    path = sys.argv[index + 1]
                except IndexError:
                    pass
                if len(path) > 0:
                    _list.append(path)
                else:
                    while True:
                        try:
                            path = raw_input()
                        except EOFError:
                            break
                        if len(path) <= 0:
                            break
                        _list.append(path)
                
                _mount(cfg)
                decode = encfstools.Decode(cfg)
                ret = decode.list(list)
                decode.close()
                _umount(cfg)
                
                print('\n'.join(ret), file=force_stdout)
                sys.exit(0)

        if arg == '--restore':
            if not cfg.is_configured():
                print("The application is not configured !", file=sys.stderr)
                sys.exit(0)
            what = None
            where = None
            snapshot_id = None
            
            try:
                what = sys.argv[index + 1]
                where = sys.argv[index + 2]
                snapshot_id = sys.argv[index + 3]
            except IndexError:
                pass
            
            _mount(cfg)
            cli.restore(cfg, snapshot_id, what, where)
            _umount(cfg)
            sys.exit(0)

        if arg == '--checksum':
            print('Force using checksum')
            cfg.force_use_checksum = True
            continue

        if arg == '--snapshots' or arg == '-s':
            continue

        if arg == '--gnome' or arg == '--kde4' or arg == '--kde3':
            continue

        if arg == '--quiet':
            continue

        if arg == '--config':
            skip = True
            continue

        if arg[0] == '-':
            if not arg[0] in extra_args:
                print("Ignore option: %s" % arg)
            continue

    return cfg


if __name__ == '__main__':
    start_app()