From 4bce5d71c4bb1758fd236e507a567a115f522979 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E5=AD=90=E6=AC=A0=E6=89=81?= <245565986@qq.com> Date: Sat, 22 Sep 2012 08:15:13 +0800 Subject: [PATCH] first commit --- .gitattributes | 22 +++++++ .gitignore | 163 ++++++++++++++++++++++++++++++++++++++++++++++++ PolicyServer.py | 52 +++++++++++++++ README.md | 9 +++ 4 files changed, 246 insertions(+) create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 PolicyServer.py create mode 100644 README.md diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..412eeda --- /dev/null +++ b/.gitattributes @@ -0,0 +1,22 @@ +# Auto detect text files and perform LF normalization +* text=auto + +# Custom for Visual Studio +*.cs diff=csharp +*.sln merge=union +*.csproj merge=union +*.vbproj merge=union +*.fsproj merge=union +*.dbproj merge=union + +# Standard to msysgit +*.doc diff=astextplain +*.DOC diff=astextplain +*.docx diff=astextplain +*.DOCX diff=astextplain +*.dot diff=astextplain +*.DOT diff=astextplain +*.pdf diff=astextplain +*.PDF diff=astextplain +*.rtf diff=astextplain +*.RTF diff=astextplain diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5ebd21a --- /dev/null +++ b/.gitignore @@ -0,0 +1,163 @@ +################# +## Eclipse +################# + +*.pydevproject +.project +.metadata +bin/ +tmp/ +*.tmp +*.bak +*.swp +*~.nib +local.properties +.classpath +.settings/ +.loadpath + +# External tool builders +.externalToolBuilders/ + +# Locally stored "Eclipse launch configurations" +*.launch + +# CDT-specific +.cproject + +# PDT-specific +.buildpath + + +################# +## Visual Studio +################# + +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.suo +*.user +*.sln.docstates + +# Build results +[Dd]ebug/ +[Rr]elease/ +*_i.c +*_p.c +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.vspscc +.builds +*.dotCover + +## TODO: If you have NuGet Package Restore enabled, uncomment this +#packages/ + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opensdf +*.sdf + +# Visual Studio profiler +*.psess +*.vsp + +# ReSharper is a .NET coding add-in +_ReSharper* + +# Installshield output folder +[Ee]xpress + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish + +# Others +[Bb]in +[Oo]bj +sql +TestResults +*.Cache +ClientBin +stylecop.* +~$* +*.dbmdl +Generated_Code #added for RIA/Silverlight projects + +# Backup & report files from converting an old project file to a newer +# Visual Studio version. Backup files are not needed, because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML + + + +############ +## Windows +############ + +# Windows image file caches +Thumbs.db + +# Folder config file +Desktop.ini + + +############# +## Python +############# + +*.py[co] + +# Packages +*.egg +*.egg-info +dist +build +eggs +parts +bin +var +sdist +develop-eggs +.installed.cfg + +# Installer logs +pip-log.txt + +# Unit test / coverage reports +.coverage +.tox + +#Translations +*.mo + +#Mr Developer +.mr.developer.cfg + +# Mac crap +.DS_Store diff --git a/PolicyServer.py b/PolicyServer.py new file mode 100644 index 0000000..d85c3ce --- /dev/null +++ b/PolicyServer.py @@ -0,0 +1,52 @@ +#!/usr/bin/env python + +from tornado import iostream +from tornado.netutil import TCPServer +from tornado import ioloop + +class PolicyServer(TCPServer): + def __init__(self): + TCPServer.__init__(self, io_loop = None, ssl_options = None) + def handle_stream(self, stream, address): + PolicyConnection(stream, address) + +class PolicyConnection(object): + def __init__(self, stream, address): + self.stream = stream + self.address = address + + self.stream.read_until('\0', self._on_read_line) + + def _on_read_line(self, data): + response = ''' + + + + + +''' + if 'policy-file-request' in data: + self.write(response) + else: + # bad request + pass + self.finish() + + def close(self): + self.stream.close() + + def write(self, response): + if not self.stream.closed(): + self.stream.write(response) + + def finish(self): + if not self.stream.writing(): + self.close() + +class BadRequestException(Exception): + pass + +if __name__ == '__main__': + policyServer = PolicyServer() + policyServer.listen(843) + ioloop.IOLoop.instance().start() diff --git a/README.md b/README.md new file mode 100644 index 0000000..0a1224a --- /dev/null +++ b/README.md @@ -0,0 +1,9 @@ +## Requirements: + +- tornado + +## Usage: + +```shell +python PolicyServer.py +```