2013-12-18 19:04:25 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# Setting up an election
							 
						 
					
						
							
								
									
										
										
										
											2013-12-18 15:42:29 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								0. vote/include/election-sql.php expects a secret config file that exists
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   only on the server and is included as PHP code.  It's hard coded currently
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   to: /home/admin/secret/anonvoting currently.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-12-18 17:09:04 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   The file should look something like this:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-12-18 19:04:25 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								         <?php
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								             $mysql_host = "localhost";
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								             $mysql_user = "someuser";
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								             $mysql_password = "somepassword";
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								             $mysql_db = "somedb";
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								             $committee_name = "The Vote Masters";
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								             $committee_email = "elections@example.org";
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								          ?>
							 
						 
					
						
							
								
									
										
										
										
											2013-12-18 15:42:29 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								1. When I deploy, I create an account for the election, as the mysql root user:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   mysql -u root -p
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   Password: <MYSQLROOTPW>
							 
						 
					
						
							
								
									
										
										
										
											2013-12-18 18:09:12 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   Then Run these commands at the mysql> prompt:
							 
						 
					
						
							
								
									
										
										
										
											2013-12-18 19:04:25 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        CREATE USER 'someusername' identified by 'somepassword';
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        CREATE DATABASE somedbname;
							 
						 
					
						
							
								
									
										
										
										
											2013-12-18 18:09:12 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   Then, exit, and at the main command line run:
							 
						 
					
						
							
								
									
										
										
										
											2013-12-18 19:04:25 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								         msyql -u root -p -D somedbname < ..../vote/include/schema.sql
							 
						 
					
						
							
								
									
										
										
										
											2013-12-18 18:09:12 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   Then run this again:
							 
						 
					
						
							
								
									
										
										
										
											2013-12-18 19:04:25 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        mysql -u root -p
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        Password: <MYSQLROOTPW>
							 
						 
					
						
							
								
									
										
										
										
											2013-12-18 18:09:12 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   and at the mysql command line, run these grant commands:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-12-18 19:04:25 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        GRANT SELECT on somedb.elections TO someuser@localhost;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        GRANT SELECT on somedb.election_choices TO someuser@localhost;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        GRANT SELECT,DELETE on somedb.election_tmp_tokens TO someuser@localhost;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        GRANT SELECT on somedb.election_voters TO someuser@localhost;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        GRANT SELECT,INSERT on somedb.election_anon_tokens TO someuser@localhost;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        GRANT INSERT on somedb.election_votes TO someuser@localhost;
							 
						 
					
						
							
								
									
										
										
										
											2013-12-18 18:09:12 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								2. Create an election, with something like this:
							 
						 
					
						
							
								
									
										
										
										
											2013-12-18 19:04:25 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        mysql -u root -D somedb -p
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        SET NAMES 'utf8';
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        INSERT t INTO elections (type, name, voting_start, voting_end, choices_nb,   question) VALUES ("elections", "2011 Spring Election", "2011-05-29 00:00:00", "2011-06-12 23:59:59", "7", "Which candidates would you like to see Elected?");
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        set @el_id = @@IDENTITY;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        INSERT INTO election_choices (election_id, choice) VALUES
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                (@el_id, 'Candidate 1'),
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                (@el_id, 'Candidate 2'),
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                (@el_id, 'Candidate 3'),
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                (@el_id, 'Candidate 4');
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        INSERT INTO election_voters (election_id, email_address) VALUES
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                (@el_id, 'voter1@example.org'),
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                (@el_id, 'voter2@example.org'),
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                (@el_id, 'voter3@example.com'),
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                (@el_id, 'voter4@example.net');
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        INSERT INTO election_tmp_tokens (election_id, election_voter_id, tmp_token)
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								           SELECT @el_id, id, SUBSTRING(MD5(RAND()) FROM 1 FOR 24) AS tmp_token
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								           FROM election_voters where election_id = @el_id;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        select @el_id;
							 
						 
					
						
							
								
									
										
										
										
											2013-12-18 18:09:12 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-12-18 19:05:03 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    That number you see at the end is this election's id.  The URL you'll
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    give out is thus something like:
							 
						 
					
						
							
								
									
										
										
										
											2013-12-18 19:04:25 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								      http://example.org/vote?election_id=THAT_NUMBER
							 
						 
					
						
							
								
									
										
										
										
											2013-12-18 18:53:50 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-12-18 19:04:41 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Dealing With Problems
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								=====================
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								## Missing Ballots
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Voters might complain that they haven't received their token.  Likely, it
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								either went missing or the email address was wrongly noted in the
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								database. In any case, you need to find the ID of the voter With the ID do
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								something like:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    SELECT * FROM election_tmp_tokens WHERE election_id = 17 AND election_voter_id  = $ID;