source: OpenRLabs-Git/web2py/applications/rlabs/modules/load_init_setup.py

main
Last change on this file was f03481a, checked in by David Fuertes <dfuertes@…>, 4 years ago

Terminado instalador fullstack

  • Property mode set to 100644
File size: 2.7 KB
Line 
1# -*- coding: utf-8 -*-
2#################################################################################
3# @file    load_init_setup.py
4# @brief   Module that get and setup initial configuration parameters
5# @warning None
6# @note Use: None     
7# @license GNU GPLv3+
8# @author  David Fuertes, EUPT, University of Zaragoza.
9# @version 1.1.0 - First version
10# @date    2019-15-11
11#################################################################################
12import os
13import base64
14
15
16def load_setup(db):
17    PORT_WSS = "8020"
18    ADMIN_PASSWD = "admin"
19
20    dir_web2py = os.path.dirname(os.path.abspath('__file__'))
21    try:
22        file_cfg = open(dir_web2py + "/setup_init.cfg",'r')
23        lines = file_cfg.readlines()
24        for line in lines:       
25            line_fields=line.split('=')
26
27            if line_fields[0] == 'SERVER_OPENGNSYS':                   
28                SERVER_OPENGNSYS = line_fields[1].rstrip('\n')                       
29               
30            if line_fields[0] == 'SERVER_RLABS':                   
31                SERVER_RLABS = line_fields[1].rstrip('\n')           
32            if line_fields[0] == 'ADMIN_RLABS':                   
33                ADMIN_RLABS = str(line_fields[1].rstrip('\n'))
34
35    except:
36        SERVER_OPENGNSYS="my_opengsys.es"
37        SERVER_RLABS="my_openrlabs.es"
38        ADMIN_RLABS="admin"
39       
40             
41    db.openRLabs_setup.insert(URL_Apache_Guacamole_WebSocket = "wss://" + SERVER_RLABS + ":" + PORT_WSS + "/websocket/tunnel-websocket",
42                              URL_openGnsys_server = "https://" + SERVER_OPENGNSYS + "/opengnsys/rest",
43                              URL_openRLabs_server = "https://" + SERVER_RLABS,)
44                             
45   
46    enabled_rows = db(db.auth_group.role == 'enabled').select()
47    if enabled_rows and len(enabled_rows) > 0:
48        enabled = enabled_rows.first()['id']
49    else:   
50        enabled = db.auth_group.insert(role = 'enabled')
51       
52    admin_rows = db(db.auth_group.role == 'admin').select()
53    if admin_rows and len(admin_rows) > 0: 
54        admin = admin_rows.first()['id']
55    else:
56        admin = db.auth_group.insert(role = 'admin')
57   
58    #NOTE: If admin passwd is too short, validate don't encrypt password
59    user = db.auth_user.insert(first_name=ADMIN_RLABS,
60                                last_name="temp_last_name",
61                                email="mail@temp.com",
62                                username=ADMIN_RLABS,
63                                password=db.auth_user.password.validate(ADMIN_PASSWD)[0],
64                                registration_id=ADMIN_RLABS)   
65   
66    db.auth_membership.insert(user_id=user, group_id=admin)
67   
Note: See TracBrowser for help on using the repository browser.