Ver código fonte

Restore files

Making my work public again!!
Deben Oldert 10 anos atrás
pai
commit
88e7446910

BIN
Functional Design.pdf


+ 340 - 0
LICENSE

@@ -0,0 +1,340 @@
+GNU GENERAL PUBLIC LICENSE
+                       Version 2, June 1991
+
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc., <http://fsf.org/>
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+                            Preamble
+
+  The licenses for most software are designed to take away your
+freedom to share and change it.  By contrast, the GNU General Public
+License is intended to guarantee your freedom to share and change free
+software--to make sure the software is free for all its users.  This
+General Public License applies to most of the Free Software
+Foundation's software and to any other program whose authors commit to
+using it.  (Some other Free Software Foundation software is covered by
+the GNU Lesser General Public License instead.)  You can apply it to
+your programs, too.
+
+  When we speak of free software, we are referring to freedom, not
+price.  Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+  To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if you
+distribute copies of the software, or if you modify it.
+
+  For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must give the recipients all the rights that
+you have.  You must make sure that they, too, receive or can get the
+source code.  And you must show them these terms so they know their
+rights.
+
+  We protect your rights with two steps: (1) copyright the software, and
+(2) offer you this license which gives you legal permission to copy,
+distribute and/or modify the software.
+
+  Also, for each author's protection and ours, we want to make certain
+that everyone understands that there is no warranty for this free
+software.  If the software is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original, so
+that any problems introduced by others will not reflect on the original
+authors' reputations.
+
+  Finally, any free program is threatened constantly by software
+patents.  We wish to avoid the danger that redistributors of a free
+program will individually obtain patent licenses, in effect making the
+program proprietary.  To prevent this, we have made it clear that any
+patent must be licensed for everyone's free use or not licensed at all.
+
+  The precise terms and conditions for copying, distribution and
+modification follow.
+
+                    GNU GENERAL PUBLIC LICENSE
+   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+  0. This License applies to any program or other work which contains
+a notice placed by the copyright holder saying it may be distributed
+under the terms of this General Public License.  The "Program", below,
+refers to any such program or work, and a "work based on the Program"
+means either the Program or any derivative work under copyright law:
+that is to say, a work containing the Program or a portion of it,
+either verbatim or with modifications and/or translated into another
+language.  (Hereinafter, translation is included without limitation in
+the term "modification".)  Each licensee is addressed as "you".
+
+Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope.  The act of
+running the Program is not restricted, and the output from the Program
+is covered only if its contents constitute a work based on the
+Program (independent of having been made by running the Program).
+Whether that is true depends on what the Program does.
+
+  1. You may copy and distribute verbatim copies of the Program's
+source code as you receive it, in any medium, provided that you
+conspicuously and appropriately publish on each copy an appropriate
+copyright notice and disclaimer of warranty; keep intact all the
+notices that refer to this License and to the absence of any warranty;
+and give any other recipients of the Program a copy of this License
+along with the Program.
+
+You may charge a fee for the physical act of transferring a copy, and
+you may at your option offer warranty protection in exchange for a fee.
+
+  2. You may modify your copy or copies of the Program or any portion
+of it, thus forming a work based on the Program, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+    a) You must cause the modified files to carry prominent notices
+    stating that you changed the files and the date of any change.
+
+    b) You must cause any work that you distribute or publish, that in
+    whole or in part contains or is derived from the Program or any
+    part thereof, to be licensed as a whole at no charge to all third
+    parties under the terms of this License.
+
+    c) If the modified program normally reads commands interactively
+    when run, you must cause it, when started running for such
+    interactive use in the most ordinary way, to print or display an
+    announcement including an appropriate copyright notice and a
+    notice that there is no warranty (or else, saying that you provide
+    a warranty) and that users may redistribute the program under
+    these conditions, and telling the user how to view a copy of this
+    License.  (Exception: if the Program itself is interactive but
+    does not normally print such an announcement, your work based on
+    the Program is not required to print an announcement.)
+
+These requirements apply to the modified work as a whole.  If
+identifiable sections of that work are not derived from the Program,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works.  But when you
+distribute the same sections as part of a whole which is a work based
+on the Program, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Program.
+
+In addition, mere aggregation of another work not based on the Program
+with the Program (or with a work based on the Program) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+  3. You may copy and distribute the Program (or a work based on it,
+under Section 2) in object code or executable form under the terms of
+Sections 1 and 2 above provided that you also do one of the following:
+
+    a) Accompany it with the complete corresponding machine-readable
+    source code, which must be distributed under the terms of Sections
+    1 and 2 above on a medium customarily used for software interchange; or,
+
+    b) Accompany it with a written offer, valid for at least three
+    years, to give any third party, for a charge no more than your
+    cost of physically performing source distribution, a complete
+    machine-readable copy of the corresponding source code, to be
+    distributed under the terms of Sections 1 and 2 above on a medium
+    customarily used for software interchange; or,
+
+    c) Accompany it with the information you received as to the offer
+    to distribute corresponding source code.  (This alternative is
+    allowed only for noncommercial distribution and only if you
+    received the program in object code or executable form with such
+    an offer, in accord with Subsection b above.)
+
+The source code for a work means the preferred form of the work for
+making modifications to it.  For an executable work, complete source
+code means all the source code for all modules it contains, plus any
+associated interface definition files, plus the scripts used to
+control compilation and installation of the executable.  However, as a
+special exception, the source code distributed need not include
+anything that is normally distributed (in either source or binary
+form) with the major components (compiler, kernel, and so on) of the
+operating system on which the executable runs, unless that component
+itself accompanies the executable.
+
+If distribution of executable or object code is made by offering
+access to copy from a designated place, then offering equivalent
+access to copy the source code from the same place counts as
+distribution of the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+  4. You may not copy, modify, sublicense, or distribute the Program
+except as expressly provided under this License.  Any attempt
+otherwise to copy, modify, sublicense or distribute the Program is
+void, and will automatically terminate your rights under this License.
+However, parties who have received copies, or rights, from you under
+this License will not have their licenses terminated so long as such
+parties remain in full compliance.
+
+  5. You are not required to accept this License, since you have not
+signed it.  However, nothing else grants you permission to modify or
+distribute the Program or its derivative works.  These actions are
+prohibited by law if you do not accept this License.  Therefore, by
+modifying or distributing the Program (or any work based on the
+Program), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Program or works based on it.
+
+  6. Each time you redistribute the Program (or any work based on the
+Program), the recipient automatically receives a license from the
+original licensor to copy, distribute or modify the Program subject to
+these terms and conditions.  You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+
+  7. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License.  If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Program at all.  For example, if a patent
+license would not permit royalty-free redistribution of the Program by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Program.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system, which is
+implemented by public license practices.  Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+  8. If the distribution and/or use of the Program is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Program under this License
+may add an explicit geographical distribution limitation excluding
+those countries, so that distribution is permitted only in or among
+countries not thus excluded.  In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+  9. The Free Software Foundation may publish revised and/or new versions
+of the General Public License from time to time.  Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+Each version is given a distinguishing version number.  If the Program
+specifies a version number of this License which applies to it and "any
+later version", you have the option of following the terms and conditions
+either of that version or of any later version published by the Free
+Software Foundation.  If the Program does not specify a version number of
+this License, you may choose any version ever published by the Free Software
+Foundation.
+
+  10. If you wish to incorporate parts of the Program into other free
+programs whose distribution conditions are different, write to the author
+to ask for permission.  For software which is copyrighted by the Free
+Software Foundation, write to the Free Software Foundation; we sometimes
+make exceptions for this.  Our decision will be guided by the two goals
+of preserving the free status of all derivatives of our free software and
+of promoting the sharing and reuse of software generally.
+
+                            NO WARRANTY
+
+  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
+REPAIR OR CORRECTION.
+
+  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGES.
+
+                     END OF TERMS AND CONDITIONS
+
+            How to Apply These Terms to Your New Programs
+
+  If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+  To do so, attach the following notices to the program.  It is safest
+to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+    {description}
+    Copyright (C) {year}  {fullname}
+
+    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 Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+Also add information on how to contact you by electronic and paper mail.
+
+If the program is interactive, make it output a short notice like this
+when it starts in an interactive mode:
+
+    Gnomovision version 69, Copyright (C) year name of author
+    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+    This is free software, and you are welcome to redistribute it
+    under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License.  Of course, the commands you use may
+be called something other than `show w' and `show c'; they could even be
+mouse-clicks or menu items--whatever suits your program.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the program, if
+necessary.  Here is a sample; alter the names:
+
+  Yoyodyne, Inc., hereby disclaims all copyright interest in the program
+  `Gnomovision' (which makes passes at compilers) written by James Hacker.
+
+  {signature of Ty Coon}, 1 April 1989
+  Ty Coon, President of Vice
+
+This General Public License does not permit incorporating your program into
+proprietary programs.  If your program is a subroutine library, you may
+consider it more useful to permit linking proprietary applications with the
+library.  If this is what you want to do, use the GNU Lesser General
+Public License instead of this License.
+

+ 7 - 0
README.md

@@ -0,0 +1,7 @@
+HvA_F.Y.S.
+==========
+
+HvA project Fasten Your Seatbelts team 3
+
+You can view our current documentation on:
+<a href="https://www.dropbox.com/sh/1dikq30pby5zfnq/AADnT18tPtWxlC7ttAtAhz3ia?dl=0" target="_blank">dropbox.com</a>

BIN
Technical design.pdf


+ 157 - 0
captiveportal/Captiveportal.css

@@ -0,0 +1,157 @@
+@CHARSET "UTF-8";
+body{
+	font-family:"Trebuchet MS", "Myriad Pro", Arial, sans-serif;
+	background:#f4f4f4 url(images/corendon8.jpg) no-repeat;
+}
+h1{
+	margin-left:auto;
+    margin-right:auto;
+    width:800px;
+	margin-bottom:0;
+	font-size:56px;
+	color:#CC0000;
+	font-family: "Arial Black", Gadget, sans-serif;
+}
+h1 span{
+	font-size:15px;
+	color:#FF9900;
+}
+h2{
+	margin-left:auto;
+    margin-right:auto;
+    width:800px;
+	font-size:20px;
+	padding:0px 0px 40px 0px;
+	color:#aaa;
+	margin-top:0;
+}
+h2 span{
+	color:#aaa;
+}
+.error{
+	display:block;
+	width: 76%;
+	margin:5px 30px 0px 30px;
+	color:#CC0000;
+	font-size:12px;
+}
+/* Form Style */
+.form_wrapper{
+	background:#fff;
+	border:1px solid #CC0000;
+	margin:auto;
+	width:350px;
+	font-size:16px;
+	-moz-box-shadow:0px 0px 25px 0px #CC0000;
+	-webkit-box-shadow:0px 0px 25px 0px #CC0000;
+	box-shadow: 0px 0px 25x 0px #CC0000;
+}
+.form_wrapper h3{
+	padding:20px;
+	background-color:#CC0000;
+	color:#fff;
+	font-size:25px;
+	border-bottom:1px solid #ddd;
+	margin-top:0;
+}
+form.login{
+	width:350px;
+	margin-bottom:0;
+}
+.form_wrapper label{
+	display:block;
+	padding:10px 30px 0px 30px;
+	margin:10px 0px 0px 0px;
+}
+.form_wrapper input[type="text"],
+.form_wrapper input[type="password"]{
+	border: solid 1px #E5E5E5;
+	background: #FFFFFF;
+	margin: 5px 30px 0px 30px;
+	padding: 9px;
+	display:block;
+	font-size:16px;
+	width:76%;
+	background: 
+		-webkit-gradient(
+			linear,
+			left top,
+			left 25,
+			from(#FFFFFF),
+			color-stop(4%, #EEEEEE),
+			to(#FFFFFF)
+		);
+	background: 
+		-moz-linear-gradient(
+			top,
+			#FFFFFF,
+			#EEEEEE 1px,
+			#FFFFFF 25px
+			);
+	-moz-box-shadow: 0px 0px 8px #f0f0f0;
+	-webkit-box-shadow: 0px 0px 8px #f0f0f0;
+	box-shadow: 0px 0px 8px #f0f0f0;
+}
+.form_wrapper input[type="text"]:focus,
+.form_wrapper input[type="password"]:focus{
+	background:#feffef;
+}
+.form_wrapper .bottom{
+	background-color:#CC0000;
+	border-top:1px solid #ddd;
+	margin-top:20px;
+	font-size:12px;
+	clear:both;
+	color:#fff;
+	text-shadow:1px 1px 1px #000;
+}
+.form_wrapper .bottom label{
+	background-color:#CC0000;
+	border-bottom:5px solid #CC0000;
+	font-size:12px;
+	clear:both;
+	color:#fff;
+	text-shadow:1px 1px 1px #000;
+}
+.form_wrapper div.remember{
+	float:left;
+	width:140px;
+	margin:20px 0px 20px 30px;
+	font-size:11px;
+}
+.form_wrapper span.error{
+	visibility:hidden;
+	color:red;
+	font-size:11px;
+	font-style:italic;
+	display:block;
+	margin:4px 30px;
+}
+.form_wrapper input[type="submit"] {
+	background: #e3e3e3;
+	border: 1px solid #ccc;
+	color: #333;
+	font-family: "Trebuchet MS", "Myriad Pro", sans-serif;
+	font-size: 14px;
+	font-weight: bold;
+	padding: 8px 0 9px;
+	text-align: center;
+	width: 150px;
+	cursor:pointer;
+	float:right;
+	margin:15px 20px 10px 10px;
+	text-shadow: 0px 1px 0px #fff;
+	-moz-border-radius: 4px;
+	-webkit-border-radius: 4px;
+	border-radius: 4px;
+	-moz-box-shadow: 0px 0px 2px #fff inset;
+	-webkit-box-shadow: 0px 0px 2px #fff inset;
+	box-shadow: 0px 0px 2px #fff inset;
+}
+.form_wrapper input[type="submit"]:hover {
+	background: #d9d9d9;
+	-moz-box-shadow: 0px 0px 2px #eaeaea inset;
+	-webkit-box-shadow: 0px 0px 2px #eaeaea inset;
+	box-shadow: 0px 0px 2px #eaeaea inset;
+	color: #222;
+}

+ 111 - 0
captiveportal/Database.java

@@ -0,0 +1,111 @@
+package captiveportal;
+
+import java.sql.*;
+
+public class Database {
+	private Connection conn = null;
+	  private Statement stmt = null;
+	  private ResultSet resultSet = null;
+	  private int count = 0;
+	  
+	  //#######Database details#######
+	  private String dbHost = "localhost"; //The ip or hostname of the database host e.g: localhost or 127.0.0.1 etc.
+	  private String dbPort = "3306"; //The port the database is listening to
+	  private String dbName = "CaptivePortal"; //The name of the scheme
+	  private String dbUser = "CaptivePortal"; //The username of the account that can 'Update and Select' on the scheme
+	  private String dbPass = "raspberry"; //The password of the account that can 'Update and Select' on the scheme
+	  //##############################
+	  
+	//Create method for checking if ticket/lastname combination exists (On SUCCES => true else => false)
+	public boolean Select(String ticket, String lastName) throws Exception {
+	    try {
+	      //Load the MySQL driver
+	      Class.forName("com.mysql.jdbc.Driver");
+	      //Setup the connection with the database
+	      conn = DriverManager.getConnection("jdbc:mysql://" +dbHost+ ":" +dbPort+ "/" +dbName, dbUser, dbPass);
+	      //Create statement to execute query
+	      stmt = conn.createStatement();
+	      //Execute query
+	      resultSet = stmt.executeQuery("select lastname, ticket from users where ticket='" +ticket+ "'and lastname='" +lastName+ "'");
+	      //Count the results that are returned (affected rows) this should be 1 (unique ticket/lastname combination)
+	      while(resultSet.next())
+	      {
+	    	  //increment count by 1
+	    	  count++;
+	      }
+	      if (count == 1)
+	         {
+	    	  	//If there is 1 row with the ticket/lastname combination => return true
+	    		return true;
+	         }
+	    	else
+	    	{
+	    		return false;
+	    	}
+	     //If there is an error, throw it
+	    } catch (Exception e) {
+	      throw e;
+	    //Finally close the connections
+	    } finally {
+	    	if (stmt != null) stmt.close();
+	           if (conn != null) conn.close();
+	    }
+
+	
+	
+	}
+	//Create method for registering internet usage per user (On SUCCES => true else => false)
+	public boolean Update(String ticket, String lastName) throws Exception {
+		try {
+		//Load the MySQL driver
+	    Class.forName("com.mysql.jdbc.Driver");
+	    //Setup the connection with the database
+	    conn = DriverManager.getConnection("jdbc:mysql://" +dbHost+ ":" +dbPort+ "/" +dbName, dbUser, dbPass);
+	    //Create statement to execute query
+	    stmt = conn.createStatement();
+	    //Execute query
+    	int result = stmt.executeUpdate("update users set internet = '1' where ticket='" +ticket+ "' and lastname='" +lastName+ "'");
+    	//Result is already an int so, if good => true else => false (executeUpdate returns the number of rows updated, so it should be 1)
+    	if(result == 1) {
+    		return true;
+    	}
+    	else {
+    		return false;
+    	}
+    	  //If there is an error, throw it
+	    } catch (Exception e) {
+	      throw e;
+	    //Finally close the connections
+	    } finally {
+	    	if (stmt != null) stmt.close();
+	           if (conn != null) conn.close();
+	    }
+	}
+	//Create method for resetting user in database (set internet to 0) (On SUCCES => true else => false)
+	public boolean Reset(String ticket, String lastName) throws Exception {
+		try {
+		//Load the MySQL driver
+	    Class.forName("com.mysql.jdbc.Driver");
+	    //Setup the connection with the database
+	    conn = DriverManager.getConnection("jdbc:mysql://" +dbHost+ ":" +dbPort+ "/" +dbName, dbUser, dbPass);
+	    //Create statement to execute query
+	    stmt = conn.createStatement();
+	    //Execute query
+    	int result = stmt.executeUpdate("update users set internet = '0' where ticket='" +ticket+ "' and lastname='" +lastName+ "'");
+    	//Result is already an int so, if good => true else => false (executeUpdate returns the number of rows updated, so it should be 1)
+    	if(result == 1) {
+    		return true;
+    	}
+    	else {
+    		return false;
+    	}
+    	  //If there is an error, throw it
+	    } catch (Exception e) {
+	      throw e;
+	    //Finally close the connections
+	    } finally {
+	    	if (stmt != null) stmt.close();
+	           if (conn != null) conn.close();
+	    }
+    }
+}

+ 37 - 0
captiveportal/Index.java

@@ -0,0 +1,37 @@
+/* 	This is the main page of the captive portal.
+*	Copy right: Deben Oldert
+*	Here users are asked about there credentials to login and allow internet access.
+*	It inserts the html page => index.html
+*/
+package captiveportal;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+
+import javax.servlet.ServletException;
+import javax.servlet.annotation.WebServlet;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * Servlet implementation class Index
+ */
+@WebServlet("/index")
+public class Index extends HttpServlet {
+	private static final long serialVersionUID = 1L;
+
+	/**
+	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
+	 */
+	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+        		response.setContentType("text/html;charset=UTF-8");
+        		PrintWriter out = response.getWriter();
+        		try {
+        		request.getRequestDispatcher("/index.html").include(request, response);
+        		} finally {
+        		out.close(); }
+        		
+	}
+
+}

+ 6 - 0
captiveportal/firewall/readme.md

@@ -0,0 +1,6 @@
+<h1>HOW TO USE</h1>
+Place the 2 files in the same folder (I recommend a folder named ```portal``` in the root folder "/portal/")<br>
+You can initialize the script by typing: ```bash /portal/rules.sh initialize```<br>
+You can grand an ip access to the internet by typing: ```bash /portal/rules.sh grand XXX.XXX.XXX.XXX``` (The ip adrress)<br>
+If you want the script to run at system stratup edit the /etc/rc.local and add <strong>before</strong> "exit 0" this code:<br>
+```bash /portal/rules.sh initialize```

+ 103 - 0
captiveportal/firewall/rules.sh

@@ -0,0 +1,103 @@
+#Captive portal iptables rule script
+#Copyright Deben Oldert
+#This script handles the rules for the captive portal
+#It is multifuncional
+#Initialize the new rules (startup)
+#Delete a rule for an ip to grand internet access
+
+#define version of the script
+version="V2.1.13"
+#load IPTables
+IPTABLES=/sbin/iptables
+#When it needs to initialize the rules, do this
+if [ "$1" == "initialize" ]
+then
+#First stop host apd so people can't connect
+sudo service hostapd stop
+#Flush all existing rules
+$IPTABLES -F
+$IPTABLES -X
+#Allow forwarding
+echo 1 > /proc/sys/net/ipv4/ip_forward
+#Boot up Wifi adapter
+echo "Booting up WiFi adapter..."
+sudo ifup wlan0
+#Add some basic rules to iptables
+while read rule
+do
+        #Execute each rule in the file
+        $($rule)
+done < /portal/firewall_Rules
+#Each ip from the list will be redirected to the captive portal
+echo "These IP's will be redirected to the Captive Portal"
+#define 1 (ip counter) and set it to zero
+i=0
+#Read all ips from ip file and make rule per ip
+#Read each line as $ip
+while read ip
+do
+        #Shits getting serious now
+        sudo $IPTABLES -t nat -A PREROUTING -s "$ip" -p tcp -j DNAT --to-destination 10.111.11.5:80
+        #Print the ip
+        echo $ip
+        #Increment 1 on i so we can see how many ip where added
+        ((i++))
+#Not the last line in file? Lets do it again!
+done < /portal/users
+#Show the amount of ip's
+echo "Added $i IP's to rule list"
+echo "Checking if site is up (might take a while)"
+#Set 1 to one, for another counter
+i=1
+        #Lets check if our portal is online
+        #The 3 here is for the amount of times you want to check (default is 3)
+        while [ $i -le 3 ]
+        do
+                #Check if the site is online 
+                if curl -s --head http://localhost/Portal/ | head -n 1 | grep "200" >/dev/null 2>&1;
+                then
+                        #If the site is up, do this:
+                        echo "Site is up!"
+                        echo "Starting hostapd"
+                        #Start hostapd so people can connect
+                        sudo service hostapd start
+                        #Set i to 4 to break the loop
+                        i=4
+                        echo "Everything is up and running!"
+                else
+                        #If site is still down do this
+                        echo "Still checking if site is up ($i/3)"
+                        #Give Tomcat some time to think
+                        sleep 30s
+                        #Increment i with 1
+                        ((i++))
+                        #If i = 4, The site is still not up, Tell whats wrong!
+                        if [ "$i" == "4" ]
+                        then
+                                echo "Site is still not online!"
+                                echo "Exiting the program (maybe reboot)"
+                        fi
+                fi
+        done
+#Show some information
+echo "Captive Portal rule script"
+echo $version
+echo "Copy right: Deben Oldert"
+fi
+#If action is permitting acces to internet, delete rule to portal
+if [ "$1" == "grand" ]
+then
+        #check if $2 (ip adress) not empty
+        if [[ ! -z "$2" ]]
+        then
+                #Delete the rule
+                sudo -u root $IPTABLES -t nat -D PREROUTING -s $2 -p tcp -j DNAT --to-destination 10.11$
+                #Tell the system its fine
+                echo "SUCCES"
+        else
+                #Missing the ip parameter
+                echo "FAIL"
+        fi
+fi
+#Uncomment for debugging
+#$IPTABLES -t nat -L PREROUTING

+ 31 - 0
captiveportal/firewall/users

@@ -0,0 +1,31 @@
+192.168.50.40
+192.168.50.41
+192.168.50.42
+192.168.50.43
+192.168.50.44
+192.168.50.45
+192.168.50.46
+192.168.50.47
+192.168.50.48
+192.168.50.49
+192.168.50.50
+192.168.50.51
+192.168.50.52
+192.168.50.53
+192.168.50.54
+192.168.50.55
+192.168.50.56
+192.168.50.57
+192.168.50.58
+192.168.50.59
+192.168.50.60
+192.168.50.61
+192.168.50.62
+192.168.50.63
+192.168.50.64
+192.168.50.65
+192.168.50.66
+192.168.50.67
+192.168.50.68
+192.168.50.69
+192.168.50.70

BIN
captiveportal/images/Thumbs.db


BIN
captiveportal/images/bg.gif


BIN
captiveportal/images/corendon.jpg


BIN
captiveportal/images/corendon2.JPG


BIN
captiveportal/images/corendon3.JPG


BIN
captiveportal/images/corendon4.jpg


BIN
captiveportal/images/corendon5.jpg


BIN
captiveportal/images/corendon6.jpg


BIN
captiveportal/images/corendon7.jpg


BIN
captiveportal/images/corendon8.jpg


BIN
captiveportal/images/loading.gif


+ 210 - 0
captiveportal/json.java

@@ -0,0 +1,210 @@
+/*
+Copy right: Deben Oldert
+This is the famous JSON class
+Every JSON request and respond is created an proccesed here
+Enjoy the show
+*/
+package captiveportal;
+
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.Random;
+import java.util.Date;
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
+import java.io.StringWriter;
+import java.net.HttpURLConnection;
+import java.net.URL;
+
+import org.json.simple.JSONObject;
+import org.json.simple.JSONArray;
+import org.json.simple.parser.ParseException;
+import org.json.simple.parser.JSONParser;
+
+public class json {
+	private final String teamKey = "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX";
+	private final String teamId = "INXXX-X";
+	private String[] listTickets(String url, String json) throws Exception {
+		 
+		//The url to the JSON listener
+		URL http = new URL(url);
+		//Make the connection to the listener
+		HttpURLConnection con = (HttpURLConnection) http.openConnection();
+ 
+		//add reuqest headers
+		con.setRequestMethod("POST");
+		con.setRequestProperty("User-Agent", "Mozilla/5.0");
+		con.setRequestProperty("Content-Type", "application/json");
+		con.setRequestProperty("Accept", "application/json");
+		con.setRequestProperty("Accept-Language", "en-US,en;q=0.5");
+ 
+		// Send post request
+		//Do some fancy shizzle
+		con.setDoOutput(true);
+		OutputStreamWriter data= new OutputStreamWriter(con.getOutputStream());
+		//Send the JSON request
+		data.write(json);
+		data.flush();
+		//Get the JSON response
+		BufferedReader in = new BufferedReader(
+		        new InputStreamReader(con.getInputStream()));
+		String inputLine;
+		StringBuffer response = new StringBuffer();
+		//Put the response in a string (not in the underpants)
+		while ((inputLine = in.readLine()) != null) {
+			response.append(inputLine);
+		}
+		in.close();
+ 
+		//Parse to JSON
+		JSONParser parser=new JSONParser();
+		  //Make it a string
+	      String s = response.toString();
+	      //Just give it a shot
+	      try{
+	    	 //Create JSON object
+	         Object obj = parser.parse(s);
+	         //Get the ticket variable from the full JSON object
+	         JSONObject tickets = (JSONObject)obj;
+	         //Make from the value of tickets an array (because we can and it simply is)
+	         JSONArray array = (JSONArray)tickets.get("tickets");
+	         //Create an array from every ticketNumber in the array (with maximum as amount if tickets)
+	         String[] ticketNumbers = new String[(int) array.size()];
+	         //Let loop it
+	         for(int i = 0; i < (int) array.size(); i++)
+	         	{
+	        	 //Get the ticket number from each ticket
+	        	 JSONObject ticketNumber = (JSONObject)array.get(i);
+	        	 //Make from the number a string and put in our newly created array
+	        	 ticketNumbers[i] = (String) ticketNumber.get("ticketNumber");
+	        	 //Not at the end? Lets do it again!
+	         	}
+	         //Now the purpose of this function Return all the ticket number in a singel array
+	         return ticketNumbers;
+	         //If you found le wild Charizard catch it.
+	      }catch(ParseException pe){
+	         System.out.println("position: " + pe.getPosition());
+	         System.out.println(pe);
+	         /*
+	          	I wanna be the very best,
+				Like no one ever was.
+				To catch them is my real test,
+				To train them is my cause.
+	          */
+	      }
+	      //If error return it
+	     String[] returnArray = {"ERROR", "BOEHOEHOE"};
+		return returnArray;
+	      
+ 
+	}
+	private String grandAccessRequest(String json) throws Exception {
+		 
+		//The url to the JSON listener
+		URL http = new URL("http://webapi.implementation.computerscience.international:9323/CFIS/Ticket");
+		//Make the connection to the listener
+		HttpURLConnection con = (HttpURLConnection) http.openConnection();
+ 
+		//add reuqest headers
+		con.setRequestMethod("POST");
+		con.setRequestProperty("User-Agent", "Mozilla/5.0");
+		con.setRequestProperty("Content-Type", "application/json");
+		con.setRequestProperty("Accept", "application/json");
+		con.setRequestProperty("Accept-Language", "en-US,en;q=0.5");
+ 
+		// Send post request
+		con.setDoOutput(true);
+		OutputStreamWriter data= new OutputStreamWriter(con.getOutputStream());
+		data.write(json);
+		//Send JSON request
+		data.flush();
+		//Read JSON response
+		BufferedReader in = new BufferedReader(
+		        new InputStreamReader(con.getInputStream()));
+		String inputLine;
+		StringBuffer response = new StringBuffer();
+		//Get all the output, and place it in one string
+		while ((inputLine = in.readLine()) != null) {
+			response.append(inputLine);
+		}
+		in.close();
+ 
+		//Parse result to JSON
+		JSONParser parser=new JSONParser();
+		  //Make from a raw JSON object an string
+	      String s = response.toString();
+	      //Create JSON object
+	      Object obj = parser.parse(s);
+	      //Get the respond code 
+	      JSONObject resultCode = (JSONObject)obj;
+	      //Make the code a string
+	      return (String) resultCode.get("result");  
+	}
+	@SuppressWarnings("unchecked")
+	//Deprecated since version 04-01-2015. So no small talk
+	public boolean checkTicket(String ticketNumber) throws Exception
+		{
+		JSONObject json=new JSONObject();
+		Random random = new Random();
+		int  requestId = random.nextInt(9999) + 1000;
+		json.put("function", "List");
+		json.put("teamId", teamId);
+		json.put("teamKey", teamKey);
+		json.put("requestId", new Integer(requestId));
+		StringWriter out = new StringWriter();
+		  json.writeJSONString(out);
+		  String jsonText = out.toString();
+		
+		String[] ticketNumbers = listTickets("http://webapi.implementation.computerscience.international:9323/CFIS/Ticket", jsonText);
+		for(int i = 0; i < ticketNumbers.length; i++)
+			{
+			if(new String(ticketNumbers[i]).equals(ticketNumber))
+				{
+				return true;
+				}
+			}
+		return false;
+		}
+	@SuppressWarnings("unchecked")
+	public boolean grandAccess(String ticketNumber) throws Exception 
+		{
+		//Create JSON object
+		JSONObject json=new JSONObject();
+		//Our unique ID will be a timestamp
+		//Set the stamp format
+		DateFormat TimeStamp = new SimpleDateFormat("MMddyyyyHHmmssSSS");
+		//Get the current date
+		Date today = Calendar.getInstance().getTime();
+		//Make it a string
+		String CurrentTimeStamp = TimeStamp.format(today);
+		//Put variables in our JSON object
+		json.put("function", "RegisterInternetAccess");
+		json.put("teamId", teamId);
+		json.put("teamKey", teamKey);
+		json.put("requestId", CurrentTimeStamp);
+		json.put("ticketNumber", ticketNumber);
+		//Write it to a string
+		StringWriter out = new StringWriter();
+		  json.writeJSONString(out);
+		  String jsonText = out.toString();
+		//Call the function grandAccessRequest
+		String grandResult = grandAccessRequest(jsonText);
+		//If login succesfull or if user already logged in. Then you may pass
+		if(grandResult.equals("0") || grandResult.equals("8"))
+		{
+			//Congrats. Now you can log in!
+			return true;
+		}
+		//Else..
+		else
+		{
+			//Not
+			//Print to the system why not
+			System.out.println("Suddenly le wild error code (" +grandResult+ ") appeared!!");
+			//Say it fails
+			return false;
+		}
+	}
+}

+ 21 - 0
captiveportal/loading.html

@@ -0,0 +1,21 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="UTF-8">
+<title>Applying request...</title>
+</head>
+<body style="background-color:rgba(139, 197, 62, 1)">
+<div style="position:fixed; top:50%; left:50%; margin-top:-150px; margin-left:-200px;">
+<img src="/Portal/Images/loading.gif" style="width:400px; height:300px;">
+</div>
+<div style="width:100%; text-align:center; height:20px; position:fixed; bottom:0; color:white; visibility:hidden;" id="manual">
+If you don't get redirected please click <a href="http://corendon.nl" target="_self">here</a>
+</div>
+</body>
+<script type="text/javascript">
+setTimeout(function() {
+	document.title = "You will be redirected";
+	document.getElementById('manual').style.visibility = "visible";
+	},2750);
+</script>
+</html>

+ 115 - 0
captiveportal/proccess.java

@@ -0,0 +1,115 @@
+/* 	This is the proccessing page of the captive portal.
+*	Copy right: Deben Oldert
+*	Here classes are called to check and update database query's and to configure iptables.
+*	Called classe are: {JSON, Command}
+*/
+package captiveportal;
+import java.io.IOException;
+import java.io.PrintWriter;
+
+import javax.servlet.ServletException;
+import javax.servlet.annotation.WebServlet;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+
+/**
+ * Servlet implementation class proccess
+ */
+@WebServlet("/proccess")
+public class proccess extends HttpServlet {
+	private static final long serialVersionUID = 1L;
+    
+	/**
+	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
+	 */
+	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+		// Set the MIME type for the page
+	      response.setContentType("text/html");
+	      PrintWriter out = response.getWriter();
+		// Send user back to login form
+	      try {
+	    	  out.println("<script>window.location.replace('http://portal.corendon.nl/Portal');</script>");
+	      	} finally {
+	      		out.close();  // Close the output writer
+	      	}
+	}
+	/**
+	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
+	 */
+	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+		 // Set the MIME type for the page
+	      response.setContentType("text/html");
+	      // Define variables
+	      //#####################################
+	      String ticketNumber = request.getParameter("ticket");
+	      int exitCode = 2;
+	      String javaReturn0 = "<script>setTimeout(function(){window.location.replace('http://corendon.nl')},2700);</script>";
+	      String javaReturnErrorS = "<script>window.location.replace('http://portal.corendon.nl/Portal/?err=";
+	      String javaReturnErrorE = "');</script>";
+	      //#####################################
+	      //Start the output writer
+	      PrintWriter out = response.getWriter();
+	      //Load classes
+	      Command CMD = new Command();
+	      json JSON = new json();
+
+	      try {
+	    	// Fallback to version 04-01-2015 (Only if you want to be a badboy)
+			//if(JSON.checkTicket(ticketNumber)) {
+	    	  	//Call to the grandAccess function in json.java
+				if(JSON.grandAccess(ticketNumber))
+					{
+					//Now lets give the user actually access to the interwebzz
+					if(CMD.Grand(request.getRemoteAddr())) {
+					  exitCode = 0;
+					}
+					//If you did not pass, say so
+					else {
+						exitCode = 3;
+					}
+				}
+				//If you did not pass, say so
+				else
+					{
+					exitCode = 2;
+					}
+			//Part of the fallback
+			/*}
+			else {
+				exitCode = 1;
+			}*/
+			// what ya' gonna do, what ya' gonna do when they come for you....
+		} catch (Exception e) {
+			e.printStackTrace();
+			exitCode = 4;
+		}
+	    //What to do with a exitCode?
+	    switch (exitCode) {
+	    //Whet could we do, what could we do...
+	    case 0:
+	    	//Eureka!! Making the path to the interwebzz
+	    	request.getRequestDispatcher("/loading.html").include(request, response);
+	    	out.println(javaReturn0);
+	    	break;
+	    //For the following cases: Get back where you came from (index.html) but with a return code
+	    case 1:
+	    	out.println(javaReturnErrorS+exitCode+javaReturnErrorE);
+	    	break;
+	    case 2:
+	    	out.println(javaReturnErrorS+exitCode+javaReturnErrorE);
+	    	break;
+	    case 3:
+	    	out.println(javaReturnErrorS+exitCode+javaReturnErrorE);
+	    	break;
+	    case 4:
+	    	out.println(javaReturnErrorS+exitCode+javaReturnErrorE);
+	    	break;
+	    case 5:
+	    	out.println(javaReturnErrorS+exitCode+javaReturnErrorE);
+	    	break;
+	    }
+	}
+
+}

+ 33 - 0
captiveportal/readme.md

@@ -0,0 +1,33 @@
+<h1>How to deploy?</h1>
+Just download the latest precompiled .WAR file from <a href="http://owncloud.hostable.nl/public.php?service=files&t=7d4dbc2080b768b97ed2a19f2d8e44a7" target="_blank">here</a>.<br>
+The password is: mojado<br>
+If you need an older version contact me or download it from your own account.
+<h2>How the portal works</h2>
+HTTP request<br>
+||>>By just typing in any website<br>
+User redirected to the captive portal<br>
+||>>By javascript<br>
+User fills in ticket number and lastname<br>
+||>>By a HTML form<br>
+Forms goes to proccess.java<br>
+________||<br>
+________||>>lastname and ticketnumber return 1 row? (lastname and ticketnumber combination is unique)<br>
+________||    Then continue<br>
+________||    else Tell the user the lastname and ticketnumber combination was not correct<br>
+________||<br>
+________||<br>
+________||>> Update Database (tell the database the user is using internet)<br>
+________||    Succes? return continue<br>
+________||    Failure? Tell the user someting went wrong<br>
+________||<br>
+________||>>Grand IP adress<br>
+________||    Succes? continue<br>
+________||    else update Database (tell the database the user is not using internet)<br>
+________||    Tell the user someting went wrong<br>
+________||<br>
+________||>>Everyting OK?<br>
+________||    Then show the user the loading.html page and The user is free to use the internet<br>
+________||    else Tell the user someting went wrong<br>
+<br>
+<br>
+This is how our captive portal in very global lines works.

BIN
captiveportal/war_exports/Portal (05-01-2015).war


BIN
captiveportal/war_exports/Portal(06-01-2015)FINAL(1.6).war


BIN
captiveportal/war_exports/Portal(06-01-2015)FINAL(1.7).war


BIN
captiveportal/war_exports/Portal(06-01-2015)FINAL.war


BIN
captiveportal/war_exports/Portal.war


+ 21 - 0
database/readme.md

@@ -0,0 +1,21 @@
+<h1>How to access the database from a remote client</h1>
+<h2>Step 1</h2>
+```mysql -u root -p``` and fill in your password as requested (you defined it during the installation of mysql-server)
+<h2>Step 2</h2>
+```use mysql;```
+<h2>Step 3</h2>
+```update user set Host="%" where Host="127.0.0.1";```
+<h2>Step 4</h2>
+```exit ```
+<h2>Step 5</h2>
+```/etc/init.d/mysql restart```
+<h2>Step 6</h2>
+Open your sql client
+<h2>Step 7</h2>
+Create a new connection:<br>
+```ip: <ip of your raspberry>```<br>
+```port: 3306```<br>
+```user: root```<br>
+```password: <password for root>```
+<h2>Step 8</h2>
+Have lots of fun! ;)

+ 1 - 0
database/users.sql

@@ -0,0 +1 @@
+**MYSQL DB FILE

BIN
jiji Business case.pdf


+ 6 - 0
raspberry/hostapd.conf

@@ -0,0 +1,6 @@
+interface=wlan0
+ssid=Team#3
+hw_mode=g
+channel=6
+auth_algs=1
+wmm_enabled=0

+ 1 - 0
raspberry/info.md

@@ -0,0 +1 @@
+test

+ 13 - 0
raspberry/interfaces

@@ -0,0 +1,13 @@
+auto lo
+
+iface lo inet loopback
+iface eth0 inet dhcp
+address 192.168.2.22
+netmask 255.255.255.0
+gateway 192.168.2.254
+dns-nameservers 8.8.8.8, 4.2.2.2
+
+iface wlan0 inet static
+address 192.168.50.99
+netmask 255.255.255.0
+post-up service udhcpd start