예제 #1
0
def request_vpn():
    user_info = get_vpn_user_details()
    logger.debug(type(user_info))
    user_name = user_info['username']
    cmd = "./vpn_client_creation.sh " + str(user_name)
    #vpn_ip=""
    vpn_ip = config.get("VPN_CONF", "vpn_server_ip")
    vpn_key_path = config.get("VPN_CONF", "vpn_key_path")

    #passwd=""
    #     password=config.get("VPN_CONF","passwd")
    try:
        var = execute_remote_cmd(vpn_ip, 'root', cmd, ret_list=True)
        filepath = vpn_key_path + str(user_name) + "_baadalVPN.tar"
        localpath = os.path.join(
            get_context_path(),
            'private/VPN/' + str(user_name) + "_baadalVPN.tar")
        sftp_files(vpn_ip, 'root', filepath, localpath)

        if "false" in str(var):
            return 1
        elif "true" in str(var):
            return 3
    #transfer_vpn_files(user_name,vpn_ip,password)
    except Exception:
        return 2
예제 #2
0
def download_sample_obect_program():
    file_name = 's3_object_key.txt'
    file_path = os.path.join(get_context_path(), 'private/Object_keys/' + file_name)
    logger.debug(file_path+"\n")
    response.headers['Content-Type'] = "text"
    response.headers['Content-Disposition']="attachment; filename=" +file_name
    try:
        return response.stream(get_file_stream(file_path),chunk_size=4096)
    except Exception:
        session.flash = "Unable to download your Keys."
    redirect(URL(r = request, c = 'user', f = 'list_my_object_store'))
예제 #3
0
def download_sample_obect_program():
    file_name = 's3_object_key.txt'
    file_path = os.path.join(get_context_path(), 'private/Object_keys/' + file_name)
    logger.debug(file_path+"\n")
    response.headers['Content-Type'] = "text"
    response.headers['Content-Disposition']="attachment; filename=" +file_name
    try:
        return response.stream(get_file_stream(file_path),chunk_size=4096)
    except Exception:
        session.flash = "Unable to download your Keys."
    redirect(URL(r = request, c = 'user', f = 'list_my_object_store'))
예제 #4
0
def task():
    file_name=request.args[0]
    print "dfghjk"
    file_name=file_name.replace('_',' ')
    print file_name
    #print file_name1
    log_dir = os.path.join(get_context_path(),'logs/' + file_name + '.log')
    logger.debug(type(log_dir))
    logger.debug("log path is : " + str(log_dir))
    logger.debug("chown -R www-data:www-data " + str(log_dir))
    os.system("chown -R www-data:www-data " + str(log_dir))
    log_dir="<br />".join(log_dir.split("\n"))
    print log_dir
    fp=open(log_dir,'rU')             
    text=fp.read()                     
    text="<br />".join(text.split("\n"))
    fp.close()  
    #redirect(URL(r=request,c='default',f='task_list',args=text))         
    return text
예제 #5
0
def task():
    file_name = request.args[0]
    print "dfghjk"
    file_name = file_name.replace('_', ' ')
    print file_name
    #print file_name1
    log_dir = os.path.join(get_context_path(), 'logs/' + file_name + '.log')
    logger.debug(type(log_dir))
    logger.debug("log path is : " + str(log_dir))
    logger.debug("chown -R www-data:www-data " + str(log_dir))
    os.system("chown -R www-data:www-data " + str(log_dir))
    log_dir = "<br />".join(log_dir.split("\n"))
    print log_dir
    fp = open(log_dir, 'rU')
    text = fp.read()
    text = "<br />".join(text.split("\n"))
    fp.close()
    #redirect(URL(r=request,c='default',f='task_list',args=text))
    return text
예제 #6
0
def download_vpn_keys():
    user_info=get_vpn_user_details()
    logger.debug(type(user_info))
    user_name=user_info['username']
    logger.debug(user_name+"\n")
    file_name = user_name+'_baadalVPN.tar'
    file_path = os.path.join(get_context_path(), 'private/VPN/' + file_name)
    logger.debug(file_path+"\n")

    #import contenttype as c
    response.headers['Content-Type'] = "application/zip"
    #response.headers['ContentType'] ="application/octet-stream";
    response.headers['Content-Disposition']="attachment; filename=" +file_name
    logger.debug("******************************************************")
    try:
        return response.stream(get_file_stream(file_path),chunk_size=4096)

    except Exception:
        session.flash = "Unable to download your VPN files. Please Register first if you have not registered yet."
    redirect(URL(r = request, c = 'user', f = 'vpn'))
예제 #7
0
def download_object_keys():
    #user_info=get_user_details()
    #user_name=user_info['username'].title()
    logger.debug(request.args[1])
#     if '_' in request.args[1]:
#         user_name,b=request.args[1].split('_', 1)
#     else:
#         user_name=request.args[1]
    object_store_name=request.args[0]
    logger.debug(object_store_name)
    file_name = object_store_name+'_key.txt'
    file_path = os.path.join(get_context_path(), 'private/Object_keys/' + file_name)
    logger.debug(file_path+"\n")
    response.headers['Content-Type'] = "text"
    response.headers['Content-Disposition']="attachment; filename=" +file_name
    try:
        return response.stream(get_file_stream(file_path),chunk_size=4096)
    except Exception:
        session.flash = "Unable to download your Keys."
    redirect(URL(r = request, c = 'user', f = 'list_my_object_store'))
예제 #8
0
def download_object_keys():
    #user_info=get_user_details()
    #user_name=user_info['username'].title()
    logger.debug(request.args[1])
#     if '_' in request.args[1]:
#         user_name,b=request.args[1].split('_', 1)
#     else:
#         user_name=request.args[1]
    object_store_name=request.args[0]
    logger.debug(object_store_name)
    file_name = object_store_name+'_key.txt'
    file_path = os.path.join(get_context_path(), 'private/Object_keys/' + file_name)
    logger.debug(file_path+"\n")
    response.headers['Content-Type'] = "text"
    response.headers['Content-Disposition']="attachment; filename=" +file_name
    try:
        return response.stream(get_file_stream(file_path),chunk_size=4096)
    except Exception:
        session.flash = "Unable to download your Keys."
    redirect(URL(r = request, c = 'user', f = 'list_my_object_store'))
예제 #9
0
def download_vpn_keys():
    user_info=get_vpn_user_details()
    logger.debug(type(user_info))
    user_name=user_info['username']
    logger.debug(user_name+"\n")
    file_name = user_name+'_baadalVPN.tar'
    file_path = os.path.join(get_context_path(), 'private/VPN/' + file_name)
    logger.debug(file_path+"\n")

    #import contenttype as c
    response.headers['Content-Type'] = "application/zip"
    #response.headers['ContentType'] ="application/octet-stream";
    response.headers['Content-Disposition']="attachment; filename=" +file_name
    logger.debug("******************************************************")
    try:
        return response.stream(get_file_stream(file_path),chunk_size=4096)

    except Exception:
        session.flash = "Unable to download your VPN files. Please Register first if you have not registered yet."
    redirect(URL(r = request, c = 'user', f = 'vpn'))
예제 #10
0
    def __init__(self,id,setProp = True,**keywords):
        self.id = id;
        self.properties = {
        
        }
        print("new file updation successful");
        if not (Container.client) :
            cert_path = os.path.join(get_context_path(), 'modules/certs/')
            tls_config = docker.tls.TLSConfig(client_cert=(cert_path+'cert.pem', cert_path+'key.pem'),verify=cert_path+'ca.pem')
            docker_machine = get_docker_daemon_address();
            client = docker.Client(base_url='https://'+docker_machine[0]+':'+docker_machine[1],version='auto', tls=tls_config)
            
            Container.setclient(client);
            logger.debug(client);

        logger.debug(Container.client);
        self.update = Container.client.update_container;
        for key in keywords:
            self.properties[key] = keywords[key];    
        if setProp :
            self.updatedetails();
예제 #11
0
def collect_data_from_host(host_ip_list,host_name_list):
    active_host_no=len(host_ip_list)
    
    data=[]
    
    indx_info=[]
    indx_info.insert(0,'current')
    indx_info.insert(1,'next')
    indx_info.insert(2,'latency')
    indx_info.insert(3,'throughput')
    data.insert(0,indx_info)

    for i in range(1,active_host_no+1):	
        host_ip=host_ip_list[i-1]

        if is_pingable(host_ip):
            
            for j in range(1,active_host_no+1):
                next_host_ip=host_ip_list[j-1]
                if is_pingable(next_host_ip):

                    row_info=[]
                    latency=get_latency_btw_hosts(next_host_ip,host_ip)
                    throughput=get_throughput_btw_hosts(next_host_ip,host_ip)
                    row_info.insert(0,str(i))
                    row_info.insert(1,str(j))
                    row_info.insert(2,latency)
                    row_info.insert(3,throughput)
                    data.insert(((active_host_no*(i-1))+j),row_info) 

                else :
                    logger.debug( "host is unreachable")
        else :
            logger.debug("host is unreachable")
   
    file_path = os.path.join(get_context_path(), 'static/sigma/graph.tsv')
    _file = open(file_path, 'w');
    writer = csv.writer(_file, dialect="excel-tab")
    for item in data:
        writer.writerow(item)
예제 #12
0
def request_vpn():
    user_info=get_vpn_user_details()
    logger.debug(type(user_info))
    user_name=user_info['username']
    cmd="./vpn_client_creation.sh "+ str(user_name)
    #vpn_ip=""
    vpn_ip=config.get("VPN_CONF","vpn_server_ip")
    vpn_key_path=config.get("VPN_CONF","vpn_key_path")

    try:
        var = execute_remote_cmd(vpn_ip, 'root',cmd, ret_list=True)
        filepath=vpn_key_path+str(user_name)+"_baadalVPN.tar"
        localpath = os.path.join(get_context_path(), 'private/VPN/' + str(user_name) +"_baadalVPN.tar")
        sftp_files(vpn_ip, 'root', filepath, localpath)

        if  "false" in str(var):
            return 1
        elif "true" in str(var):
            return 3
    #transfer_vpn_files(user_name,vpn_ip,password)
    except Exception:
        return 2
예제 #13
0
    def __init__(self, _id, setProp=True, **keywords):
        self.id = _id
        self.properties = {}
        print("new file updation successful")
        if not (Container.client):
            cert_path = os.path.join(get_context_path(), 'modules/certs/')
            tls_config = docker.tls.TLSConfig(
                client_cert=(cert_path + 'cert.pem', cert_path + 'key.pem'),
                verify=cert_path + 'ca.pem')
            docker_machine = get_docker_daemon_address()
            client = docker.Client(base_url='https://' + docker_machine[0] +
                                   ':' + docker_machine[1],
                                   version='auto',
                                   tls=tls_config)

            Container.setclient(client)
            logger.debug(client)

        logger.debug(Container.client)
        self.update = Container.client.update_container
        for key in keywords:
            self.properties[key] = keywords[key]
        if setProp:
            self.updatedetails()
예제 #14
0
def get_startup_data():
    from xml.dom import minidom

    xmldoc = minidom.parse(os.path.join(get_context_path(), 'static/startup_data.xml'))
    return xmldoc
예제 #15
0
def get_startup_data():
    from xml.dom import minidom

    xmldoc = minidom.parse(os.path.join(get_context_path(), 'private/startup_data.xml'))
    return xmldoc
예제 #16
0
from cont_handler import Container, addip
from gluon import current
from helper import get_context_path, get_docker_daemon_address, \
    get_nginx_server_address, log_exception , config
from images import getImageProfile
from log_handler import logger
import docker
import os
import random
import remote_vm_task as remote_machine

if config.getboolean("GENERAL_CONF", "docker_enabled"):
    cert_path = os.path.join(get_context_path(), 'modules/certs/')
    tls_config = docker.tls.TLSConfig(client_cert=(cert_path + 'cert.pem',
                                                   cert_path + 'key.pem'),
                                      verify=cert_path + 'ca.pem')

    docker_machine = get_docker_daemon_address()
    #client = docker.Client(base_url='https://:10.237.20.236:3376',version='auto', tls=tls_config)
    client = docker.Client(base_url='https://' + docker_machine[0] + ':' +
                           docker_machine[1],
                           version='auto',
                           tls=tls_config)
    Container.setclient(client)


def proxieddomain(name):
    #alias = '.baadalgateway.cse.iitd.ac.in'
    alias = '.docker.iitd.ac.in'
    address = name + alias
    return address[1:]
예제 #17
0
def create_graph(rrd_file_name, graph_type, rrd_file_path, graph_period):

    rrd_logger.debug(rrd_file_name+" : "+graph_type+" : "+rrd_file_path+" : "+graph_period)
    #rrd_file = rrd_file_name + '.rrd'       

    #shutil.copyfile(rrd_file_path, rrd_file)
    graph_file = rrd_file_name + "_" + graph_type + ".png"
    graph_file_dir = os.path.join(get_context_path(), 'static' + get_constant('graph_file_dir'))
    graph_file_path = graph_file_dir + os.sep + graph_file

    start_time = None
    consolidation = 'MIN'
    ds = ds1 = ds2 = None
    line = line1 = line2 = None

    
    if graph_period == 'hour':
        start_time = 'now - ' + str(24*60*60)
    elif graph_period == 'day':
        start_time = '-1w'
    elif graph_period == 'month':
        start_time = '-1y'
    elif graph_period == 'week':
        start_time = '-1m'
    elif graph_period == 'year':
        start_time = '-5y'
  
    if ((graph_type == 'ram') or (graph_type == 'cpu')):

        if graph_type == 'ram':
            ds = 'DEF:ram=' + rrd_file_path + ':ram:' + consolidation
            line = 'LINE1:ram#0000FF:Memory'
            graph_type += " (Bytes/Sec)"
            upper_limit = ""
        elif graph_type == 'cpu':
            ds = 'DEF:cpu=' + rrd_file_path + ':cpu:' + consolidation
            line = 'LINE1:cpu#0000FF:CPU'
            graph_type += " (%)"
            upper_limit = "-u 100"
                
        rrdtool.graph(graph_file_path, '--start', start_time, '--end', 'now', '--vertical-label', graph_type, '--watermark', time.asctime(), '-t', ' ' + rrd_file_name, ds, line, "-l 0 --alt-y-grid -L 6" + upper_limit )

    else:

        if graph_type == 'nw':
            ds1 = 'DEF:nwr=' + rrd_file_path + ':tx:' + consolidation
            ds2 = 'DEF:nww=' + rrd_file_path + ':rx:' + consolidation
            line1 = 'LINE1:nwr#0000FF:Transmit'
            line2 = 'LINE1:nww#FF7410:Receive'

        elif graph_type == 'disk':
            ds1 = 'DEF:diskr=' + rrd_file_path + ':dr:' + consolidation
            ds2 = 'DEF:diskw=' + rrd_file_path + ':dw:' + consolidation
            line1 = 'LINE1:diskr#0000FF:DiskRead'
            line2 = 'LINE1:diskw#FF7410:DiskWrite'

        graph_type += " (Bytes/Sec)"

        rrdtool.graph(graph_file_path, '--start', start_time, '--end', 'now', '--vertical-label', graph_type, '--watermark', time.asctime(), '-t', ' ' + rrd_file_name, ds1, ds2, line1, line2, "-l 0 --alt-y-grid -L 6" )

    rrd_logger.debug(graph_file_path)

    if os.path.exists(graph_file_path):
        return True
    else:
        return False
예제 #18
0
from cont_handler import Container
from gluon import current
from helper import get_context_path, get_docker_daemon_address, \
    get_nginx_server_address, log_exception , config
from images import getImageProfile
from log_handler import logger
import docker
import os
import random
import remote_vm_task as remote_machine

cert_path = os.path.join(get_context_path(), 'modules/certs/')
tls_config = docker.tls.TLSConfig(client_cert=(cert_path+'cert.pem', cert_path+'key.pem'),verify=cert_path+'ca.pem')

docker_machine = get_docker_daemon_address();
client = docker.Client(base_url='https://'+docker_machine[0]+':'+docker_machine[1],version='auto', tls=tls_config)
Container.setclient(client);


def proxieddomain (name) :
    alias = '.baadalgateway.cse.iitd.ac.in'
    address = name +alias;
    return address[1:];         # required name contains '/' at start


def install_cont(parameters):
    try:
        cont_id = parameters['cont_id']
        logger.debug("In install_container() function...")
        cont_details = current.db.container_data[cont_id]
        logger.debug(cont_details)