1010require_once $ _SERVER ['DOCUMENT_ROOT ' ] . '/php/templates/language/lang.php ' ;
1111require_once $ _SERVER ['DOCUMENT_ROOT ' ] . '/php/templates/security.php ' ;
1212
13+ // capture the redirect to after log in query string if available
14+ $ redirectTo = 'devices.php ' ; // Default destination
15+ if (!empty ($ _GET ['next ' ])) {
16+ $ decoded = base64_decode ($ _GET ['next ' ]);
17+ // Validate that it's a local path to prevent Open Redirect vulnerabilities
18+ if (strpos ($ decoded , '/ ' ) === 0 && strpos ($ decoded , '// ' ) !== 0 ) {
19+ $ redirectTo = $ decoded ;
20+ }
21+ }
22+
1323$ CookieSaveLoginName = 'NetAlertX_SaveLogin ' ;
1424
1525if ($ nax_WebProtection != 'true ' )
1626{
17- header ('Location: devices.php ' );
27+ if (!empty ($ _POST ['url_hash ' ])) {
28+ $ redirectTo .= $ _POST ['url_hash ' ];
29+ }
30+ header ("Location: $ redirectTo " );
1831 $ _SESSION ["login " ] = 1 ;
1932 exit ;
2033}
3144// Password without Cookie check -> pass and set initial cookie
3245if (isset ($ _POST ["loginpassword " ]) && $ nax_Password === hash ('sha256 ' ,$ _POST ["loginpassword " ]))
3346{
34- header ('Location: devices.php ' );
47+ if (!empty ($ _POST ['url_hash ' ])) {
48+ $ redirectTo .= $ _POST ['url_hash ' ];
49+ }
50+ header ("Location: $ redirectTo " );
3551 $ _SESSION ["login " ] = 1 ;
3652 if (isset ($ _POST ['PWRemember ' ])) {setcookie ($ CookieSaveLoginName , hash ('sha256 ' ,$ _POST ["loginpassword " ]), time ()+604800 );}
53+ exit ;
3754}
3855
3956// active Session or valid cookie (cookie not extends)
4057if (( isset ($ _SESSION ["login " ]) && ($ _SESSION ["login " ] == 1 )) || (isset ($ _COOKIE [$ CookieSaveLoginName ]) && $ nax_Password === $ _COOKIE [$ CookieSaveLoginName ]))
4158{
42- header ('Location: devices.php ' );
59+ if (!empty ($ _POST ['url_hash ' ])) {
60+ $ redirectTo .= $ _POST ['url_hash ' ];
61+ }
62+ header ("Location: $ redirectTo " );
4363 $ _SESSION ["login " ] = 1 ;
4464 if (isset ($ _POST ['PWRemember ' ])) {setcookie ($ CookieSaveLoginName , hash ('sha256 ' ,$ _POST ["loginpassword " ]), time ()+604800 );}
65+ exit ;
4566}
4667
4768$ login_headline = lang ('Login_Toggle_Info_headline ' );
5374// no active session, cookie not checked
5475if (isset ($ _SESSION ["login " ]) == FALSE || $ _SESSION ["login " ] != 1 )
5576{
56- if ($ nax_Password === '8d969eef6ecad3c29a3a629280e686cf0c3f5d5a86aff3ca12020c923adc6c92 ' )
77+ if ($ nax_Password === '8d969eef6ecad3c29a3a629280e686cf0c3f5d5a86aff3ca12020c923adc6c92 ' )
5778 {
5879 $ login_info = lang ('Login_Default_PWD ' );
5980 $ login_mode = 'danger ' ;
6081 $ login_display_mode = 'display: block; ' ;
6182 $ login_headline = lang ('Login_Toggle_Alert_headline ' );
6283 $ login_icon = 'fa-ban ' ;
63- }
64- else
84+ }
85+ else
6586 {
6687 $ login_mode = 'info ' ;
6788 $ login_display_mode = 'display: none; ' ;
109130 <!-- /.login-logo -->
110131 <div class="login-box-body">
111132 <p class="login-box-msg"><?= lang ('Login_Box ' );?> </p>
112- <form action="index.php" method="post">
133+ <form action="index.php<?php echo ! empty ( $ _GET [ ' next ' ]) ? ' ?next= ' . htmlspecialchars ( $ _GET [ ' next ' ]) : '' ; ?> " method="post">
113134 <div class="form-group has-feedback">
135+ <input type="hidden" name="url_hash" id="url_hash">
114136 <input type="password" class="form-control" placeholder="<?= lang ('Login_Psw-box ' );?> " name="loginpassword">
115137 <span class="glyphicon glyphicon-lock form-control-feedback"></span>
116138 </div>
119141 <div class="checkbox icheck">
120142 <label>
121143 <input type="checkbox" name="PWRemember">
122- <div style="margin-left: 10px; display: inline-block; vertical-align: top;">
144+ <div style="margin-left: 10px; display: inline-block; vertical-align: top;">
123145 <?= lang ('Login_Remember ' );?> <br><span style="font-size: smaller"><?= lang ('Login_Remember_small ' );?> </span>
124146 </div>
125147 </label>
129151 <div class="col-xs-4" style="padding-top: 10px;">
130152 <button type="submit" class="btn btn-primary btn-block btn-flat"><?= lang ('Login_Submit ' );?> </button>
131153 </div>
132- <!-- /.col -->
154+ <!-- /.col -->
133155 </div>
134156 </form>
135157
159181<!-- iCheck -->
160182<script src="lib/iCheck/icheck.min.js"></script>
161183<script>
184+ if (window.location.hash) {
185+ document.getElementById('url_hash').value = window.location.hash;
186+ }
162187 $(function () {
163188 $('input').iCheck({
164189 checkboxClass: 'icheckbox_square-blue',
@@ -174,7 +199,7 @@ function Passwordhinfo() {
174199 } else {
175200 x.style.display = "none";
176201 }
177- }
202+ }
178203
179204</script>
180205</body>
0 commit comments