kritbit

kritbit Commit Details


Date:2015-11-22 14:34:26 (9 years 29 days ago)
Author:Natalie Adams
Branch:master
Commit:555bd1d25a7c972c853b0d8d07582942ea929d0f
Parents: 8a032e1f54dbdb4c9b9d5e35ab0a647beb25ed65
Message:Updating readme Adding kritbit maintenance program

Changes:

File differences

README.md
1717
1818
1919
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
2059
2160
2261
......
3372
3473
3574
75
3676
3777
Kritbit is designed to be simple and flexible. It makes no assumptions about your security and only provides minimal security procedures. I am not a crypto expert - but I make tools that work. So while I cannot guarantee that big brother won't be able to decrypt messages from external services - it should be good enough for most implementations. So please, if you find that the crypto security is less than perfect I accept patches of any size, creed, or color. The encryption technology used isn't meant to prevent a guy with a Beowulf cluster from cracking your message - but rather preventing some script kiddie with Firesheep from seeing what you are doing.
# Authentication/Authorization
Each user logs in using OAuth (see below for setup) and can only edit jobs that they have created (there are no groups or way of "granting" permission). A job history can have a flag to allow anonymous users to view the history. However, kritbit does not censor the output so be careful allowing people to view history of jobs that may contain sensitive information.
# Install
1. Copy web/application/config.dist.php to web/application/config.php
2. Edit values for your environment[1]
3. Run `php migrations.php run` to setup your database
4. Run `php kritbit.php all-clear` to remove all sample data populated from the migrations
5. Run `php kritbit.php adduser you@gmail.com` to add yourself as an authorized user
6. Navigate to http://example.com/kritbit and you should be prompted to login with Google
[1] - Kritbit is designed to authenticate through Google OAuth. Since Kritbit uses an OAuth library you can really use any OAuth provider such as Facebook (which is included).
You must remember to change the REDIRECT_URI in config.php. If you don't want to use OAuth for login but want local users or Apache basic auth - all you have to do is modify login.php to read the user from those sources (which should be pretty simple as the login code there is very simple).
To get OAuth keys needed for Google Auth you need to create a project on [Google's Developers Dashboard](https://console.developers.google.com/), which is free.
kritbit can run on SQLite - however if you are going to deal with any volume you should use MySQL/MaraiaDB (other databases can be used - but you will need to modify some code).
To use MySQL/MaraiaDB specify in config.php (MariaDB is a drop-in replacement for MySQL so it doesn't matter if you specify MySQL):
$config["DATABASE_TYPE"] = "MySQL";
$config['MYSQL_DBNAME'] = "dbname";
$config['MYSQL_HOST'] = "localhost";
$config['MYSQL_USER'] = "user";
$config['MYSQL_PASS'] = "pass";
# Long-term TODO
- Provide a way to offer more customization for viewing job information. Right now it's very generic - but it might be useful to be able to parse output and present custom columns or other data.
- Permission matrix allowing people to grant fine permissions to jobs and job history
# Patches
Patches are welcome of any kind. But please do note that your code will be integrated into the project under the MIT license. Mention to your contribution may not appear in the code or file. But we can certainly make mention on the README describing your contribution.
# Attributions
Kritbit uses the following projects
- [jQuery confirm](http://craftpip.github.io/jquery-confirm/)
- [bootstrap fullscreen](http://craftpip.github.io/bootstrap-fullscreen-select/)
- [dynatable](http://www.dynatable.com/)
- [is_cli](http://stackoverflow.com/a/25967493/195722)
Made with <3 by Nathan Adams
web/application/config.dist.php
88
99
1010
11
12
13
14
1115
$config["GOOGLE_OAUTH_ID"] = "";
$config["GOOGLE_OAUTH_SECRET"] = "";
$config["ACCEPTED_IPS"] = ["127.0.0.1", "::1"];
$config["REDIRECT_URI"] = "";
return $config;
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:8080/login"
"redirect_uri" => $this->config["REDIRECT_URI"]
]);
$oauth = new OAuth($authProvider, $_GET);
web/kritbit.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php
spl_autoload_extensions(".php"); // comma-separated list
spl_autoload_register();
foreach (glob("system/vendor/*.php") as $filename)
{
include $filename;
}
if (!is_cli()) {
die("This script must be ran from the command line");
}
$core = new \system\engine\HF_Core(true);
$core->setupDatabaseConnection();
if (count($argv) == 1) {
echo "Possible commands are all-clear or adduser";
exit(0);
}
switch ($argv[1]) {
case "all-clear":
\vendor\DB\DB::query("DELETE FROM histories");
\vendor\DB\DB::query("DELETE FROM users");
\vendor\DB\DB::query("DELETE FROM sessions");
\vendor\DB\DB::query("DELETE FROM jobs");
break;
case "adduser":
$user = $argv[2];
\vendor\DB\DB::query("INSERT INTO users VALUES (null, ?)", [$user]);
break;
}
web/migrations.php
11
22
3
4
35
46
57
......
810
911
1012
13
14
15
16
1117
1218
<?php
spl_autoload_extensions(".php"); // comma-separated list
spl_autoload_register();
include $filename;
}
if (!is_cli()) {
die("This script must be ran from the command line");
}
$core = new \system\engine\HF_Core(true);
$core->runMigrations();
web/system/engine/HF_Core.php
283283
284284
285285
286
287
286
288287
289288
290289
291290
292291
293
294
295
296
297
298
299
300
301
302
292
293
294
295
296
297
298
299
300
301
303302
304303
305
304
305
306306
307
308
309
307310
308311
309312
}
}
public function runMigrations() {
global $argv;
public function setupDatabaseConnection() {
switch($this->config["DATABASE_TYPE"]) {
case "SQLITE":
DB::$c = new \PDO("sqlite:" . $this->config["DATABASE_FILE"]);
break;
case "MySQL":
DB::$c = new \PDO(
"mysql:dbname={$this->config['MYSQL_DBNAME']};host={$this->config['MYSQL_HOST']}",
$this->config['MYSQL_USER'],
$this->config['MYSQL_PASS'],
array(
\PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8",
\PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_OBJ,
\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION
)
);
DB::$c = new \PDO(
"mysql:dbname={$this->config['MYSQL_DBNAME']};host={$this->config['MYSQL_HOST']}",
$this->config['MYSQL_USER'],
$this->config['MYSQL_PASS'],
array(
\PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8",
\PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_OBJ,
\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION
)
);
break;
}
DB::$c->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
DB::$c->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
}
public function runMigrations() {
global $argv;
$this->setupDatabaseConnection();
DB::query("CREATE TABLE IF NOT EXISTS migrations (
id INTEGER PRIMARY KEY AUTOINCREMENT,
migration INTEGER,
web/system/vendor/is_cli.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<?php
function is_cli()
{
if( defined('STDIN') )
{
return true;
}
if( empty($_SERVER['REMOTE_ADDR']) and !isset($_SERVER['HTTP_USER_AGENT']) and count($_SERVER['argv']) > 0)
{
return true;
}
return false;
}

Archive Download the corresponding diff file

Branches

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