[05b1088] | 1 | # |
---|
| 2 | # Copyright (C) 2020 Soleta Networks <info@soleta.eu> |
---|
| 3 | # |
---|
| 4 | # This program is free software: you can redistribute it and/or modify it under |
---|
| 5 | # the terms of the GNU Affero General Public License as published by the |
---|
| 6 | # Free Software Foundation, version 3. |
---|
| 7 | # |
---|
| 8 | |
---|
[62a8ca4] | 9 | import os |
---|
| 10 | import subprocess |
---|
| 11 | |
---|
[2997952] | 12 | OG_PATH = '/opt/opengnsys/' |
---|
| 13 | |
---|
[ebd640a] | 14 | def poweroff(): |
---|
[62a8ca4] | 15 | if os.path.exists('/scripts/oginit'): |
---|
[2997952] | 16 | subprocess.call('source ' + OG_SCRIPT_PATH + 'etc/preinit/loadenviron.sh; ' + OG_SCRIPT_PATH + 'scripts/poweroff', shell=True) |
---|
[62a8ca4] | 17 | else: |
---|
| 18 | subprocess.call(['/sbin/poweroff']) |
---|
[ebd640a] | 19 | |
---|
[fdf7701] | 20 | def reboot(): |
---|
[dbbc7fa] | 21 | if os.path.exists('/scripts/oginit'): |
---|
[2997952] | 22 | subprocess.call('source ' + OG_SCRIPT_PATH + 'etc/preinit/loadenviron.sh; ' + OG_SCRIPT_PATH + 'scripts/reboot', shell=True) |
---|
[dbbc7fa] | 23 | else: |
---|
| 24 | subprocess.call(['/sbin/reboot']) |
---|
[e20daf6] | 25 | |
---|
[d5dca0f] | 26 | def execCMD(httpparser, ogRest): |
---|
[2e342b5] | 27 | cmd = httpparser.getCMD() |
---|
[e20daf6] | 28 | cmds = cmd.split(" ") |
---|
[e6eba4b] | 29 | try: |
---|
[d5dca0f] | 30 | ogRest.proc = subprocess.Popen(cmds, stdout=subprocess.PIPE, shell=True) |
---|
| 31 | (output, error) = ogRest.proc.communicate() |
---|
[e6eba4b] | 32 | except: |
---|
| 33 | raise ValueError('Error: Incorrect command value') |
---|
| 34 | |
---|
[d5dca0f] | 35 | return output.decode('utf-8') |
---|
[2fa8aa4] | 36 | |
---|
[d5dca0f] | 37 | def procsession(httpparser, ogRest): |
---|
[2e342b5] | 38 | disk = httpparser.getDisk() |
---|
| 39 | partition = httpparser.getPartition() |
---|
| 40 | |
---|
[0f32b9c] | 41 | try: |
---|
[d5dca0f] | 42 | ogRest.proc = subprocess.Popen([OG_PATH + 'interfaceAdm/IniciarSesion', disk, partition], stdout=subprocess.PIPE, shell=True) |
---|
| 43 | (output, error) = ogRest.proc.communicate() |
---|
[0f32b9c] | 44 | except: |
---|
| 45 | raise ValueError('Error: Incorrect command value') |
---|
| 46 | |
---|
[d5dca0f] | 47 | return output.decode('utf-8') |
---|
[6d1e79b] | 48 | |
---|
[d5dca0f] | 49 | def procsoftware(httpparser, path, ogRest): |
---|
[2e342b5] | 50 | disk = httpparser.getDisk() |
---|
| 51 | partition = httpparser.getPartition() |
---|
| 52 | |
---|
[683afa6] | 53 | try: |
---|
[d5dca0f] | 54 | ogRest.proc = subprocess.Popen([OG_PATH + 'interfaceAdm/InventarioSoftware', disk, partition, path], stdout=subprocess.PIPE, shell=True) |
---|
| 55 | (output, error) = ogRest.proc.communicate() |
---|
[683afa6] | 56 | except: |
---|
| 57 | raise ValueError('Error: Incorrect command value') |
---|
| 58 | |
---|
[d5dca0f] | 59 | return output.decode('utf-8') |
---|
[261a5ed] | 60 | |
---|
[d5dca0f] | 61 | def prochardware(path, ogRest): |
---|
[1ced3dd] | 62 | try: |
---|
[d5dca0f] | 63 | ogRest.proc = subprocess.Popen([OG_PATH + 'interfaceAdm/InventarioHardware', path], stdout=subprocess.PIPE, shell=True) |
---|
| 64 | (output, error) = ogRest.proc.communicate() |
---|
[1ced3dd] | 65 | except: |
---|
| 66 | raise ValueError('Error: Incorrect command value') |
---|
| 67 | |
---|
[d5dca0f] | 68 | return output.decode('utf-8') |
---|
[efbe8a7] | 69 | |
---|
[d5dca0f] | 70 | def procsetup(httpparser, ogRest): |
---|
[2e342b5] | 71 | disk = httpparser.getDisk() |
---|
| 72 | cache = httpparser.getCache() |
---|
| 73 | cachesize = httpparser.getCacheSize() |
---|
| 74 | partlist = httpparser.getPartitionSetup() |
---|
[38b57c4] | 75 | listConfigs = [] |
---|
[2e342b5] | 76 | |
---|
[efbe8a7] | 77 | for part in partlist: |
---|
[38b57c4] | 78 | i = 0 |
---|
| 79 | json = {} |
---|
[efbe8a7] | 80 | cfg = 'dis=' + disk + '*che=' + cache + '*tch=' + cachesize + '!par=' + part["partition"] + '*cpt='+part["code"] + '*sfi=' + part['filesystem'] + '*tam=' + part['size'] + '*ope=' + part['format'] + '%' |
---|
[d5dca0f] | 81 | if ogRest.terminated: |
---|
| 82 | break |
---|
| 83 | |
---|
[38b57c4] | 84 | try: |
---|
[d5dca0f] | 85 | ogRest.proc = subprocess.Popen([OG_PATH + 'interfaceAdm/Configurar', disk, cfg], stdout=subprocess.PIPE, shell=True) |
---|
| 86 | (output, error) = ogRest.proc.communicate() |
---|
[38b57c4] | 87 | except: |
---|
| 88 | continue |
---|
| 89 | |
---|
| 90 | result = subprocess.check_output([OG_PATH + 'interfaceAdm/getConfiguration'], shell=True) |
---|
| 91 | val = result.decode('utf-8').rstrip().split('\t') |
---|
| 92 | while i < len(val): |
---|
| 93 | val[i] = val[i].split('=')[1] |
---|
| 94 | i += 1 |
---|
| 95 | |
---|
| 96 | json['partition'] = val[1] |
---|
| 97 | json['code'] = val[4] |
---|
| 98 | json['filesystem'] = val[2] |
---|
| 99 | json['size'] = val[5] |
---|
| 100 | json['format'] = val[6] |
---|
| 101 | listConfigs.append(json) |
---|
| 102 | |
---|
| 103 | return listConfigs |
---|
[cc11d8f] | 104 | |
---|
[d5dca0f] | 105 | def procirestore(httpparser, ogRest): |
---|
[2e342b5] | 106 | disk = httpparser.getDisk() |
---|
| 107 | partition = httpparser.getPartition() |
---|
| 108 | name = httpparser.getName() |
---|
| 109 | repo = httpparser.getRepo() |
---|
| 110 | ctype = httpparser.getType() |
---|
| 111 | profile = httpparser.getProfile() |
---|
| 112 | cid = httpparser.getId() |
---|
| 113 | |
---|
[a306b8b] | 114 | try: |
---|
[d5dca0f] | 115 | ogRest.proc = subprocess.Popen([OG_PATH + 'interfaceAdm/RestaurarImagen', disk, partition, name, repo, ctype], stdout=subprocess.PIPE, shell=True) |
---|
| 116 | (output, error) = ogRest.proc.communicate() |
---|
[a306b8b] | 117 | except: |
---|
| 118 | raise ValueError('Error: Incorrect command value') |
---|
| 119 | |
---|
[d5dca0f] | 120 | return output.decode('utf-8') |
---|
[b2fd0b5] | 121 | |
---|
| 122 | def procicreate(path, httpparser, ogRest): |
---|
| 123 | disk = httpparser.getDisk() |
---|
| 124 | partition = httpparser.getPartition() |
---|
| 125 | name = httpparser.getName() |
---|
| 126 | repo = httpparser.getRepo() |
---|
| 127 | |
---|
| 128 | try: |
---|
| 129 | ogRest.proc = subprocess.Popen([OG_PATH + 'interfaceAdm/InventarioSoftware', disk, partition, path], stdout=subprocess.PIPE, shell=True) |
---|
| 130 | (output, error) = ogRest.proc.communicate() |
---|
| 131 | except: |
---|
| 132 | raise ValueError('Error: Incorrect command value') |
---|
| 133 | |
---|
| 134 | if ogRest.terminated: |
---|
| 135 | return |
---|
| 136 | |
---|
| 137 | try: |
---|
| 138 | ogRest.proc = subprocess.Popen([OG_PATH + 'interfaceAdm/CrearImagen', disk, partition, name, repo], stdout=subprocess.PIPE, shell=True) |
---|
| 139 | ogRest.proc.communicate() |
---|
| 140 | except: |
---|
| 141 | raise ValueError('Error: Incorrect command value') |
---|
| 142 | |
---|
| 143 | return output.decode('utf-8') |
---|