django settings.py

"""
Django settings for password project. Generated by 'django-admin startproject' using Django 1.9.. For more information on this file, see
https://docs.djangoproject.com/en/1.9/topics/settings/ For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.9/ref/settings/
""" import os # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) # Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.9/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'twc7jzj(@kgl(jaa6hhy1y1!z(b75_ex^=76a(b6j1u76d3=h!' # SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True ALLOWED_HOSTS = [] # Application definition INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'app01',
] MIDDLEWARE_CLASSES = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
#'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
] ROOT_URLCONF = 'password.urls' TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')]
,
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
] WSGI_APPLICATION = 'password.wsgi.application' # Database
# https://docs.djangoproject.com/en/1.9/ref/settings/#databases DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME':'fengjian',
'USER': 'fengjian',
'PASSWORD': '',
'HOST': '127.0.0.1',
'PORT': '',
}
} # Password validation
# https://docs.djangoproject.com/en/1.9/ref/settings/#auth-password-validators AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
] # Internationalization
# https://docs.djangoproject.com/en/1.9/topics/i18n/ LANGUAGE_CODE = 'en-us' TIME_ZONE = 'UTC' USE_I18N = True USE_L10N = True USE_TZ = True # Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.9/howto/static-files/ STATIC_URL = '/static/' SESSION_COOKIE_AGE =

urls.py

"""password URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/1.9/topics/http/urls/
Examples:
Function views
. Add an import: from my_app import views
. Add a URL to urlpatterns: url(r'^$', views.home, name='home')
Class-based views
. Add an import: from other_app.views import Home
. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home')
Including another URLconf
. Import the include() function: from django.conf.urls import url, include
. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls'))
"""
from django.conf.urls import url,include
from django.contrib import admin urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^app01/',include('app01.urls')), ]

passpor document

models.py

from __future__ import unicode_literals

from django.db import models

# Create your models here.

class UserType(models.Model):
name = models.CharField(max_length=) class User(models.Model):
username = models.CharField(max_length=)
password = models.CharField(max_length=)
user_type = models.ForeignKey('UserType') class UserGroup(models.Model):
groupname = models.CharField(max_length=)
user_group = models.ManyToManyField('User') class Asset(models.Model):
hostname = models.CharField(max_length=)
ip = models.GenericIPAddressField()
asset_usergroup = models.ForeignKey('UserGroup')

vim paramiko_modle.py

#!/usr/bin/env python
#-*- coding:utf- -*- import paramiko def paramiko_command(ipaddr,username,timeout=): private_key_path = '/root/.ssh/id_rsa' key = paramiko.RSAKey.from_private_key_file(private_key_path) ssh = paramiko.SSHClient() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh.connect(ipaddr,,username,pkey=key) stdin, stdout, stderr = ssh.exec_command('/usr/bin/mkpasswd %s' %username) return stdout.read().strip() ssh.close(); paramiko_command('192.168.99.131','root')

urls.py

"""password URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/1.9/topics/http/urls/
Examples:
Function views
. Add an import: from my_app import views
. Add a URL to urlpatterns: url(r'^$', views.home, name='home')
Class-based views
. Add an import: from other_app.views import Home
. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home')
Including another URLconf
. Import the include() function: from django.conf.urls import url, include
. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls'))
"""
from django.conf.urls import url,include
from django.contrib import admin
import views urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^login/',views.login),
url(r'^index/',views.index),
url(r'^delete/',views.delete),
]

views.py

from django.shortcuts import render,render_to_response,redirect,HttpResponse
import models
import paramiko_modle
# Create your views here. def login(request):
ret = {'status':""}
if request.method == 'POST':
username = request.POST.get('username',None)
print username
password= request.POST.get('password',None) is_empty = all([username,password]) print is_empty
if is_empty: request.session['is_ssession'] = {'username':username} userobj = models.User.objects.filter(username=username,password=password)
print userobj if userobj: return redirect('/app01/index/') else:
ret['status'] = 'username or password input error'
else:
ret['status'] = 'Input is not empty' return render_to_response('login.html',ret) def index(request): ret = {'status':"",
'data':"",
'session':"",
'user':"",
'ipaddr':"",
}
ssesiondict = request.session.get('is_ssession',None) if not ssesiondict:
return redirect('/app01/login/')
else:
if request.method == 'POST': username = request.POST.get('username',None)
ip = request.POST.get('ip',None) is_empty = all({username,ip}) if is_empty:
result = paramiko_modle.paramiko_command(ip,username)
ret['data'] = result
ret['session'] = ssesiondict['username']
ret['user'] = username
ret['ipaddr'] = ip
else:
ret['status'] = 'username or ip is not empty' return render_to_response('index.html',ret) def delete(request):
del request.session['is_ssession']
return redirect('/app01/login/')

templates   index.html

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<h5>index page loginusername:{{ session }} </h5>
<h3><a href="/app01/delete/"> logout </a></h3> <form action="/app01/index/" method="POST">
<table>
<tr>
<td>username</td>
<td><input type="text" name="username" value="{{ user }}" /></td>
</tr>
<tr>
<td>IP</td>
<td><input type="text" name="ip" value="{{ ipaddr }}" /></td>
</tr>
<tr>
<td>password</td>
<td><input type="text" name="password" value="{{ data }}" /></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" value="commit" /><span>{{ status }}</span></td>
</tr>
</table>
</form>
</body>
</html>

login.html

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<form method="POST" action="/app01/login/">
<p>username:<input type="text" name="username" placeholder="username" /></p>
<p>password:<input type="text" name="password" placeholder="passpwrd" /></p>
<input type="submit" value="commit" />
<label style="color: red">{{ status }}</label>
</form>
</body>
</html>

passport 自动取密码的更多相关文章

  1. 关于谷歌浏览器下自动填写密码的bug

    有的时候我们需要用到h5中input的新类型,type=password 这个可以很好的将输入的内容变成圆点,但是这样做也有一个小bug就是在某些我们不希望自动保存密码的页面中,也会出现浏览器自动帮我 ...

  2. C# 实现对接电信交费易自动缴费 续(winio/winring0 自动填密码)

    原文:C# 实现对接电信交费易自动缴费 续(winio/winring0 自动填密码) 自动填密码大家可能都不莫生,最有名的应该是 按键精灵 只要是一个可以输入的地方都可以能过按键精灵来完成输入.我今 ...

  3. 关于.net 保存 decimal类型数据到SQLServer2012数据库时自动取整的问题

    公司同事问我有没有遇到过decimal类型数据入库时,会自动取整的问题(比如12.3入库后值是12,12.8入库后值是13,入库后自动四舍五入自动取整): 之前就遇到过从数据去decimal类型数据时 ...

  4. mac securecrt自动保存密码

    一.问题描述 mac有自带的终端,可以运行ssl和sftp,但是目录操作,文件操作和文件上传是分开的,很不方便,并且文件上传命令需要文件的全路路径. 使用securecrt能方便的解决上述的问题,并且 ...

  5. 解决chrome浏览器自动填充密码

    chrome会自动填充密码,解决方法很简单 使用下面的参考代码即可: <input type="password" readonly οnfοcus="this.r ...

  6. Golang对方法接收者变量的自动“取引用”和“解引用”

    原文:https://blog.csdn.net/u014633283/article/details/83826413 --------------------------------------- ...

  7. chrome表单禁止自动填充密码

    在用户登录成功以后,chrome会提示用户记住密码. 用户退出以后若前往注册.忘记密码页时会自动填充密码. 若不希望自动填充密码,只需在input里设置autoComplete="new-p ...

  8. 配置windows自动修改密码和自动登录

    日常运维多台服务器,每季度要修改一次密码,非常麻烦,现做一个VBS脚本,计划任务设置每季度第一天三点定时运行,则可解决该问题,具体实现脚本如下:autochg_pwd.vbs ystr=year(No ...

  9. chrome防止自动填充密码

    是防止,不是禁止.禁止需要在浏览器设置. chrome浏览器保存密码之后,页面上有password存在的时候会出现自动填充用户名和密码的情况. 添加disableautocomplete和autoco ...

随机推荐

  1. svn搭建,很简单

    yum install subversion 2015年1月7日15:23:07 我测试的时间 系统是centos6.5 直接yum,centos是可以直接解决apr apr-util 依赖问题,如果 ...

  2. 解决Eclipse Debug 的source not found问题

    最近在做Android 4.4系统的定制开发(RockIII)进行Debug时,并打上断点,运行到断点处时,Debug窗口出现source not found问题(没有自动关联程序编码): 解决办法: ...

  3. FZU 2032 高精度小数加法

    题目描写很没意思..就是说给出n个小数 求它们的总和 因为给出的小数点后最多16位而要求保存至12位 而能直接使用的最精确的double只能到12位 于是13的进位可能被忽略 于是不可以用double ...

  4. DX11.2 Tiled Resource Pool

    Nvidia white paper : https://developer.nvidia.com/content/taking-advantage-directx112-tiled-resource ...

  5. Guilty Gear Xrd 资源Rip(1)

    资源破解   首先先要下载GGXrd的PS3游戏,用psarc.exe先把游戏解包 http://files.cnblogs.com/TracePlus/psarc.exe.zip   下载UMode ...

  6. 用 BigDump 工具导入超大 MySQL 数据库备份文件

    用 BigDump 工具导入超大 MySQL 数据库备份文件  创建于 2010-07-01, 周四 00:00  作者 白建鹏 在<Joomla! 1.5 网站防黑9条戒律>这篇文章中, ...

  7. General protection fault Exceptions in Linux/IA32 Systems

    Computer Systems A Programmer's Perspective Second Edition Exception number Description Exception cl ...

  8. [have_fun] 好玩哒小游戏

    好玩哒,打字小游戏:http://zty.pe/ 可好玩了,一起来玩吧!

  9. 详解linux系统的启动过程及系统初始化

    一.linux系统的启动流程 关于linux系统的启动流程我们可以按步进行划分为如下: POST加电自检 -->BIOS(Boot Sequence)-->加载对应引导上的MBR(boot ...

  10. 设计模式:状态模式(State)

    定  义:当一个对象内在状态改变时允许改变其行为,这个对象看起来像是改变了其类. 状态模式主要解决的是当控制一个对象状态转换的条件表达式过于复杂时的情况, 把状态的判断逻辑转移到表示不同状态的一系列子 ...