index.php 5.03 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
   // Load ORM
   use Illuminate\Database\Capsule\Manager as Capsule;
   use Illuminate\Events\Dispatcher;
   use Illuminate\Container\Container;

33
   // Global array for Smarty data
34
   $smarty_data = array(
35
36
37
38
       'skynet_favicon' => $skynet_favicon,
       'skynet_stylesheet' => $skynet_stylesheet,
       'skynet_homepage' => $skynet_homepage,
       'skynet_version' => $skynet_version,
39
40
       'skynet_useCDN' => $skynet_useCDN,
       'skynet_bootstrap_root' => $skynet_bootstrap_root,
41
42
43
   );

   // Instantiate a slim instance
44
   $app = new \Slim\Slim(array(
45
46
47
48
49
50
51
      'view' => new \Slim\Views\Smarty(),
      'debug' => true,
      'log.enable' => true,
      'log.path' => 'logs/',
      'log.level' => 4,
      'mode' => 'development',
      'templates.path' => '../app/templates'
52
53
       ));
   
54
55
   // We want to use Smarty for templates, this sets up the necessary Smarty
   // configuration within Slim
56
57
58
59
   $view = $app->view();
   $view->parserCompileDirectory = "$skynet_work_dir/templates_c";
   $view->parserCacheDirectory = "$skynet_work_dir/cache";
   $view->parserExtensions = array(
60
      '../app/libs',
61
62
   );

63
64
65
   $app->hook('slim.before', function () use ($app) {
      $app->view()->appendData(array('baseUrl' => '/index.php/'));
   });
66

67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
   // Register the DB handler as a framework singleton
   $app->container->singleton('db', function () use ($app) {
      global $skynet_dbHost, $skynet_dbName, $skynet_dbUser, $skynet_dbPass;
   
      // 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'    => '',
          ]);
   
      // Set the event dispatcher used by Eloquent models...
      $sqlhdlr->setEventDispatcher(new Dispatcher(new Container));
   
      // Make this Capsule instance available globally via static methods...
      $sqlhdlr->setAsGlobal();
   
      // Setup the Eloquent ORM...
      $sqlhdlr->bootEloquent();
      
      return $sqlhdlr;
   });

97
98
   // Load the authentication routes
   include('../app/authentication.php');
99

100
101
   // Load the report routes
   include('../app/reports.php');
102

103
104
   // Home Page Route
   $app->get('/', $isauthenticated(), function () use ($app) {
105
      global $smarty_data;
106

107
      $smarty_data['total_servers'] = $app->db->table('cloud')
108
109
         ->where('disabled', 0)
         ->count();
110
      $smarty_data['total_scanners'] = $app->db->table('spawn')
111
112
         ->where('disabled', 0)
         ->count();
113
      $smarty_data['total_targets'] = $app->db->table('target')
114
115
         ->where('disabled', 0)
         ->count();
116
      $smarty_data['total_timers'] = $app->db->table('timers')
117
118
         ->where('disabled', 0)
         ->count();
119
      $smarty_data['total_results'] = $app->db->table('results')
120
         ->count();
121

122
123
      prep_smarty($app);

124
      $app->render('main.tpl', $smarty_data);
125
126
127
128
   
   });

   // About Page
129
   $app->get('/about', $isauthenticated('guest'), function () use ($app) {
130
      global $smarty_data;
131
132
   
      prep_smarty($app);
133

134
      $app->render('about.tpl', $smarty_data);
135
136
137
138
   
   });

   $app->run();
139

140
141
142
143
144
145
146
147
148
149
150
   // 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;
   }

?>