index.php 4.75 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<?php
/* Skynet - Automated "Cloud" Security Scanner                                *#
#* Copyright (C) 2014-present  Jason Frisvold <friz@godshell.com>             *#
#*                                                                            *#
#* This program is free software; you can redistribute it and/or modify       *#
#* it under the terms of the GNU General Public License as published by       *#
#* the Free Software Foundation; either version 2 of the License, or          *#
#* (at your option) any later version.                                        *#
#*                                                                            *#
#* This program is distributed in the hope that it will be useful,            *#
#* but WITHOUT ANY WARRANTY; without even the implied warranty of             *#
#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              *#
#* GNU General Public License for more details.                               *#
#*                                                                            *#
#* You should have received a copy of the GNU General Public License          *#
#* along with this program; if not, write to the Free Software                *#
#* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */

   // Define skynet (to allow access to files)
   define('skynet', 1);

22
   // Load framework
23
   require '../app/vendor/autoload.php';
24
25

   // Load the configuration file
26
   require_once('../app/config.php');
27

28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
   // Load ORM
   use Illuminate\Database\Capsule\Manager as Capsule;

   // Initiate ORM instance
   $sqlhdlr = new Capsule;

   $sqlhdlr->addConnection([
       'driver'    => 'mysql',
       'host'      => $skynet_dbHost,
       'database'  => $skynet_dbName,
       'username'  => $skynet_dbUser,
       'password'  => $skynet_dbPass,
       'charset'   => 'utf8',
       'collation' => 'utf8_unicode_ci',
       'prefix'    => '',
       ]);

45
   // Set the event dispatcher used by Eloquent models...
46
47
48
49
   use Illuminate\Events\Dispatcher;
   use Illuminate\Container\Container;
   $sqlhdlr->setEventDispatcher(new Dispatcher(new Container));

50
   // Make this Capsule instance available globally via static methods...
51
52
   $sqlhdlr->setAsGlobal();

53
   // Setup the Eloquent ORM...
54
55
   $sqlhdlr->bootEloquent();

56
   // Global array for Smarty data
57
   $smarty_data = array(
58
59
60
61
       'skynet_favicon' => $skynet_favicon,
       'skynet_stylesheet' => $skynet_stylesheet,
       'skynet_homepage' => $skynet_homepage,
       'skynet_version' => $skynet_version,
62
63
       'skynet_useCDN' => $skynet_useCDN,
       'skynet_bootstrap_root' => $skynet_bootstrap_root,
64
65
66
   );

   // Instantiate a slim instance
67
   $app = new \Slim\Slim(array(
68
69
70
71
72
73
74
      'view' => new \Slim\Views\Smarty(),
      'debug' => true,
      'log.enable' => true,
      'log.path' => 'logs/',
      'log.level' => 4,
      'mode' => 'development',
      'templates.path' => '../app/templates'
75
76
       ));
   
77
78
   // We want to use Smarty for templates, this sets up the necessary Smarty
   // configuration within Slim
79
80
81
82
   $view = $app->view();
   $view->parserCompileDirectory = "$skynet_work_dir/templates_c";
   $view->parserCacheDirectory = "$skynet_work_dir/cache";
   $view->parserExtensions = array(
83
      '../app/libs',
84
85
   );

86
87
88
   $app->hook('slim.before', function () use ($app) {
      $app->view()->appendData(array('baseUrl' => '/index.php/'));
   });
89

90
91
   // Load the authentication routes
   include('../app/authentication.php');
92

93
94
   // Load the report routes
   include('../app/reports.php');
95

96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
   // Home Page Route
   $app->get('/', $isauthenticated(), function () use ($app) {
      global $smarty_data, $sqlhdlr;

      $smarty_data['total_servers'] = $sqlhdlr->table('cloud')
         ->where('disabled', 0)
         ->count();
      $smarty_data['total_scanners'] = $sqlhdlr->table('spawn')
         ->where('disabled', 0)
         ->count();
      $smarty_data['total_targets'] = $sqlhdlr->table('target')
         ->where('disabled', 0)
         ->count();
      $smarty_data['total_timers'] = $sqlhdlr->table('timers')
         ->where('disabled', 0)
         ->count();
      $smarty_data['total_results'] = $sqlhdlr->table('results')
         ->count();
114

115
116
      prep_smarty($app);

117
      $app->render('main.tpl', $smarty_data);
118
119
120
121
   
   });

   // About Page
122
   $app->get('/about', $isauthenticated('guest'), function () use ($app) {
123
      global $smarty_data;
124
125
   
      prep_smarty($app);
126

127
      $app->render('about.tpl', $smarty_data);
128
129
130
131
   
   });

   $app->run();
132

133
134
135
136
137
138
139
140
141
142
143
   // Loads the whitespace_control filter for handling comments within the
   // Smarty templates
   function prep_smarty($app) {
      global $skynet_debug;

      $smarty = $app->view()->getInstance();
      $smarty->loadFilter("pre", 'whitespace_control');
      $smarty->debugging = $skynet_debug;
   }

?>