Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Godshell
Skynet
Commits
162e9384
Commit
162e9384
authored
Nov 10, 2014
by
Jason Frisvold
Browse files
- Change the database object into a slim singleton
parent
9901fd59
Changes
5
Show whitespace changes
Inline
Side-by-side
gui/app/authentication.php
View file @
162e9384
...
...
@@ -16,14 +16,14 @@
#* along with this program; if not, write to the Free Software *#
#* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
$isauthenticated
=
function
(
$role
=
'user'
)
{
return
function
()
use
(
$role
)
{
$isauthenticated
=
function
(
$role
=
'user'
)
use
(
$app
)
{
return
function
()
use
(
$app
,
$role
)
{
// Globalize the phptodo variables needed
global
$skynet_sessTime
,
$skynet_serveruri
,
$smarty_data
,
$sqlhdlr
;
global
$skynet_sessTime
,
$skynet_serveruri
,
$smarty_data
;
// Try and get the id, last time, and user id from the sessions
// database
$result
=
$
sqlhdlr
->
table
(
'sessions'
)
$result
=
$
app
->
db
->
table
(
'sessions'
)
->
select
(
'id'
,
'last'
,
'user_id'
)
->
where
(
'phpsessid'
,
'='
,
session_id
())
->
first
();
...
...
@@ -36,14 +36,14 @@
// Check to see if an id was set, and if the time is valid
if
((
isset
(
$id
))
&&
((
$last
+
$skynet_sessTime
)
>=
time
()))
{
// Good session, update the timestamp
$
sqlhdlr
->
table
(
'sessions'
)
$
app
->
db
->
table
(
'sessions'
)
->
where
(
'id'
,
'='
,
$id
)
->
update
(
array
(
'last'
=>
time
()));
// Create the user object
$user_obj
=
new
skynetUser
(
$
sqlhdlr
,
$user_id
);
$user_obj
=
new
skynetUser
(
$
app
->
db
,
$user_id
);
// Assign the appropriate data to the smarty
$smarty_data
array
// Assign the appropriate data to the smarty array
$smarty_data
[
'username'
]
=
$user_obj
->
username
();
$smarty_data
[
'adminflag'
]
=
$user_obj
->
adminflag
();
...
...
@@ -51,8 +51,8 @@
$smarty_data
[
'fullname'
]
=
stripslashes
(
htmlentities
(
$user_obj
->
fullname
(),
ENT_QUOTES
));
}
else
{
$smarty_data
[
'fullname'
]
=
htmlentities
(
$user_obj
->
fullname
(),
ENT_QUOTES
);
$smarty_data
[
'fullname'
]
=
htmlentities
(
$user_obj
->
fullname
(),
ENT_QUOTES
);
}
return
(
$user_obj
);
...
...
gui/app/libs/sec_check.php
View file @
162e9384
...
...
@@ -24,10 +24,10 @@ session_start();
function
login
(
$username
,
$password
)
{
// Globalize the phptodo variables needed
global
$skynet_sessTime
,
$
sqlhdlr
;
global
$skynet_sessTime
,
$
app
;
// Create user class
$user_obj
=
new
skynetUser
(
$
sqlhdlr
,
-
1
,
$username
,
$password
,
true
);
$user_obj
=
new
skynetUser
(
$
app
->
db
,
-
1
,
$username
,
$password
,
true
);
if
(
$user_obj
->
logged_in
())
{
// Regenerate the session ID (security enhancement)
...
...
@@ -35,7 +35,7 @@ function login($username, $password) {
// Insert the user_id into the sessions database along with the
// session ID and the current time
$
sqlhdlr
->
table
(
'sessions'
)
$
app
->
db
->
table
(
'sessions'
)
->
insert
(
array
(
'phpsessid'
=>
session_id
(),
'user_id'
=>
$user_obj
->
user_id
(),
...
...
@@ -44,7 +44,7 @@ function login($username, $password) {
// Clean up any old sessions that have timed out
$
sqlhdlr
->
table
(
'sessions'
)
$
app
->
db
->
table
(
'sessions'
)
->
where
(
'last'
,
'<'
,
time
()
-
$skynet_sessTime
)
->
delete
();
...
...
@@ -62,10 +62,10 @@ function login($username, $password) {
function
authenticate
()
{
// Globalize the phptodo variables needed
global
$skynet_sessTime
,
$smarty_data
,
$sqlhdlr
;
global
$skynet_sessTime
,
$app
,
$smarty_data
;
// Try and get the id, last time, and user if from the sessions database
$results
=
$
sqlhdlr
->
table
(
'sessions'
)
$results
=
$
app
->
db
->
table
(
'sessions'
)
->
select
(
'id'
,
'last'
,
'user_id'
)
->
where
(
'phpsessid'
,
session_id
())
->
first
();
...
...
@@ -77,14 +77,14 @@ function authenticate() {
// Check to see if an id was set, and if the time is good
if
((
isset
(
$id
))
&&
((
$last
+
$skynet_sessTime
)
>=
time
()))
{
// Good session, update the timestamp
$
sqlhdlr
->
table
(
'sessions'
)
$
app
->
db
->
table
(
'sessions'
)
->
where
(
'id'
,
$id
)
->
update
(
array
(
'last'
,
time
()
));
// Create the user object
$user_obj
=
new
skynetUser
(
$
sqlhdlr
,
$user_id
);
$user_obj
=
new
skynetUser
(
$
app
->
db
,
$user_id
);
// Assign the username to the smarty template
$smarty_data
[
'username'
]
=
$user_obj
->
username
();
...
...
@@ -93,8 +93,8 @@ function authenticate() {
$smarty_data
[
'fullname'
]
=
stripslashes
(
htmlentities
(
$user_obj
->
fullname
(),
ENT_QUOTES
));
}
else
{
$smarty_data
[
'fullname'
]
=
htmlentities
(
$user_obj
->
fullname
(),
ENT_QUOTES
);
$smarty_data
[
'fullname'
]
=
htmlentities
(
$user_obj
->
fullname
(),
ENT_QUOTES
);
}
return
(
$user_obj
);
...
...
@@ -110,7 +110,7 @@ function authenticate() {
function
feed_authenticate
(
$user_id
,
$feed_id
,
$secret
)
{
// Globalize the phptodo variables needed
global
$skynet_dbHost
,
$skynet_dbUser
,
$skynet_dbPass
,
$skynet_dbName
,
$skynet_sessTime
,
$
sqlhdlr
;
$skynet_sessTime
,
$
app
;
// Create the skynetFeed object
$feed
=
new
skynetFeed
(
$skynet_dbHost
,
$skynet_dbUser
,
$skynet_dbPass
,
...
...
@@ -118,7 +118,7 @@ function feed_authenticate($user_id, $feed_id, $secret) {
if
(
$feed
->
secret
()
==
$secret
)
{
// Create the user object
$user_obj
=
new
skynetUser
(
$
sqlhdlr
,
$user_id
);
$user_obj
=
new
skynetUser
(
$
app
->
db
,
$user_id
);
return
Array
(
$feed
,
$user_obj
);
}
else
{
...
...
@@ -131,10 +131,10 @@ function feed_authenticate($user_id, $feed_id, $secret) {
}
function
logout
()
{
global
$
sqlhdlr
;
global
$
app
;
// Try and get the id, last time, and user if from the sessions database
$
sqlhdlr
->
table
(
'sessions'
)
$
app
->
db
->
table
(
'sessions'
)
->
where
(
'phpsessid'
,
session_id
())
->
delete
();
...
...
gui/app/libs/skynetUser.php
View file @
162e9384
gui/app/reports.php
View file @
162e9384
gui/public_html/index.php
View file @
162e9384
...
...
@@ -27,31 +27,8 @@
// 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'
=>
''
,
]);
// Set the event dispatcher used by Eloquent models...
use
Illuminate\Events\Dispatcher
;
use
Illuminate\Container\Container
;
$sqlhdlr
->
setEventDispatcher
(
new
Dispatcher
(
new
Container
));
// Make this Capsule instance available globally via static methods...
$sqlhdlr
->
setAsGlobal
();
// Setup the Eloquent ORM...
$sqlhdlr
->
bootEloquent
();
// Global array for Smarty data
$smarty_data
=
array
(
...
...
@@ -87,6 +64,36 @@
$app
->
view
()
->
appendData
(
array
(
'baseUrl'
=>
'/index.php/'
));
});
// 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
;
});
// Load the authentication routes
include
(
'../app/authentication.php'
);
...
...
@@ -95,21 +102,21 @@
// Home Page Route
$app
->
get
(
'/'
,
$isauthenticated
(),
function
()
use
(
$app
)
{
global
$smarty_data
,
$sqlhdlr
;
global
$smarty_data
;
$smarty_data
[
'total_servers'
]
=
$
sqlhdlr
->
table
(
'cloud'
)
$smarty_data
[
'total_servers'
]
=
$
app
->
db
->
table
(
'cloud'
)
->
where
(
'disabled'
,
0
)
->
count
();
$smarty_data
[
'total_scanners'
]
=
$
sqlhdlr
->
table
(
'spawn'
)
$smarty_data
[
'total_scanners'
]
=
$
app
->
db
->
table
(
'spawn'
)
->
where
(
'disabled'
,
0
)
->
count
();
$smarty_data
[
'total_targets'
]
=
$
sqlhdlr
->
table
(
'target'
)
$smarty_data
[
'total_targets'
]
=
$
app
->
db
->
table
(
'target'
)
->
where
(
'disabled'
,
0
)
->
count
();
$smarty_data
[
'total_timers'
]
=
$
sqlhdlr
->
table
(
'timers'
)
$smarty_data
[
'total_timers'
]
=
$
app
->
db
->
table
(
'timers'
)
->
where
(
'disabled'
,
0
)
->
count
();
$smarty_data
[
'total_results'
]
=
$
sqlhdlr
->
table
(
'results'
)
$smarty_data
[
'total_results'
]
=
$
app
->
db
->
table
(
'results'
)
->
count
();
prep_smarty
(
$app
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment