예제 #1
0
def main():
    parser = argparse.ArgumentParser(
        description=
        'Computer Aided Integration of Requirements and Information Security - Add CAIRIS user'
    )
    parser.add_argument('user', help='Email address')
    parser.add_argument('password', help='password')
    parser.add_argument('name', help='Full name')
    args = parser.parse_args()

    rp = ''.join(
        choice(string.ascii_letters + string.digits) for i in range(255))

    createDatabaseAccount(b.rPasswd, b.dbHost, b.dbPort, args.user, rp)
    createDatabaseAndPrivileges(b.rPasswd, b.dbHost, b.dbPort, args.user, rp,
                                args.user + '_default')
    createDatabaseSchema(b.cairisRoot, b.dbHost, b.dbPort, args.user, rp,
                         args.user + '_default')

    db.create_all()
    user_datastore.create_user(email=args.user,
                               password=args.password,
                               dbtoken=rp,
                               name='Default user')
    db.session.commit()
예제 #2
0
def quick_setup(dbHost, dbPort, dbRootPassword, tmpDir, rootDir, imageDir,
                configFile, webPort, logLevel, staticDir, assetDir, uploadDir,
                userName, passWd):
    if (len(userName) > 255):
        raise ARMException("Username cannot be longer than 255 characters")
    if (userName == "root"):
        raise ARMException("Username cannot be root")
    createUserDatabase(dbHost, dbPort, dbRootPassword, rootDir)
    os.environ["CAIRIS_CFG"] = configFile
    pathName = os.path.split(
        os.path.split(os.path.realpath(os.path.dirname(__file__)))[0])[0]
    sys.path.insert(0, pathName)
    fileName = os.environ.get("HOME") + "/.bashrc"
    f = open(fileName, 'a')
    f.write("export CAIRIS_CFG=" + configFile + "\n")
    f.write("export PYTHONPATH=${PYTHONPATH}:" + pathName + "\n")
    f.close()
    createCairisCnf(configFile, dbRootPassword, dbHost, dbPort, tmpDir,
                    rootDir, imageDir, webPort, logLevel, staticDir, assetDir,
                    uploadDir)

    from cairis.bin.add_cairis_user import user_datastore, db

    db.create_all()
    user_datastore.create_user(email=userName,
                               password=passWd,
                               name='Default user')
    db.session.commit()
    createDatabaseAccount(dbRootPassword, dbHost, dbPort, userName, '')
    createDatabaseAndPrivileges(dbRootPassword, dbHost, dbPort, userName, '',
                                userName + '_default')
    createDatabaseSchema(rootDir, dbHost, dbPort, userName, '',
                         userName + '_default')
예제 #3
0
파일: quickSetup.py 프로젝트: failys/cairis
def quick_setup(dbHost,dbPort,dbRootPassword,tmpDir,rootDir,configFile,webPort,logLevel,staticDir,assetDir,userName,passWd):
  if (len(userName) > 255):
    raise ARMException("Username cannot be longer than 255 characters")
  if (userName == "root"):
    raise ARMException("Username cannot be root")
  createUserDatabase(dbHost,dbPort,dbRootPassword,rootDir)
  os.environ["CAIRIS_CFG"] = configFile
  pathName = os.path.split(os.path.split(os.path.realpath(os.path.dirname(__file__)))[0])[0]
  sys.path.insert(0, pathName)
  fileName = os.environ.get("HOME") + "/.bashrc"
  f = open(fileName,'a')
  f.write("export CAIRIS_CFG="+ configFile +"\n")
  f.write("export PYTHONPATH=${PYTHONPATH}:" + pathName +"\n")
  f.close()
  createCairisCnf(configFile,dbRootPassword,dbHost,dbPort,tmpDir,rootDir,webPort,logLevel,staticDir,assetDir)

  from cairis.bin.add_cairis_user import user_datastore, db

  db.create_all()
  rp = ''.join(choice(ascii_letters + digits) for i in range(255))
  user_datastore.create_user(email=userName, password=passWd,dbtoken=rp,name = 'Default user')
  db.session.commit()

  createDatabaseAccount(dbRootPassword,dbHost,dbPort,userName,rp)
  createDatabaseAndPrivileges(dbRootPassword,dbHost,dbPort,userName,rp,userName + '_default')
  createDatabaseSchema(rootDir,dbHost,dbPort,userName,rp,userName + '_default')
예제 #4
0
def createUserDatabase(dbHost, dbPort, dbRootPassword, rootDir):
    try:
        rootConn = MySQLdb.connect(host=dbHost,
                                   port=int(dbPort),
                                   user='******',
                                   passwd=dbRootPassword)
        rootCursor = rootConn.cursor()
    except _mysql_exceptions.DatabaseError as e:
        id, msg = e
        exceptionText = 'Error connecting to MySQL (id:' + str(
            id) + ',message:' + msg + ')'
        raise ARMException(exceptionText)

    try:
        dropUserDbSql = "drop database if exists cairis_user"
        rootCursor.execute(dropUserDbSql)
    except _mysql_exceptions.DatabaseError as e:
        id, msg = e
        exceptionText = 'MySQL error removing existing cairis_user database (id: ' + str(
            id) + ', message: ' + msg
        raise ARMException(exceptionText)

    createDatabaseAccount(dbRootPassword, dbHost, dbPort, 'cairis_test',
                          'cairis_test')
    createDatabaseAndPrivileges(dbRootPassword, dbHost, dbPort, 'cairis_test',
                                'cairis_test', 'cairis_test_default')
    createDatabaseSchema(rootDir, dbHost, dbPort, 'cairis_test', 'cairis_test',
                         'cairis_test_default')

    try:
        createUserDbSql = "create database if not exists cairis_user"
        rootCursor.execute(createUserDbSql)
    except _mysql_exceptions.DatabaseError as e:
        id, msg = e
        exceptionText = 'MySQL error creating cairis_user database (id: ' + str(
            id) + ', message: ' + msg
        raise ARMException(exceptionText)

    try:
        recursionDepthSql = "set global max_sp_recursion_depth = 255"
        rootCursor.execute(recursionDepthSql)
    except _mysql_exceptions.DatabaseError as e:
        id, msg = e
        exceptionText = 'MySQL error setting recursion depth (id: ' + str(
            id) + ', message: ' + msg
        raise ARMException(exceptionText)

    try:
        flushPrivilegesSql = "flush privileges"
        rootCursor.execute(flushPrivilegesSql)
    except _mysql_exceptions.DatabaseError as e:
        id, msg = e
        exceptionText = 'MySQL error flushing privileges (id: ' + str(
            id) + ', message: ' + msg
        raise ARMException(exceptionText)

    rootCursor.close()
    rootConn.close()
예제 #5
0
def main():
  parser = argparse.ArgumentParser(description='Computer Aided Integration of Requirements and Information Security - Add CAIRIS user')
  parser.add_argument('user',help='Email address')
  parser.add_argument('password',help='password')
  parser.add_argument('name',help='Full name')
  args = parser.parse_args()

  rp = ''.join(choice(string.ascii_letters + string.digits) for i in range(255))

  createDatabaseAccount(b.rPasswd,b.dbHost,b.dbPort,args.user,rp)
  createDatabaseAndPrivileges(b.rPasswd,b.dbHost,b.dbPort,args.user,rp,args.user + '_default')
  createDatabaseSchema(b.cairisRoot,b.dbHost,b.dbPort,args.user,rp,args.user + '_default')

  db.create_all()
  user_datastore.create_user(email=args.user, password=args.password,dbtoken=rp,name = 'Default user')
  db.session.commit()
예제 #6
0
파일: quickSetup.py 프로젝트: failys/cairis
def createUserDatabase(dbHost,dbPort,dbRootPassword,rootDir):
  try:
    rootConn = MySQLdb.connect(host=dbHost,port=int(dbPort),user='******',passwd=dbRootPassword)
    rootCursor = rootConn.cursor()
  except _mysql_exceptions.DatabaseError as e:
    id,msg = e
    exceptionText = 'Error connecting to MySQL (id:' + str(id) + ',message:' + msg + ')'
    raise ARMException(exceptionText)

  try:
    dropUserDbSql = "drop database if exists cairis_user"
    rootCursor.execute(dropUserDbSql)
  except _mysql_exceptions.DatabaseError as e:
    id,msg = e
    exceptionText = 'MySQL error removing existing cairis_user database (id: ' + str(id) + ', message: ' + msg
    raise ARMException(exceptionText)

  createDatabaseAccount(dbRootPassword,dbHost,dbPort,'cairis_test','cairis_test')
  createDatabaseAndPrivileges(dbRootPassword,dbHost,dbPort,'cairis_test','cairis_test','cairis_test_default')
  createDatabaseSchema(rootDir,dbHost,dbPort,'cairis_test','cairis_test','cairis_test_default')

  try:
    createUserDbSql = "create database if not exists cairis_user"
    rootCursor.execute(createUserDbSql)
  except _mysql_exceptions.DatabaseError as e:
    id,msg = e
    exceptionText = 'MySQL error creating cairis_user database (id: ' + str(id) + ', message: ' + msg
    raise ARMException(exceptionText)

  try:
    recursionDepthSql = "set global max_sp_recursion_depth = 255"
    rootCursor.execute(recursionDepthSql)
  except _mysql_exceptions.DatabaseError as e:
    id,msg = e
    exceptionText = 'MySQL error setting recursion depth (id: ' + str(id) + ', message: ' + msg
    raise ARMException(exceptionText)

  try:
    flushPrivilegesSql = "flush privileges"
    rootCursor.execute(flushPrivilegesSql)
  except _mysql_exceptions.DatabaseError as e:
    id,msg = e
    exceptionText = 'MySQL error flushing privileges (id: ' + str(id) + ', message: ' + msg
    raise ARMException(exceptionText)

  rootCursor.close()
  rootConn.close()
예제 #7
0
def main():
    parser = argparse.ArgumentParser(
        description=
        'Computer Aided Integration of Requirements and Information Security - Add CAIRIS user'
    )
    parser.add_argument('user', help='Email address')
    parser.add_argument('password', help='password')
    args = parser.parse_args()

    createDatabaseAccount(b.rPasswd, b.dbHost, b.dbPort, args.user, '')
    createDatabaseAndPrivileges(b.rPasswd, b.dbHost, b.dbPort, args.user, '',
                                args.user + '_default')
    createDatabaseSchema(b.cairisRoot, b.dbHost, b.dbPort, args.user, '',
                         args.user + '_default')

    db.create_all()
    user_datastore.create_user(email=args.user, password=args.password)
    db.session.commit()
예제 #8
0
    def on_ok(self):
        try:
            if (len(self.theUsername.value) > 255):
                raise ARMException(
                    "Username cannot be longer than 255 characters")
            self.createUserDatabase()
            self.createCairisCnf()
            os.environ["CAIRIS_CFG"] = str(self.theFileName.value)
            sys.path.insert(0, self.pathName)
            fileName = os.environ.get("HOME") + "/.bashrc"
            f = open(fileName, 'a')
            f.write("export CAIRIS_CFG=" + str(self.theFileName.value) + "\n")
            f.write("export PYTHONPATH=${PYTHONPATH}:" + self.pathName + "\n")
            f.close()

            from cairis.bin.add_cairis_user import user_datastore, db
            db.create_all()
            user_datastore.create_user(email=self.theUsername.value,
                                       password=self.thePassword.value)
            db.session.commit()
            createDatabaseAccount(self.theRootPassword.value,
                                  self.theHost.value, self.thePort.value,
                                  self.theUsername.value, '')
            createDatabaseAndPrivileges(self.theRootPassword.value,
                                        self.theHost.value, self.thePort.value,
                                        self.theUsername.value, '',
                                        self.theUsername.value + '_default')
            createDatabaseSchema(self.theRootDir.value, self.theHost.value,
                                 self.thePort.value, self.theUsername.value,
                                 '', self.theUsername.value + '_default')

            self.parentApp.setNextForm(None)
        except ARMException as e:
            np.notify_confirm(str(e), title='Error')
        except SQLAlchemyError as e:
            np.notify_confirm('Error adding CAIRIS user: '******'Error')
예제 #9
0
파일: quickSetup.py 프로젝트: nebloc/cairis
    rootCursor = rootConn.cursor()
  except _mysql_exceptions.DatabaseError as e:
    id,msg = e
    exceptionText = 'Error connecting to MySQL (id:' + str(id) + ',message:' + msg + ')'
    raise ARMException(exceptionText)

  try:
    dropUserDbSql = "drop database if exists cairis_user"
    rootCursor.execute(dropUserDbSql)
  except _mysql_exceptions.DatabaseError, e:
    id,msg = e
    exceptionText = 'MySQL error removing existing cairis_user database (id: ' + str(id) + ', message: ' + msg
    raise ARMException(exceptionText)

  createDatabaseAccount(dbRootPassword,dbHost,dbPort,'cairis_test','cairis_test')
  createDatabaseAndPrivileges(dbRootPassword,dbHost,dbPort,'cairis_test','cairis_test','cairis_test_default')
  createDatabaseSchema(rootDir,dbHost,dbPort,'cairis_test','cairis_test','cairis_test_default')

  try:
    createUserDbSql = "create database if not exists cairis_user"
    rootCursor.execute(createUserDbSql)
  except _mysql_exceptions.DatabaseError, e:
    id,msg = e
    exceptionText = 'MySQL error creating cairis_user database (id: ' + str(id) + ', message: ' + msg
    raise ARMException(exceptionText)

  try:
    recursionDepthSql = "set global max_sp_recursion_depth = 255"
    rootCursor.execute(recursionDepthSql)
  except _mysql_exceptions.DatabaseError, e:
    id,msg = e
예제 #10
0
class CAIRISDatabaseConfigurationForm(np.ActionForm):
    def create(self):
        self.findRootDir()
        self.pathName = os.path.realpath(__file__)
        self.pathName = self.pathName.replace("quick_setup.py", "")
        self.name = "Configure CAIRIS database and initial account"
        self.theHost = self.add(np.TitleText,
                                name="Database host:",
                                value="localhost")
        self.thePort = self.add(np.TitleText,
                                name="Database port:",
                                value="3306")
        self.theRootPassword = self.add(np.TitlePassword,
                                        name="Database root password:"******"")
        self.theTmpDir = self.add(np.TitleText,
                                  name="Temp directory:",
                                  value="/tmp")
        self.theRootDir = self.add(np.TitleText,
                                   name="Root directory:",
                                   value=self.pathName + "cairis")
        self.theImageDir = self.add(np.TitleText,
                                    name="Default image directory:",
                                    value=".")
        self.theFileName = self.add(np.TitleText,
                                    name="CAIRIS configuration file name:",
                                    value=os.environ.get("HOME") +
                                    "/cairis.cnf")
        self.theWebPort = self.add(np.TitleText,
                                   name="Web port:",
                                   value="7071")
        self.theLogLevel = self.add(np.TitleText,
                                    name="Log level:",
                                    value="warning")
        self.theStaticDir = self.add(np.TitleText,
                                     name="Static directory:",
                                     value=self.pathName + "cairis/web")
        self.theUploadDir = self.add(np.TitleText,
                                     name="Upload directory:",
                                     value="/tmp")

        self.theUsername = self.add(np.TitleText,
                                    name="Initial Username:"******"")
        self.thePassword = self.add(np.TitlePassword,
                                    name="Initial Password:"******"")

        self.theSecretKey = os.urandom(16).encode('hex')
        self.theSalt = os.urandom(16).encode('hex')

    def findRootDir(self):
        self.defaultRootDir = "/usr/local/lib/python2.7/dist-packages/cairis"
        for cpath in sys.path:
            if "/dist-packages/cairis-" in cpath and cpath.endswith(".egg"):
                self.defaultRootDir = os.path.join(cpath, "cairis")
                break

    def on_ok(self):
        try:
            if (len(self.theUsername.value) > 255):
                raise ARMException(
                    "Username cannot be longer than 255 characters")
            self.createUserDatabase()
            self.createCairisCnf()
            os.environ["CAIRIS_CFG"] = str(self.theFileName.value)
            sys.path.insert(0, self.pathName)
            fileName = os.environ.get("HOME") + "/.bashrc"
            f = open(fileName, 'a')
            f.write("export CAIRIS_CFG=" + str(self.theFileName.value) + "\n")
            f.write("export PYTHONPATH=${PYTHONPATH}:" + self.pathName + "\n")
            f.close()

            from cairis.bin.add_cairis_user import user_datastore, db
            db.create_all()
            user_datastore.create_user(email=self.theUsername.value,
                                       password=self.thePassword.value)
            db.session.commit()
            createDatabaseAccount(self.theRootPassword.value,
                                  self.theHost.value, self.thePort.value,
                                  self.theUsername.value, '')
            createDatabaseAndPrivileges(self.theRootPassword.value,
                                        self.theHost.value, self.thePort.value,
                                        self.theUsername.value, '',
                                        self.theUsername.value + '_default')
            createDatabaseSchema(self.theRootDir.value, self.theHost.value,
                                 self.thePort.value, self.theUsername.value,
                                 '', self.theUsername.value + '_default')

            self.parentApp.setNextForm(None)
        except ARMException as e:
            np.notify_confirm(str(e), title='Error')
        except SQLAlchemyError as e:
            np.notify_confirm('Error adding CAIRIS user: '******'Error')

    def on_cancel(self):
        self.parentApp.setNextForm(None)

    def createUserDatabase(self):
        try:
            rootConn = MySQLdb.connect(host=self.theHost.value,
                                       port=int(self.thePort.value),
                                       user='******',
                                       passwd=self.theRootPassword.value)
            rootCursor = rootConn.cursor()
        except _mysql_exceptions.DatabaseError as e:
            id, msg = e
            exceptionText = 'Error connecting to MySQL (id:' + str(
                id) + ',message:' + msg + ')'
            raise ARMException(exceptionText)

        try:
            dropUserDbSql = "drop database if exists cairis_user"
            rootCursor.execute(dropUserDbSql)
        except _mysql_exceptions.DatabaseError, e:
            id, msg = e
            exceptionText = 'MySQL error removing existing cairis_user database (id: ' + str(
                id) + ', message: ' + msg
            raise ARMException(exceptionText)

        createDatabaseAccount(self.theRootPassword.value, self.theHost.value,
                              self.thePort.value, 'cairis_test', 'cairis_test')
        createDatabaseAndPrivileges(self.theRootPassword.value,
                                    self.theHost.value, self.thePort.value,
                                    'cairis_test', 'cairis_test',
                                    'cairis_test_default')
        createDatabaseSchema(self.theRootDir.value, self.theHost.value,
                             self.thePort.value, 'cairis_test', 'cairis_test',
                             'cairis_test_default')

        try:
            createUserDbSql = "create database if not exists cairis_user"
            rootCursor.execute(createUserDbSql)
        except _mysql_exceptions.DatabaseError, e:
            id, msg = e
            exceptionText = 'MySQL error creating cairis_user database (id: ' + str(
                id) + ', message: ' + msg
            raise ARMException(exceptionText)