• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python nfp_db.init_web_db函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中nfp_db.init_web_db函数的典型用法代码示例。如果您正苦于以下问题:Python init_web_db函数的具体用法?Python init_web_db怎么用?Python init_web_db使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了init_web_db函数的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: POST

    def POST(self):
        if not "user" in session or session.user is None:
            f = register_form()
            return render.login(f)

        i = web.input(samples_path="", templates_path="", nightmare_path="", temporary_path="")
        if i.samples_path == "" or i.templates_path == "" or i.nightmare_path == "" or i.temporary_path == "":
            render.error("Invalid samples, templates, temporary or nightmare path")

        db = init_web_db()
        with db.transaction():
            sql = "select 1 from config where name = 'SAMPLES_PATH'"
            res = list(db.query(sql))
            if len(res) > 0:
                sql = "update config set value = $value where name = 'SAMPLES_PATH'"
            else:
                sql = "insert into config (name, value) values ('SAMPLES_PATH', $value)"
            db.query(sql, vars={"value": i.samples_path})

            sql = "select 1 from config where name = 'TEMPLATES_PATH'"
            res = list(db.query(sql))
            if len(res) > 0:
                sql = "update config set value = $value where name = 'TEMPLATES_PATH'"
            else:
                sql = "insert into config (name, value) values ('TEMPLATES_PATH', $value)"
            db.query(sql, vars={"value": i.templates_path})

            sql = "select 1 from config where name = 'NIGHTMARE_PATH'"
            res = list(db.query(sql))
            if len(res) > 0:
                sql = "update config set value = $value where name = 'NIGHTMARE_PATH'"
            else:
                sql = "insert into config (name, value) values ('NIGHTMARE_PATH', $value)"
            db.query(sql, vars={"value": i.nightmare_path})

            sql = "select 1 from config where name = 'TEMPORARY_PATH'"
            res = list(db.query(sql))
            if len(res) > 0:
                sql = "update config set value = $value where name = 'TEMPORARY_PATH'"
            else:
                sql = "insert into config (name, value) values ('TEMPORARY_PATH', $value)"
            db.query(sql, vars={"value": i.temporary_path})

            sql = "select 1 from config where name = 'QUEUE_HOST'"
            res = list(db.query(sql))
            if len(res) > 0:
                sql = "update config set value = $value where name = 'QUEUE_HOST'"
            else:
                sql = "insert into config (name, value) values ('QUEUE_HOST', $value)"
            db.query(sql, vars={"value": i.queue_host})

            sql = "select 1 from config where name = 'QUEUE_PORT'"
            res = list(db.query(sql))
            if len(res) > 0:
                sql = "update config set value = $value where name = 'QUEUE_PORT'"
            else:
                sql = "insert into config (name, value) values ('QUEUE_PORT', $value)"
            db.query(sql, vars={"value": i.queue_port})

        return web.redirect("/config")
开发者ID:hangoversec,项目名称:nightmare,代码行数:60,代码来源:nightmare_frontend.py


示例2: GET

  def GET(self):
    if not 'user' in session or session.user is None:
      f = register_form()
      return render.login(f)

    i = web.input()
    if not i.has_key("id"):
      return render.error("No crash identifier given")
    if i.has_key("diff"):
      is_diff = True
    else:
      is_diff = False

    db = init_web_db()

    try:
      original_file, crash_file = find_original_file(db, i.id)
    except:
      return render.error(sys.exc_info()[1])

    if original_file is not None:
      basename = os.path.basename(original_file)
      web.header("Content-type", "application/octet-stream")
      web.header("Content-disposition", "attachment; filename=%s" % basename)
      f = open(original_file, 'rb')
      return f.read()

    return render.error("Cannot find original sample.")
开发者ID:ssatanss,项目名称:nightmare,代码行数:28,代码来源:nightmare_frontend.py


示例3: POST

  def POST(self):
    if not 'user' in session or session.user is None:
      f = register_form()
      return render.login(f)
    i = web.input(id=-1, name="", description="", subfolder="",
                  tube_prefix="", enabled="", archived="")
    if i.id == -1:
      return render.error("Invalid project identifier")
    elif i.name == "":
      return render.error("No project name specified")
    elif i.description == "":
      return render.error("No project description specified")
    elif i.tube_prefix == "":
      return render.error("No tube prefix specified")

    if i.enabled == "on":
      enabled = 1
    else:
      enabled = 0
    
    if i.archived == "on":
      archived = 1
    else:
      archived = 0

    db = init_web_db()
    with db.transaction():
      enabled = i.enabled == "on"
      archived = i.archived == "on"
      db.update("projects", name=i.name, description=i.description, 
                subfolder=i.subfolder, tube_prefix=i.tube_prefix,
                maximum_samples=i.max_files, enabled=enabled,
                archived=archived, where="project_id = $project_id",
                vars={"project_id":i.id})
    return web.redirect("/projects")
开发者ID:andres-root,项目名称:nightmare,代码行数:35,代码来源:nightmare_frontend.py


示例4: POST

  def POST(self):
    if not 'user' in session or session.user is None:
      f = register_form()
      return render.login(f)
    
    i = web.input(name="", description="", subfolder="", tube_prefix="",
                  max_files=100, max_iteration=1000000,
                  ignore_duplicates=0)
    if i.name == "":
      return render.error("No project name specified")
    elif i.description == "":
      return render.error("No project description specified")
    elif i.tube_prefix == "":
      return render.error("Invalid tube prefix")
    
    if i.ignore_duplicates == "on":
      ignore_duplicates = 1
    else:
      ignore_duplicates = 0

    db = init_web_db()
    with db.transaction():
      db.insert("projects", name=i.name, description=i.description,
              subfolder=i.subfolder, tube_prefix=i.tube_prefix, 
              maximum_samples=i.max_files, archived=0,
              maximum_iteration=i.max_iteration,
              date=web.SQLLiteral("CURRENT_DATE"),
              ignore_duplicates=ignore_duplicates)

    return web.redirect("/projects")
开发者ID:joxeankoret,项目名称:nightmare,代码行数:30,代码来源:nightmare_frontend.py


示例5: POST

 def POST(self):
   if not 'user' in session or session.user is None:
     f = register_form()
     return render.login(f)
   i = web.input(id=-1, name="", description="", command="")
   if i.id == -1:
     return render.error("Invalid mutation engine identifier")
   elif i.name == "":
     return render.error("No mutation engine name specified")
   elif i.description == "":
     return render.error("No mutation engine description specified")
   elif i.command == "":
     return render.error("No mutation engine command specified")
   elif i.command.find("%INPUT%") == -1 and i.command.find("%TEMPLATES_PATH%") == -1:
     return render.error("No input template filename specified in the mutation engine command")
   elif i.command.find("%OUTPUT%") == -1:
     return render.error("No output mutated filename specified in the mutation engine command")
   
   db = init_web_db()
   with db.transaction():
     where = "mutation_engine_id = $id"
     vars = {"id":i.id}
     db.update("mutation_engines", name=i.name, command=i.command,
               description=i.description, where=where, vars=vars)
   return web.redirect("/engines")
开发者ID:chubbymaggie,项目名称:nightmare,代码行数:25,代码来源:nightmare_frontend.py


示例6: POST

  def POST(self):
    if not 'user' in session or session.user is None:
      f = register_form()
      return render.login(f)
    i = web.input(id=-1, sure="")
    if i.id == -1:
      return render.error("Invalid project identifier")
    elif i.sure != "on":
      return render.error("You must check the \"I'm sure\" field.")
    
    db = init_web_db()

    sql = """select value from config where name in ('WORKING_PATH')"""
    res = db.query(sql)
    res = list(res)
    working_path = res[0]['value']

    what = """project_id, name, description, subfolder, tube_prefix,
              maximum_samples, enabled, date, archived,
              maximum_iteration, ignore_duplicates """
    where = "project_id = $project_id"
    vars = {"project_id":i.id}
    res = db.select("projects", what=what, where=where, vars=vars)
    res = list(res)

    shutil.rmtree(os.path.join(working_path, res[0]['subfolder']))

    with db.transaction():
      vars={"project_id":i.id}
      where = "project_id=$project_id"
      db.delete("projects", where=where, vars=vars)
    return web.redirect("/projects")
开发者ID:pyoor,项目名称:nightmare-cometh,代码行数:32,代码来源:nightmare_frontend.py


示例7: render_crash

def render_crash(crash_id):
  # XXX: FIXME: Joxean, why do 2 queries instead of one????
  # Get the project_id from the crash_id
  db = init_web_db()
  vars = {"id":crash_id}
  res = db.select("crashes", where="crash_id=$id", vars=vars)
  crash_row = res[0]

  # Get the project name
  where = "project_id=$id"
  vars = {"id":crash_row.project_id}
  res = db.select("projects", what="name", where=where, vars=vars)
  project_name = res[0].name
  
  crash_data = {}
  crash_data["crash_id"] = crash_row.crash_id
  crash_data["project_id"] = crash_row.project_id
  crash_data["sample_id"] = crash_row.sample_id
  crash_data["program_counter"] = crash_row.program_counter
  crash_data["crash_signal"] = crash_row.crash_signal
  crash_data["exploitability"] = crash_row.exploitability
  crash_data["disassembly"] = crash_row.disassembly
  crash_data["date"] = crash_row.date
  crash_data["total_samples"] = crash_row.total_samples

  additional = json.loads(crash_row.additional)
  crash_data["additional"] = additional

  return render.view_crash(project_name, crash_data, str=str, map=map, \
                           repr=myrepr, b64=b64decode, sorted=sorted, \
                           type=type, hexor=hexor)
开发者ID:ssatanss,项目名称:nightmare,代码行数:31,代码来源:nightmare_frontend.py


示例8: POST

  def POST(self):
    if not 'user' in session or session.user is None:
      f = register_form()
      return render.login(f)

    i = web.input()
    if not i.has_key('samples_dir'):
      return render.error("No samples sub-directory specified.")
    if not i.has_key('magic'):
      return render.error("No magic header specified.")
    if not i.has_key('extension'):
      return render.error("No file extension specified.")
    if not i.has_key('search'):
      search = ""
    else:
      search = i["search"]
    if i["samples_dir"].find(".") > -1 or \
       i["samples_dir"].find("/") > -1 or \
       i["samples_dir"].find("\\") > -1:
      return render.error("Invalid sub-directory")

    db = init_web_db()
    res = db.select("config", what="value", where="name = 'TEMPLATES_PATH'")
    res = list(res)
    if len(res) == 0:
      return render.error("Samples path is not yet configured. Please configure it in the configuration section.")
    whole_dir = os.path.join(res[0].value, i.samples_dir)

    if not os.path.exists(whole_dir):
      os.makedirs(whole_dir)

    from find_samples import CSamplesFinder
    finder = CSamplesFinder()
    finder.find(i.extension, i.magic, whole_dir, search)
    return render.message("Process finished.")
开发者ID:ssatanss,项目名称:nightmare,代码行数:35,代码来源:nightmare_frontend.py


示例9: GET

  def GET(self):
    if not 'user' in session or session.user is None:
      f = register_form()
      return render.login(f)
    
    i = web.input(show_all=0, field="", fieldValue="", no_field="",
                  no_fieldValue="")

    db = init_web_db()
    # XXX: There is neither CONV nor CONCAT functions in either PgSQL or
    # SQLite so, in order to support them, I have to create a function
    # for both SQLite and PgSQL to mimic this behaviour.
    sql = """ select crash_id, p.project_id, p.name, sample_id,
                     concat("0x", CONV(program_counter, 10, 16)) pc,
                     crash_signal, exploitability, disassembly, c.date
                from crashes c,
                     projects p
               where p.project_id = c.project_id
                 and p.enabled = 1 """
    
    valid_fields = ["crash_signal", "program_counter", "exploitability", 
                    "disassembly", "date"]
    if i.field != "" and i.fieldValue != "":
      if i.field not in valid_fields:
        return render.error("Invalid field %s" % i.field)
      
      value = i.fieldValue.replace("'", "").replace("\n", "")
      if i.field != "program_counter":
        sql += " and lower(c.%s) like lower('%s')" % (i.field, value)
      else:
        sql += " and lower(concat(\"0x\", CONV(program_counter, 10, 16))) like lower('%s')" % (value)

    if i.no_field != "" and i.no_fieldValue != "":
      if i.no_field not in valid_fields:
        return render.error("Invalid field %s" % i.no_field)
      
      value = i.no_fieldValue.replace("'", "").replace("\n", "")
      if i.no_field != "program_counter":
        sql += " and lower(c.%s) not like lower('%s')" % (i.no_field, value)
      else:
        sql += " and lower(concat(\"0x\", CONV(program_counter, 10, 16))) not like lower('%s')" % (value)

    sql += """order by crash_id desc """
    res = db.query(sql)
    results = {}
    for row in res:
      project_name = row.name
      try:
        results[project_name].append(row)
      except:
        results[project_name] = [row]

    return render.results(results, i.show_all, i.field, i.fieldValue,
                          i.no_field, i.no_fieldValue)
开发者ID:bahtiyarb-ef,项目名称:nightmare,代码行数:54,代码来源:nightmare_frontend.py


示例10: GET

  def GET(self):
    if not 'user' in session or session.user is None:
      f = register_form()
      return render.login(f)

    i = web.input()
    if not i.has_key("id"):
      return render.error("No crash identifier given")
    if i.has_key("diff"):
      is_diff = True
    else:
      is_diff = False

    db = init_web_db()
    print i.id
    res = db.query("""SELECT t1.sample_hash,
                             t3.subfolder
                      FROM samples t1
                           JOIN crashes t2
                             ON t1.sample_id = t2.sample_id
                           JOIN projects t3
                             ON t3.project_id = t2.project_id
                      WHERE t1.sample_id = %s""", (i.id,))
    res = list(res)
    if len(res) == 0:
      return render.error("Invalid crash identifier")
    row = res[0]
    sample_hash = row.sample_hash
    subfolder = row.subfolder

    res = db.select("config", what="value", where="name='WORKING_PATH'")
    res = list(res)
    if len(res) == 0:
      return render.error("Invalid configuration value for 'WORKING_PATH'")
    working_path = res[0].value

    path = os.path.join(working_path, subfolder, "samples", sample_hash)
    if not os.path.exists(path):
      return render.error("Crash sample does not exist! %s" % path)

    if is_diff:
      if not os.path.exists(path + ".diff"):
        return render.error("No diff file for this sample. It may be because the mutation engine doesn't generate a diff file.")
      else:
        sample_hash += ".diff"
        path += ".diff"

    web.header("Content-type", "application/octet-stream")
    web.header("Content-disposition", "attachment; filename=%s" % sample_hash)
    f = open(path, 'rb')
    return f.read()
开发者ID:pyoor,项目名称:nightmare-cometh,代码行数:51,代码来源:nightmare_frontend.py


示例11: GET

    def GET(self):
        if not "user" in session or session.user is None:
            f = register_form()
            return render.login(f)

        i = web.input()
        if not i.has_key("id"):
            return render.error("No crash identifier given")
        if i.has_key("diff"):
            is_diff = True
        else:
            is_diff = False

        db = init_web_db()
        what = "sample_hash"
        where = "sample_id = $id"
        vars = {"id": i.id}
        res = db.select("samples", what=what, where=where, vars=vars)
        res = list(res)
        if len(res) == 0:
            return render.error("Invalid crash identifier")
        row = res[0]
        sample_hash = row.sample_hash

        res = db.select("config", what="value", where="name='SAMPLES_PATH'")
        res = list(res)
        if len(res) == 0:
            return render.error("Invalid configuration value for 'SAMPLES_PATH'")
        row = res[0]

        path = os.path.join(row.value, "crashes")
        path = os.path.join(path, sample_hash)
        if not os.path.exists(path):
            return render.error("Crash sample does not exists! %s" % path)

        if is_diff:
            if not os.path.exists(path + ".diff"):
                return render.error(
                    "No diff file for this sample. It may be because the mutation engine doesn't generate a diff file."
                )
            else:
                sample_hash += ".diff"
                path += ".diff"

        web.header("Content-type", "application/octet-stream")
        web.header("Content-disposition", "attachment; filename=%s" % sample_hash)
        f = open(path, "rb")
        return f.read()
开发者ID:hangoversec,项目名称:nightmare,代码行数:48,代码来源:nightmare_frontend.py


示例12: GET

 def GET(self):
   if not 'user' in session or session.user is None:
     f = register_form()
     return render.login(f)
   
   db = init_web_db()
   sql = """ select concat('0x???????', substr(conv(program_counter, 10, 16), length(conv(program_counter, 10, 16))-2)) address,
                    crash_signal, substr(disassembly, instr(disassembly, ' ')+1) dis, count(*) count
               from crashes c,
                    projects p
              where p.project_id = c.project_id
                and crash_signal != 'UNKNOWN'
                and p.enabled = 1
              group by 1
              order by 4 desc"""
   bugs = list(db.query(sql))
   return render.bugs(bugs)
开发者ID:chubbymaggie,项目名称:nightmare,代码行数:17,代码来源:nightmare_frontend.py


示例13: GET

 def GET(self):
   if not 'user' in session or session.user is None:
     f = register_form()
     return render.login(f)
   i = web.input(id=-1)
   if i.id == -1:
     return render.error("Invalid project identifier")
   
   db = init_web_db()
   what = """project_id, name, description, subfolder, tube_prefix,
             maximum_samples, enabled, date, archived"""
   where = "project_id = $project_id"
   vars = {"project_id":i.id}
   res = db.select("projects", what=what, where=where, vars=vars)
   res = list(res)
   if len(res) == 0:
     return render.error("Invalid project identifier")
   return render.edit_project(res[0])
开发者ID:andres-root,项目名称:nightmare,代码行数:18,代码来源:nightmare_frontend.py



注:本文中的nfp_db.init_web_db函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python nfp_log.debug函数代码示例发布时间:2022-05-27
下一篇:
Python nflgame.games函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap