text:
body, h1, h2, h3, h4, h5, h6, hr, p, blockquote, dl, dt, dd, ul, ol, li, pre, form, fieldset, legend, button, input, textarea, th, td, img {margin:0;padding:0;}
body {font-family: Arial;font-size: 12px;line-height: 1.5;}
html.off,html.off body {background: #ebefef url(bgimg/left_bg.png) repeat-y -40px top;}
html.on,html.on body{background: #e2e9ea; background-image:none;}
html.addbg,html.addbg body{background:#e2e9ea}
h1, h2, h3, h4, h5, h6 {font-size:100%;}
ol, ul, li, dl, dd, dt {list-style:none;}
table {border-collapse:collapse;border-spacing:0;}
.fl {float:left;}
.fr {float:right;}
.cb {clear:both;}
.tl {text-align:left;}
.tc {text-align:center;}
.tr {text-align:right;}
fieldset, img {border:0;}
input,label,img,th{vertical-align:middle;}
button, input, select, textarea {font-size:100%;}
.hidden {display:none;}
.block {display: block;}
.invisible {visibility:hidden;}
.hand { cursor:pointer; }
.cu,.cu_li li,.cu_span span {cursor: hand;!important;cursor: pointer}
.clearfix:after {content:"\0020";display:block;height:0;clear:both;visibility:hidden;}
.clearfix {clear:both;zoom:1;}

/*字体样式*/
.fb { font-weight:bold;}
.em{ font-style:italic;}
.u{ text-decoration:underline;}
.strike{ text-decoration:line-through;}
.f11 { font-size:11px; }
.f14 { font-size:14px; }
address,cite,dfn,em,var{font-style:normal;}

/*链接样式*/
a{text-decoration:none; color:#444;}
a:hover{text-decoration:underline;}
.white,.white a{color:#fff}
.blue,.blue a{color:#004499}
.gray4,a.gray4{color:#999}
.red, .red a, a.red{color:red;}
.green{color:#0E774A}
.blue{color:#00F;}
.green{ color:#0C0;}
.gray { color:#999;}
.black{ color:#000;}
.highlight{color: #C00;font-weight: 700;}

.img_border img{border:1px #cfcdcd solid;padding:1px;}

.bk,.bk3,.bk6,.bk8,.bk10,.bk15,.bk20,.bk30{clear: both;font-size: 1px;height: 0;line-height: 1px}
.bk3{height: 3px;}.bk6{height: 6px}.bk8{height: 8px}.bk10{height: 10px}.bk15{height: 15px}.bk20{height: 20px}.bk30{height: 30px}

.mr3{ margin-right:3px;} .mr5{ margin-right:5px;} .mr10{ margin-right:10px;}
.ml5{ margin-left: 5px;} .ml10{ margin-left: 10px;} .ml20{ margin-left: 20px;}
.mt10{ margin-top:10px;}
.mt5{ margin-top:5px;}

.pad_6{padding:6px; overflow:hidden}
.pad_10{padding:10px; overflow:hidden}
.pad_lr_10{padding:0 10px}
.pad_lr_6{padding:0 6px}
.lh20{line-height: 20px}.lh22{line-height: 22px}.lh24{line-height: 24px}.lh26{line-height: 26px}.lh28{line-height: 28px}
.line_x{border-bottom:1px solid #eee;}
.title_1{border-bottom:1px solid #eee; padding-left:5px}
.title_2{text-align:left;height:25px;*height:24px;font:14px "MicroSoft YaHei","SimHei";color:#333;*line-height:25px; margin:0; padding:4px 0 3px 0px}
.title_3{ text-align:left; font-size:12px; font-weight:normal; padding:4px 0 4px 0px}

.ib, .ib_li li, .ib_a a, .ib-span span,.common_form ul li span.text,.fixed_bottom .fixed_but .btn,.arrowhead,.arrowhead-b,shortcut a,.shortcut a span,.picBut a,.tab_use{display:inline-block;display:-moz-inline-stack;zoom:1;*display:inline;}
.cut_line span.cut{color:#4d82bc; padding:0 4px}

/*按钮*/
.btn{color:#333;background:#f1f0f0;border:1px solid #c4c4c4;border-radius:2px;text-shadow:0 1px 1px rgba(255, 255, 255, 0.75);padding:4px 15px;display:inline-block;
cursor:pointer;text-decoration:none;overflow:visible;text-align:center;zoom:1;white-space:nowrap;margin-right:10px;font-family:inherit;position:relative;}
.btn:hover{background:#e9e7e7;}

.btn_submit{color:#FFFFFF; background:#318dd0; text-shadow:0 -1px 0 rgba(0, 0, 0, 0.25); border-color:#106BAB #106BAB #0D68A9;}
.btn_submit:hover{background:#3486c1;}

.upload_btn{float:left;color:#333;background:#f1f0f0;border:1px solid #c4c4c4;border-radius:2px;text-shadow:0 1px 1px rgba(255, 255, 255, 0.75);display:inline-block;cursor:pointer;width:60px;height:22px;text-align:center;}
.upload_btn span{*position:absolute;right:0;top:0;width:60px;height:22px;line-height:22px;float:right;;}
.btn_disabled span{color:#ffffff;background:#cacaca;}

.btn_blue{display:inline-block;color:#fff;background:#39F;border:1px #39F solid;border-radius:3px;text-decoration:none;cursor:pointer; padding:0 8px;}
.btn_blue:hover{ background:#2983E4; text-decoration: none;}

/*列表表格*/
.table_list{border:1px solid #d5dfe8; margin-bottom: 40px;}
.table_list td,.table_list th{padding:0 4px;}
.table_list thead th{height:30px; background:#eaf0f7; font-weight:normal; font-weight:700;}
.table_list tbody td{border-top:1px solid #d5dfe8; padding:4px 4px; line-height:24px;}
.table_list tr:hover,.table_list table tbody tr:hover{ background:#ffffe1}
.table_list .input-text-c{ padding:0; height:18px}
.input-text-c{border:1px solid #A7A6AA; height:18px; padding:2px 0 0; text-align:center}
.table_list tr.on,.table_list tr.on td,.table_list tr.on th,.table_list td.on,.table_list th.on{background:#fdf9e5;}

/*表单表格*/
.table_form{}
.table_form input{}
.table_form td{padding-left:12px}
.table_form td label{ vertical-align:middle}
.table_form td,.table_form th{padding:8px 0 8px 8px}
.table_form thead {}
.table_form thead th {color:#777;padding:5px 0 5px 8px;background:#eaf0f7; font-weight:normal; font-weight:700; border-bottom:1px solid #eee; }
.table_form tbody td,.table_form tbody th{border-bottom:1px solid #eee; }
.colorpanel tbody td,.colorpanel tbody th{ padding:0;border-bottom: none;}
.table_form tbody th{font-weight:normal; text-align:right;padding-right:10px; color:#777;}

.table-other{border:1px solid #d5dfe8;}
.table-other td,.table-other th{ padding:0 10px;border:1px solid #d5dfe8;padding:5px 10px;}

/*操作条*/
.btn_wrap,.btn_wrap_fixed{padding:4px 10px; background:#FFFFE1; line-height:normal; border-top: 1px #a5bcf4 solid;}
.btn_wrap_fixed{position:fixed; bottom:0; left:0; width:100%; z-index:5; _position: absolute; _top: expression(documentElement.scrollTop+documentElement.clientHeight-this.offsetHeight);}
.select_all input{ margin: 0 5px;}

/*字段排序*/
.sort_th{ color: #5252f2; cursor: pointer;}
.sort_desc{background:url(bgimg/desc.gif) no-repeat right; padding-right:12px;}
.sort_asc{background:url(bgimg/asc.gif) no-repeat right; padding-right:12px;}

.tdedit{background: url(bgimg/tdedit.gif) no-repeat right 2px; padding-right: 14px;}
.lt_input_text{height:14px; line-height:100%; padding:2px 4px;border: 1px solid #A8D0F4;font-family: Verdana, Geneva, sans-serif,"宋体";font-size:12px;}

.input-text,.measure-input,textarea,input.date,input.endDate,.input-focus{border:1px solid #A7A6AA;height:18px;padding:2px 0 2px 5px;border: 1px solid #d0d0d0;background: #FFF url(bgimg/input.png) repeat-x; font-family: Verdana, Geneva, sans-serif,"宋体";font-size:12px;}
.input-focus{background: #FFF url(bgimg/input_focus.png) repeat-x; border-color:#afcee6;font-size:12px;}
input.date,input.endDate{background: #fff url(bgimg/input_date.png) no-repeat right 3px; padding-right:18px;font-size:12px;}
textarea,textarea.input-text,textarea.input-focus{font-size:12px;height:auto; padding:5px; margin:0;}
select{ vertical-align:middle;background:none repeat scroll 0 0 #F9F9F9;border-color:#666666 #CCCCCC #CCCCCC #666666;border-style:solid;border-width:1px;color:#333;padding:2px;}

.search_form{ margin-bottom:10px}
.explain_col{ border:1px solid #ffbe7a;zoom:1; background: #fffced; padding:8px 10px; line-height:20px}

.table_block{border:1px solid #ccc;zoom:1; float:left; margin:0 5px 10px;}
.table_block th{font-weight:normal; text-align:right;padding:4px 8px; color:#777}
.table_block td,.table_block th{border-bottom:1px solid #eee;}

.tip_list{ color: #555;}
.tip_list li {margin-bottom: 2px;padding: 0 20px 5px 0;line-height: 120%; float: left;}

.loading{ background:url(bgimg/ajax_loading.gif) no-repeat; padding-left: 30px; line-height: 20px;}

/*ajax加载*/
.ajax_loading{ color:#FFF; padding:2px 5px 2px 25px; background:url(bgimg/ajax_loading.gif) #FF5151 no-repeat 3px 2px; position:absolute; right:0; top:0; display:none;}

/*错误提示*/
#message_list {}
#message_list .list_error{ border:1px #FF9B9B solid; height:30px; line-height:30px; background:url(bgimg/error_icon.gif) no-repeat 10px 5px #FFFFE9; padding-left:40px; color:#F00; margin-bottom:5px;}

/*登陆页面*/
.login_body{background:#3a6ea5;}
.login_table{width:450px;height:140px;margin:150px auto 0;}
.login_table td.logo{width:210px;background:url(bgimg/login_bg.gif) no-repeat right;}
.login_table td.logo h1{width:200px;height:54px;overflow:hidden;background:url(bgimg/logo.gif) no-repeat; text-indent:-9999px;}
.login_table td.logo p{color:#e0e0e0;line-height:25px;}
.login_table td.loginform{padding:28px 0 0 25px;vertical-align:top;}
.login_table td.loginform table th{color:#FFF;font-weight:normal; height:38px; padding-right:5px;}
.login_table td.loginform table input.text{width:125px;height:22px; line-height:22px; border:1px #e3f0fc solid; border-top:1px #8cb7e1 solid; border-left:1px #8cb7e1 solid;}
.login_table td.loginform table input.user{ background:url(bgimg/login_user_bg.gif) #FFF no-repeat 5px 4px;; padding-left:22px;}
.login_table td.loginform table input.pass{ background:url(bgimg/login_pass_bg.gif) #FFF no-repeat 5px 4px;; padding-left:22px;}
.login_table td.loginform table input.vifity{ width:60px; margin-right:5px;}
.login_table td.loginform table .verify_img{ cursor:pointer;}
.login_table td.loginform table input.login_btn{width:71px;height:24px; background:url(bgimg/login_btn.gif) no-repeat; border:none; cursor:pointer;}

/*控制面板*/
.table_panel{text-align:left;}
.table_panel th{vertical-align:middle;padding:0 10px;color:#333;}

/*后台地图*/
.table_map{text-align:left; line-height:30px; width:100%;border:1px solid #eee; border-bottom:none;}
.table_map tr{border-bottom:1px solid #eee;}
.table_map tr:hover{ background:#fbffe4}
.table_map th{vertical-align:middle;background:#cde8f5; padding:0 10px; color:#666; text-align:right}
.table_map_sub tr{border:none;}
.table_map_sub th{ background:none; font-weight:normal; text-align:left;}
.table_map_sub td a{float:left;color:#0364ae; margin-right:20px;}
.table_map_sub td label{float:left;color:#0364ae; width:120px;}
.table_map_sub td label input{ float:left; margin:8px 5px 0 0;}

/*表格*/
.border_table{}
.border_table th,.border_table td{border:1px solid #E3E3E3; background:#F4FAFF;}

/*表单验证*/
.onShow,.onFocus,.onError,.onCorrect,.onLoad,.onTime{display:inline-block;display:-moz-inline-stack;zoom:1;*display:inline; vertical-align:middle;background:url(bgimg/msg_bg.png) no-repeat;	color:#444;line-height:18px;padding:2px 10px 2px 23px; margin-left:10px;_margin-left:5px}
.onShow{background-position:3px -147px;border-color:#40B3FF;color:#959595}
.onFocus{background-position:3px -147px;border-color:#40B3FF;}
.onError{background-position:3px -47px;border-color:#40B3FF; color:red}
.onCorrect{background-position:3px -247px;border-color:#40B3FF;}
.onLamp{background-position:3px -200px}
.onTime{background-position:3px -1356px}

/*列表状态列*/
.enabled{display:inline-block;cursor:pointer;width:17px;height:17px;background:url(bgimg/msg_bg.png) no-repeat 0 -250px;}
.disabled{display:inline-block;cursor:pointer;width:17px;height:17px;background:url(bgimg/msg_bg.png) no-repeat;}

/*头部*/
#header {
	height: 55px;
	overflow: hidden;
	background-attachment: scroll;
	background-color: #06062B;
	background-image: url(/static/images/admin/pancl/topbg.png);
	background-repeat: no-repeat;
	background-position: right 0;
}
#header .logo{float:left;margin-right:20px; padding:8px 0 0 0;}
#header .logo a{display:block;text-decoration: none;height:50px; width:400px; background:url(bgimg/logo.png) no-repeat;}
#header .nav{ display:inline-block; height:34px; position:relative; margin-top:15px;}
#header .col-auto{ overflow:visible}
#header .nav li,
#header .nav li a{background: url(bgimg/nav_bg.png) no-repeat;display:block;_float:left;height:34px; line-height:38px; font-size:14px; font-weight:700; text-decoration:none;}
#header .nav li{float:left;padding:0 0 0 8px}
#header .nav li a{background-position: right top; padding:0 15px 0 7px}
#header .nav li.on{background-position: left -43px;}
#header .nav li.on a{background-position: right -43px; color:#367abb;}
#header .admin_info{padding:18px 14px 0 0; color:#FFF;}
#header .admin_info a{ text-decoration:none; color:#FFF;}

.left_menu{margin-right:8px; padding:8px;_padding:8px 0 8px 8px;width:118px; position:relative; display:block;}
.left_menu_on{ width:0; padding:0;}
.left_menu_on div{ visibility:hidden;_display:none}
.left_menu h3{font-weight: 700;color: #275d96;border-bottom:1px solid #d9e4ea; line-height:24px; height:24px; margin-bottom:4px;_width:112px;_margin-right:12px}
.left_menu ul li a{line-height:24px;padding-left:8px;display:block;text-decoration: none;background-color:#f7fbfc;_width:100px;outline:none;}
.left_menu ul li a:hover,
.left_menu ul li.on,.left_menu h3 span{background: url(bgimg/left_menu.png) no-repeat;text-decoration: none}
.left_menu ul li.on{width:104px; height:29px; padding-left:20px; margin:0}
.left_menu ul li.on a{ height:29px; line-height:29px; background:none; padding:0; display:block}
.left_menu ul li.on a:hover{background:none}
.left_menu ul li a:hover{background-position: left -38px}
.left_menu a.open,.left_menu a.close{background: url(bgimg/left_menu_openClose.png) no-repeat 1px center;width:8px; display:block; position:absolute; z-index:100; height:auto; right:-9px; top:0}
.left_menu a.close{background-position:right center}
.left_menu h3 span{background-position: left -78px; display:block; float:right; height:14px; width:14px; margin-top:5px}
.left_menu h3 span.on{background-position: -33px -78px;}

.right_main{overflow:hidden;_zoom:1;_float:left;}

/*页面tab*/
.crumbs{height:26px;position:relative;}
.mtab{ width:100%;}
.mtab_pre,.mtab_next,.mtab_nopre,.mtab_nonext,.mtab_h li .del{background:url(bgimg/options_ico.png) no-repeat;}
.mtab_pre,.mtab_next {width:24px;height:26px;display:block;overflow:hidden;text-indent:-2000em;}
.mtab_pre{background-position:9px -16px;}
.mtab_next{background-position:-5px -16px;margin-right:190px; display: inline;}
.mtab_nopre{background-position:-20px -16px;}
.mtab_nonext{background-position:-34px -16px;margin-right:190px;}
.mtab_p{margin:0 214px 0 24px;}
.mtab_b{position:relative;height:26px;width:100%;overflow:hidden;}
.mtab_h{position:absolute;white-space:nowrap;border-right:1px solid #DEDEDE;height:26px;overflow:hidden; top:0; left:0;}
.mtab_h li{border-left:1px solid #DEDEDE;display:inline-block;height:26px; overflow: hidden; float: left;}
.mtab_h li span{display:inline-block;line-height:26px;height:26px;padding:0 10px 0 15px;cursor: pointer;}
.mtab_h li span:hover{background:#e6ebeb}
.mtab_h li a {outline:none;float:left;color:#666;padding-right:8px;text-decoration:none;}
.mtab_h li .del{width:7px;height:7px;overflow:hidden;display:block;text-indent:-2000em;background-position:-58px -24px;margin:10px 0 0 0;position:relative;padding:0;}
.mtab_h li .del:hover{background-position:-65px -24px;}
.mtab_h li.current .del{background-position:-74px -24px;}
.mtab_h li.current .del:hover{background-position:-81px -24px;}
.mtab_h li.current span{background:#89a5ea;}
.mtab_h li.current a{color:#fff;}

.options {background: url(bgimg/options.png) no-repeat scroll 0 0 transparent;height:20px;overflow: hidden;width:179px; position:absolute;top:3px; right:10px;}
.options a{float: left;font-style: normal;height: 18px;line-height: 18px;margin-top: 1px;overflow: hidden; text-decoration:none;}
.options a:hover{ background-color:#F2F2F2;}
.refresh, .admin_full, .admin_unfull {background: url(bgimg/options_ico.png) no-repeat scroll 0 0 transparent;}
.refresh {background-position: -61px 2px;text-indent: -2000em;width: 29px;}
.admin_full, .admin_unfull {background-position: 8px 3px;text-indent: -2000em;width: 27px;}
.admin_unfull {background-position: -27px 3px;}
.flush_cache,.admin_map{ width:60px;color: #989898;text-align: center;}
.admin_map{width:62px;}

.rframe_b {background:#fff;border:1px solid #c2d1d8;position:relative; overflow:hidde;}

.subnav{ padding:10px;}

/*容器样式*/
.col_tab{ }
.col_tab ul.tab_but{height:27px; padding-left:14px;position:relative;bottom:-1px}
.col_tab ul.tab_but li{float:left; border:1px solid #dce3ed; height:25px; line-height:26px; margin-right:5px;}
.col_tab ul.tab_but li{ background:#eaeef4; padding:0 8px;}
.col_tab ul.tab_but li.current{position:relative; background:#fff;border-bottom:0;height:26px;_height:27px; font-weight:700;}
.col_tab .content{border:1px solid #dce3ed;_zoom:1;}
.col_tab .content_r{border-top:1px solid #dce3ed}
.col_tab .content_list{border:1px solid #dce3ed;_zoom:1;}

.col-1{ border:1px solid #f4f6f5;zoom:1; background:#fff}
.col-1 div.content{border:1px solid #c2d1d8;zoom:1;}

.col-2{ border:1px solid #c7d8ea;zoom:1;}
.col-2 h6{border-bottom:1px solid #c7d8ea; color:#3a6ea5; background:#f8fafa; height:26px; line-height:28px; padding:0 10px}
.col-2 div.content{ padding:9px 10px}

/*内容菜单*/
.content_menu{ padding:0 0 6px;}
.content_menu a:hover{text-decoration: none;}
.content_menu a em{display:inline-block;display:-moz-inline-stack;zoom:1;*display:inline;}
.content_menu a.add,.content_menu a.add em,
.content_menu a.on,.content_menu a.on em{background:url(bgimg/bnt_bg.png) no-repeat;height:28px;line-height:28px;*line-height:28px}
.content_menu span{color:#ddd;padding:0 8px}
.content_menu a{cursor:pointer;}
.content_menu a.add{ padding:0 0 0 5px;}
.content_menu a.add em{ padding:0 10px 0 5px;color:#fff;background-position: right top;background-position:right -1px\0;}
.content_menu a.on{background-position:left -40px;*background-position:left -41px;_background-position:left -39px;color:#fff;padding:0 0 0 5px;}
.content_menu a.on em{background-position:right -40px;background-position:right -41px\0;*background-position:right -41px;_background-position:right -39px;padding:0 10px 0 5px}

.cache_ifm{height: 22px; line-height: 22px; border: none;}

/*商品图片模式*/
.item_imglist{margin-bottom:20px;}
.item_imglist .item{width:120px;margin:0 15px 15px 0;border:1px #E0E0E0 solid;padding:5px; position: relative;}
.item_imglist .item .check{ position: absolute; top: 5px; left: 5px;}
.item_imglist .item .img{width: 120px; height: 120px; overflow: hidden;}
.item_imglist .item .img img{width: 120px;}
.item_imglist .item span{height: 35px; display: block; overflow: hidden; line-height: 16px; color: #444;}
.item_imglist .item ul{ margin-top: 5px;}
.item_imglist .item ul li{float: left; width: 50%; text-align: center; margin-top: 5px;}

/*专辑图片模式*/
.album_imglist{margin-bottom:20px;}
.album_imglist .album{width:167px;margin:0 15px 15px 0;border:1px #E0E0E0 solid;padding:5px;}
.album_imglist .album h4{color:#666;}
.album_imglist .album li{height:55px;width:55px;margin:1px 0 0 1px;display:inline;background:#E9E9E9;overflow:hidden;}
.album_imglist .album li.left{margin:1px 0 0;}
.album_imglist .album .check{ margin-top: 4px;}

/*分类标签设置*/
.tag_list { border: 1px solid #CCCCCC; float: left; overflow-x: hidden; overflow-y: scroll; width: 100%; padding:0 0 5px 0;}
.tag_list li { border: 1px solid #999999; cursor: pointer; float: left; margin: 5px 0 0 5px; padding: 2px 4px; white-space: nowrap;}
.cate_tags li{ background:#09F; color:#FFF;}

/*tooltip*/
.tooltip {display:none;background:transparent url(bgimg/black_arrow.png);font-size:12px;height:70px;width:160px;padding:25px;color:#eee;}
.tooltip.bottom {background:url(bgimg/black_arrow_bottom.png);padding-top:40px;height:55px;}

/*分页*/
#pages {text-align:right; float:right; margin-right:20px;}
#pages a { display:inline-block; height:22px; line-height:22px; background:#4d81bb; border:1px solid #e3e3e3; text-align:center; color:#fff; margin-left:4px; padding:0 4px;}
#pages a.current { display:inline-block; width:26px; height:22px; line-height:22px; background:#5a85b2; border:1px solid #5a85b2; color:#fff; text-align:center; }
#pages a.page_prev,#pages a.page_first,#pages a.page_last,#pages a.page_next { background:#4d81bb  0 5px; width:50px;}
#pages a:hover { background:#F96; color:#000; text-decoration:none; }

/* jquery.treeTable.collapsible
 * ------------------------------------------------------------------------- */
.treeTable tr td .expander {background-position: left center; background-repeat: no-repeat; cursor: pointer; padding: 0; zoom: 1;}
.treeTable tr.collapsed td .expander {background-image: url(bgimg/tv-expandable.gif);}
.treeTable tr.expanded td .expander {background-image: url(bgimg/tv-collapsable.gif);}

/*编辑器*/
.ke-container td,.ke-container th{padding:0;}

/*dialog*/
body { _margin:0; _height:100%; }/*IE6 BUG*/
.d-outer { text-align:left; }
.d-border, .d-dialog { border:0 none; margin:0; border-collapse:collapse; width:auto; }
.d-nw, .d-n, .d-ne, .d-w, .d-c, .d-e, .d-sw, .d-s, .d-se, .d-header, .d-main, .d-footer { padding:0; }
.d-header, .d-button { font: 12px/1.11 'Microsoft Yahei', Tahoma, Arial, Helvetica, STHeiti; _font-family:Tahoma,Arial,Helvetica,STHeiti; -o-font-family: Tahoma, Arial; }
.d-title { overflow:hidden; text-overflow: ellipsis; cursor:default; }
.d-state-noTitle .d-title { display:none; }
.d-close { display:block; position:absolute; text-decoration:none; outline:none; _cursor:pointer; }
.d-close:hover { text-decoration:none; }
.d-main { text-align:center; vertical-align:top; min-width:9em; }
.d-content { display:inline-block; display:block\0/*IE8 BUG*/; display:inline-block\9\0; *zoom:1; *display:inline; text-align:left; border:0 none; width:100%;  }
.d-content.d-state-full { display:block; width:100%; margin:0; padding:0!important; height:100%; }
.d-loading { height:32px; text-indent:-999em; overflow:hidden; background:url(bgimg/dialog/loading.gif) no-repeat center center; }
.d-buttons { padding:5px 8px; text-align:right; white-space:nowrap; }
.d-button { margin-left:15px; padding: 0 8px; cursor: pointer; display: inline-block; min-height:2.1em; text-align: center; *padding:4px 10px; *height:2em; letter-spacing:2px; font-family: Tahoma, Arial/9!important; width:auto; overflow:visible; *width:1; color: #333; border: 1px solid #999; border-radius: 5px; background: #DDD; filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#FFFFFF', endColorstr='#DDDDDD'); background: linear-gradient(top, #FFF, #DDD); background: -moz-linear-gradient(top, #FFF, #DDD); background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#FFF), to(#DDD)); text-shadow: 0px 1px 1px rgba(255, 255, 255, 1); box-shadow: 0 1px 0 rgba(255, 255, 255, .7),  0 -1px 0 rgba(0, 0, 0, .09); -moz-transition:-moz-box-shadow linear .2s; -webkit-transition: -webkit-box-shadow linear .2s; transition: box-shadow linear .2s; }
.d-button::-moz-focus-inner, .d-button::-moz-focus-outer { border:0 none; padding:0; margin:0; }
.d-button:focus { outline:none 0; border-color:#426DC9; box-shadow:0 0 8px rgba(66, 109, 201, .9); }
.d-button:hover { color:#000; border-color:#666; }
.d-button:active { border-color:#666; filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#DDDDDD', endColorstr='#FFFFFF'); background: linear-gradient(top, #DDD, #FFF); background: -moz-linear-gradient(top, #DDD, #FFF); background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#DDD), to(#FFF)); box-shadow:inset 0 1px 5px rgba(66, 109, 201, .9), inset 0 1px 1em rgba(0, 0, 0, .3); }
.d-button[disabled] { cursor:default; color:#666; background:#DDD; border: 1px solid #999; filter:alpha(opacity=50); opacity:.5; box-shadow:none; }
.d-state-highlight { color: #FFF; border: 1px solid #1c6a9e; background: #2288cc; filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#33bbee', endColorstr='#2288cc'); background: linear-gradient(top, #33bbee, #2288cc); background: -moz-linear-gradient(top, #33bbee, #2288cc); background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#33bbee), to(#2288cc)); text-shadow: -1px -1px 1px #1c6a9e; }
.d-state-highlight:hover { color:#FFF; border-color:#0F3A56; }
.d-state-highlight:active { border-color:#1c6a9e; filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#33bbee', endColorstr='#2288cc'); background: linear-gradient(top, #33bbee, #2288cc); background: -moz-linear-gradient(top, #33bbee, #2288cc); background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#33bbee), to(#2288cc)); }
.d-mask { background:#FFF; filter:alpha(opacity=30); opacity:.3; }

.d-inner { background:#FFF; border:1px solid #999; }
.d-nw, .d-ne, .d-sw, .d-se { width:6px; height:6px; }
.d-nw, .d-n, .d-ne, .d-w, .d-e, .d-sw, .d-s, .d-se { background:rgba(0, 0, 0, .2); background:#000\9!important; filter:alpha(opacity=20);}
.d-state-lock .d-nw, .d-state-lock .d-n, .d-state-lock .d-ne, .d-state-lock .d-w, .d-state-lock .d-e, .d-state-lock .d-sw, .d-state-lock .d-s, .d-state-lock .d-se { background:rgba(0, 0, 0, .2); background:#000\9!important; filter:alpha(opacity=20); }
.d-titleBar { position:relative; height:100%; }
.d-title { height:30px; line-height:30px; padding:0 48px 0 10px; background-color:#edf5f8; font-weight:bold; font-size:14px; color:#999; background-color:#f2f2f3; border-bottom:1px solid #c7ced8; }
.d-state-focus .d-title { color:#4c5a5f; }
.d-state-drag .d-title { cursor:move;}
.d-close { padding:0; top:0; right:8px; width:28px; height:18px; background-image:url(bgimg/dialog/close.gif); background-repeat:no-repeat; text-indent:-9em; overflow:hidden; }
.d-close:hover { background-position:0 -18px; }
.d-close:active { background-position:0 -18px; }
.d-content { color:#666; }
.d-state-focus .d-content { color:#000; }.d-buttons { background-color:#F6F6F6; border-top: 1px solid #DADEE5; }
.d-state-noTitle .d-close { top:0; right:0; width:18px; height:18px; line-height:18px; text-align:center; text-indent:0; font-size:18px; text-decoration:none; color:#214FA3; background:none; filter:!important; }
.d-state-noTitle .d-close:hover, .d-state-noTitle .d-close:active { text-decoration:none; color:#900; }

@media screen and (min-width:0) {/* css3 */
	.d-state-focus .d-dialog { box-shadow: 0 0 3px rgba(0, 0, 0, .2); }
	.d-state-drag, .d-state-focus:active  { box-shadow:none; }
	.d-state-focus { box-shadow:0 3px 8px rgba(0, 0, 0, .3);  }
	.d-outer { -webkit-transform: scale(0); transform: scale(0); -webkit-transition: -webkit-box-shadow .2s ease-in-out, -webkit-transform .2s ease-in-out; transition: box-shadow .2s ease-in-out, transform .2s ease-in-out; }
	.d-state-visible { -webkit-transform: scale(1); transform: scale(1); }
}

.color_picker_btn{display:inline-block;position:relative;}

/* 提示信息 */
.tipbox{ height:54px; line-height:54px; position:absolute; display:none;}
.tipbox .tip-l{ float:left; width:45px; height:54px; background-image:url(bgimg/tip_layer.png); background-repeat:no-repeat; background-position:-5px 0;}
.tipbox .tip-c{ float:left; height:54px; line-height:52px; padding:0 10px 0 5px; background-image:url(bgimg/tip_layer.png); background-repeat:repeat-x; background-position:0 -161px;}
.tipbox .tip-r{ float:left; width:5px; height:54px; background-image:url(bgimg/tip_layer.png); background-repeat:no-repeat; background-position:0 0;}
.tip-success .tip-l{ background-position:-6px 0;}
.tip-alert .tip-l{ background-position:-6px -54px;}
.tip-error .tip-l{ background-position:-6px -108px;}

/* 附件tip */
.attachment_icon{ margin-left:8px; position:relative;}
.attachment_tip{ border:1px #CCC solid; position:absolute; left:16px; top:16px; display:none; padding:1px; z-index:9;}


text:
/*global jQuery:false */
if (typeof toolkit==='undefined') toolkit={};
toolkit.accordion = (function (toggle) {
    "use strict";

    function Accordion($element){
        this.$container = $element;
        this.$headings = $element.find('.accordion-heading');
        this.bindEvents();
    }

    function rotateIcon($elClicked) {
        $elClicked.find('i').toggleClass('rotate-180');
    }

    Accordion.prototype = {
        bindEvents:function(){
            this.$headings.on("click",this.toggleContent.bind(this));
        },
        toggleContent:function(e){
            e.preventDefault();
            var $heading = $(e.currentTarget);
            toggle({$elClicked:$heading});
            rotateIcon($heading);
        }
    };

    $.fn.accordion = function() {
        return this.each(function() {
            var accordion = new Accordion($(this));
        });
    };

    return Accordion;
});

if (typeof window.define === "function" && window.define.amd) {
    define('components/accordion', ['utils/toggle'], function(toggle) {
        return toolkit.accordion(toggle);
    });
} else {
    toolkit.accordion = toolkit.accordion(toolkit.toggle);
}

redpajama_set_name: RedPajamaGithub


text:
[![License][License-Image]][License-Url] [![ReportCard][ReportCard-Image]][ReportCard-Url] [![Build][Build-Status-Image]][Build-Status-Url] [![Release][Release-Image]][Release-Url] [![Coverage][Coverage-Image]][Coverage-Url]

A High Performance [NATS](https://nats.io) Server written in [Go.](http://golang.org)

## Quickstart

If you just want to start using NATS, and you have [installed Go](https://golang.org/doc/install) 1.5+ and set your $GOPATH:

Install and run the NATS server:

```
go get github.com/glycerine/gnatsd
gnatsd -D -V
```

Install the [Go NATS client](https://github.com/glycerine/go-nats/blob/master/README.md):

```
go get github.com/glycerine/go-nats
```

## Installation

You can install the NATS server binary or Docker image, connect to a NATS service, or build the server from source.

### Download

The recommended way to install the NATS server is to [download](http://nats.io/download/) one of the pre-built release binaries which are available for OSX, Linux (x86-64/ARM), Windows, and Docker. Instructions for using these binaries are on the [GitHub releases page][github-release].

### Demo

You can connect to a public NATS server that is running at our demo site: [nats://demo.nats.io:4222](nats://demo.nats.io:4222), and a secure version at [tls://demo.nats.io:4443](nats://demo.nats.io:4443). See the [protocol](#protocol) section for usage.

### Build

You can build the latest version of the server from the `master` branch. The master branch generally should build and pass tests, but may not work correctly in your environment. Note that stable branches of operating system packagers provided by your OS vendor may not be sufficient.

You need [*Go*](http://golang.org/) version 1.5+ [installed](https://golang.org/doc/install) to build the NATS server. We support vendored dependencies, which are fully supported in Go 1.6. For Go 1.5, build with `GO15VENDOREXPERIMENT=1`.

- Run `go version` to verify that you are running Go 1.5+. (Run `go help` for more guidance.)
- Clone the <https://github.com/glycerine/gnatsd> repository.
- Run `go build` inside the `/nats-io/gnatsd` directory. A successful build produces no messages and creates the server executable `gnatsd` in the directory.
- Run `go test ./...` to run the unit regression tests.

## Running

To start the NATS server with default settings (and no authentication or clustering), you can invoke the `gnatsd` binary with no [command line options](#command-line-arguments) or [configuration file](#configuration-file).

```sh
> ./gnatsd
[37274] 2016/12/15 18:33:12.119961 [INF] Starting nats-server version 0.9.6
[37274] 2016/12/15 18:33:12.120060 [INF] Listening for client connections on 0.0.0.0:4222
[37274] 2016/12/15 18:33:12.120154 [INF] Server is ready
```

The server is started and listening for client connections on port 4222 (the default) from all available interfaces. The logs are displayed to stdout as shown above in the server output.

### Clients

The NATS ecosystem provides a large range of supported and community [clients](http://nats.io/documentation/clients/nats-clients/), including Go, Java, Node, and many more. For the complete up-to-date list, visit the [NATS download site](https://nats.io/download).

### Protocol

The NATS server uses a [text based protocol](http://nats.io/documentation/internals/nats-protocol/), so interacting with it can be as simple as using telnet as shown below. See also the [protocol demo](http://nats.io/documentation/internals/nats-protocol-demo/).

```sh
> telnet demo.nats.io 4222
Trying 107.170.221.32...
Connected to demo.nats.io.
Escape character is '^]'.
INFO {"server_id":"kG19DsXX1UVeSyEjhl3RFw","version":"0.9.6","go":"go1.7.4","host":"0.0.0.0","port":4222, ...}
SUB foo 1
+OK
PUB foo 11
Hello World
+OK
MSG foo 1 11
Hello World
```

## Command line arguments

The NATS server accepts command line arguments to control its behavior. Usage is shown below. Note that command line arguments override those items in the [configuration file](#configuration-file).

```
Server Options:
    -a, --addr <host>                Bind to host address (default: 0.0.0.0)
    -p, --port <port>                Use port for clients (default: 4222)
    -P, --pid <file>                 File to store PID
    -m, --http_port <port>           Use port for http monitoring
    -ms,--https_port <port>          Use port for https monitoring
    -c, --config <file>              Configuration file

Logging Options:
    -l, --log <file>                 File to redirect log output
    -T, --logtime                    Timestamp log entries (default: true)
    -s, --syslog                     Enable syslog as log method
    -r, --remote_syslog <addr>       Syslog server addr (udp://localhost:514)
    -D, --debug                      Enable debugging output
    -V, --trace                      Trace the raw protocol
    -DV                              Debug and trace

Authorization Options:
        --user <user>                User required for connections
        --pass <password>            Password required for connections
        --auth <token>               Authorization token required for connections

TLS Options:
        --tls                        Enable TLS, do not verify clients (default: false)
        --tlscert <file>             Server certificate file
        --tlskey <file>              Private key for server certificate
        --tlsverify                  Enable TLS, verify client certificates
        --tlscacert <file>           Client certificate CA for verification

Cluster Options:
        --routes <rurl-1, rurl-2>    Routes to solicit and connect
        --cluster <cluster-url>      Cluster URL for solicited routes
        --no_advertise <bool>        Advertise known cluster IPs to clients

Common Options:
    -h, --help                       Show this message
    -v, --version                    Show version
        --help_tls                   TLS help
```

## Configuration file

Typically you configure the NATS server using a configuration file, an example of which is shown below. See also the [server configuration file](http://nats.io/documentation/server/gnatsd-config/) documentation for details on the configuration language.

```
listen: localhost:4242 # host/port to listen for client connections

http: localhost:8222 # HTTP monitoring port

# Authorization for client connections
authorization {
  user:     derek
  # ./util/mkpassword -p T0pS3cr3t
  password: $2a$11$W2zko751KUvVy59mUTWmpOdWjpEm5qhcCZRd05GjI/sSOT.xtiHyG
  timeout:  1
}

# Cluster definition

cluster {

  listen: localhost:4244 # host/port for inbound route connections

  # Authorization for route connections
  authorization {
    user: route_user
    # ./util/mkpassword -p T0pS3cr3tT00!
    password: $2a$11$xH8dkGrty1cBNtZjhPeWJewu/YPbSU.rXJWmS6SFilOBXzmZoMk9m
    timeout: 0.5
  }

  # Routes are actively solicited and connected to from this server.
  # Other servers can connect to us if they supply the correct credentials
  # in their routes definitions from above.

  routes = [
    nats-route://user1:pass1@127.0.0.1:4245
    nats-route://user2:pass2@127.0.0.1:4246
  ]
}

# logging options
debug:   false
trace:   true
logtime: false
log_file: "/tmp/nats-server.log"

# pid file
pid_file: "/tmp/nats-server.pid"

# Some system overides

# max_connections
max_connections: 100

# maximum protocol control line
max_control_line: 512

# maximum payload
max_payload: 65536
```

## Variables

The NATS sever configuration language supports block-scoped variables that can be used for templating in the configuration file, and specifically to ease setting of group values for [permission fields](#authorization) and [user authentication](#authentication).

Variables can be referenced by the prefix `$`, for example: `$PASSWORD`. Variables can be defined in the configuration file itself or reference environment variables.

Any value in the configuration language can be a variable reference (`key=$VALUE`). Note that the variable identifier (name) is not case sensitive, but is capitalized by convention for readability.

## Clustering

Clustering lets you scale NATS messaging by having multiple NATS servers communicate with each other. Clustering lets messages published to one server be routed and received by a subscriber on another server. See also the [clustered NATS](http://nats.io/documentation/server/gnatsd-cluster/) documentation.

### Full mesh required

In order for clustering to work correctly, all NATS servers must be connected to each other.

NATS servers have a forwarding limit of one hop. This means that each server will **only** forward a message that it has received **from a client** to  all connected servers that expressed interest in the message's published subject. A message received **from** a route will only be distributed to local clients.

### Configuration options

NATS supports running each server in clustered mode. The following command line options are supported:

    --cluster [cluster url]     Cluster URL for solicited routes
    --routes [rurl-1, rurl-2]   Routes to solicit and connect

The `--cluster` flag specifies the NATS URL where the server listens for connections from other servers.

The `--routes` flag specifies the NATS URL for one or more servers in the cluster. When a server connects to a specified route, it will advertise its own cluster URL to other servers. Note that when the `--routes` option is specified a `--cluster` option is also required.

Previous releases required you to build the complete mesh using the `--routes` flag. To define your cluster in the current release, please follow the "Basic example" as described below.

### Basic example

NATS makes building the full mesh easy. Simply designate a server to be a *seed* server. All other servers in the cluster simply specify the *seed* server as its server's routes option as indicated below.

When running NATS Servers in different hosts, the command line parameters for all servers could be as simple as:

```
gnatsd --cluster nats://$HOSTNAME:$NATS_CLUSTER_PORT --routes nats://$NATS_SEED_HOST:$NATS_CLUSTER_PORT
```

Even on the host where the *seed* is running, the above would work as the server would detect an attempt to connect to itself and ignore that. In other words, the same command line could be deployed in several hosts and the full mesh will properly form.

Note that you don't have to connect all servers to the same *seed* server, any server accepting a connection will inform other servers in the mesh about that new server so that they can connect to it. The advantage of the seed approach, is that you can deploy the same configuration to all hosts.

### 3-node example

The following example demonstrates how to run a cluster of 3 servers on the same host. We will start with the seed server and use the `-D` command line parameter to produce debug information.

See also [clustered NATS](http://nats.io/documentation/server/gnatsd-cluster/) for clustered NATS examples using Docker.

```
gnatsd -p 4222 -cluster nats://localhost:4248 -D
```

Alternatively, you could use a configuration file, let's call it `seed.conf`, with a content similar to this:

```
# Cluster Seed Node

listen: 127.0.0.1:4222
http: 8222

cluster {
  listen: 127.0.0.1:4248
}
```

And start the server like this:

```
gnatsd -config ./seed.conf -D
```

This will produce an output similar to:

```
[75653] 2016/04/26 15:14:47.339321 [INF] Listening for route connections on 127.0.0.1:4248
[75653] 2016/04/26 15:14:47.340787 [INF] Listening for client connections on 127.0.0.1:4222
[75653] 2016/04/26 15:14:47.340822 [DBG] server id is xZfu3u7usAPWkuThomoGzM
[75653] 2016/04/26 15:14:47.340825 [INF] server is ready
```

It is also possible to specify the hostname and port independently. At least the port is required. If you leave the hostname off it will bind to all the interfaces ('0.0.0.0').

```
cluster {
  host: 127.0.0.1
  port: 4248
}
```

Now let's start two more servers, each one connecting to the seed server.

```
gnatsd -p 5222 -cluster nats://localhost:5248 -routes nats://localhost:4248 -D
```

When running on the same host, we need to pick different ports for the client connections `-p`, and for the port used to accept other routes `-cluster`. Note that `-routes` points to the `-cluster` address of the seed server (`localhost:4248`).

Here is the log produced. See how it connects and registers a route to the seed server (`...GzM`).

```
[75665] 2016/04/26 15:14:59.970014 [INF] Listening for route connections on localhost:5248
[75665] 2016/04/26 15:14:59.971150 [INF] Listening for client connections on 0.0.0.0:5222
[75665] 2016/04/26 15:14:59.971176 [DBG] server id is 53Yi78q96t52QdyyWLKIyE
[75665] 2016/04/26 15:14:59.971179 [INF] server is ready
[75665] 2016/04/26 15:14:59.971199 [DBG] Trying to connect to route on localhost:4248
[75665] 2016/04/26 15:14:59.971551 [DBG] 127.0.0.1:4248 - rid:1 - Route connection created
[75665] 2016/04/26 15:14:59.971559 [DBG] 127.0.0.1:4248 - rid:1 - Route connect msg sent
[75665] 2016/04/26 15:14:59.971720 [DBG] 127.0.0.1:4248 - rid:1 - Registering remote route "xZfu3u7usAPWkuThomoGzM"
[75665] 2016/04/26 15:14:59.971731 [DBG] 127.0.0.1:4248 - rid:1 - Route sent local subscriptions
```

From the seed's server log, we see that the route is indeed accepted:

```
[75653] 2016/04/26 15:14:59.971602 [DBG] 127.0.0.1:52679 - rid:1 - Route connection created
[75653] 2016/04/26 15:14:59.971733 [DBG] 127.0.0.1:52679 - rid:1 - Registering remote route "53Yi78q96t52QdyyWLKIyE"
[75653] 2016/04/26 15:14:59.971739 [DBG] 127.0.0.1:52679 - rid:1 - Route sent local subscriptions
```

Finally, let's start the third server:

```
gnatsd -p 6222 -cluster nats://localhost:6248 -routes nats://localhost:4248 -D
```

Again, notice that we use a different client port and cluster address, but still point to the same seed server at the address `nats://localhost:4248`:

```
[75764] 2016/04/26 15:19:11.528185 [INF] Listening for route connections on localhost:6248
[75764] 2016/04/26 15:19:11.529787 [INF] Listening for client connections on 0.0.0.0:6222
[75764] 2016/04/26 15:19:11.529829 [DBG] server id is IRepas80TBwJByULX1ulAp
[75764] 2016/04/26 15:19:11.529842 [INF] server is ready
[75764] 2016/04/26 15:19:11.529872 [DBG] Trying to connect to route on localhost:4248
[75764] 2016/04/26 15:19:11.530272 [DBG] 127.0.0.1:4248 - rid:1 - Route connection created
[75764] 2016/04/26 15:19:11.530281 [DBG] 127.0.0.1:4248 - rid:1 - Route connect msg sent
[75764] 2016/04/26 15:19:11.530408 [DBG] 127.0.0.1:4248 - rid:1 - Registering remote route "xZfu3u7usAPWkuThomoGzM"
[75764] 2016/04/26 15:19:11.530414 [DBG] 127.0.0.1:4248 - rid:1 - Route sent local subscriptions
[75764] 2016/04/26 15:19:11.530595 [DBG] 127.0.0.1:52727 - rid:2 - Route connection created
[75764] 2016/04/26 15:19:11.530659 [DBG] 127.0.0.1:52727 - rid:2 - Registering remote route "53Yi78q96t52QdyyWLKIyE"
[75764] 2016/04/26 15:19:11.530664 [DBG] 127.0.0.1:52727 - rid:2 - Route sent local subscriptions
```

First a route is created to the seed server (`...GzM`) and after that, a route from `...IyE` - which is the ID of the second server - is accepted.

The log from the seed server shows that it accepted the route from the third server:

```
[75653] 2016/04/26 15:19:11.530308 [DBG] 127.0.0.1:52726 - rid:2 - Route connection created
[75653] 2016/04/26 15:19:11.530384 [DBG] 127.0.0.1:52726 - rid:2 - Registering remote route "IRepas80TBwJByULX1ulAp"
[75653] 2016/04/26 15:19:11.530389 [DBG] 127.0.0.1:52726 - rid:2 - Route sent local subscriptions
```

And the log from the second server shows that it connected to the third.

```
[75665] 2016/04/26 15:19:11.530469 [DBG] Trying to connect to route on 127.0.0.1:6248
[75665] 2016/04/26 15:19:11.530565 [DBG] 127.0.0.1:6248 - rid:2 - Route connection created
[75665] 2016/04/26 15:19:11.530570 [DBG] 127.0.0.1:6248 - rid:2 - Route connect msg sent
[75665] 2016/04/26 15:19:11.530644 [DBG] 127.0.0.1:6248 - rid:2 - Registering remote route "IRepas80TBwJByULX1ulAp"
[75665] 2016/04/26 15:19:11.530650 [DBG] 127.0.0.1:6248 - rid:2 - Route sent local subscriptions
```

At this point, there is a full mesh cluster of NATS servers.

## Securing NATS

This section describes how to secure the NATS server, including authentication, authorization, and encryption using TLS and bcrypt.

### Authentication

The NATS server supports single and multi-user/client authentication. See also the [server authentication](http://nats.io/documentation/server/gnatsd-authentication/) documentation.

**Single user authentication**

For single-user authentication, you can start the NATS server with authentication enabled by passing in the required credentials on the command line, or by passing in a token.

```
gnatsd -DV --user foo --pass bar
```

```
gnatsd -DV -auth 'S3Cr3T0k3n!'
```

Clients can connect using:

```
nats://foo:bar@localhost:4222
```

```
nats://S3Cr3T0k3n!@localhost:4222
```

You can also enable single-user authentication and set the credentials in the server configuration file as follows:

```
authorization {
  user:     derek
  password: T0pS3cr3t
  timeout:  1
}
```

**Multi-user authentication**

You can enable multi-user authentication using a NATS server configuration file that defines user credentials (`user` and `password`), and optionally `permissions`, for two or more users. Multi-user authentication leverages [variables](#variables).

```
authorization {
  users = [
    {user: value or $VARIABLE, password: value or $VARIABLE}
    {user: value or $VARIABLE, password: value or $VARIABLE, [permissions: $PERMISSION]}
    ...
  ]
}
```

For example:

```
authorization {
  PASS: abcdefghijklmnopqrstuvwxwz0123456789
  users = [
    {user: alice, password: foo, permissions: $ADMIN}
    {user: bob,   password: bar, permissions: $REQUESTOR}
    {user: joe,   password: $PASS}
  ]
}
```

### Authorization

The NATS server supports authorization using subject-level permissions on a per-user basis. Permission-based authorization is available with [multi-user authentication](#authentication). See also the [Server Authorization](http://nats.io/documentation/server/gnatsd-authorization) documentation.

Each permission grant is an object with two fields: what subject(s) the authenticated user can publish to, and what subject(s) the authenticated user can subscribe to. The parser is generous at understanding what the intent is, so both arrays and singletons are processed. Subjects themselves can contain wildcards. Permissions make use of [variables](#variables).

You set permissions by creating an entry inside of the `authorization` configuration block that conforms to the following syntax:

```
authorization {
  PERMISSION_NAME = {
    publish = "singleton" or ["array", ...]
    subscribe = "singleton" or ["array", ...]
  }
}
```

Here is an example authorization configuration that defines three users, two of whom are assigned explicit permissions.

```
authorization {
  ADMIN = {
    publish = ">"
    subscribe = ">"
  }
  REQUESTOR = {
    publish = ["req.foo", "req.bar"]
    subscribe = "_INBOX.*"
  }
  DEFAULT_PERMISSIONS = {
    publish = "SANDBOX.*"
    subscribe = ["PUBLIC.>", "_INBOX.>"]
  }

  PASS: abcdefghijklmnopqrstuvwxwz0123456789
  users = [
    {user: alice, password: foo, permissions: $ADMIN}
    {user: bob,   password: bar, permissions: $REQUESTOR}
    {user: joe,   password: $PASS}
  ]
}
```

Since Alice is an ADMIN she can publish/subscribe on any subject. We use the wildcard ">" to match any subject.

Bob is REQUESTOR and can publish requests on subjects "req.foo" or "req.bar", and subscribe to anything that is a response ("_INBOX.*").

Joe has no permission grant and therefore inherits the default permission set. You set the inherited default permissions by assigning them to the `default_permissions` entry inside of the `authorization` configuration block.

Note that `_INBOX.*` subscribe permissions must be granted in order to use the request APIs in Apcera supported clients. If an unauthorized client publishes or attempts to subscribe to a subject, the action fails and is logged at the server, and an error message is returned to the client.

### TLS

As of Release 0.7.0, the server can use modern TLS semantics for client connections, route connections, and the HTTPS monitoring port.
The server requires TLS version 1.2, and sets preferences for modern cipher suites that avoid those known with vulnerabilities. The
server's preferences when building with Go1.5 are as follows.

```go
func defaultCipherSuites() []uint16 {
	return []uint16{
		// The SHA384 versions are only in Go1.5+
		tls.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
		tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
		tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
		tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
	}
}
```
The curve preferences are also re-ordered to provide the most secure
environment available, and are as follows:
```go
func defaultCurvePreferences() []tls.CurveID {
	return []tls.CurveID{
		tls.CurveP521,
		tls.CurveP384,
		tls.CurveP256,
	}
}
```
Generating self signed certs and intermediary certificate authorities is beyond the scope here, but this document can be helpful in addition to Google Search: <a href="https://docs.docker.com/engine/articles/https/" target="_blank">https://docs.docker.com/engine/articles/https/</a>.

The server **requires** a certificate and private key. Optionally the server can require that clients need to present certificates, and the server can be configured with a CA authority to verify the client certificates.

```
# Simple TLS config file

listen: 127.0.0.1:4443

tls {
  cert_file:  "./configs/certs/server-cert.pem"
  key_file:   "./configs/certs/server-key.pem"
  timeout:    2
}

authorization {
  user:     derek
  password: $2a$11$W2zko751KUvVy59mUTWmpOdWjpEm5qhcCZRd05GjI/sSOT.xtiHyG
  timeout:  1
}
```

If requiring client certificates as well, simply change the TLS section as follows.

```
tls {
  cert_file: "./configs/certs/server-cert.pem"
  key_file:  "./configs/certs/server-key.pem"
  ca_file:   "./configs/certs/ca.pem"
  verify:    true
}
```

When setting up clusters, all servers in the cluster, if using TLS, will both verify the connecting endpoints and the server responses. So certificates are checked in both directions. Certificates can be configured only for the server's cluster identity, keeping client and server certificates separate from cluster formation.

```
cluster {
  listen: 127.0.0.1:4244

  tls {
    # Route cert
    cert_file: "./configs/certs/srva-cert.pem"
    # Private key
    key_file:  "./configs/certs/srva-key.pem"
    # Optional certificate authority verifying connected routes
    # Required when we have self-signed CA, etc.
    ca_file:   "./configs/certs/ca.pem"
  }
  # Routes are actively solicited and connected to from this server.
  # Other servers can connect to us if they supply the correct credentials
  # in their routes definitions from above.
  routes = [
    nats-route://127.0.0.1:4246
  ]
}
```

The server can be run using command line arguments to enable TLS functionality.

```
--tls                        Enable TLS, do not verify clients (default: false)
--tlscert FILE               Server certificate file
--tlskey FILE                Private key for server certificate
--tlsverify                  Enable TLS, verify client certificates
--tlscacert FILE             Client certificate CA for verification
```

Examples using the test certificates which are self signed for localhost and 127.0.0.1.

```bash
> ./gnatsd --tls --tlscert=./test/configs/certs/server-cert.pem --tlskey=./test/configs/certs/server-key.pem

[2935] 2016/04/26 13:34:30.685413 [INF] Starting nats-server version 0.8.0.beta
[2935] 2016/04/26 13:34:30.685509 [INF] Listening for client connections on 0.0.0.0:4222
[2935] 2016/04/26 13:34:30.685656 [INF] TLS required for client connections
[2935] 2016/04/26 13:34:30.685660 [INF] Server is ready
```

Notice that the log  indicates that the client connections will be required to use TLS. If you run the server in Debug mode with -D or -DV, the logs will show the cipher suite selection for each connected client.

```
[15146] 2015/12/03 12:38:37.733139 [DBG] ::1:63330 - cid:1 - Starting TLS client connection handshake
[15146] 2015/12/03 12:38:37.751948 [DBG] ::1:63330 - cid:1 - TLS handshake complete
[15146] 2015/12/03 12:38:37.751959 [DBG] ::1:63330 - cid:1 - TLS version 1.2, cipher suite TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
```

If you want the server to enforce and require client certificates as well via the command line, utilize this example.

```
> ./gnatsd --tlsverify --tlscert=./test/configs/certs/server-cert.pem --tlskey=./test/configs/certs/server-key.pem --tlscacert=./test/configs/certs/ca.pem
```

### Bcrypt

In addition to TLS functionality, the server now also supports bcrypt for passwords and tokens. This is transparent and you can simply replace the plaintext password in the configuration with the bcrypt hash, the server will automatically utilize bcrypt as needed.

There is a utility bundled under /util/mkpasswd. By default with no arguments it will generate a secure password and the associated hash. This can be used for a password or a token in the configuration. If you already have a password selected, you can supply that on stdin with the -p flag.

```bash
~/go/src/github.com/glycerine/gnatsd/util> ./mkpasswd
pass: #IclkRPHUpsTmACWzmIGXr
bcrypt hash: $2a$11$3kIDaCxw.Glsl1.u5nKa6eUnNDLV5HV9tIuUp7EHhMt6Nm9myW1aS
```

Add into the server configuration file's authorization section.
```
  authorization {
    user: derek
    password: $2a$11$3kIDaCxw.Glsl1.u5nKa6eUnNDLV5HV9tIuUp7EHhMt6Nm9myW1aS
  }
```

## Monitoring

If the monitoring port is enabled, the NATS server runs a lightweight HTTP server that has the following endpoints: /varz, /connz, /routez, and /subsz. All endpoints return a JSON object. See [NATS Server monitoring](http://nats.io/documentation/server/gnatsd-monitoring/) for endpoint examples.

To see a demonstration of NATS monitoring, run a command similar to the following for each desired endpoint:

```
curl demo.nats.io:8222/varz
```

To enable the monitoring server, start the NATS server with the monitoring flag `-m` (or `-ms`) and specify the monitoring port.

Monitoring options

    -m, --http_port PORT             HTTP PORT for monitoring
    -ms,--https_port PORT            Use HTTPS PORT for monitoring (requires TLS cert and key)

To enable monitoring via the configuration file, use `host:port` (there is no explicit configuration flag for the monitoring interface).

For example, running the `gnatsd -m 8222` command, you should see that the NATS server starts with the HTTP monitoring port enabled. To view the monitoring home page, go to <a href="http://localhost:8222/" target="_blank">http://localhost:8222/</a>.

```
[83249] 2016/06/23 19:39:35.173557 [INF] Starting nats-server version 0.8.0
[83249] 2016/06/23 19:39:35.173835 [INF] Starting http monitor on 0.0.0.0:8222
[83249] 2016/06/23 19:39:35.175193 [INF] Listening for client connections on 0.0.0.0:4222
[83249] 2016/06/23 19:39:35.175226 [INF] Server is ready
```

## License

(The MIT License)

Copyright (c) 2012-2016 Apcera Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to
deal in the Software without restriction, including without limitation the
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.

[License-Url]: http://opensource.org/licenses/MIT
[License-Image]: https://img.shields.io/badge/License-MIT-blue.svg
[Build-Status-Url]: http://travis-ci.org/nats-io/gnatsd
[Build-Status-Image]: https://travis-ci.org/nats-io/gnatsd.svg?branch=master
[Release-Url]: https://github.com/glycerine/gnatsd/releases/tag/v0.9.6
[Release-image]: http://img.shields.io/badge/release-v0.9.6-1eb0fc.svg
[Coverage-Url]: https://coveralls.io/r/nats-io/gnatsd?branch=master
[Coverage-image]: https://coveralls.io/repos/github/nats-io/gnatsd/badge.svg?branch=master
[ReportCard-Url]: http://goreportcard.com/report/nats-io/gnatsd
[ReportCard-Image]: http://goreportcard.com/badge/github.com/glycerine/gnatsd
[github-release]: https://github.com/glycerine/gnatsd/releases/


text:
"""Tests for `grumpy_tools` package."""

import tempfile
import unittest

import pytest

from click.testing import CliRunner

from grumpy_tools import cli

@pytest.fixture
def response():
    """Sample pytest fixture.

    See more at: http://doc.pytest.org/en/latest/fixture.html
    """
    # import requests
    # return requests.get('https://github.com/audreyr/cookiecutter-pypackage')

def test_content(response):
    """Sample pytest test function with the pytest fixture as an argument."""
    # from bs4 import BeautifulSoup
    # assert 'GitHub' in BeautifulSoup(response.content).title.string

@pytest.mark.xfail
def test_command_line_interface(capfd):
    """Test the CLI."""
    runner = CliRunner()
    out, err = capfd.readouterr()

    help_result = runner.invoke(cli.main, ['--help'])
    assert help_result.exit_code == 0

    result = runner.invoke(cli.main)
    assert result.exit_code == 0
    assert '>>> ' in out, (result.output, out, err)

def test_run_input_inline(capfd):
    runner = CliRunner()
    result = runner.invoke(cli.main, ['run', '-c', "print('Hello World')",])
    out, err = capfd.readouterr()
    assert out == 'Hello World\n', (err, result.output)
    assert result.exit_code == 0

def test_run_input_stdin(capfd):
    runner = CliRunner()
    result = runner.invoke(cli.main, ['run'], input="print('Hello World')")

    out, err = capfd.readouterr()
    assert out == 'Hello World\n', (err, result.output)
    assert result.exit_code == 0

def test_run_input_file(capfd):
    runner = CliRunner()
    with tempfile.NamedTemporaryFile() as script_file:
        script_file.write("print('Hello World')")
        script_file.flush()

        result = runner.invoke(cli.main, ['run', script_file.name])

    out, err = capfd.readouterr()
    assert out == 'Hello World\n', (err, result.output)
    assert result.exit_code == 0