kritbit

kritbit Commit Details


Date:2015-11-21 22:08:37 (9 years 1 month ago)
Author:Natalie Adams
Branch:master
Commit:9eccb77b6c4315e527821d45d172eed16cfa18dc
Parents: 6c436f3ff5b2594e7a7b4887a5f34d9ce015d879
Message:Adding jquery confirm on delete updating runcommand storing nonce to prevent replay attacks

Changes:

File differences

README.md
2727
2828
2929
30
30
31
32
33
34
35
36
- [AES PHP support](http://stackoverflow.com/a/8232171/195722)
- [CRON expression](https://github.com/mtdowling/cron-expression) - MIT
- [phpoauthlib2](https://srchub.org/p/phpoauthlib2/) - MIT
- [stacktraceprint](http://stackoverflow.com/a/4282133/195722)
- [stacktraceprint](http://stackoverflow.com/a/4282133/195722)
- [Twitter Bootstrap](http://getbootstrap.com/2.3.2/)
- [jQuery](https://jquery.com/)
- [jQuery confirm](http://craftpip.github.io/jquery-confirm/)
- [bootstrap fullscreen](http://craftpip.github.io/bootstrap-fullscreen-select/)
Made with <3 by Nathan Adams
scripts/runcommand.py
2121
2222
2323
24
25
26
27
2428
2529
30
31
32
33
34
2635
2736
2837
......
99108
100109
101110
102
111
103112
104
105
113
except ImportError:
from io import StringIO
#
# REPLACE THESE VALUES
#
SHARED_KEY = ""
HASH = ""
URL = ""
#
#
#
# source http://stackoverflow.com/a/8232171/195722
KEY_SIZE = 16
message["nonce"] = nonce
message["message"] = json.dumps({"output":out, "time_taken": total, "result": exitcode})
message["signature"] = hashlib.sha256(message["message"] + nonce + HASH).hexdigest()
print encrypt(SHARED_KEY, "test")
print hashlib.sha256(message["message"]).hexdigest()
message["message"] = encrypt(SHARED_KEY, message["message"])
print json.dumps(message)
print curl_post("http://192.168.128.36:8080/service/upload/5/", {"data": json.dumps(message)}).getvalue()
print curl_post(URL, {"data": json.dumps(message)}).getvalue()
web/application/config.php
11
2
2
33
44
55
6
7
8
9
10
11
612
713
<?php
date_default_timezone_set("America/Chicago");
$config["ADMINS"] = array("adamsna@datanethost.net");
$config["DATABASE_TYPE"] = "SQLITE";
$config["DATABASE_FILE"] = "kritbot.sqlite3";
$config["GOOGLE_OAUTH_ID"] = "";
$config["GOOGLE_OAUTH_SECRET"] = "";
$config["ACCEPTED_IPS"] = ["192.168.128.36", "127.0.0.1", "::1"];
return $config;
web/application/controllers/job.php
55
66
77
8
8
9
10
11
12
13
14
15
16
17
18
19
20
21
922
1023
1124
class job extends base {
public function add() {
if (!isset($_POST["jobName"])) {
$sharedkey = bin2hex(openssl_random_pseudo_bytes(16, $bool));
$keyChars = [
'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',
'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z',
'1','2','3','4','5','6','7','8','9','0',
'!','{','}','-','#','%','^','*','[',']','<','>',':','?'
];
shuffle($keyChars);
shuffle($keyChars);
$sharedkey = "";
$bool = true;
for($i = 0; $i < 32; $i++) {
$sharedkey .= $keyChars[mt_rand(0, count($keyChars) - 1)];
}
//$sharedkey = bin2hex(openssl_random_pseudo_bytes(16, $bool));
$hash = bin2hex(openssl_random_pseudo_bytes(32, $bool));
echo $this->loadRender("add.html", ["hash" => $hash, "sharedkey" => $sharedkey]);
} else {
web/application/controllers/login.php
1515
1616
1717
18
18
1919
2020
2121
$authProvider = new GoogleAuthProvider($_GET, [
"client_id" => $this->config["GOOGLE_OAUTH_ID"],
"client_secret" => $this->config["GOOGLE_OAUTH_SECRET"],
"redirect_uri" => "http://localhost/login"
"redirect_uri" => "http://localhost:8080/login"
]);
$oauth = new OAuth($authProvider, $_GET);
web/application/controllers/service.php
2424
2525
2626
27
28
29
30
31
32
33
34
35
36
27
28
29
30
31
32
33
34
35
36
37
38
39
3740
3841
3942
4043
4144
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
4557
4658
4759
*/
public function upload($jobId) {
if ($jobId && is_numeric($jobId)) {
try {
/** @var \application\models\Jobs $job */
$job = \application\models\Jobs::getByField("id", $jobId)[0];
//decrypt message
$data = json_decode($_POST["data"], true);
$rawMessage = aes_decrypt($job->sharedkey, $data["message"]);
} catch (\Exception $e) {
echo $e;
exit(1);
}
/** @var \application\models\Jobs $job */
$job = \application\models\Jobs::getByField("id", $jobId)[0];
//decrypt message
$data = json_decode($_POST["data"], true);
$rawMessage = aes_decrypt($job->sharedkey, $data["message"]);
/*$rawMessage = str_replace("\\n", "", $rawMessage);
$rawMessage = str_replace("\\r", "", $rawMessage);
$rawMessage = str_replace("\\", "", $rawMessage);*/
$rawMessage = preg_replace('/[^(\x20-\x7F)]*/','', $rawMessage);
// if decryption was successful -
// check signature
if (hash("sha256", $rawMessage . $data["nonce"] . $job->hash) == $data["signature"]) {
// the message is verified
$messageJson = json_decode($rawMessage);
$history = \application\models\Histories::create($messageJson);
$history->jobs_id = $job->id;
$message = json_decode($rawMessage, true);
$replayAttackCheck = DB::fetch("SELECT id FROM histories WHERE jobs_id = ? AND nonce = ?", [$job->id, $data["nonce"]]);
if (count($replayAttackCheck) == 0) {
$history = \application\models\Histories::create($message);
$history->run_date = date("Y-m-d H:i:s");
$history->jobs_id = $job->id;
$history->nonce = $data["nonce"];
$history->save();
$job->last_result = $history->result;
$job->last_run = $history->run_date;
$job->save();
}
}
}
}
web/application/migrations/3.php
99
1010
1111
12
12
13
1314
1415
15
16
jobs_id INTEGER,
run_date DATETIME,
time_taken DECIMAL(10,5),
result INTEGER
result INTEGER,
nonce VARCHAR(255)
);");
DB::query("INSERT INTO histories VALUES (null, 'THIS IS ONLY A TEST', 1, '2015-01-01', 10, 0)");
DB::query("INSERT INTO histories VALUES (null, 'THIS IS ONLY A TEST', 1, '2015-01-01', 10, 0, 'ABC')");
web/application/models/Histories.php
88
99
1010
11
1112
public $run_date;
public $time_taken;
public $result;
public $nonce;
}
web/application/views/base.html
77
88
99
10
1011
1112
1213
......
1617
1718
1819
20
21
1922
2023
2124
<script src="/media/js/jqueryui.js"></script>
<link rel="stylesheet" type="text/css" href="/media/css/jqueryui.css" />
<link rel="stylesheet" type="text/css" href="/media/css/jquery-confirm.min.css" />
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" integrity="sha512-dTfge/zgoMYpP7QbHy4gWMEGsbsdZeCXz7irItjcC3sPUFtf0kuFbDz/ixG7ArTxmDjLXDmezHubeNikyKGVyQ==" crossorigin="anonymous">
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js" integrity="sha512-K1qjQ+NcF2TYO/eI3M6v8EiNYZfA95pQumfvcVrTHtwQVDG+aHRqLi/ETn2uB+1JqwYqVG3LIvdm9lj6imS/pQ==" crossorigin="anonymous"></script>
<script src="/media/js/jquery-confirm.min.js"></script>
<title>{{title}}</title>
<style type="text/css">
.text-center {
web/application/views/main.html
3030
3131
3232
33
33
3434
3535
3636
......
4141
4242
4343
44
45
46
47
48
49
50
51
52
4453
<td>{{job.getLastRun}}</td>
<td>{{job.last_result}}</td>
<td><a class="btn btn-default" href="/history/view/{{job.jobName}}-{{job.id}}" role="button">History</a></td>
<td><a class="btn btn-danger" href="/job/delete/{{job.id}}" role="button">Delete</a></td>
<td><a class="btn btn-danger btn-delete" href="/job/delete/{{job.id}}" role="button">Delete</a></td>
{% if job.force_run == 1 %}
<td><a class="btn btn-warning" href="/job/force/{{job.id}}" role="button">Enabled</a></td>
{% else %}
</tbody>
</table>
<script type="text/javascript">
$(function () {
$('.btn-delete').confirm({
title: 'Confirm',
content: "Are you sure you want to delete this job?"
});
});
</script>
{% endblock %}
web/media/css/jquery-confirm.min.css
1
2
3
4
5
6
7
8
9
/*!
* jquery-confirm v2.0.0 (http://craftpip.github.io/jquery-confirm/)
* Author: boniface pereira
* Website: www.craftpip.com
* Contact: hey@craftpip.com
*
* Copyright 2013-2015 jquery-confirm
* Licensed under MIT (https://github.com/craftpip/jquery-confirm/blob/master/LICENSE)
*/body.jconfirm-noscroll{overflow:hidden!important}@-webkit-keyframes jconfirm-rotate{from{-webkit-transform:rotate(0deg);transform:rotate(0deg)}to{-webkit-transform:rotate(360deg);transform:rotate(360deg)}}@keyframes jconfirm-rotate{from{-webkit-transform:rotate(0deg);transform:rotate(0deg)}to{-webkit-transform:rotate(360deg);transform:rotate(360deg)}}.jconfirm{position:fixed;top:0;left:0;right:0;bottom:0;z-index:99999999;font-family:inherit;overflow:hidden}.jconfirm .jconfirm-bg{position:fixed;top:0;left:0;right:0;bottom:0;opacity:0;-webkit-transition:all .4s;transition:all .4s}.jconfirm .jconfirm-bg.seen{opacity:1}.jconfirm .jconfirm-scrollpane{position:fixed;top:0;left:0;right:0;bottom:0;overflow-y:auto}.jconfirm .jconfirm-box{background:white;border-radius:4px;position:relative;outline:0}.jconfirm .jconfirm-box div.closeIcon{height:20px;width:20px;position:absolute;top:12px;right:12px;cursor:pointer;opacity:.6;text-align:center;display:none}.jconfirm .jconfirm-box div.closeIcon:hover{opacity:1}.jconfirm .jconfirm-box div.title{font-size:24px;font-weight:bold;font-family:inherit;padding:10px 15px 5px}.jconfirm .jconfirm-box div.content{padding-top:10px;padding:10px 15px 10px}.jconfirm .jconfirm-box div.content:empty{height:40px;position:relative;opacity:.6}.jconfirm .jconfirm-box div.content:empty:before{content:'';height:20px;width:20px;border:solid 2px #aaa;position:absolute;left:50%;margin-left:-45px;border-radius:20%;-webkit-animation:jconfirm-rotate 1s infinite;animation:jconfirm-rotate 1s infinite}.jconfirm .jconfirm-box div.content:empty:after{content:'loading..';position:absolute;left:50%;margin-left:-15px}.jconfirm .jconfirm-box .buttons{padding:10px 15px}.jconfirm .jconfirm-box .buttons button+button{margin-left:5px}.jconfirm .jquery-clear{clear:both}.jconfirm.rtl{direction:rtl}.jconfirm.rtl div.closeIcon{left:12px;right:auto}.jconfirm.white .jconfirm-bg{background-color:rgba(0,0,0,0.2)}.jconfirm.white .jconfirm-box{box-shadow:0 2px 6px rgba(0,0,0,0.2);border-radius:5px}.jconfirm.white .jconfirm-box .buttons{float:right}.jconfirm.white .jconfirm-box .buttons button{border:0;background-image:none;text-transform:uppercase;font-size:14px;font-weight:bold;text-shadow:none;-webkit-transition:background .1s;transition:background .1s;color:white}.jconfirm.white .jconfirm-box .buttons button.btn-default{box-shadow:none;color:#333}.jconfirm.white .jconfirm-box .buttons button.btn-default:hover{background:#ddd}.jconfirm.black .jconfirm-bg{background-color:rgba(0,0,0,0.5)}.jconfirm.black .jconfirm-box{box-shadow:0 2px 6px rgba(0,0,0,0.2);background:#444;border-radius:5px;color:white}.jconfirm.black .jconfirm-box .buttons{float:right}.jconfirm.black .jconfirm-box .buttons button{border:0;background-image:none;text-transform:uppercase;font-size:14px;font-weight:bold;text-shadow:none;-webkit-transition:background .1s;transition:background .1s;color:white}.jconfirm.black .jconfirm-box .buttons button.btn-default{box-shadow:none;color:#fff;background:0}.jconfirm.black .jconfirm-box .buttons button.btn-default:hover{background:#666}.jconfirm.hololight .jconfirm-bg{background-color:rgba(0,0,0,0.5)}.jconfirm.hololight .jconfirm-box{box-shadow:0 2px 6px rgba(0,0,0,0.4);border-radius:2px;overflow:hidden}.jconfirm.hololight .jconfirm-box div.title{font-weight:inherit;border-bottom:solid 2px #76cfdf;color:#76cfdf}.jconfirm.hololight .jconfirm-box .buttons{border-top:solid 2px #e7e7e7;width:100%;float:none;padding:0}.jconfirm.hololight .jconfirm-box .buttons button{margin:0;border:0;background:#fff;border-radius:0;width:50%;padding:13px;font-size:16px;font-weight:bold;color:#666}.jconfirm.hololight .jconfirm-box .buttons button+button{border-left:solid 2px #e7e7e7}.jconfirm.holodark .jconfirm-bg{background-color:rgba(0,0,0,0.5)}.jconfirm.holodark .jconfirm-box{box-shadow:0 2px 6px rgba(0,0,0,0.4);border-radius:2px;background:#333;overflow:hidden}.jconfirm.holodark .jconfirm-box div.closeIcon{color:white}.jconfirm.holodark .jconfirm-box div.title{font-weight:inherit;border-bottom:solid 2px #76cfdf;color:#76cfdf}.jconfirm.holodark .jconfirm-box div.content{color:white}.jconfirm.holodark .jconfirm-box .buttons{border-top:solid 2px rgba(255,255,255,0.2);width:100%;float:none;padding:0}.jconfirm.holodark .jconfirm-box .buttons button{margin:0;border:0;background:#333;border-radius:0;width:50%;padding:13px;font-size:16px;font-weight:bold;color:#fff;text-shadow:none}.jconfirm.holodark .jconfirm-box .buttons button+button{border-left:solid 2px rgba(255,255,255,0.2)}.jconfirm .jconfirm-box.hilight{-webkit-animation:hilight .82s cubic-bezier(0.36,0.07,0.19,0.97) both;animation:hilight .82s cubic-bezier(0.36,0.07,0.19,0.97) both;-webkit-transform:translate3d(0,0,0);transform:translate3d(0,0,0)}@-webkit-keyframes hilight{10%,90%{-webkit-transform:translate3d(-2px,0,0);transform:translate3d(-2px,0,0)}20%,80%{-webkit-transform:translate3d(4px,0,0);transform:translate3d(4px,0,0)}30%,50%,70%{-webkit-transform:translate3d(-8px,0,0);transform:translate3d(-8px,0,0)}40%,60%{-webkit-transform:translate3d(8px,0,0);transform:translate3d(8px,0,0)}}@keyframes hilight{10%,90%{-webkit-transform:translate3d(-2px,0,0);transform:translate3d(-2px,0,0)}20%,80%{-webkit-transform:translate3d(4px,0,0);transform:translate3d(4px,0,0)}30%,50%,70%{-webkit-transform:translate3d(-8px,0,0);transform:translate3d(-8px,0,0)}40%,60%{-webkit-transform:translate3d(8px,0,0);transform:translate3d(8px,0,0)}}.jconfirm{-webkit-perspective:400px;perspective:400px}.jconfirm .jconfirm-box{opacity:1;-webkit-transition-property:-webkit-transform,opacity,box-shadow;transition-property:transform,opacity,box-shadow}.jconfirm .jconfirm-box.anim-top,.jconfirm .jconfirm-box.anim-left,.jconfirm .jconfirm-box.anim-right,.jconfirm .jconfirm-box.anim-bottom,.jconfirm .jconfirm-box.anim-opacity,.jconfirm .jconfirm-box.anim-zoom,.jconfirm .jconfirm-box.anim-scale,.jconfirm .jconfirm-box.anim-none,.jconfirm .jconfirm-box.anim-rotate,.jconfirm .jconfirm-box.anim-rotatex,.jconfirm .jconfirm-box.anim-rotatey,.jconfirm .jconfirm-box.anim-scaley,.jconfirm .jconfirm-box.anim-scalex{opacity:0}.jconfirm .jconfirm-box.anim-rotate{-webkit-transform:rotate(90deg);-ms-transform:rotate(90deg);transform:rotate(90deg)}.jconfirm .jconfirm-box.anim-rotatex{-webkit-transform:rotateX(90deg);transform:rotateX(90deg);-webkit-transform-origin:center;-ms-transform-origin:center;transform-origin:center}.jconfirm .jconfirm-box.anim-rotatey{-webkit-transform:rotatey(90deg);-ms-transform:rotatey(90deg);transform:rotatey(90deg);-webkit-transform-origin:center;-ms-transform-origin:center;transform-origin:center}.jconfirm .jconfirm-box.anim-scaley{-webkit-transform:scaley(1.5);-ms-transform:scaley(1.5);transform:scaley(1.5);-webkit-transform-origin:center;-ms-transform-origin:center;transform-origin:center}.jconfirm .jconfirm-box.anim-scalex{-webkit-transform:scalex(1.5);-ms-transform:scalex(1.5);transform:scalex(1.5);-webkit-transform-origin:center;-ms-transform-origin:center;transform-origin:center}.jconfirm .jconfirm-box.anim-top{-webkit-transform:translate(0px,-100px);-ms-transform:translate(0px,-100px);transform:translate(0px,-100px)}.jconfirm .jconfirm-box.anim-left{-webkit-transform:translate(-100px,0px);-ms-transform:translate(-100px,0px);transform:translate(-100px,0px)}.jconfirm .jconfirm-box.anim-right{-webkit-transform:translate(100px,0px);-ms-transform:translate(100px,0px);transform:translate(100px,0px)}.jconfirm .jconfirm-box.anim-bottom{-webkit-transform:translate(0px,100px);-ms-transform:translate(0px,100px);transform:translate(0px,100px)}.jconfirm .jconfirm-box.anim-zoom{-webkit-transform:scale(1.2);-ms-transform:scale(1.2);transform:scale(1.2)}.jconfirm .jconfirm-box.anim-scale{-webkit-transform:scale(0.5);-ms-transform:scale(0.5);transform:scale(0.5)}.jconfirm .jconfirm-box.anim-none{display:none}.jconfirm.supervan .jconfirm-bg{background-color:rgba(54,70,93,0.95)}.jconfirm.supervan .jconfirm-box{background-color:transparent}.jconfirm.supervan .jconfirm-box div.closeIcon{color:white}.jconfirm.supervan .jconfirm-box div.title{text-align:center;color:white;font-size:28px;font-weight:normal}.jconfirm.supervan .jconfirm-box div.content{text-align:center;color:white}.jconfirm.supervan .jconfirm-box .buttons{text-align:center}.jconfirm.supervan .jconfirm-box .buttons button{font-size:16px;border-radius:2px;background:#303f53;text-shadow:none;border:0;color:white;width:25%;padding:10px}
web/media/js/jquery-confirm.min.js
1
2
3
4
5
6
7
8
9
10
/*!
* jquery-confirm v2.0.0 (http://craftpip.github.io/jquery-confirm/)
* Author: Boniface Pereira
* Website: www.craftpip.com
* Contact: hey@craftpip.com
*
* Copyright 2013-2015 jquery-confirm
* Licensed under MIT (https://github.com/craftpip/jquery-confirm/blob/master/LICENSE)
*/
if(typeof jQuery==="undefined"){throw new Error("jquery-confirm requires jQuery")}var jconfirm,Jconfirm;(function(b){b.fn.confirm=function(c){if(typeof c==="undefined"){c={}}var d=b(this);d.on("click",function(f){f.preventDefault();if(d.attr("href")){c.confirm=function(){location.href=d.attr("href")}}b.confirm(c)});return d};b.confirm=function(c){return jconfirm(c)};b.alert=function(c){c.cancelButton=false;return jconfirm(c)};b.dialog=function(c){c.cancelButton=false;c.confirmButton=false;c.confirmKeys=[13];return jconfirm(c)};jconfirm=function(c){if(typeof c==="undefined"){c={}}if(jconfirm.defaults){b.extend(jconfirm.pluginDefaults,jconfirm.defaults)}var c=b.extend({},jconfirm.pluginDefaults,c);return new Jconfirm(c)};Jconfirm=function(c){b.extend(this,c);this._init()};Jconfirm.prototype={_init:function(){var c=this;this._rand=Math.round(Math.random()*99999);this._buildHTML();this._bindEvents();setTimeout(function(){c.open()},0)},animations:["anim-scale","anim-top","anim-bottom","anim-left","anim-right","anim-zoom","anim-opacity","anim-none","anim-rotate","anim-rotatex","anim-rotatey","anim-scalex","anim-scaley"],_buildHTML:function(){this.animation="anim-"+this.animation.toLowerCase();this.closeAnimation="anim-"+this.closeAnimation.toLowerCase();this.$el=b(this.template).appendTo(this.container).addClass(this.theme);this.$el.find(".jconfirm-box-container").addClass(this.columnClass);this.CSS={"-webkit-transition-duration":this.animationSpeed/1000+"s","transition-duration":this.animationSpeed/1000+"s","-webkit-transition-timing-function":"cubic-bezier(.38,1.28,.2, "+this.animationBounce+")","transition-timing-function":"cubic-bezier(.38,1.28,.2, "+this.animationBounce+")"};this.$el.find(".jconfirm-bg").css(this.CSS);this.$b=this.$el.find(".jconfirm-box").css(this.CSS).addClass(this.animation);this.$body=this.$b;if(this.rtl){this.$el.addClass("rtl")}this.$title=this.$el.find("div.title");this.setTitle();this.contentDiv=this.$el.find("div.content");this.$content=this.contentDiv;this.$btnc=this.$el.find(".buttons");if(this.confirmButton&&this.confirmButton.trim()!==""){this.$confirmButton=b('<button class="btn">'+this.confirmButton+"</button>").appendTo(this.$btnc).addClass(this.confirmButtonClass)}if(this.cancelButton&&this.cancelButton.trim()!==""){this.$cancelButton=b('<button class="btn">'+this.cancelButton+"</button>").appendTo(this.$btnc).addClass(this.cancelButtonClass)}if(!this.confirmButton&&!this.cancelButton){this.$btnc.remove()}if(!this.confirmButton&&!this.cancelButton&&this.closeIcon===null){this.$closeButton=this.$b.find(".closeIcon").show()}if(this.closeIcon===true){this.$closeButton=this.$b.find(".closeIcon").show()}this.setContent();if(this.autoClose){this._startCountDown()}},setTitle:function(c){this.title=(typeof c!=="undefined")?c:this.title;if(this.title&&this.$title){this.$title.html('<i class="'+this.icon+'"></i> '+this.title)}else{this.$title.remove()}},setContent:function(e){var f=this;this.content=(e)?e:this.content;var c=(e)?true:false;if(typeof this.content==="boolean"){if(!this.content){this.contentDiv.remove()}else{console.error("Invalid option for property content: passed TRUE")}}else{if(typeof this.content==="string"){if(this.content.substr(0,4).toLowerCase()==="url:"){this.contentDiv.html("");this.$btnc.find("button").prop("disabled",true);var d=this.content.substring(4,this.content.length);b.get(d).done(function(h){f.contentDiv.html(h)}).always(function(i,h,j){if(typeof f.contentLoaded==="function"){f.contentLoaded(i,h,j)}f.$btnc.find("button").prop("disabled",false);f.setDialogCenter()})}else{this.contentDiv.html(this.content)}}else{if(typeof this.content==="function"){this.contentDiv.html("");this.$btnc.find("button").attr("disabled","disabled");var g=this.content(this);if(typeof g!=="object"){console.error("The content function must return jquery promise.")}else{if(typeof g.always!=="function"){console.error("The object returned is not a jquery promise.")}else{g.always(function(i,h){f.$btnc.find("button").removeAttr("disabled");f.setDialogCenter()})}}}else{console.error("Invalid option for property content, passed: "+typeof this.content)}}}this.setDialogCenter(c)},_startCountDown:function(){var c=this.autoClose.split("|");if(/cancel/.test(c[0])&&this.type==="alert"){return false}else{if(/confirm|cancel/.test(c[0])){this.$cd=b('<span class="countdown">').appendTo(this["$"+c[0]+"Button"]);var d=this;d.$cd.parent().click();var e=c[1]/1000;this.interval=setInterval(function(){d.$cd.html(" ["+(e-=1)+"]");if(e===0){d.$cd.parent().trigger("click");clearInterval(d.interval)}},1000)}else{console.error("Invalid option "+c[0]+", must be confirm/cancel")}}},_bindEvents:function(){var d=this;var c=false;this.$el.find(".jconfirm-scrollpane").click(function(f){if(!c){if(d.backgroundDismiss){d.cancel();d.close()}else{d.$b.addClass("hilight");setTimeout(function(){d.$b.removeClass("hilight")},400)}}c=false});this.$el.find(".jconfirm-box").click(function(f){c=true});if(this.$confirmButton){this.$confirmButton.click(function(g){g.preventDefault();var f=d.confirm(d.$b);d.onAction("confirm");if(typeof f==="undefined"||f){d.close()}})}if(this.$cancelButton){this.$cancelButton.click(function(g){g.preventDefault();var f=d.cancel(d.$b);d.onAction("cancel");if(typeof f==="undefined"||f){d.close()}})}if(this.$closeButton){this.$closeButton.click(function(f){f.preventDefault();d.cancel();d.onAction("close");d.close()})}if(this.keyboardEnabled){setTimeout(function(){b(window).on("keyup."+this._rand,function(f){d.reactOnKey(f)})},500)}b(window).on("resize."+this._rand,function(){d.setDialogCenter(true)})},reactOnKey:function a(f){var c=b(".jconfirm");if(c.eq(c.length-1)[0]!==this.$el[0]){return false}var d=f.which;if(this.contentDiv.find(":input").is(":focus")&&/13|32/.test(d)){return false}if(b.inArray(d,this.cancelKeys)!==-1){if(!this.backgroundDismiss){this.$el.find(".jconfirm-bg").click();return false}if(this.$cancelButton){this.$cancelButton.click()}else{this.close()}}if(b.inArray(d,this.confirmKeys)!==-1){if(this.$confirmButton){this.$confirmButton.click()}}},setDialogCenter:function(d){var h=b(window).height();var g=this.$b.outerHeight();var c=(h-g)/2;var f=100;if(g>(h-f)){var e={"margin-top":f/2,"margin-bottom":f/2}}else{var e={"margin-top":c}}if(d){this.$b.animate(e,{duration:this.animationSpeed,queue:false})}else{this.$b.css(e)}},close:function(){var c=this;if(this.isClosed()){return false}if(typeof this.onClose==="function"){this.onClose()}b(window).unbind("resize."+this._rand);if(this.keyboardEnabled){b(window).unbind("keyup."+this._rand)}c.$el.find(".jconfirm-bg").removeClass("seen");this.$b.addClass(this.closeAnimation);var d=(this.closeAnimation=="anim-none")?0:this.animationSpeed;setTimeout(function(){c.$el.remove()},d+50);jconfirm.record.closed+=1;jconfirm.record.currentlyOpen-=1;if(jconfirm.record.currentlyOpen<1){b("body").removeClass("jconfirm-noscroll")}return true},open:function(){var d=this;if(this.isClosed()){return false}d.$el.find(".jconfirm-bg").addClass("seen");b("body").addClass("jconfirm-noscroll");this.$b.removeClass(this.animations.join(" "));this.$b.find("input[autofocus]:visible:first").focus();jconfirm.record.opened+=1;jconfirm.record.currentlyOpen+=1;if(typeof this.onOpen==="function"){this.onOpen()}var c="jconfirm-box"+this._rand;this.$b.attr("aria-labelledby",c).attr("tabindex",-1).focus();if(this.$title){this.$title.attr("id",c)}else{if(this.$content){this.$content.attr("id",c)}}return true},isClosed:function(){return this.$el.css("display")===""}};jconfirm.pluginDefaults={template:'<div class="jconfirm"><div class="jconfirm-bg"></div><div class="jconfirm-scrollpane"><div class="container"><div class="row"><div class="jconfirm-box-container span6 offset3"><div class="jconfirm-box" role="dialog" aria-labelledby="labelled" tabindex="-1"><div class="closeIcon"><span class="glyphicon glyphicon-remove"></span></div><div class="title"></div><div class="content"></div><div class="buttons"></div><div class="jquery-clear"></div></div></div></div></div></div></div>',title:"Hello",content:"Are you sure to continue?",contentLoaded:function(){},icon:"",confirmButton:"Okay",cancelButton:"Cancel",confirmButtonClass:"btn-default",cancelButtonClass:"btn-default",theme:"white",animation:"zoom",closeAnimation:"scale",animationSpeed:500,animationBounce:1.2,keyboardEnabled:false,rtl:false,confirmKeys:[13,32],cancelKeys:[27],container:"body",confirm:function(){},cancel:function(){},backgroundDismiss:true,autoClose:false,closeIcon:null,columnClass:"col-md-4 col-md-offset-4",onOpen:function(){},onClose:function(){},onAction:function(){}};jconfirm.record={opened:0,closed:0,currentlyOpen:0}})(jQuery);

Archive Download the corresponding diff file

Branches

Number of commits:
Page rendered in 0.08506s using 14 queries.