or .\n"); printf( "\n\n SERVER CONFIGURATION PARAMETERS\n\n"); //prompt for name and password of mysql user with root priveleges print("\nEnter a MySQL account that has root priveleges on the database.\n"); print("This user will only be used to install Ensemble schema and establish\n"); print("privileges for the database.\n"); print("MySQL account with root privileges on the database [$mysql_user]: "); $input = trim(fgets(STDIN,256)); if($input != "") { $mysql_user = $input; } print "\nPlease enter the password for account $mysql_user.\n"; print "Have you created a password for $mysql_user? If $mysql_user\n"; print "doesn't have a password yet, you can just click .\n"; print "In this case, make sure to assign a password to $mysql_user "; print "immediately after installation.\n"; printf("Password for $mysql_user (input is invisible): "); system('stty -echo'); $mysql_password = trim(fgets(STDIN,256)); system('stty echo'); //prompt for the hostname where mysql is hosted print "\n\nEnter the IP address or hostname where the MySQL server resides\n"; print "If the MySQL server is on this computer, just use localhost\n"; print "Otherwise, enter the hostname or IP address of the MySQL server\n"; print("Hostname or IP address of mysql server [$mysql_hostname]: "); $input = trim(fgets(STDIN,256)); if($input != "") { $mysql_hostname = $input; } $conn = mysql_connect($mysql_hostname,$mysql_user,$mysql_password); if(!$conn) { print("\nUNABLE TO ESTABLISH DATABASE CONNECTION.\nCHECK USERNAME, PASSWORD, AND HOSTNAME\n"); print("If using 'localhost' for hostname, make sure that your mysql socket connection settings are correct in php.ini.\n\n"); die(); } //prompt for the database name to install to print ("\nPlease enter the name of the database "); print("that you wish to use with Ensemble [$db_name]: "); $input = trim(fgets(STDIN,256)); if($input != "") { $db_name = $input; } printf( "\n\nMYSQL SCHEMA INSTALLATION\n"); //install database schema print( "\nDo you wish to install the Ensemble database schema?\n"); print( "Unless you have already installed it by some other means\n"); print( "or have installed it by running this installation script\n"); print( "in the past, you should enter 'y'\n"); print( "Install MySQL schema? (y/n):"); $input = trim(fgets(STDIN,256)); while(!preg_match('|[YyNn]|',$input)) { print "Please enter 'y' for yes or 'n' for no"; $input = trim(fgets(STDIN,256)); } if (preg_match('|[Yy]|',$input)) { $replace = array("ensemble" => $db_name); $success = parse_replace_sql($mysql_schema_file,$replace); if($success) print "\nSCHEMA INSTALLED\n"; else print "\nFAILED TO INSTALL SCHEMA\n"; } printf( "\n\nMYSQL USER CONFIGURATION\n"); //prompt whether to create researcher and user accounts print "\nIn order for Ensemble to work, you need to create researcher and subject user accounts.\n"; print "If this is your first installation of Ensemble on this computer, it is recommended that\n"; print "you create the accounts now.\n"; print "Create MySQL users for ensemble (y/n)?"; $input = trim(fgets(STDIN,256)); while(!preg_match('|[YyNn]|',$input)) { print "Please enter 'y' for yes or 'n' for no"; $input = trim(fgets(STDIN,256)); } //Create the resarcher and subject users and sets their priveleges in MySQL if ((preg_match('|[Yy]|',$input))) { print "Please enter the account name to use for subjects.\n"; print "Note that it will be used in the background and participants will not be\n"; print "aware that the account exists.\nSubject account username [$subject_account]: "; $input = trim(fgets(STDIN,256)); if ($input != '') { $subject_account=$input; } print "Please enter a password for the account $subject_account : "; $subject_password = trim(fgets(STDIN,256)); print "\nPlease enter an account name that researchers will use.\n"; print "All researchers in your lab or organization may use this account.\n"; print "If you wish to establish different user accounts for researchers, they may\n"; print "simply be created in phpMyAdmin by copying the researcher account.\n"; print "Researcher account [$researcher_account]: "; $input = trim(fgets(STDIN,256)); if ($input != '') { $researcher_account=$input; } print "Please enter a password for account $researcher_account : "; $researcher_password = trim(fgets(STDIN,256)); $replace = array("subject_account" => $subject_account, "subject_password" => $subject_password, "researcher_account" => $researcher_account, "researcher_password" => $researcher_password, "mysql_hostname" => $mysql_hostname, "db_name" => $db_name); $success = parse_replace_sql($mysql_user_file,$replace); if($success) { print "\n\nACCOUNTS '$researcher_account' AND '$subject_account' CREATED.\n"; print "PLEASE STORE THE PASSWORDS IN A SECURE LOCATION.\n"; $mysql_accounts_created = TRUE; } else print "\n\nFAILED TO CREATE RESEARCHER AND SUBJECT MYSQL ACCOUNTS.\n"; } printf( "\n\nSUBJECT USER STORAGE\n"); //prompt whether to configure subject login info for QPI print "\nSave the subject login and password information for the QPI?\n"; print "If this is the first installation of Ensemble on\n"; print "this computer say 'y'. \n"; print "Save subject login and password for the QPI (y/n)?"; $input = trim(fgets(STDIN,256)); while(!preg_match('|[YyNn]|',$input)) { print "Please enter 'y' for yes or 'n' for no"; $input = trim(fgets(STDIN,256)); } //Copy conn_subject.php and configure it if ((preg_match('|[Yy]|',$input))) { print "\nEnter the location where the subject login/password and the encryption key should be saved.\n"; print "The specified directory will be created as long as its parent directory exists.\n"; print "(e.g. if specifying /var/private/ensemble_info, make sure that /var/private exists).\n"; print "You must have write privilege to this directory in order to create it.\n"; print "After the installation script is finished, make sure to set the appropriate privileges to this directory.\n"; print "Only the web server application (e.g. apache user) and administrators should have access.\n"; $do_create_dir = true; while($do_create_dir) { print "Directory path for subject MySQL connectivity information and the encryption key [$conn_subject_location] : "; $input = trim(fgets(STDIN,256)); if($input != '') { $conn_subject_location=$input; } $conn_subject_location = remove_trailing_slash($conn_subject_location); if(is_dir($conn_subject_location)) { print "Directory $conn_subject_location exists. Using this directory.\n"; break; } print "\nThe specified directory $conn_subject_location doesn't exist. Create it (y/n)?"; $input = trim(fgets(STDIN,256)); while(!preg_match('|[YyNn]|',$input)) { print "Please enter 'y' for yes or 'n' for no"; $input = trim(fgets(STDIN,256)); } if ((preg_match('|[Yy]|',$input))) { mkdir ($conn_subject_location); if(!is_dir($conn_subject_location)) { //failed to create directory, try again print "FAILED TO CREATE DIRECTORY. CHECK PERMISSIONS AND TRY AGAIN.\n"; continue; } else $do_create_dir = false; } else { print "TRYING AGAIN...\n"; continue; } } if (!$mysql_accounts_created) { print "Subject account username [$subject_account]: "; $input = trim(fgets(STDIN,256)); if ($input != '') { $subject_account=$input; } print "Password for $subject_account? "; $subject_password = trim(fgets(STDIN,256)); } $mysql_conn_subject_dest = $mysql_conn_subject; print "\n\nDESTINATION FOR SUBJECT MYSQL CONNECTION INFORMATION\n"; print "Choose the filename that will contain subject MySQL connectivity information.\n"; printf("It will be stored in the directory you have just chosen (%s)\n",$conn_subject_location); $valid_input = FALSE; while(!$valid_input) { print("The filename must end in \".php\"\n"); printf("[%s]: ",$mysql_conn_subject_dest); $input = trim(fgets(STDIN,256)); if($input != '') { if(!preg_match('|^.+\.php|',$input)) continue; $mysql_conn_subject_dest = $input; $valid_input = TRUE; } } $file_contents = file_get_contents($mysql_conn_subject); $replace = array("" => $subject_account,"" => $subject_password); $file_contents = strtr($file_contents,$replace); print "\n\nTrying to write to $conn_subject_location/$mysql_conn_subject_dest\n"; $try2write = true; while($try2write) { $fid = fopen($conn_subject_location."/".$mysql_conn_subject_dest,"w"); if(fwrite($fid,$file_contents)) { print "CREATED FILE $conn_subject_location/$mysql_conn_subject_dest\n"; fclose($fid); $try2write = false; } else { fclose($fid); $try2write = prompt_to_rewrite($conn_subject_location."/".$mysql_conn_subject_dest); if(!$try2write) { print "YOU CAN RERUN THIS SCRIPT AND BYPASS SECTIONS THAT RAN SUCCESSFULLY\n"; print "TO CREATE THE FILE $mysql_conn_subject_dest.\n"; print "MAKE SURE YOU ENTER THE SUBJECT PASSWORD IDENTICALLY WHEN YOU RERUN THIS SECTION.\n"; print "ENSEMBLE WILL NOT RUN PROPERLY UNTIL THIS IS CONFIGURED\n"; } } } } print "\n\nENCRYPTION KEY\n"; $encryption_key_default_loc = $conn_subject_location."/ensemble_encryption_key.txt"; print "Enter a file path to store the Ensemble encryption key.\n"; print "It is recommended that you use the same path as conn_subject.php\n"; print "Just click or if the default path is acceptible.\n"; print "If the encryption key file already exists, enter the path here.\n"; $enc_key_isset = false; while(!$enc_key_isset) { $do_prompt_path = true; while($do_prompt_path) { print "Encryption key path [$encryption_key_default_loc]: "; $input = trim(fgets(STDIN,256)); if ($input == '') $encryption_key_location = $encryption_key_default_loc; else $encryption_key_location = $input; $encryption_key_exists = file_exists($encryption_key_location); if($encryption_key_exists) { print "$encryption_key_location exists. Use this file (y/n): "; $use_file= y_or_n(); if(!$use_file) { //user chose to not use this existing file. //they will be prompted again $do_prompt_path = true; } else { //using an existing encryption key file //we're done here. $do_prompt_path= false; $do_prompt_key = false; $enc_key_isset = true; } } else { //using a new encryption key path //need to prompt for a key $do_prompt_path= false; $do_prompt_key = true; } } if($do_prompt_key) { print "\n\nThe key phrase to use for encypting identifying subject info.\n"; print "This may include spaces and non-alphanumeric characters\n"; print "and may be of any length (16 or more characters recommended).\n"; print "It is recommended that you file a printout of the encryption key, and back it up.\n"; print "IF THIS KEY IS LOST, IDENTIFYING SUBJECT DATA WILL BE IRRETRIEVABLE!!!\n"; $encryption_key = ''; while(empty($encryption_key)) { print "Encryption key: "; $encryption_key = trim(fgets(STDIN,256)); } $fid = fopen($encryption_key_location,"w"); if(fwrite($fid,$encryption_key)) { print "CREATED FILE $encryption_key_location\n"; print "DO NOT LOSE THE ENCRYPTION KEY!!!\n"; fclose($fid); $do_prompt_key = false; $enc_key_isset = true; } else { fclose($fid); $retry = prompt_to_rewrite($encryption_key_location); if(!$retry) { print "YOU CAN RERUN THIS SCRIPT AND BYPASS SECTIONS THAT RAN SUCCESSFULLY\n"; print "ENSEMBLE WILL NOT RUN PROPERLY UNTIL THE ENCRYPTION KEY IS CONFIGURED.\n"; break; } } } } print "\n\nQEI AND QPI CONFIGURATION\n"; print "\n\nConfigure the QEI/QPI?\n"; print "This will configure the web interfaces so that they can communicate "; print "with the database (y/n)?"; $input = trim(fgets(STDIN,256)); while(!preg_match('|[YyNn]|',$input)) { print "Please enter 'y' for yes or 'n' for no"; $input = trim(fgets(STDIN,256)); } if ((preg_match('|[Yy]|',$input))) { $qei_qpi_dir = getcwd(); $indiv_dirs = explode('/',$qei_qpi_dir); $top_level = $indiv_dirs[sizeof($indiv_dirs)-1]; $qei_qpi_dir = substr($qei_qpi_dir, 0, strlen($qei_qpi_dir) - strlen($top_level) - 1); print "\n\nEnter the directory of your Ensemble QEI/QPI (web scripts): [$qei_qpi_dir]: "; $input = trim(fgets(STDIN,256)); if ($input != '') { $qei_qpi_dir=$input; } //remove trailing slash from directory, if present $qei_qpi_dir = remove_trailing_slash($qei_qpi_dir); $config_dir = $qei_qpi_dir."/include/"; $config_file = $config_dir."variables_config_default.php"; $output_file = $config_dir."variables_config.php"; printf("\n\n"); $fid = fopen($config_file,"r"); // get the " 0) { if (!in_array($sigmatch[1],$idgen_scripts)) { array_push($idgen_scripts,$sigmatch[1]); } } } //closing the directory closedir($dir_handle); // get a filename $valid_input = FALSE; while (!$valid_input) { print "\n\nenter the script you would like to use to generate your subject ids"; print "\n\t(type 'l' to list the available scripts)\n"; printf("[%s]: ",$matches[3]); $input=trim(fgets(STDIN,256)); if (preg_match("|^[Ll]$|",$input)) { foreach ($idgen_scripts as $sname) { print "\t$sname\n"; } } elseif ($input == NULL) { $valid_input = TRUE; } elseif (in_array($input,$idgen_scripts)) { $valid_input = TRUE; } // if preg_match("|[Ll]| } // while (!$continue break; case "\$ENCRYPTION_KEY_PATH": $input = $encryption_key_location; print "Setting to $encryption_key_location\n"; break; default: printf("[%s]: ",$matches[3]); $input = trim(fgets(STDIN,256)); break; } $new_file_buffer[] = sprintf("%s = %s%s%s;\n",$matches[1],$matches[2],(($input != NULL)? $input : $matches[3]),$matches[4]); } elseif(preg_match("|\?\>|",$line)) $new_file_buffer[] = $line; else { $new_file_buffer[] = $line."\n"; if(preg_match('|//(.*)|',$line,$matches)) printf("%s\n",$matches[1]); } } fclose($fid); $fid2 = fopen($output_file,"w"); for($row = 0;$row < count($new_file_buffer); $row++) { fwrite($fid2,$new_file_buffer[$row]); } fclose($fid2); } ?>