Ejemplo n.º 1
0
def check_process(secret_key, uuid):
    
    uuid=uuid.replace('/', '-')
    uuid=uuid.replace("\\", '-')
    
    if filterip()==True:
        
        result={'ERROR': 1, 'MESSAGE': '', 'CODE_ERROR' : 0, 'PROGRESS': 100}

        if check_hash(secret_key):
            if os.path.isfile(logs+'/log_'+uuid):
                f=open(logs+'/log_'+uuid)
                
                for line in f:
                    pass
                
                try:
                
                    result=json.loads(line)
                    
                    f.close()
                    
                except:
                    
                    f.close()
                    
                    result['MESSAGE']='Cannot decode json message'

    return result
Ejemplo n.º 2
0
def home(secret_key=''):  

    global cache_file_scripts

    if filterip()==True:
        
        result={'ERROR': 0, 'MESSAGE': '', 'CODE_ERROR': 0}

        if check_hash(secret_key):

            if request.query.get('script', '')!='' and request.query.get('module', '')!='' and request.query.get('category', '')!='':
                
                if os.path.isfile('./settings/scripts'):
                
                    file=open('./settings/scripts')
                    
                    new_line=''
                    
                    if len(cache_file_scripts)==0:
                        for line in file:
                            cache_file_scripts.append(line.strip())                   
                    else:
                        for line in reversed(list(file)):
                            #cache_file_scripts.append(line.strip())
                            new_line=line.strip()
                            
                            if new_line!='':
                                break
                        if new_line not in cache_file_scripts:
                            cache_file_scripts.append(new_line)
                            
                    file.close()

                uuid=str(uuid4())
                
                script=os.path.basename(request.query['category'])+'/'+os.path.basename(request.query['module'])+'/'+os.path.basename(request.query['script'])
                
                script=quote(script)
                
                if script in cache_file_scripts:
                
                    #Search script in list of scripts
                    
                    del request.query['script']
                    del request.query['module']
                    del request.query['category']
                    
                    arr_params=[ '--'+x+' '+y for x,y in request.query.items() ]
                    
                    params=' '.join(arr_params)
                    
                    args=['sudo '+python_command+' '+config.base_modules.replace('.', '/')+'/pastafari/daemon/daemon.py --script "'+script+'" --uuid '+uuid+' --arguments "'+params+'"']

                    daemon=Popen(args, bufsize=-1, executable=None, stdin=None, stdout=None, stderr=None, preexec_fn=None, close_fds=True, shell=True, cwd=None, env=None, universal_newlines=True, startupinfo=None, creationflags=0, restore_signals=True, start_new_session=True, pass_fds=())

                    #daemon.pid

                    result['UUID']=uuid

                    result['MESSAGE']='Executing script...'
                    
                    result['PROGRESS']=0
                    
                else:
                    result['ERROR']=1
                    result['MESSAGE']='Scripts not exists in database'
                    result['CODE_ERROR']=3
                    result['PROGRESS']=100
            else:
                result['ERROR']=1
                result['MESSAGE']='Not task specified'
                result['CODE_ERROR']=1
                result['PROGRESS']=100
                
        else:
            result['ERROR']=1
            result['MESSAGE']='Not authenticated'
            result['CODE_ERROR']=2
            result['PROGRESS']=100

        return result
    
    else:
        
        return 'This IP is not allowed'