-
Notifications
You must be signed in to change notification settings - Fork 9
/
login.php
142 lines (113 loc) · 4.19 KB
/
login.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<?php
require_once('config.php');
require_once('lang.php');
require_once('php/session-options.php');
$info = "";
$infoClass = "";
if(isset($_GET['logout'])) {
// sign out
session_unset();
session_destroy();
$infoClass = "ok";
$info = translate('Successfully logged out', false);
} elseif(isset($_POST['username']) && isset($_POST['password'])) {
// test connection, if username and password is OK
foreach(SWITCHES as $s) {
$connection = ssh2_connect($s['addr'], 22);
if($connection !== false) {
if(ssh2_auth_password($connection, $_POST['username'], $_POST['password']) !== false) {
// auth OK
$_SESSION['username'] = $_POST['username'];
$_SESSION['password'] = $_POST['password'];
$_SESSION['last_activity'] = time(); // set last activity time stamp for timeout
header('Location: index.php'); exit(); break;
}
break; // only test first switch (testing all switches would take too long)
}
}
// error message - login not valid
$infoClass = "error";
$info = translate('Login failed', false);
} elseif(isset($_GET['reason']) && $_GET['reason'] == 'unavailable') {
$infoClass = "info";
$info = translate('Maintenance Mode - Please try again later.', false);
} elseif(isset($_GET['reason']) && $_GET['reason'] == 'timeout') {
$infoClass = "warn";
$info = translate('Session timed out. Please log in again.', false);
} elseif(isset($_GET['reason']) && $_GET['reason'] == 'notloggedin') {
$infoClass = "warn";
$info = translate('Please log in first.', false);
} elseif(isset($_SESSION['username']) && isset($_SESSION['password'])) {
// already signed in
header('Location: index.php'); exit();
}
?>
<!DOCTYPE html>
<html>
<head>
<title><?php translate('Switchconfig'); ?> - <?php translate('Log In'); ?></title>
<?php require('head.inc.php'); ?>
<script type='text/javascript' src='webdesign-template/js/main.js'></script>
<script type='text/javascript' src='js/explode.js'></script>
<style>
#forkme {
position: absolute;
top: 0; right: 0;
}
@media only screen and (max-width: 620px) {
#logincontainer {
margin-top: 20px;
}
}
</style>
</head>
<body>
<script>
function beginFadeOutAnimation() {
document.getElementById('imgSwitch').style.opacity = 0;
document.getElementById('imgLoading').style.opacity = 1;
document.getElementById('submitLogin').disabled = true;
document.getElementById('username').readOnly = true;
document.getElementById('password').readOnly = true;
}
</script>
<a id='forkme' href='https://github.com/slub/switchconfig'><img src='img/forkme.png'></a>
<div id='container'>
<h1 id='title'><div id='logo'></div></h1>
<div id='splash' class='login'>
<div id='subtitle'>
<div id='imgContainer'>
<img id='imgLoading' src='img/loading.svg'></img>
<img id='imgSwitch' src='img/switch.login.png' class='easteregg-trigger' onclick='boom()' title='initiate self destruction'></img>
</div>
<p class='first'>
<?php translate('This web application allows you to configure Cisco switches through a graphical interface.'); ?>
</p>
<p class='toolbar-margin-top'>
<b><?php translate('Switch Authentication'); ?></b><br>
<?php translate('Please log in with your switch credentials (SSH).'); ?>
</p>
</div>
<?php require_once('php/browsercheck.php'); ?>
<?php if($info != '') { ?>
<div class='infobox <?php echo $infoClass; ?>'><?php echo $info; ?></div>
<?php } ?>
<form method='POST' action='login.php' name='loginform' id='frmLogin' onsubmit='beginFadeOutAnimation();'>
<div class='form-row icon'>
<input type='text' id='username' name='username' placeholder='<?php translate("Username"); ?>' autofocus='true' />
<img src='webdesign-template/img/person.svg'>
</div>
<div class='form-row password icon'>
<input type='password' id='password' name='password' placeholder='<?php translate("Password"); ?>' />
<img src='webdesign-template/img/key.svg'>
<img src='webdesign-template/img/eye.svg' class='right showpassword' title='Kennwort anzeigen'>
</div>
<div class='form-row'>
<button id='submitLogin' class='slubbutton'><?php translate("Log In"); ?></button>
</div>
</form>
</div>
<?php require('foot.inc.php'); ?>
</div>
</body>
</html>