[62a8ca4] | 1 | import os |
---|
| 2 | import subprocess |
---|
| 3 | |
---|
[2997952] | 4 | OG_PATH = '/opt/opengnsys/' |
---|
| 5 | |
---|
[ebd640a] | 6 | def poweroff(): |
---|
[62a8ca4] | 7 | if os.path.exists('/scripts/oginit'): |
---|
[2997952] | 8 | subprocess.call('source ' + OG_SCRIPT_PATH + 'etc/preinit/loadenviron.sh; ' + OG_SCRIPT_PATH + 'scripts/poweroff', shell=True) |
---|
[62a8ca4] | 9 | else: |
---|
| 10 | subprocess.call(['/sbin/poweroff']) |
---|
[ebd640a] | 11 | |
---|
[fdf7701] | 12 | def reboot(): |
---|
[dbbc7fa] | 13 | if os.path.exists('/scripts/oginit'): |
---|
[2997952] | 14 | subprocess.call('source ' + OG_SCRIPT_PATH + 'etc/preinit/loadenviron.sh; ' + OG_SCRIPT_PATH + 'scripts/reboot', shell=True) |
---|
[dbbc7fa] | 15 | else: |
---|
| 16 | subprocess.call(['/sbin/reboot']) |
---|
[e20daf6] | 17 | |
---|
[2e342b5] | 18 | def execCMD(httpparser): |
---|
| 19 | cmd = httpparser.getCMD() |
---|
[e20daf6] | 20 | cmds = cmd.split(" ") |
---|
[e6eba4b] | 21 | try: |
---|
| 22 | result = subprocess.check_output(cmds) |
---|
| 23 | except: |
---|
| 24 | raise ValueError('Error: Incorrect command value') |
---|
| 25 | |
---|
| 26 | return result.decode('utf-8') |
---|
[2fa8aa4] | 27 | |
---|
[2e342b5] | 28 | def procsession(httpparser): |
---|
| 29 | disk = httpparser.getDisk() |
---|
| 30 | partition = httpparser.getPartition() |
---|
| 31 | |
---|
[0f32b9c] | 32 | try: |
---|
| 33 | result = subprocess.check_output([OG_PATH + 'interfaceAdm/IniciarSesion', disk, partition], shell=True) |
---|
| 34 | except: |
---|
| 35 | raise ValueError('Error: Incorrect command value') |
---|
| 36 | |
---|
[2fa8aa4] | 37 | return result.decode('utf-8') |
---|
[6d1e79b] | 38 | |
---|
[2e342b5] | 39 | def procsoftware(httpparser, path): |
---|
| 40 | disk = httpparser.getDisk() |
---|
| 41 | partition = httpparser.getPartition() |
---|
| 42 | |
---|
[683afa6] | 43 | try: |
---|
| 44 | result = subprocess.check_output([OG_PATH + 'interfaceAdm/InventarioSoftware', disk, partition, path], shell=True) |
---|
| 45 | except: |
---|
| 46 | raise ValueError('Error: Incorrect command value') |
---|
| 47 | |
---|
[6d1e79b] | 48 | return result.decode('utf-8') |
---|
[261a5ed] | 49 | |
---|
| 50 | def prochardware(path): |
---|
[1ced3dd] | 51 | try: |
---|
| 52 | result = subprocess.check_output([OG_PATH + 'interfaceAdm/InventarioHardware', path], shell=True) |
---|
| 53 | except: |
---|
| 54 | raise ValueError('Error: Incorrect command value') |
---|
| 55 | |
---|
[261a5ed] | 56 | return result.decode('utf-8') |
---|
[efbe8a7] | 57 | |
---|
[2e342b5] | 58 | def procsetup(httpparser): |
---|
| 59 | disk = httpparser.getDisk() |
---|
| 60 | cache = httpparser.getCache() |
---|
| 61 | cachesize = httpparser.getCacheSize() |
---|
| 62 | partlist = httpparser.getPartitionSetup() |
---|
[38b57c4] | 63 | listConfigs = [] |
---|
[2e342b5] | 64 | |
---|
[efbe8a7] | 65 | for part in partlist: |
---|
[38b57c4] | 66 | i = 0 |
---|
| 67 | json = {} |
---|
[efbe8a7] | 68 | cfg = 'dis=' + disk + '*che=' + cache + '*tch=' + cachesize + '!par=' + part["partition"] + '*cpt='+part["code"] + '*sfi=' + part['filesystem'] + '*tam=' + part['size'] + '*ope=' + part['format'] + '%' |
---|
[38b57c4] | 69 | try: |
---|
| 70 | subprocess.check_output([OG_PATH + 'interfaceAdm/Configurar', disk, cfg], shell=True) |
---|
| 71 | except: |
---|
| 72 | continue |
---|
| 73 | |
---|
| 74 | result = subprocess.check_output([OG_PATH + 'interfaceAdm/getConfiguration'], shell=True) |
---|
| 75 | val = result.decode('utf-8').rstrip().split('\t') |
---|
| 76 | while i < len(val): |
---|
| 77 | val[i] = val[i].split('=')[1] |
---|
| 78 | i += 1 |
---|
| 79 | |
---|
| 80 | json['partition'] = val[1] |
---|
| 81 | json['code'] = val[4] |
---|
| 82 | json['filesystem'] = val[2] |
---|
| 83 | json['size'] = val[5] |
---|
| 84 | json['format'] = val[6] |
---|
| 85 | listConfigs.append(json) |
---|
| 86 | |
---|
| 87 | return listConfigs |
---|
[cc11d8f] | 88 | |
---|
[2e342b5] | 89 | def procirestore(httpparser): |
---|
| 90 | disk = httpparser.getDisk() |
---|
| 91 | partition = httpparser.getPartition() |
---|
| 92 | name = httpparser.getName() |
---|
| 93 | repo = httpparser.getRepo() |
---|
| 94 | ctype = httpparser.getType() |
---|
| 95 | profile = httpparser.getProfile() |
---|
| 96 | cid = httpparser.getId() |
---|
| 97 | |
---|
[a306b8b] | 98 | try: |
---|
| 99 | result = subprocess.check_output([OG_PATH + 'interfaceAdm/RestaurarImagen', disk, partition, name, repo, ctype], shell=True) |
---|
| 100 | except: |
---|
| 101 | raise ValueError('Error: Incorrect command value') |
---|
| 102 | |
---|
[cc11d8f] | 103 | return result.decode('utf-8') |
---|