Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.91 KB | None | 0 0
  1. #!/usr/bin/perl
  2.  
  3. # chilli - chillispot.info. A Wireless LAN Access Point Controller
  4. # Copyright (C) 2003, 2004 Mondru AB.
  5. #
  6. # The contents of this file may be used under the terms of the GNU
  7. # General Public License Version 2, provided that the above copyright
  8. # notice and this permission notice is included in all copies or
  9. # substantial portions of the software.
  10.  
  11. # Redirects from Chillispot daemon:
  12. #
  13. # Redirection when not yet or already authenticated
  14. # notyet: chillispot daemon redirects to login page.
  15. # already: chillispot daemon redirects to success status page.
  16. #
  17. # Response to login:
  18. # already: Attempt to login when already logged in.
  19. # failed: Login failed
  20. # success: Login succeded
  21. #
  22. # logoff: Response to a logout
  23.  
  24.  
  25. # Shared secret used to encrypt challenge with. Prevents dictionary attacks.
  26. # You should change this to your own shared secret.
  27. $uamsecret = "easyhotspot";
  28.  
  29. # Uncomment the following line if you want to use ordinary user-password
  30. # for radius authentication. Must be used together with $uamsecret.
  31. #$userpassword=1;
  32.  
  33. # Our own path
  34. $loginpath = "/cgi-bin/hotspotlogin.cgi";
  35.  
  36. use Digest::MD5 qw(md5 md5_hex md5_base64);
  37.  
  38. # Make sure that the form parameters are clean
  39. $OK_CHARS='-a-zA-Z0-9_.@&=%!';
  40. $_ = $input = <STDIN>;
  41. s/[^$OK_CHARS]/_/go;
  42. $input = $_;
  43.  
  44. # Make sure that the get query parameters are clean
  45. $OK_CHARS='-a-zA-Z0-9_.@&=%!';
  46. $_ = $query=$ENV{QUERY_STRING};
  47. s/[^$OK_CHARS]/_/go;
  48. $query = $_;
  49.  
  50.  
  51. # If she did not use https tell her that it was wrong.
  52. if (!($ENV{HTTPS} =~ /^on$/)) {
  53. print "Content-type: text/html\n\n
  54. <!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">
  55. <html>
  56. <head>
  57. <title>EasyHotspot Login Failed</title>
  58. <meta http-equiv=\"Cache-control\" content=\"no-cache\">
  59. <meta http-equiv=\"Pragma\" content=\"no-cache\">
  60. <link href=http://192.168.182.1/public/frontend/css/fal_style.css rel=stylesheet></head>
  61. <body bgColor = '#ffffff'>
  62. <h1 style=\"text-align: center;\">EasyHotspot Login Failed</h1>
  63. <center>
  64. Login must use encrypted connection.
  65. </center>
  66. </body>
  67. <!--
  68. <?xml version=\"1.0\" encoding=\"UTF-8\"?>
  69. <WISPAccessGatewayParam
  70. xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
  71. xsi:noNamespaceSchemaLocation=\"http://www.acmewisp.com/WISPAccessGatewayParam.xsd\">
  72. <AuthenticationReply>
  73. <MessageType>120</MessageType>
  74. <ResponseCode>102</ResponseCode>
  75. <ReplyMessage>Login must use encrypted connection</ReplyMessage>
  76. </AuthenticationReply>
  77. </WISPAccessGatewayParam>
  78. -->
  79. </html>
  80. ";
  81. exit(0);
  82. }
  83.  
  84.  
  85. #Read form parameters which we care about
  86. @array = split('&',$input);
  87. foreach $var ( @array )
  88. {
  89. @array2 = split('=',$var);
  90. if ($array2[0] =~ /^UserName$/) { $username = $array2[1]; }
  91. if ($array2[0] =~ /^Password$/) { $password = $array2[1]; }
  92. if ($array2[0] =~ /^challenge$/) { $challenge = $array2[1]; }
  93. if ($array2[0] =~ /^button$/) { $button = $array2[1]; }
  94. if ($array2[0] =~ /^logout$/) { $logout = $array2[1]; }
  95. if ($array2[0] =~ /^prelogin$/) { $prelogin = $array2[1]; }
  96. if ($array2[0] =~ /^res$/) { $res = $array2[1]; }
  97. if ($array2[0] =~ /^uamip$/) { $uamip = $array2[1]; }
  98. if ($array2[0] =~ /^uamport$/) { $uamport = $array2[1]; }
  99. if ($array2[0] =~ /^userurl$/) { $userurl = $array2[1]; }
  100. if ($array2[0] =~ /^timeleft$/) { $timeleft = $array2[1]; }
  101. if ($array2[0] =~ /^redirurl$/) { $redirurl = $array2[1]; }
  102. }
  103.  
  104. #Read query parameters which we care about
  105. @array = split('&',$query);
  106. foreach $var ( @array )
  107. {
  108. @array2 = split('=',$var);
  109. if ($array2[0] =~ /^res$/) { $res = $array2[1]; }
  110. if ($array2[0] =~ /^challenge$/) { $challenge = $array2[1]; }
  111. if ($array2[0] =~ /^uamip$/) { $uamip = $array2[1]; }
  112. if ($array2[0] =~ /^uamport$/) { $uamport = $array2[1]; }
  113. if ($array2[0] =~ /^reply$/) { $reply = $array2[1]; }
  114. if ($array2[0] =~ /^userurl$/) { $userurl = $array2[1]; }
  115. if ($array2[0] =~ /^timeleft$/) { $timeleft = $array2[1]; }
  116. if ($array2[0] =~ /^redirurl$/) { $redirurl = $array2[1]; }
  117. }
  118.  
  119.  
  120. $reply =~ s/\+/ /g;
  121. $reply =~s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/seg;
  122.  
  123. $userurldecode = $userurl;
  124. $userurldecode =~ s/\+/ /g;
  125. $userurldecode =~s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/seg;
  126.  
  127. $redirurldecode = $redirurl;
  128. $redirurldecode =~ s/\+/ /g;
  129. $redirurldecode =~s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/seg;
  130.  
  131. $password =~ s/\+/ /g;
  132. $password =~s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/seg;
  133.  
  134. # If attempt to login
  135. if ($button =~ /^Login$/) {
  136. $hexchal = pack "H32", $challenge;
  137. if (defined $uamsecret) {
  138. $newchal = md5($hexchal, $uamsecret);
  139. }
  140. else {
  141. $newchal = $hexchal;
  142. }
  143. $response = md5_hex("\0", $password, $newchal);
  144. $pappassword = unpack "H32", ($password ^ $newchal);
  145. #sleep 5;
  146. print "Content-type: text/html\n\n";
  147. print "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">
  148. <html>
  149. <head>
  150. <title>EasyHotspot Login</title>
  151. <meta http-equiv=\"Cache-control\" content=\"no-cache\">
  152. <meta http-equiv=\"Pragma\" content=\"no-cache\">";
  153. if ((defined $uamsecret) && defined($userpassword)) {
  154. print " <meta http-equiv=\"refresh\" content=\"0;url=http://$uamip:$uamport/logon?username=$username&password=$pappassword\">";
  155. } else {
  156. print " <meta http-equiv=\"refresh\" content=\"0;url=http://$uamip:$uamport/logon?username=$username&response=$response&userurl=$userurl\">";
  157. }
  158. print "<link href=http://192.168.182.1/public/frontend/css/fal_style.css rel=stylesheet></head>
  159. <body bgColor = '#ffffff'>";
  160. print "<h1 style=\"text-align: center;\">Logging in to EasyHotspot</h1>";
  161. print "
  162. <center>
  163. Please wait......
  164. </center>
  165. </body>
  166. <!--
  167. <?xml version=\"1.0\" encoding=\"UTF-8\"?>
  168. <WISPAccessGatewayParam
  169. xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
  170. xsi:noNamespaceSchemaLocation=\"http://www.acmewisp.com/WISPAccessGatewayParam.xsd\">
  171. <AuthenticationReply>
  172. <MessageType>120</MessageType>
  173. <ResponseCode>201</ResponseCode>
  174. ";
  175. if ((defined $uamsecret) && defined($userpassword)) {
  176. print "<LoginResultsURL>http://$uamip:$uamport/logon?username=$username&password=$pappassword</LoginResultsURL>";
  177. } else {
  178. print "<LoginResultsURL>http://$uamip:$uamport/logon?username=$username&response=$response&userurl=$userurl</LoginResultsURL>";
  179. }
  180. print "</AuthenticationReply>
  181. </WISPAccessGatewayParam>
  182. -->
  183. </html>
  184. ";
  185. exit(0);
  186. }
  187.  
  188.  
  189. # Default: It was not a form request
  190. $result = 0;
  191.  
  192. # If login successful
  193. if ($res =~ /^success$/) {
  194. $result = 1;
  195. }
  196.  
  197. # If login failed
  198. if ($res =~ /^failed$/) {
  199. $result = 2;
  200. }
  201.  
  202. # If logout successful
  203. if ($res =~ /^logoff$/) {
  204. $result = 3;
  205. }
  206.  
  207. # If tried to login while already logged in
  208. if ($res =~ /^already$/) {
  209. $result = 4;
  210. }
  211.  
  212. # If not logged in yet
  213. if ($res =~ /^notyet$/) {
  214. $result = 5;
  215. }
  216.  
  217. # If login from smart client
  218. if ($res =~ /^smartclient$/) {
  219. $result = 6;
  220. }
  221.  
  222. # If requested a logging in pop up window
  223. if ($res =~ /^popup1$/) {
  224. $result = 11;
  225. }
  226.  
  227. # If requested a success pop up window
  228. if ($res =~ /^popup2$/) {
  229. $result = 12;
  230. }
  231.  
  232. # If requested a logout pop up window
  233. if ($res =~ /^popup3$/) {
  234. $result = 13;
  235. }
  236.  
  237.  
  238. # Otherwise it was not a form request
  239. # Send out an error message
  240. if ($result == 0) {
  241. print "Content-type: text/html\n\n
  242. <!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">
  243. <html>
  244. <head>
  245. <title>EasyHotspot Login Failed</title>
  246. <meta http-equiv=\"Cache-control\" content=\"no-cache\">
  247. <meta http-equiv=\"Pragma\" content=\"no-cache\">
  248. <link href=http://192.168.182.1/public/frontend/css/fal_style.css rel=stylesheet></head>
  249. <body bgColor = '#ffffff'>
  250. <h1 style=\"text-align: center;\">EasyHotspot Login Failed</h1>
  251. <center>
  252. Login must be performed through EasyHotspot daemon.
  253. </center>
  254. </body>
  255. </html>
  256. ";
  257. exit(0);
  258. }
  259.  
  260. #Generate the output
  261. print "Content-type: text/html\n\n
  262. <!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">
  263. <html>
  264. <head>
  265. <title>EasyHotspot Login</title>
  266. <meta http-equiv=\"Cache-control\" content=\"no-cache\">
  267. <meta http-equiv=\"Pragma\" content=\"no-cache\">
  268. <SCRIPT LANGUAGE=\"JavaScript\">
  269. var blur = 0;
  270. var starttime = new Date();
  271. var startclock = starttime.getTime();
  272. var mytimeleft = 0;
  273. function doTime() {
  274. window.setTimeout( \"doTime()\", 1000 );
  275. t = new Date();
  276. time = Math.round((t.getTime() - starttime.getTime())/1000);
  277. if (mytimeleft) {
  278. time = mytimeleft - time;
  279. if (time <= 0) {
  280. window.location = \"$loginpath?res=popup3&uamip=$uamip&uamport=$uamport\";
  281. }
  282. }
  283. if (time < 0) time = 0;
  284. hours = (time - (time % 3600)) / 3600;
  285. time = time - (hours * 3600);
  286. mins = (time - (time % 60)) / 60;
  287. secs = time - (mins * 60);
  288. if (hours < 10) hours = \"0\" + hours;
  289. if (mins < 10) mins = \"0\" + mins;
  290. if (secs < 10) secs = \"0\" + secs;
  291. title = \"Online time: \" + hours + \":\" + mins + \":\" + secs;
  292. if (mytimeleft) {
  293. title = \"Remaining time: \" + hours + \":\" + mins + \":\" + secs;
  294. }
  295. if(document.all || document.getElementById){
  296. document.title = title;
  297. }
  298. else {
  299. self.status = title;
  300. }
  301. }
  302. function popUp(URL) {
  303. if (self.name != \"chillispot_popup\") {
  304. chillispot_popup = window.open(URL, 'chillispot_popup', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=500,height=375');
  305. }
  306. }
  307. function doOnLoad(result, URL, userurl, redirurl, timeleft) {
  308. if (timeleft) {
  309. mytimeleft = timeleft;
  310. }
  311. if ((result == 1) && (self.name == \"chillispot_popup\")) {
  312. doTime();
  313. }
  314. if ((result == 1) && (self.name != \"chillispot_popup\")) {
  315. chillispot_popup = window.open(URL, 'chillispot_popup', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=500,height=375');
  316. }
  317. if ((result == 2) || result == 5) {
  318. document.form1.UserName.focus()
  319. }
  320. if ((result == 2) && (self.name != \"chillispot_popup\")) {
  321. chillispot_popup = window.open('', 'chillispot_popup', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=400,height=200');
  322. chillispot_popup.close();
  323. }
  324. if ((result == 12) && (self.name == \"chillispot_popup\")) {
  325. doTime();
  326. if (redirurl) {
  327. opener.location = redirurl;
  328. }
  329. else if (opener.home) {
  330. opener.home();
  331. }
  332. else {
  333. opener.location = \"about:home\";
  334. }
  335. self.focus();
  336. blur = 0;
  337. }
  338. if ((result == 13) && (self.name == \"chillispot_popup\")) {
  339. self.focus();
  340. blur = 1;
  341. }
  342. }
  343. function doOnBlur(result) {
  344. if ((result == 12) && (self.name == \"chillispot_popup\")) {
  345. if (blur == 0) {
  346. blur = 1;
  347. self.focus();
  348. }
  349. }
  350. }
  351. </script>
  352. <link href=http://192.168.182.1/public/frontend/css/fal_style.css rel=stylesheet></head>
  353. <body onLoad=\"javascript:doOnLoad($result, '$loginpath?res=popup2&uamip=$uamip&uamport=$uamport&userurl=$userurl&redirurl=$redirurl&timeleft=$timeleft','$userurldecode', '$redirurldecode', '$timeleft')\" onBlur = \"javascript:doOnBlur($result)\" bgColor = '#ffffff'>";
  354.  
  355.  
  356. # if (!window.opener) {
  357. # document.bgColor = '#ffffff';
  358. # }
  359.  
  360. #print "THE INPUT: $input";
  361. #foreach $key (sort (keys %ENV)) {
  362. # print $key, ' = ', $ENV{$key}, "<br>\n";
  363. #}
  364.  
  365. if ($result == 2) {
  366. print "
  367. <h1 style=\"text-align: center;\">EasyHotspot Login Failed</h1>";
  368. if ($reply) {
  369. print "<center> $reply </BR></BR></center>";
  370. }
  371. }
  372.  
  373. if ($result == 5) {
  374. print "
  375. <h1 style=\"text-align: center;\">EasyHotspot Login</h1>";
  376. }
  377.  
  378. if ($result == 2 || $result == 5) {
  379. print "
  380. <form name=\"form1\" method=\"post\" action=\"$loginpath\">
  381. <INPUT TYPE=\"hidden\" NAME=\"challenge\" VALUE=\"$challenge\">
  382. <INPUT TYPE=\"hidden\" NAME=\"uamip\" VALUE=\"$uamip\">
  383. <INPUT TYPE=\"hidden\" NAME=\"uamport\" VALUE=\"$uamport\">
  384. <INPUT TYPE=\"hidden\" NAME=\"userurl\" VALUE=\"$userurl\">
  385. <center>
  386. <table border=\"0\" cellpadding=\"5\" cellspacing=\"0\" style=\"width: 217px;\">
  387. <tbody>
  388. <tr>
  389. <td align=\"right\">Username:</td>
  390. <td><input STYLE=\"font-family: Arial\" type=\"text\" name=\"UserName\" size=\"20\" maxlength=\"128\"></td>
  391. </tr>
  392. <tr>
  393. <td align=\"right\">Password:</td>
  394. <td><input STYLE=\"font-family: Arial\" type=\"password\" name=\"Password\" size=\"20\" maxlength=\"128\"></td>
  395. </tr>
  396. <tr>
  397. <td align=\"center\" colspan=\"2\" height=\"23\"><input type=\"submit\" name=\"button\" value=\"Login\" onClick=\"javascript:popUp('$loginpath?res=popup1&uamip=$uamip&uamport=$uamport')\"></td>
  398. </tr>
  399. </tbody>
  400. </table>
  401. </center>
  402. </form>
  403. </body>
  404. </html>";
  405. }
  406.  
  407. if ($result == 1) {
  408. print "
  409. <h1 style=\"text-align: center;\">Logged in to EasyHotspot</h1>";
  410.  
  411. if ($reply) {
  412. print "<center> $reply </BR></BR></center>";
  413. }
  414.  
  415. print "
  416. <center>
  417. <a href=\"http://$uamip:$uamport/logoff\">Logout</a>
  418. </center>
  419. </body>
  420. </html>";
  421. }
  422.  
  423. if (($result == 4) || ($result == 12)) {
  424. print "
  425. <h1 style=\"text-align: center;\">Logged in to EasyHotspot</h1>
  426. <center>
  427. <a href=\"http://$uamip:$uamport/logoff\">Logout</a>
  428. </center>
  429. </body>
  430. </html>";
  431. }
  432.  
  433.  
  434. if ($result == 11) {
  435. print "<h1 style=\"text-align: center;\">Logging in to EasyHotspot</h1>";
  436. print "
  437. <center>
  438. Please wait......
  439. </center>
  440. </body>
  441. </html>";
  442. }
  443.  
  444.  
  445. if (($result == 3) || ($result == 13)) {
  446. print "
  447. <h1 style=\"text-align: center;\">Logged out from EasyHotspot</h1>
  448. <center>
  449. <a href=\"http://$uamip:$uamport/prelogin\">Login</a>
  450. </center>
  451. </body>
  452. </html>";
  453. }
  454.  
  455.  
  456. exit(0);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement