Example #1
0
    def updateNetworkData(self, rq):
        data = {}
        self.dns_name = rq['data']['dns_name']
        self.auto_to_ap = rq['data']['auto_to_ap']

        config = weioConfig.getConfiguration()
        config['dns_name'] = self.dns_name + ".local"
        config['auto_to_ap'] = self.auto_to_ap
      
        if (platform.machine() == 'mips'):
            # Change avahi name
            command = "sh scripts/change_boardname.sh " + self.dns_name
            try:
                subprocess.call(command, shell=True)
                firstTimeSwitch = "NO"
                config['first_time_run']=firstTimeSwitch
                data['data'] = "msg_success"
            except:
                output = "ERR_CMD BRDNAME"
                data['data'] = "msg_fail"
                print output
        else:
            # On PC
            firstTimeSwitch = "NO"
            config['first_time_run']=firstTimeSwitch
            data['data'] = "msg_success"
       
        # Save new user data in config file 
        weioConfig.saveConfiguration(config);
        data['requested'] = "updataNetwork"
        self.send(json.dumps(data))
Example #2
0
    def changeProject(self,rq):
        #print "CHANGE PROJECT", rq
        # get configuration from file
        print "TO CHANGE ", rq
        config = weioConfig.getConfiguration()

        virtPath = rq['data']
        storage = os.path.dirname(virtPath)
        print 'STORAGE', storage
        path = "www/"+virtPath
        print 'STORAGE', path

        config["last_opened_project"] = path
        weioConfig.saveConfiguration(config);

        # In this way we avoid migrations between pc and weio and other archs
        try :
            os.remove(path+"/www")
        except:
            print "Symlink don't exist. Will create new one for www in this project"
        os.symlink(config["absolut_root_path"] + "/www/", path + "/www")

        data = {}
        data['requested'] = rq['request']
        self.broadcast(clients, json.dumps(data))

        rqlist = ["stop", "getLastProjectName", "getUserProjetsFolderList"]

        for i in range(0,len(rqlist)):
            rq['request'] = rqlist[i]
            callbacks[ rq['request'] ](self, rq)
Example #3
0
    def newProject(self, rq):
        config = weioConfig.getConfiguration()
        print "NEW PROJECT", rq
        data = {}
        data['requested'] = rq['request']
        path = ""
        storage = rq['storageUnit']

        path = "www/" + rq['storageUnit'] + "/" + rq['path']

        print "CREATE PROJECT", path
        if (len(path)>0):
            if (weioFiles.checkIfDirectoryExists(path)):
                print "ALREADY EXISTS"
                data['status'] = "Can't create project"
                data['error'] = "already exists"
                data['path'] = path
                self.broadcast(clients, json.dumps(data))
            else :
                weioFiles.createDirectory(path)
                # ADD HERE SOME DEFAULT FILES
                # adding __init__.py
                weioFiles.saveRawContentToFile(path + "/__init__.py", "")

                # make symlink to www/
                if (storage == "sd" or storage == "usbFlash"):
                    if (storage == "sd"):
                        if os.path.isdir(path):
                            if not (os.path.exists(path + "/www")):
                                print "COPYING TO ", path + "/www"
                                copytree(config["absolut_root_path"] + "/www/", path + "/www", ignore=ignore_patterns('sd', 'flash', 'examples', 'usbFlash'))
                                print "OK"
                    else:
                        if not (os.path.exists(path + "/www")):
                            print "COPYING TO ", path + "/www"
                            copytree(config["absolut_root_path"] + "/www/", path + "/www", ignore=ignore_patterns('sd', 'flash', 'examples', 'usbFlash'))
                            print "OK"
                else:
                    try:
                        os.remove(path + "/www")
                    except:
                        print "Symlink don't exist. Will create new one for this project"
                    os.symlink(config["absolut_root_path"] + "/www/", path + "/www")

                # copy all files from directory boilerplate to destination
                mypath = "www/libs/weio/boilerPlate/"
                onlyfiles = [ f for f in os.listdir(mypath) if isfile(join(mypath,f)) ]
                for f in onlyfiles:
                    copyfile(mypath+f, path +"/"+f)

                print "LASTOPENED new project", path
                config["last_opened_project"] = path
                weioConfig.saveConfiguration(config);

                data['status'] = "New project created"
                data['path'] = path
                self.broadcast(clients, json.dumps(data))
        else:
            print "BAD PATHNAME"
Example #4
0
    def downloadUpdate(self, data):
        config = weioConfig.getConfiguration()

        # ok now save binary in /tmp (folder in RAM)
        print "downloaded"

        fileToStoreUpdate = ""
        if (platform.machine()=="mips") :
            fileToStoreUpdate = "/tmp/weioUpdate.tar.gz"
            pathToDecompressUpdate = "/tmp"
        else :
            fileToStoreUpdate = "./weioUpdate.tar.gz"
            pathToDecompressUpdate = "./"

        if not(self.downloadUpdateLink is None):

            sw = functools.partial(self.sizeWatcher, fileToStoreUpdate, self.updateDownloadSize)
            sizeCheckerCallback = ioloop.PeriodicCallback(sw, 500)
            sizeCheckerCallback.start()
            self.startDownload(self.downloadUpdateLink, fileToStoreUpdate)
            sizeCheckerCallback.stop()

        # Check is file size is the same as on the server
        sizeOnDisk = os.path.getsize(fileToStoreUpdate)
        print "comparing sizes", sizeOnDisk, self.updateDownloadSize
        if (sizeOnDisk == self.updateDownloadSize):
            # OK
            print "File size is OK"
            self.progressInfo("50%", "File size OK")
            print "Bundle decompressing"
            tar = tarfile.open(fileToStoreUpdate)
            tar.extractall(pathToDecompressUpdate)
            tar.close()
            print "Bundle decompressed"
            #self.progressInfo("80%", "WeIO Bundle decompressed")

            # kill arhive that we don't need anymore to free RAM
            os.remove(fileToStoreUpdate)
            global currentWeioConfigurator
            print "Setting kill flag to YES in current config.weio"
            print "Now I'm ready to exit Tornado and install new version"
            config["kill_flag"] = "YES"
            weioConfig.saveConfiguration(config)
            #self.progressInfo("81%", "WeIO installing")
            # Now quit Tornado and leave script to do his job
            ioloop.IOLoop.instance().stop()
            exit()

        else :
            print "MD5 checksum is not OK, retrying..."
            if (self.downloadTries<2):
                self.progressInfo("5%", "Downloading Bundle again, MD5 checkum was not correct")
                self.downloadUpdate(None)
            else:
                print "Something went wrong. Check Internet connection and try again later"
                self.progressInfo("0%", "Something went wrong. Check Internet connection and try again later")

            self.downloadTries+=1
Example #5
0
    def post(self):
        confFile = weioConfig.getConfiguration()
        fullName = self.get_argument("fullName", "")
        passwd = self.get_argument("password", "")
        boardname = self.get_argument("boardname", "")

        # This is two letters country code to be used to setup wifi region
        countryCode = self.get_argument("countryCode", "")

        print "************ ", fullName, passwd, boardname, countryCode

        data = {}
        # OK now is time to setup username and password
        confFile['user'] = fullName
        weioConfig.saveConfiguration(confFile)

        output = "OK PASSWD"
        #echo -e "weio\nweio" | passwd

        # ATTENTION, DON'T MESS WITH THIS STUFF ON YOUR LOCAL COMPUTER
        # First protection is mips detection, second is your own OS
        # who hopefully needs sudo to change passwd on the local machine
        if (platform.machine() == 'mips'):

            # Change root password
            command = "sh scripts/change_root_pswd.sh " + passwd
            print "EXEC : " + command

            try:
                subprocess.call(command, shell=True)
                firstTimeSwitch = "NO"
                confFile['first_time_run']=firstTimeSwitch
            except:
                output = "ERR_CMD PASSWD"
                print output

            # Change avahi name
            command = "sh scripts/change_boardname.sh " + boardname
            print "EXEC : " + command

            try:
                subprocess.call(command, shell=True)
            except:
                output = "ERR_CMD BRDNAME"

        else:
            # On PC
            firstTimeSwitch = "NO"
            confFile['first_time_run']=firstTimeSwitch
        
        # Save new password in the config file
        confFile['password'] = passwd

        # Write in config file
        weioConfig.saveConfiguration(confFile)

        self.set_secure_cookie("user", tornado.escape.json_encode("weio"))
        self.redirect(self.get_argument("next", u"/"))
Example #6
0
    def duplicateProject(self, rq):
        config = weioConfig.getConfiguration()

        print "DUPLICATE",rq

        storage = rq['storageUnit']

        path = "www/" + rq['storageUnit'] + "/" + rq['path']

        print "DUPLICATE PROJECT", path
        data = {}
        if (len(path)>0):
            if (storage != "sd" and storage != "usbFlash"):
                # Destroy symlink
                if os.path.islink(config["last_opened_project"]+"/www"):
                    os.remove(config["last_opened_project"]+"/www")
                else:
                    shutil.rmtree(config["last_opened_project"]+"/www")
                # copy all files
                try:
                    copytree(config["last_opened_project"], path)
                except:
                    print sys.exc_info()[0]
            else:
                if os.path.isdir("www/"+rq['storageUnit']):
                    try: 
                        copytree(config["last_opened_project"], path, ignore=ignore_patterns('www'))
                    except:
                        print sys.exc_info()[0]

            if (storage != "sd" and storage != "usbFlash"):
                # Recreate symlink
                os.symlink(config["absolut_root_path"] + "/www/", path + "/www")
            else:
                if not (os.path.exists(path + "/www")):
                    copytree(config["absolut_root_path"] + "/www/", path + "/www", ignore=ignore_patterns('sd', 'flash', 'examples', 'usbFlash'))

            config["last_opened_project"] = path
            weioConfig.saveConfiguration(config)

            data['status'] = "Project duplicated"

            data['requested'] = "status"
            self.broadcast(clients, json.dumps(data))

            # now go to newely duplicated project

            data['request'] = "changeProject"
            data['data'] = rq['storageUnit'] + "/" + rq['path']

            self.changeProject(data)
        else:
            print "BAD PATHNAME"
            data['status'] = "Error duplicating project"

            data['requested'] = "status"
            self.broadcast(clients, json.dumps(data))
Example #7
0
 def downloadComplete(self, binary):
     # ok now save binary in /tmp (folder in RAM)
     if (platform.machine()=="mips") :    
         fileToStoreUpdate = "/tmp/weioUpdate.tar.gz"
         pathToDecompressUpdate = "/tmp"
     else :
         fileToStoreUpdate = "./weioUpdate.tar.gz"
         pathToDecompressUpdate = "./"
         
     with open(fileToStoreUpdate, "w") as f:
            f.write(binary.body)
            
     # check file integrity with MD5 checksum
     md5local = self.getMd5sum(fileToStoreUpdate)
     
     if (md5local == self.distantJsonUpdater["md5"]) :
         print "MD5 checksum OK"
         self.progressInfo("50%", "MD5 checksum OK")
         print "Bundle decompressing"
         #self.progressInfo("52%", "WeIO Bundle decompressing")
         tar = tarfile.open(fileToStoreUpdate)
         tar.extractall(pathToDecompressUpdate)
         tar.close()
         print "Bundle decompressed"
         #self.progressInfo("80%", "WeIO Bundle decompressed")
         
         # kill arhive that we don't need anymore to free RAM
         os.remove(fileToStoreUpdate)
         global currentWeioConfigurator
         print "Setting kill flag to YES in current config.weio"
         print "Now I'm ready to exit Tornado and install new version"
         currentWeioConfigurator["kill_flag"] = "YES"
         weioConfig.saveConfiguration(currentWeioConfigurator)
         #self.progressInfo("81%", "WeIO installing")
         # Now quit Tornado and leave script to do his job
         exit()
         
     else :
         print "MD5 checksum is not OK, retrying..."
         if (self.downloadTries<2):
             self.progressInfo("5%", "Downloading Bundle again, MD5 checkum was not correct")
             self.downloadUpdate(None)
         else:
             print "Something went wrong. Check Internet connection and try again later"
             self.progressInfo("0%", "Something went wrong. Check Internet connection and try again later")
         
         self.downloadTries+=1
Example #8
0
    def post(self):
        confFile = weioConfig.getConfiguration()
        fullName = self.get_argument("fullName", "")
        passwd = self.get_argument("password", "")
        hostname = self.get_argument("hostname", "")

        # This is two letters country code to be used to setup wifi region
        countryCode = self.get_argument("countryCode", "")

        print "************ ", fullName, passwd, hostname, countryCode

        data = {}
        # OK now is time to setup username and password
        confFile['user'] = fullName
        weioConfig.saveConfiguration(confFile)

        output = "OK PASSWD"
        #echo -e "weio\nweio" | passwd

        if (platform.machine() == 'mips'):
            command = "sh scripts/change_root_pswd.sh " + passwd
            print "EXEC : " + command

        try:
            # ATTENTION, DON'T MESS WITH THIS STUFF ON YOUR LOCAL COMPUTER
            # First protection is mips detection, second is your own OS
            # who hopefully needs sudo to change passwd on the local machine
            if (platform.machine() == 'mips'):
                print Popen(command, stdout=PIPE, shell=True).stdout.read()
                firstTimeSwitch = "NO"
                confFile['first_time_run'] = firstTimeSwitch
            else:
                firstTimeSwitch = "NO"
                confFile['first_time_run'] = firstTimeSwitch
        except:
            output = "ERR_CMD"
        print output

        # Save new password in the config file
        confFile['password'] = passwd

        # Write in config file
        weioConfig.saveConfiguration(confFile)

        self.set_secure_cookie("user", tornado.escape.json_encode("weio"))
        self.redirect(self.get_argument("next", u"/"))
Example #9
0
    def updateNetworkData(self, rq):
        data = {}
        self.dns_name = rq['data']['dns_name']
        self.auto_to_ap = rq['data']['auto_to_ap']
        self.timezone = rq['data']['timezone']

        config = weioConfig.getConfiguration()
        config['dns_name'] = self.dns_name + ".local"
        config['auto_to_ap'] = self.auto_to_ap

        # Check timezone
        if self.timezone:
            config["timezone"] = self.timezone

        if (platform.machine() == 'mips'):
            # Change avahi name
            command = "sh scripts/change_boardname.sh " + self.dns_name
            if self.timezone:
                commandConfig = "uci set system.@system[0].timezone=" + self.timezone  # Set timezone on openwrt config (required for system reboot)
                commandCommitConfig = "uci commit system.@system[0].timezone"

            try:
                subprocess.call(command, shell=True)
                subprocess.call(commandConfig, shell=True)
                subprocess.call(commandCommitConfig, shell=True)

                firstTimeSwitch = "NO"
                config['first_time_run'] = firstTimeSwitch
                data['data'] = "msg_success"
            except:
                output = "ERR_CMD BRDNAME"
                data['data'] = "msg_fail"
                print output
        else:
            # On PC
            firstTimeSwitch = "NO"
            config['first_time_run'] = firstTimeSwitch
            data['data'] = "msg_success"

        # Save new user data in config file
        weioConfig.saveConfiguration(config)
        data['requested'] = "updataNetwork"
        self.send(json.dumps(data))
Example #10
0
    def updateNetworkData(self, rq):
        data = {}
        self.dns_name = rq['data']['dns_name']
        self.auto_to_ap = rq['data']['auto_to_ap']
        self.timezone = rq['data']['timezone']
       
        config = weioConfig.getConfiguration()
        config['dns_name'] = self.dns_name + ".local"
        config['auto_to_ap'] = self.auto_to_ap

         # Check timezone
        if self.timezone:
            config["timezone"] = self.timezone
         
        if (platform.machine() == 'mips'):
            # Change avahi name
            command = "sh scripts/change_boardname.sh " + self.dns_name
            if self.timezone:
                commandConfig = "uci set system.@system[0].timezone=" + self.timezone  # Set timezone on openwrt config (required for system reboot)
                commandCommitConfig = "uci commit system.@system[0].timezone"
         
            try:
                subprocess.call(command, shell=True)
                subprocess.call(commandConfig, shell=True)
                subprocess.call(commandCommitConfig, shell=True)
            
                firstTimeSwitch = "NO"
                config['first_time_run']=firstTimeSwitch
                data['data'] = "msg_success"
            except:
                output = "ERR_CMD BRDNAME"
                data['data'] = "msg_fail"
                print output
        else:
            # On PC
            firstTimeSwitch = "NO"
            config['first_time_run']=firstTimeSwitch
            data['data'] = "msg_success"
       
        # Save new user data in config file 
        weioConfig.saveConfiguration(config);
        data['requested'] = "updataNetwork"
        self.send(json.dumps(data))
Example #11
0
    def updateUserData(self, rq):
        data = {}
        self.user = rq['data']['user']
        self.password = rq['data']['password']
        self.play_composition_on_server_boot = rq['data'][
            'play_composition_on_server_boot']
        config = weioConfig.getConfiguration()
        config["user"] = self.user
        config[
            "play_composition_on_server_boot"] = self.play_composition_on_server_boot
        # Check if new password is sent
        if self.password:
            config["password"] = self.password

        # ATTENTION, DON'T MESS WITH THIS STUFF ON YOUR LOCAL COMPUTER
        # First protection is mips detection, second is your own OS
        # who hopefully needs sudo to change passwd on the local machine
        if (platform.machine() == 'mips'):
            # Change root password
            command = "sh scripts/change_root_pswd.sh " + self.password

            try:
                subprocess.call(command, shell=True)
                firstTimeSwitch = "NO"
                config['first_time_run'] = firstTimeSwitch
                data['data'] = "msg_success"

            except:
                output = "ERR_CMD PASSWD"
                data['data'] = "msg_fail"
                print output
        else:
            # On PC
            firstTimeSwitch = "NO"
            config['first_time_run'] = firstTimeSwitch
            data['data'] = "msg_success"

        # Save new user data in config file
        weioConfig.saveConfiguration(config)
        data['requested'] = "updateSettings"
        self.send(json.dumps(data))
Example #12
0
    def updateUserData(self, rq):
        data = {}
        self.user =  rq['data']['user']
        self.password =  rq['data']['password']
        self.login_required = rq['data']['login_required']
        self.play_composition_on_server_boot = rq['data']['play_composition_on_server_boot']
        config = weioConfig.getConfiguration()
        config["user"] = self.user
        config["play_composition_on_server_boot"] = self.play_composition_on_server_boot
        config["login_required"] = self.login_required
        # Check if new password is sent
        if self.password:
            config["password"] = self.password
       
        # ATTENTION, DON'T MESS WITH THIS STUFF ON YOUR LOCAL COMPUTER
        # First protection is mips detection, second is your own OS
        # who hopefully needs sudo to change passwd on the local machine
        if (platform.machine() == 'mips'):
            # Change root password
            command = "sh scripts/change_root_pswd.sh " + self.password

            try:
                subprocess.call(command, shell=True)
                firstTimeSwitch = "NO"
                config['first_time_run']=firstTimeSwitch
                data['data'] = "msg_success"
            
            except:
                output = "ERR_CMD PASSWD"
                data['data'] = "msg_fail"
                print output
        else:
             # On PC
            firstTimeSwitch = "NO"
            config['first_time_run']=firstTimeSwitch
            data['data'] = "msg_success"
        
        # Save new user data in config file 
        weioConfig.saveConfiguration(config);
        data['requested'] = "updateSettings"
        self.send(json.dumps(data))
Example #13
0
    def duplicateProject(self, rq):
        config = weioConfig.getConfiguration()

        print "DUPLICATE",rq

        storage = rq['storageUnit']

        path = "www/" + rq['storageUnit'] + "/" + rq['path']

        print "DUPLICATE PROJECT", path
        data = {}
        if (len(path)>0):

            # Destroy symlink
            os.remove(config["last_opened_project"]+"/www")
            # copy all files
            copytree(config["last_opened_project"], path)
            # Recreate symlink
            os.symlink(config["absolut_root_path"] + "/www/", config["last_opened_project"] + "/www")

            config["last_opened_project"] = path
            weioConfig.saveConfiguration(config)

            data['status'] = "Project duplicated"

            data['requested'] = "status"
            self.broadcast(clients, json.dumps(data))

            # now go to newely duplicated project

            data['request'] = "changeProject"
            data['data'] = rq['storageUnit'] + "/" + rq['path']

            self.changeProject(data)
        else:
            print "BAD PATHNAME"
            data['status'] = "Error duplicating project"

            data['requested'] = "status"
            self.broadcast(clients, json.dumps(data))
Example #14
0
    def newProject(self, rq):
        config = weioConfig.getConfiguration()
        print "NEW PROJECT", rq
        data = {}
        data['requested'] = rq['request']
        path = ""
        storage = rq['storageUnit']

        path = "www/" + rq['storageUnit'] + "/" + rq['path']

        print "CREATE PROJECT", path
        if (len(path)>0):
            weioFiles.createDirectory(path)
            # ADD HERE SOME DEFAULT FILES
            # adding __init__.py
            weioFiles.saveRawContentToFile(path + "/__init__.py", "")
            
            
            # make symlink to www/
            try :
                os.remove(path + "/www")
            except:
                print "Symlink don't exist. Will create new one for this project"
            os.symlink(config["absolut_root_path"] + "/www/", path + "/www")

            # copy all files from directory boilerplate to destination
            mypath = "www/libs/weio/boilerPlate/"
            onlyfiles = [ f for f in os.listdir(mypath) if isfile(join(mypath,f)) ]
            for f in onlyfiles:
                copyfile(mypath+f, path +"/"+f)

            print "LASTOPENED new project", path
            config["last_opened_project"] = path
            weioConfig.saveConfiguration(config);

            data['status'] = "New project created"
            data['path'] = path
            self.broadcast(clients, json.dumps(data))
        else:
            print "BAD PATHNAME"
Example #15
0
    def changeProject(self, rq):
        #print "CHANGE PROJECT", rq
        # get configuration from file
        print "TO CHANGE ", rq
        config = weioConfig.getConfiguration()

        virtPath = rq['data']
        storage = os.path.dirname(virtPath)
        print 'STORAGE', storage
        path = "www/" + virtPath
        print 'STORAGE', path

        config["last_opened_project"] = path
        weioConfig.saveConfiguration(config)

        # In this way we avoid migrations between pc and weio and other archs
        if (storage != "sd" and storage != "usbFlash"):
            try:
                os.remove(path + "/www")
            except:
                print "Symlink don't exist. Will create new one for www in this project"
            os.symlink(config["absolut_root_path"] + "/www/", path + "/www")
        elif not os.path.exists(path + "/www"):
            print "COPYING TO ", path + "/www"
            copytree(config['absolut_root_path'] + "/www/",
                     path + "/www",
                     ignore=ignore_patterns('sd', 'flash', 'examples',
                                            'usbFlash'))
            print "OK"

        data = {}
        data['requested'] = rq['request']
        self.broadcast(clients, json.dumps(data))

        rqlist = ["stop", "getLastProjectName", "getUserProjetsFolderList"]

        for i in range(0, len(rqlist)):
            rq['request'] = rqlist[i]
            callbacks[rq['request']](self, rq)
Example #16
0
    def deleteCurrentProject(self, rq):
        data = {}
        data['requested'] = rq['request']

        config = weioConfig.getConfiguration()
        projectToKill = config["last_opened_project"]

        print "PROJECT TO KILL ", projectToKill

        weioFiles.removeDirectory(projectToKill)

        folders = weioFiles.listOnlyFolders("www/examples")

        if len(folders) > 0:
            config["last_opened_project"] = ""
            weioConfig.saveConfiguration(config)

            data['data'] = "reload page"
        else:
            data['data'] = "ask to create new project"

        self.broadcast(clients, json.dumps(data))
Example #17
0
    def deleteCurrentProject(self, rq):
        data = {}
        data['requested'] = rq['request']

        config = weioConfig.getConfiguration()
        projectToKill = config["last_opened_project"]

        print "PROJECT TO KILL ", projectToKill

        weioFiles.removeDirectory(projectToKill)

        folders = weioFiles.listOnlyFolders("www/examples")

        if len(folders) > 0 :
         config["last_opened_project"] = ""
         weioConfig.saveConfiguration(config)

         data['data'] = "reload page"
        else :
         data['data'] = "ask to create new project"

        self.broadcast(clients, json.dumps(data))
Example #18
0
    def runWeio(self, rq):

        fullName = rq['fullName']
        passwd1 = rq['password1']
        passwd2 = rq['password2']
        dnsName = rq['dnsName']

        # This is two letters country code to be used to setup wifi region
        countryCode = rq['countryCode']

        passwd = ""
        if (passwd1 == passwd2):
            passwd = passwd1

        data = {}
        if (fullName != "" and passwd != "" and dnsName != ""):
            confFile = weioConfig.getConfiguration()
            # OK now is time to setup username and password
            confFile['user'] = fullName
            weioConfig.saveConfiguration(confFile)

            output = "OK PASSWD"
            #echo -e "weio\nweio" | passwd
            command = "sh scripts/change_root_pswd.sh " + passwd
            print "EXEC : " + command
            try:
                # ATTENTION, DON'T MESS WITH THIS STUFF ON YOUR LOCAL COMPUTER
                # First protection is mips detection, second is your own OS
                # who hopefully needs sudo to change passwd on the local machine
                if (platform.machine() == 'mips'):

                    print Popen(command, stdout=PIPE, shell=True).stdout.read()

                    firstTimeSwitch = "NO"
                    confFile['first_time_run'] = firstTimeSwitch
                    weioConfig.saveConfiguration(confFile)
                else:
                    print command
                    firstTimeSwitch = "NO"
                    confFile['first_time_run'] = firstTimeSwitch
                    weioConfig.saveConfiguration(confFile)
            except:
                print("Comand ERROR : " + str(output) + " " + command)
                output = "ERR_CMD"
            print output

            #sucess
            data['requested'] = rq['request']
            data['data'] = 'OK'
            self.send(json.dumps(data))

        else:

            if (fullName == ""):
                data['serverPush'] = 'error'
                data['data'] = 'Please enter your full name'
                self.send(json.dumps(data))
            elif (passwd == ""):
                data['serverPush'] = 'error'
                data['data'] = 'Please enter valid password'
                self.send(json.dumps(data))
            elif (dnsName == ""):
                data['serverPush'] = 'error'
                data['data'] = 'Please enter valid DNS name'
                self.send(json.dumps(data))
Example #19
0
            # go to sta


if __name__ == '__main__':
    # Take configuration from conf file and use it to define parameters
    global wifiButtons
    global wifiPeriodicCheck

    confFile = weioConfig.getConfiguration()

    # Create symlinks to external projects
    weioFiles.symlinkExternalProjects()

    # put absolut path in conf, needed for local testing on PC
    confFile['absolut_root_path'] = os.path.abspath(".")
    weioConfig.saveConfiguration(confFile)
    firstTimeSwitch = confFile['first_time_run']

    import logging
    logging.getLogger().setLevel(logging.DEBUG)

    ###
    # Routers
    ###
    # EDITOR ROUTES
    WeioEditorRouter = SockJSRouter(editorHandler.WeioEditorHandler,
                                    '/editorSocket')

    # DASHBOARD ROUTE websocket
    WeioDashboardRouter = SockJSRouter(dashboardHandler.WeioDashBoardHandler,
                                       '/dashboard')
Example #20
0
    def newProject(self, rq):
        config = weioConfig.getConfiguration()
        print "NEW PROJECT", rq
        data = {}
        data['requested'] = rq['request']
        path = ""
        storage = rq['storageUnit']

        path = "www/" + rq['storageUnit'] + "/" + rq['path']

        print "CREATE PROJECT", path
        if (len(path) > 0):
            if (weioFiles.checkIfDirectoryExists(path)):
                print "ALREADY EXISTS"
                data['status'] = "Can't create project"
                data['error'] = "already exists"
                data['path'] = path
                self.broadcast(clients, json.dumps(data))
            else:
                weioFiles.createDirectory(path)
                # ADD HERE SOME DEFAULT FILES
                # adding __init__.py
                weioFiles.saveRawContentToFile(path + "/__init__.py", "")

                # make symlink to www/
                if (storage == "sd" or storage == "usbFlash"):
                    if (storage == "sd"):
                        if os.path.isdir(path):
                            if not (os.path.exists(path + "/www")):
                                print "COPYING TO ", path + "/www"
                                copytree(config["absolut_root_path"] + "/www/",
                                         path + "/www",
                                         ignore=ignore_patterns(
                                             'sd', 'flash', 'examples',
                                             'usbFlash'))
                                print "OK"
                    else:
                        if not (os.path.exists(path + "/www")):
                            print "COPYING TO ", path + "/www"
                            copytree(config["absolut_root_path"] + "/www/",
                                     path + "/www",
                                     ignore=ignore_patterns(
                                         'sd', 'flash', 'examples',
                                         'usbFlash'))
                            print "OK"
                else:
                    try:
                        os.remove(path + "/www")
                    except:
                        print "Symlink don't exist. Will create new one for this project"
                    os.symlink(config["absolut_root_path"] + "/www/",
                               path + "/www")

                # copy all files from directory boilerplate to destination
                mypath = "www/libs/weio/boilerPlate/"
                onlyfiles = [
                    f for f in os.listdir(mypath) if isfile(join(mypath, f))
                ]
                for f in onlyfiles:
                    copyfile(mypath + f, path + "/" + f)

                print "LASTOPENED new project", path
                config["last_opened_project"] = path
                weioConfig.saveConfiguration(config)

                data['status'] = "New project created"
                data['path'] = path
                self.broadcast(clients, json.dumps(data))
        else:
            print "BAD PATHNAME"
Example #21
0
    def duplicateProject(self, rq):
        config = weioConfig.getConfiguration()

        print "DUPLICATE", rq

        storage = rq['storageUnit']

        path = "www/" + rq['storageUnit'] + "/" + rq['path']

        print "DUPLICATE PROJECT", path
        data = {}
        if (len(path) > 0):
            if (storage != "sd" and storage != "usbFlash"):
                # Destroy symlink
                if os.path.islink(config["last_opened_project"] + "/www"):
                    os.remove(config["last_opened_project"] + "/www")
                else:
                    shutil.rmtree(config["last_opened_project"] + "/www")
                # copy all files
                try:
                    copytree(config["last_opened_project"], path)
                except:
                    print sys.exc_info()[0]
            else:
                if os.path.isdir("www/" + rq['storageUnit']):
                    try:
                        copytree(config["last_opened_project"],
                                 path,
                                 ignore=ignore_patterns('www'))
                    except:
                        print sys.exc_info()[0]

            if (storage != "sd" and storage != "usbFlash"):
                # Recreate symlink
                os.symlink(config["absolut_root_path"] + "/www/",
                           path + "/www")
            else:
                if not (os.path.exists(path + "/www")):
                    copytree(config["absolut_root_path"] + "/www/",
                             path + "/www",
                             ignore=ignore_patterns('sd', 'flash', 'examples',
                                                    'usbFlash'))

            config["last_opened_project"] = path
            weioConfig.saveConfiguration(config)

            data['status'] = "Project duplicated"

            data['requested'] = "status"
            self.broadcast(clients, json.dumps(data))

            # now go to newely duplicated project

            data['request'] = "changeProject"
            data['data'] = rq['storageUnit'] + "/" + rq['path']

            self.changeProject(data)
        else:
            print "BAD PATHNAME"
            data['status'] = "Error duplicating project"

            data['requested'] = "status"
            self.broadcast(clients, json.dumps(data))
Example #22
0
if __name__ == '__main__':
    # Take configuration from conf file and use it to define parameters
    global confFile
    global firstTimeSwitch
    global wifiButtons
    global wifiPeriodicCheck

    confFile = weioConfig.getConfiguration()
    
    # Create symlinks to external projects
    weioFiles.symlinkExternalProjects()

    # put absolut path in conf, needed for local testing on PC
    confFile['absolut_root_path'] = os.path.abspath(".")
    weioConfig.saveConfiguration(confFile)
    firstTimeSwitch = confFile['first_time_run']


    import logging
    logging.getLogger().setLevel(logging.DEBUG)


    ###
    # Routers
    ###
    # EDITOR ROUTES
    WeioEditorRouter = SockJSRouter(editorHandler.WeioEditorHandler, '/editorSocket')

    # DASHBOARD ROUTE websocket
    WeioDashboardRouter = SockJSRouter(dashboardHandler.WeioDashBoardHandler, '/dashboard')
Example #23
0
    def downloadUpdate(self, data):
        config = weioConfig.getConfiguration()

        # ok now save binary in /tmp (folder in RAM)
        print "downloaded"

        fileToStoreUpdate = ""
        if (platform.machine() == "mips"):
            fileToStoreUpdate = "/tmp/weioUpdate.tar.gz"
            pathToDecompressUpdate = "/tmp"
        else:
            fileToStoreUpdate = "./weioUpdate.tar.gz"
            pathToDecompressUpdate = "./"

        if not (self.downloadUpdateLink is None):

            sw = functools.partial(self.sizeWatcher, fileToStoreUpdate,
                                   self.updateDownloadSize)
            sizeCheckerCallback = ioloop.PeriodicCallback(sw, 500)
            sizeCheckerCallback.start()
            self.startDownload(self.downloadUpdateLink, fileToStoreUpdate)
            sizeCheckerCallback.stop()

        # Check is file size is the same as on the server
        sizeOnDisk = os.path.getsize(fileToStoreUpdate)
        print "comparing sizes", sizeOnDisk, self.updateDownloadSize
        if (sizeOnDisk == self.updateDownloadSize):
            # OK
            print "File size is OK"
            self.progressInfo("50%", "File size OK")
            print "Bundle decompressing"
            tar = tarfile.open(fileToStoreUpdate)
            tar.extractall(pathToDecompressUpdate)
            tar.close()
            print "Bundle decompressed"
            #self.progressInfo("80%", "WeIO Bundle decompressed")

            # kill arhive that we don't need anymore to free RAM
            os.remove(fileToStoreUpdate)
            global currentWeioConfigurator
            print "Setting kill flag to YES in current config.weio"
            print "Now I'm ready to exit Tornado and install new version"
            config["kill_flag"] = "YES"
            weioConfig.saveConfiguration(config)
            #self.progressInfo("81%", "WeIO installing")
            # Now quit Tornado and leave script to do his job
            ioloop.IOLoop.instance().stop()
            exit()

        else:
            print "MD5 checksum is not OK, retrying..."
            if (self.downloadTries < 2):
                self.progressInfo(
                    "5%",
                    "Downloading Bundle again, MD5 checkum was not correct")
                self.downloadUpdate(None)
            else:
                print "Something went wrong. Check Internet connection and try again later"
                self.progressInfo(
                    "0%",
                    "Something went wrong. Check Internet connection and try again later"
                )

            self.downloadTries += 1
Example #24
0
    def runWeio(self,rq):

        fullName = rq['fullName']
        passwd1 = rq['password1']
        passwd2 = rq['password2']
        dnsName = rq['dnsName']

        # This is two letters country code to be used to setup wifi region
        countryCode = rq['countryCode']

        passwd = ""
        if (passwd1==passwd2):
            passwd = passwd1

        data = {}
        if (fullName!="" and passwd!="" and dnsName!=""):
            confFile = weioConfig.getConfiguration()
            # OK now is time to setup username and password
            confFile['user'] = fullName
            weioConfig.saveConfiguration(confFile)

            output = "OK PASSWD"
            #echo -e "weio\nweio" | passwd
            command = "sh scripts/change_root_pswd.sh " + passwd
            print "EXEC : " + command
            try :
                # ATTENTION, DON'T MESS WITH THIS STUFF ON YOUR LOCAL COMPUTER
                # First protection is mips detection, second is your own OS
                # who hopefully needs sudo to change passwd on the local machine
                if (platform.machine() == 'mips') :

                    print Popen(command, stdout=PIPE, shell=True).stdout.read()

                    firstTimeSwitch = "NO"
                    confFile['first_time_run']=firstTimeSwitch
                    weioConfig.saveConfiguration(confFile)
                else :
                    print command
                    firstTimeSwitch = "NO"
                    confFile['first_time_run']=firstTimeSwitch
                    weioConfig.saveConfiguration(confFile)
            except :
                print("Comand ERROR : " + str(output) + " " + command)
                output = "ERR_CMD"
            print output

            #sucess
            data['requested'] = rq['request']
            data['data'] = 'OK'
            self.send(json.dumps(data))

        else :

            if (fullName==""):
                data['serverPush'] = 'error'
                data['data'] = 'Please enter your full name'
                self.send(json.dumps(data))
            elif (passwd==""):
                data['serverPush'] = 'error'
                data['data'] = 'Please enter valid password'
                self.send(json.dumps(data))
            elif (dnsName==""):
                data['serverPush'] = 'error'
                data['data'] = 'Please enter valid DNS name'
                self.send(json.dumps(data))
Example #25
0
    def post(self):
        confFile = weioConfig.getConfiguration()
        fullName = self.get_argument("fullName", "")
        passwd = self.get_argument("password", "")
        login_required = self.get_argument("loginRequired", "NO")
        boardname = self.get_argument("boardname", "")
        timezone = self.get_argument("timezone", "UTC+1")
        # This is two letters country code to be used to setup wifi region
        countryCode = self.get_argument("countryCode", "")

        print "************ ", fullName, passwd, boardname, countryCode

        data = {}
        # OK now is time to setup username and password
        confFile['user'] = fullName
        confFile['login_required'] = login_required
        weioConfig.saveConfiguration(confFile)
        confFile['timezone'] = timezone
        output = "OK PASSWD"

        #echo -e "weio\nweio" | passwd

        # ATTENTION, DON'T MESS WITH THIS STUFF ON YOUR LOCAL COMPUTER
        # First protection is mips detection, second is your own OS
        # who hopefully needs sudo to change passwd on the local machine
        if (platform.machine() == 'mips'):

            # Change root password
            command = "sh scripts/change_root_pswd.sh " + passwd
            print "EXEC : " + command

            try:
                subprocess.call(command, shell=True)
                firstTimeSwitch = "NO"
                confFile['first_time_run'] = firstTimeSwitch
            except:
                output = "ERR_CMD PASSWD"
                print output

            # Change avahi name
            command = "sh scripts/change_boardname.sh " + boardname
            confFile['dns_name'] = boardname + ".local"
            weioConfig.saveConfiguration(confFile)
            print "EXEC : " + command

            try:
                subprocess.call(command, shell=True)
            except:
                output = "ERR_CMD BRDNAME"
            # Change user time zone
            if timezone:
                commandConfig = "uci set system.@system[0].timezone=" + timezone  # Set timezone on openwrt config (required for system reboot)
                commandCommitConfig = "uci commit system.@system[0].timezone"
                try:
                    subprocess.call(commandConfig, shell=True)
                    subprocess.call(commandCommitConfig, shell=True)
                except:
                    output = "ERR_CMD TIMEZONE"
        else:
            # On PC
            firstTimeSwitch = "NO"
            confFile['first_time_run'] = firstTimeSwitch

        # Save new password in the config file
        confFile['password'] = passwd

        # Write in config file
        weioConfig.saveConfiguration(confFile)

        self.set_secure_cookie("user", tornado.escape.json_encode("weio"))
        self.redirect(self.get_argument("next", u"/"))