Example #1
0
 def createPassword():
     Security.deletePassword()
     p = Security.promptForPassword(True)
     Msg.flush()
     Msg.show("Thanks ... please wait")
     Msg.flush()
     h = Security.hashAndSaltPassword(p)
     File.setContent(Security.__passwordPath, {"Password": h}, asJson=True)
Example #2
0
 def getCredentials(self):
     stack = inspect.stack()
     className = str(stack[1][0].f_locals["self"].__class__.__name__)
     path = "{0}/{1}.json".format(Framework.getVaultDir(), className)
     if not File.exists(path):
         self.raiseException(
             "Missing {0} credentials file".format(className))
     return File.getContent(path, asJson=True)
Example #3
0
 def certsAndKeysExist():
     for path in [
             Security.__privateKeyPath, Security.__publicKeyPath,
             Security.__certificatePemPath
     ]:
         if not File.exists(path):
             return False
     if Security.hasOpenSSL():
         return File.exists(Security.__certificateCrtPath)
     return True
Example #4
0
def deleteSafe():
    try:
        for path in [
                "./", "./Core", "./Plugin", "./Plugin/Analyzer",
                "./Plugin/Demo", "./Plugin/IO", "./Plugin/Test",
                "./Plugin/Translator"
        ]:
            Directory.delete("{0}/__pycache__".format(path))
            for path in glob.glob("./Test/Tmp/*"):
                File.delete(File.getCanonicalPath(path))
    except Exception as e:
        Error.handleException(e, True)
Example #5
0
def deleteProtected(cfgPath):
    try:
        cfg = Cfg(cfgPath)
        cfg.load()
        for path in [
                "./Database/{0}.db".format(cfg.cfg["Database"]["Name"]),
                "./Database/CocoscatsTest.db", "./Vault/Certificate.pem",
                "./Vault/Password.json", "./Vault/PrivateKey.pem",
                "./Vault/PublicKey.pem"
        ]:
            File.delete(path)
    except Exception as e:
        Error.handleException(e, True)
Example #6
0
 def __runTranslator(action=None):
     WebApp.checkAuthentication()
     header = WebApp.getHeader("Translator")
     footer = WebApp.getFooter()
     pluginName = Web.cocoscats.cfg["Workflow"]["Translator"]["Plugin"]
     navigation = WebApp.getNavigation("Translator", 3, pluginName)
     path = Web.cocoscats.frameworkParams["translatorPath"]
     if not action is None and action == "Save":
         File.setContent(path, bottle.request.forms.Content)
         WebApp.translatorTainted = True
         WebApp.outputTainted = False
         return "Successfully saved to '" + path + "'"
     content = None
     if WebApp.translatorTainted:
         content = File.getContent(path)
     else:
         content = Web.cocoscats.runTranslator()
     editor = WebApp.getEditor(content)
     body = """{0}{1}""".format(navigation, editor)
     return "{0}{1}{2}".format(header, body, footer)
Example #7
0
 def __showHiddenPrompt(prompt):
     response = None
     sys.stdout.write("{0}: ".format(prompt))
     sys.stdout.flush()
     if sys.stdout.isatty():
         response = getpass.getpass(prompt="")
     else:
         if File.finds(["stty", "stty.exe"]) is not None:
             os.system("stty -echo")
             response = sys.stdin.readline()
             os.system("stty echo")
         else:
             response = input("")
     sys.stdout.write("\n")
     return response.rstrip()
Example #8
0
 def createCertsAndKeys(host=None):
     if host is None:
         host = socket.gethostname()
     File.deletes([
         Security.__privateKeyPath, Security.__publicKeyPath,
         Security.__certificatePemPath, Security.__certificateCrtPath
     ])
     key = OpenSSL.crypto.PKey()
     key.generate_key(OpenSSL.crypto.TYPE_RSA, 2048)
     certificate = OpenSSL.crypto.X509()
     certificate.get_subject().C = "US"
     certificate.get_subject().ST = "Oregon"
     certificate.get_subject().L = "Portland"
     certificate.get_subject().O = "Cocoscats"
     certificate.get_subject().OU = "Cocoscats"
     certificate.get_subject().CN = host
     certificate.set_serial_number(random.randint(1, 99999999999))
     certificate.gmtime_adj_notBefore(0)
     certificate.gmtime_adj_notAfter(10 * 365 * 24 * 60 * 60)
     certificate.set_issuer(certificate.get_subject())
     certificate.set_pubkey(key)
     certificate.sign(key, "sha512")
     privateKeyData = OpenSSL.crypto.dump_privatekey(
         OpenSSL.crypto.FILETYPE_PEM, key)
     publicKeyData = OpenSSL.crypto.dump_publickey(
         OpenSSL.crypto.FILETYPE_PEM, key)
     certificateData = OpenSSL.crypto.dump_certificate(
         OpenSSL.crypto.FILETYPE_PEM, certificate)
     File.setContent(Security.__privateKeyPath,
                     privateKeyData,
                     asBytes=True,
                     mkdirs=True)
     File.setContent(Security.__publicKeyPath,
                     publicKeyData,
                     asBytes=True,
                     mkdirs=True)
     File.setContent(Security.__certificatePemPath,
                     certificateData,
                     asBytes=True,
                     mkdirs=True)
     if Security.hasOpenSSL():
         ret = os.system(
             "openssl x509 -outform der -in {0} -out {1}".format(
                 Security.__certificatePemPath,
                 Security.__certificateCrtPath))
Example #9
0
 def run(self):
     application = self.getPluginParamValue("Application").lower()
     source = self.getPluginParamValue("Source").lower()
     content = None
     path = None
     cmd = None
     if source == "database":
         content = self.getOutputContentDB()
         path = File.setContentToTempFile(content["Content"], ".txt")
     elif source == "path" or source == "target":
         path = self.getWorkflowTarget()
     if self.getPluginParamValue("Application").lower() == "default":
         if self.__isWindows():
             cmd = "start {0}".format(path)
         else:
             cmd = "open {0}".format(path)
     else:
         cmd = self.getPluginParamValue("Application")
     return self.__exe(cmd)
Example #10
0
    def initialize(self, params):
        self.__PARAMS = params
        self.__ASSETS_DIR = "{0}/__YouTube".format(
            os.path.dirname(os.path.realpath(__file__)).replace('\\', '/'))
        self.__CLIENT_API_CAPTIONS_FILE = "{0}/youtube-v3-api-captions.json".format(
            self.__ASSETS_DIR)
        if not os.path.isfile(self.__CLIENT_API_CAPTIONS_FILE):
            raise Exception(
                "Missing YouTube API file file. Download it from Google and put in this path: {0}"
                .format(self.__CLIENT_API_CAPTIONS_FILE))
        self.__DOWNLOADED_PATH = "{0}/downloadedCaptions.srt".format(
            self.__ASSETS_DIR)
        self.__TRANSLATED_PATH = "{0}/translatedCaptions.txt".format(
            self.__ASSETS_DIR)
        self.__CLIENT_SECRETS_FILE = "{0}/client_secrets.json".format(
            self.__PARAMS["VaultPath"])
        if not os.path.isfile(self.__CLIENT_SECRETS_FILE):
            raise Exception(
                "Missing client_secrets.json file. Download it from your Google account and put under the Cocoscat's Vault directory"
            )
        self.__CLIENT_OAUTH2_ACCESS_TOKEN_FILE = "{0}/client_secrets_oauth2.json".format(
            self.__PARAMS["VaultPath"])
        parser = argparse.ArgumentParser(parents=[argparser])
        parser.add_argument(
            "--videoid",
            help="ID for video for which the caption track will be uploaded.",
            default=self.__PARAMS["URL"]["VideoID"])
        parser.add_argument("--name",
                            help="Caption track name",
                            default=self.__PARAMS["CaptionName"])
        parser.add_argument("--file", help="Captions track file to upload")
        parser.add_argument("--language",
                            help="Caption track language",
                            default=self.__PARAMS["L1"])
        parser.add_argument(
            "--captionid",
            help="Required; ID of the caption track to be processed")
        parser.add_argument("--action", help="Action", default="all")

        # Using argsparse is dumb idea in a class but it's not my design. I need to include main client's args
        # until I can figure a better way here to do this here
        parser.add_argument("-c",
                            "--cfg",
                            metavar="'cfg'",
                            type=str,
                            default="cfg.json",
                            help="JSON configuration file")
        parser.add_argument("-C",
                            "--cli",
                            action="store_true",
                            help="Run command line interface")
        parser.add_argument("-W",
                            "--web",
                            action="store_true",
                            help="Run web interface")

        self.__ARGS_PARSER = parser

        if Text.isTrue(self.__PARAMS["RefreshOAUTH2AccessToken"]):
            File.delete(self.__CLIENT_OAUTH2_ACCESS_TOKEN_FILE)

        if not File.exists(self.__CLIENT_OAUTH2_ACCESS_TOKEN_FILE):
            self.generateOAUTH2AccessToken()
Example #11
0
 def runOutputUsingLocalFile(self):
     rawContent = File.getContent(self.getWorkflowSource())
     content = self.__parseContentForOutputSRT(rawContent)
     self.setOutputContent(content)
     return content
Example #12
0
 def runInputUsingLocalFile(self):
     target = self.getWorkflowSource()
     rawContent = File.getContent(target)
     return self.__parseContentForInputSRT(rawContent)
Example #13
0
 def saveTranslatedCaptions(self, content):
     File.setContent(self.__TRANSLATED_PATH, content)
Example #14
0
 def hasPasswordFile():
     return File.exists(Security.__passwordPath)
Example #15
0
 def getVaultContent(self, name, asJson=False):
     path = "{0}/{1}".format(Framework.getVaultDir(), name)
     return File.getContent(path, asJson)
Example #16
0
    def updateDatabase(self):
        #Database.connect()
        #projects = Database.getProject("MyProjectID")
        #print(projects)
        #Database.disconnect()
        #sys.exit()
        if not Text.isTrue(self.cfg["Database"]["Enable"]):
            Msg.showWarning("Database is NOT enabled in {0}".format(
                self.cfgPath))
            return
        Database.connect()
        Database.setDebug(Text.toTrueOrFalse(self.cfg["Database"]["Debug"]))
        with Database.ORM.db_session:
            records = Database.Table.Project.get(ID=self.getProjectID())
            if records is not None:
                records.delete()
                Database.commit()

            projectTable = Database.Table.Project(
                ID=self.getProjectID(),
                Title=Database.sanitize(self.cfg["Title"]),
                Description=Database.sanitize(self.cfg["Description"]),
                DateTime=self.frameworkParams["dateTime"],
                Workflow=self.cfg["Workflow"])

            inputTable = Database.Table.Input(
                ProjectID=projectTable,
                Content=Database.sanitize(
                    File.getContent(self.frameworkParams["inputPath"])),
                Source=Database.sanitize(
                    self.cfg["Workflow"]["Input"]["Source"]),
                PluginName=Database.sanitize(
                    self.cfg["Workflow"]["Input"]["Plugin"]),
                PluginMethod=Database.sanitize(
                    self.cfg["Workflow"]["Input"]["Method"]),
                Plugin=self.cfg["Workflow"]["Input"])

            analyzerTable = Database.Table.Analyzer(
                ProjectID=projectTable,
                Content=Database.sanitize(
                    File.getContent(self.frameworkParams["analyzerPath"])),
                PluginName=Database.sanitize(
                    self.cfg["Workflow"]["Analyzer"]["Plugin"]),
                PluginMethod=Database.sanitize(
                    self.cfg["Workflow"]["Analyzer"]["Method"]),
                Plugin=self.cfg["Workflow"]["Analyzer"])

            content = Database.sanitize(
                File.getContent(self.frameworkParams["translatorPath"]))
            translatorTable = Database.Table.Translator(
                ProjectID=projectTable,
                Content=content,
                ContentParsed=Result.parseTranslatorContent(content),
                PluginName=Database.sanitize(
                    self.cfg["Workflow"]["Translator"]["Plugin"]),
                PluginMethod=Database.sanitize(
                    self.cfg["Workflow"]["Translator"]["Method"]),
                Plugin=self.cfg["Workflow"]["Translator"])

            outputTable = Database.Table.Output(
                ProjectID=projectTable,
                Content=Database.sanitize(
                    File.getContent(self.frameworkParams["outputPath"])),
                Target=Database.sanitize(
                    self.cfg["Workflow"]["Output"]["Target"]),
                PluginName=Database.sanitize(
                    self.cfg["Workflow"]["Output"]["Plugin"]),
                PluginMethod=Database.sanitize(
                    self.cfg["Workflow"]["Output"]["Method"]),
                Plugin=self.cfg["Workflow"]["Output"])

        Database.disconnect()
Example #17
0
 def testCocoscatsOutputPlugins(self):
     File.delete(self.databasePath)
     plugins = []
     plugins.append(
         {
             "ProjectID": "TestTextFileOutput",
             "InputSource": "{0}/house.txt".format(self.testDir),
             "Database":
             {
                 "Name": self.databaseName,
                 "Enable": True,
                 "Debug": False,
                 "Rebuild": False
             },
             "Workflow":
             {
                 "Plugin": "TextFile",
                 "Method": "runOutput",
                 "Target": "{0}/Tmp/houseResults.txt".format(self.testDir),
                 "Edit": False,
                 "Debug": False
             }
         }
     )
     plugins.append(
         {
             "ProjectID": "TestHtmlFileOutput",
             "InputSource": "{0}/house.txt".format(self.testDir),
             "Database":
             {
                 "Name": self.databaseName,
                 "Enable": True,
                 "Debug": False,
                 "Rebuild": False
             },
             "Workflow":
             {
                 "Plugin": "HtmlFile",
                 "Method": "runOutput",
                 "Target": "{0}/Tmp/houseResults.html".format(self.testDir),
                 "Edit": False,
                 "Debug": False
             }
         }
     )
     plugins.append(
         {
             "ProjectID": "TestJsonFileOutput",
             "InputSource": "{0}/house.txt".format(self.testDir),
             "Database":
             {
                 "Name": self.databaseName,
                 "Enable": True,
                 "Debug": False,
                 "Rebuild": False
             },
             "Workflow":
             {
                 "Plugin": "JsonFile",
                 "Method": "runOutput",
                 "Target": "{0}/Tmp/houseResults.json".format(self.testDir),
                 "Edit": False,
                 "Debug": False
             }
         }
     )
     for plugin in plugins:
         cfgEditor = CfgEditor()
         cfgEditor.loadCfg(self.cfgPath)
         cfgEditor.setDatabase(plugin["Database"])
         cfgEditor.setProjectID(plugin["ProjectID"])
         cfgEditor.setWorkflowInputSource(plugin["InputSource"])
         cfgEditor.setWorkflowPlugin("Output", plugin["Workflow"])
         cfgEditor.saveCfg(self.tmpCfgPath)
         cocoscats = Cocoscats(self.tmpCfgPath)
         cocoscats.initialize()
         Cli.run(cocoscats)
Example #18
0
 def deletePassword():
     File.delete(Security.__passwordPath)
Example #19
0
 def getSubresourceIntegrityHash(path):
     content = File.getContent(path)
     hash = hashlib.sha512(content.encode("utf-8")).digest()
     return "sha512-{}".format(base64.b64encode(hash).decode())
Example #20
0
 def verifyPasswordByFile(password, path):
     return Security.verifyPassword(
         password,
         File.getContent(path, asJson=True)["Password"])
Example #21
0
 def runAnalyzer(self):
     content = self.__callPluginMethod("Analyzer",
                                       self.getWorkflowPlugin("Analyzer"),
                                       self.frameworkParams)
     return File.getContent(self.frameworkParams["analyzerPath"])
Example #22
0
 def deleteCertsAndKeys():
     File.deletes([
         Security.__certificateCrtPath, Security.__certificatePemPath,
         Security.__privateKeyPath, Security.__publicKeyPath
     ])
Example #23
0
 def runInput(self):
     content = self.__callPluginMethod("IO",
                                       self.getWorkflowPlugin("Input"),
                                       self.frameworkParams)
     File.setContent(self.frameworkParams["originalPath"], content)
     return content
Example #24
0
 def downloadCaption(self):
     captions = self.download_caption().decode()
     File.setContent(self.__DOWNLOADED_PATH, captions)
     return captions
Example #25
0
 def purgeContentByTypes(self, contentTypes):
     for contentType in contentTypes:
         File.delete(self.frameworkParams[contentType])
Example #26
0
 def getDownloadedCaptions(self):
     return File.getContent(self.__DOWNLOADED_PATH)
Example #27
0
 def deleteCfg(self):
     if Text.isNone(self.cfgPath):
         return
     File.delete(self.cfgPath)
Example #28
0
 def hasOpenSSL():
     if File.find("openssl") is not None:
         return True
     ret = os.system("openssl version")
     return ret == 0
Example #29
0
 def runInput(self):
     content = File.getContent(self.getWorkflowSource())
     self.setInputContent(content)
     return content
Example #30
0
 def __getContent(self, inputType):
     return File.getContent(self.__frameworkParams[inputType])