diff --git a/components/README b/components/README index bcae188520735d94949c0fb0744d764913c5d82d..001f8b510ce38abaf68f60c11889eb4a5abb0c55 100644 --- a/components/README +++ b/components/README @@ -24,7 +24,8 @@ $component The pagemap record used for the current page: [component] component name $smarty The smarty object -$DB The ADODB database object +$DB The sucssite ADODB database object +$sucsDB The sucs ADODB databse object $session The Session object Session has the following properties diff --git a/components/membershiprenew.php b/components/membershiprenew.php index a0c833c76ded399563d20ac7d5e466b0450baa20..2a87046ae36ac7e860fc994b8f652b3a828c8ed9 100644 --- a/components/membershiprenew.php +++ b/components/membershiprenew.php @@ -12,24 +12,20 @@ $paydate = paidUntil(time()); // Only staff can use this page if (isset($session->groups[$permission])) { $smarty->assign("staff", TRUE); - // connect to sucs database - $sucsDB = NewADOConnection('postgres8'); - $sucsDB->Connect('dbname=sucs user=apache'); - $sucsDB->SetFetchMode(ADODB_FETCH_ASSOC); // $sucsDB->debug = true; - + // handle updates if(isset($_POST['uid']) && isset($_POST['lastupdate'])){ // Check data hasn't changed and that nothing is broked $query = "SELECT * FROM members WHERE uid=? AND lastupdate=?"; $array = array($_POST['uid'], $_POST['lastupdate']); $data = $sucsDB->GetAll($query,$array); - + // If there is only one record then everything is fine if(sizeof($data)==1){ // get info on currently logged in user $user = posix_getpwnam($session->username); - + // Update record $record = $data[0]; $query = "UPDATE members"; @@ -39,7 +35,7 @@ if (isset($session->groups[$permission])) { if($enable){ $sucsDB->query($query,$array); } - + // emailing contact (tresurer) $message = "Account renewal notification\n\n"; $message .= "Account : ".$record['username']."\n"; @@ -47,7 +43,7 @@ if (isset($session->groups[$permission])) { $message .= "Renewed by: ".$user['name']."\n\n"; $message .= "Regards\n eclipse's script"; mail($inform,"Account Renewal",$message); - + // emailing user $message = "Your Swansea University Computer Society (SUCS) membership has been renewed\n\n"; $message .= "Username: ".$record['username']."\n"; @@ -59,14 +55,14 @@ if (isset($session->groups[$permission])) { mail($record['email'],"SUCS account renewal",$message,$header); // sucs account mail($record['username']."@sucs.org","SUCS account renewal",$message,$header); - + message_flash("Renewed account for: ".htmlentities($record['username'])); } else{ trigger_error("Number of recored returned: ".sizeof($data).". Expected: 1.", E_USER_ERROR); } } - + // if sort is specified in GET if(isset($_GET["sort"])){ $sortoptions = array("username","sid","realname"); @@ -85,8 +81,8 @@ if (isset($session->groups[$permission])) { else{ $sort='username'; } - - + + //Get members details $query = "SELECT * FROM members, member_type"; $query .= " WHERE paid != ?"; @@ -96,7 +92,7 @@ if (isset($session->groups[$permission])) { $array = array($paydate); $data = $sucsDB->GetAll($query, $array); $smarty->assign("members", $data); - + // set refresh rate $autorefresh=$_GET["autorefresh"]; // if autorefresh is not 'n' @@ -120,13 +116,13 @@ if (isset($session->groups[$permission])) { $getrefresh='n'; $optrefresh='n'; } - + // compile passthrough url // sort if(isset($getsort)){ $getout="?sort=".$getsort; } - + // autorefresh if(isset($getrefresh)){ if(isset($getout)){ @@ -136,7 +132,7 @@ if (isset($session->groups[$permission])) { $getout = "?autorefresh=".$getrefresh; } } - + // set smarty variables $smarty->assign("self",$baseurl.$path.$getout); $smarty->assign("optionrefresh",$optrefresh); diff --git a/components/motd_wrapper.php b/components/motd_wrapper.php index b6f274d21e9721c71cb0f45e17b9044c5a650fe3..602a148f4c997ade4cea8a943c49526fa61960be 100644 --- a/components/motd_wrapper.php +++ b/components/motd_wrapper.php @@ -2,12 +2,6 @@ require("/var/www/sucssite/htdocs/settings.php"); require("/usr/share/php/adodb/adodb.inc.php"); -$dbname = 'sucssite'; -$dbuser = 'apache'; - -$DB = NewADOConnection('postgres8'); -$DB->Connect('dbname='.$dbname.' user='.$dbuser); $DB->SetCharSet('utf8'); -$DB->SetFetchMode(ADODB_FETCH_ASSOC); include($base."components/motd.php"); diff --git a/components/options.php b/components/options.php index 9e4303c37d4083ea576e1192c6a1c73438ad2bd1..f6068a350287864f5aff41d7d973e379f86d2faf 100644 --- a/components/options.php +++ b/components/options.php @@ -10,7 +10,6 @@ include_once("../lib/date.php"); // These could possibly be moved somewhere saner? define('GUESTNET_LOW','137.44.10.130'); // These could possibly be a set of ranges or a subnet which might be saner? define('GUESTNET_HIGH','137.44.10.134'); // These could possibly be a set of ranges or a subnet which might be saner? -$sucsdbname = 'sucs'; // This was stored in config, I just don't have it here in the test // Helper Functions // Could these be moved to some kind of library? @@ -38,7 +37,7 @@ function changePassword ($oldpass, $newpass1, $newpass2) { trigger_error("LDAP connect failed", E_USER_ERROR); return FALSE; } - + if (!($ldapbind = ldap_bind($ldap, "uid=".$session->username.",ou=People,dc=sucs,dc=org",$oldpass))) { trigger_error("Existing password incorrect", E_USER_WARNING); ldap_close($ldap); @@ -58,14 +57,14 @@ function changeContactDetails($address, $phone, $externalEmail) { global $sucsDB, $session, $error; // Do some kind of checking here // Check valid email (do we have a function for this? - if (!validEmail($externalEmail)) + if (!validEmail($externalEmail)) return FALSE; // Valid Email handles errors itself // Check valid phone number (do we have a function for this?) if (empty($phone) || (strlen($phone) < 6)) { trigger_error("You must have a contact phone number!", E_USER_WARNING); return FALSE; } - // Update + // Update if ($sucsDB->Execute('UPDATE members SET address = ?,phone = ?, email = ?, lastupdate = now(), lastedit = uid WHERE username = ?', array($address, $phone, $externalEmail, $session->username)) === FALSE) { trigger_error("There was an error updating your contact details. Please contact admin.", E_USER_ERROR); @@ -76,7 +75,7 @@ function changeContactDetails($address, $phone, $externalEmail) { function changeGuestnetDetails($wiredMAC) { global $sucsDB, $session, $error; - // Get UID as we don't have it yet + // Get UID as we don't have it yet if(($uid = $sucsDB->GetOne("SELECt uid FROM members WHERE username = ?", array($session->username))) === FALSE) { trigger_error("There was an error updating your GuestNET MAC Address. Please contact admin. (UID)", E_USER_ERROR); return FALSE; @@ -87,7 +86,7 @@ function changeGuestnetDetails($wiredMAC) { return FALSE; } exec('/usr/local/bin/update-dhcpd', $placeholder, $returnVar); - + if ($returnVar == 0) { return TRUE; // $message[] = 'GuestNet MAC Address updated. Please wait a minute or two for the changes to take effect.'; @@ -112,7 +111,7 @@ function getGuestNetMAC() { // Sanity Check ip? // Check we are in the correct ip range (unregistered GuestNET addresses) if (ip2long($ip) && (ip2long($ip) >= ip2long(GUESTNET_LOW)) && (ip2long($ip) <= ip2long(GUESTNET_HIGH))) { - + exec("sudo /usr/local/sbin/gw-copy-arp.sh", $placeholder, $returnVar); if ($returnVar == 0) { $arpLines = file('/tmp/gwarp'); @@ -158,8 +157,7 @@ function hackergotchiPath($username) { // Takes an entry from $_FILES and makes this the new hackergotchi function updateHackergotchi($fileDetails) { global $session; - if ( ((list($width, $height, $type, $attr) = @getimagesize($fileDetails['tmp_name'])) !== false)) { - + if ( ((list($width, $height, $type, $attr) = @getimagesize($fileDetails['tmp_name'])) !== false)) { if ($type != IMAGETYPE_PNG) { trigger_error("Uploaded hackergotchi is not in PNG format. Please convert your image to PNG and try again.", E_USER_ERROR); return FALSE; @@ -174,7 +172,7 @@ function updateHackergotchi($fileDetails) { if( move_uploaded_file($fileDetails['tmp_name'], $imagefilepath) && chmod($imagefilepath, 0644) ) { return TRUE; } - } + } // We should have returned True by now trigger_error("There was an error updating your hackergotchi. Please contact admin.", E_USER_ERROR); return FALSE; @@ -217,11 +215,8 @@ $smarty->assign('session', $session); if ($session->loggedin === TRUE) { - $sucsDB = NewADOConnection('postgres8'); - $sucsDB->Connect('dbname='.$sucsdbname.' user=apache'); - $sucsDB->SetFetchMode(ADODB_FETCH_ASSOC); // $sucsDB->debug = true; - + $newGuestNetMAC = getGuestNetMAC(); // Handle Postbacks @@ -248,7 +243,7 @@ if ($session->loggedin === TRUE) { case 'updatehackergotchi' : if (updateHackergotchi($_FILES['hackergotchi'])) { message_flash('Hackergotchi Updated'); - } + } break; case 'clearhackergotchi' : if (clearHackergotchi()) { diff --git a/components/printer.graph.php b/components/printer.graph.php index db4f3096bb4002eed46996b60297aedea18cc814..fee1be1face2c3cbf9f0f069e1e4dd20a482a916 100644 --- a/components/printer.graph.php +++ b/components/printer.graph.php @@ -1,8 +1,4 @@ <? -include("adodb/adodb.inc.php"); -$sucsDB = NewADOConnection('postgres8'); -$sucsDB->Connect('dbname=sucs user=apache'); -$sucsDB->SetFetchMode(ADODB_FETCH_ASSOC); $res = $sucsDB->Execute("select username, sum(pages) as pages from printer where username != 'old' group by username order by sum(pages) desc"); $num = $res->RecordCount(); @@ -19,7 +15,7 @@ $num = $res->RecordCount(); } // $itemName[]="Other"; // $sliceSize[]=$otherSize; - + $slice = array_merge(array($otherSize),$slice); $item = array_merge(array("Other"), $item); @@ -29,4 +25,4 @@ $num = $res->RecordCount(); include("../../lib/pieChart.php"); piechart("Top 12, Users of Printing", $slice, $item,0) -?> +?> \ No newline at end of file diff --git a/components/printer.php b/components/printer.php index 83a77ace70971a4512c2e766c918cbaa76ffb4c6..239c96e1bf58da98a89adfb41d015e0467d89b69 100644 --- a/components/printer.php +++ b/components/printer.php @@ -9,9 +9,6 @@ $max=10; //Set this to number of users to display in chart $timestamp = '2014-02-05 18:29:02+00'; //display printer stats since this time $smarty->assign('title',"Printer Statistics"); -$sucsDB = NewADOConnection('postgres8'); -$sucsDB->Connect('dbname=sucs user=apache'); -$sucsDB->SetFetchMode(ADODB_FETCH_ASSOC); // $out="<img src=\"/images/printer.graph.php\" alt=\"pie chart of top 12 printer users\"/>"; $table="<table border=1 cellpadding=3>\n<tr>\n<th>Username</th>\n<th>Pages</th>\n<th>Projected Monthly Usage</th>\n<th>Printed This Month</th>\n<th>What it would cost in the library</th></tr>\n"; @@ -38,7 +35,7 @@ for ($i=0;$i<$num;$i++) { $res = $sucsDB->Execute("select username, pages, start from printer where username != 'old'"); $datesnum = $res->RecordCount();//for each row stuff the infomation into an array, then free up the database resorces -for ($i=0;$i<$datesnum;$i++) { +for ($i=0;$i<$datesnum;$i++) { $dates[$i] = $res->FetchRow($res, $i); } $res->Close(); @@ -55,7 +52,7 @@ for ($i=0;$i<$datesnum;$i++) { if ($data[$j]['username'] == $dates[$i]['username']) { $data[$j]['month'] += $dates[$i]['pages']; } - } + } } } @@ -69,7 +66,7 @@ for ($i=0;$i<$num;$i++) { //avg pages per month = seconds in a month / (now - first print) * pages $crazyGuess = round((2629743.83/($thisSecond-$data[$i]['first']))*$data[$i]['pages']); //if the user has only started printing in the last month its not sensible to give a guess of average useage - if ($thisSecond-$data[$i]['first'] <= 2629743.83) { + if ($thisSecond-$data[$i]['first'] <= 2629743.83) { $table.="<td>Not enough data</td>\n"; } //traffic lights for pinter useage, adjust values as required diff --git a/components/signup-admin.php b/components/signup-admin.php index f0dc026bfdab824eac240abf30b1891dcdeb232b..3ac13a1e31ecc9f5cfc0b995ebd7c3e98e6caefb 100644 --- a/components/signup-admin.php +++ b/components/signup-admin.php @@ -5,10 +5,6 @@ $permission="sucsstaff"; if (isset($session->groups[$permission])) { $smarty->assign("staff",TRUE); - // connect to sucs database - $sucsDB = NewADOConnection('postgres8'); - $sucsDB->Connect('dbname=sucs user=apache'); - $sucsDB->SetFetchMode(ADODB_FETCH_ASSOC); //get unused signup slips $query = "SELECT signup.id, signup.sid, member_type.typename, members.username, signup.card"; $query .= " FROM signup LEFT JOIN member_type ON signup.type = member_type.id LEFT JOIN members ON signup.issuedby=members.uid"; diff --git a/components/signup.php b/components/signup.php index 181376cfe9da55001fd389300e8b95751da1ce45..bcd46f066289d245f8b009fc65e874585a4042be 100644 --- a/components/signup.php +++ b/components/signup.php @@ -35,17 +35,9 @@ if(isset($_REQUEST['signupid'])&&isset($_REQUEST['signuppw'])){ //set signup details $signupid = $_REQUEST['signupid']; $signuppw = $_REQUEST['signuppw']; - // connect to sucs database - $sucsDB = NewADOConnection('postgres8'); - //$sucsDB->debug = true; - - // ------------------------------------------------- - // DEV:SET THIS TO YOUR DATBASE FOR DEV MODE - // ------------------------------------------------- - $sucsDB->Connect('dbname=sucs'); + //$sucsDB->debug = true; - $sucsDB->SetFetchMode(ADODB_FETCH_ASSOC); // get row(s) $query = "SELECT * FROM signup WHERE id=? AND password=?"; $array = array($signupid,$signuppw); @@ -379,7 +371,7 @@ if(isset($_REQUEST['signupid'])&&isset($_REQUEST['signuppw'])){ $smarty->assign("fields",$fields); $smarty->assign("errors",$errors); $smarty->append('extra_scripts', $script); - $mode='re-form'; + $mode='re-form'; } } else{ diff --git a/components/susignup-admin.php b/components/susignup-admin.php index c0694f9657d9d92ff3d310b0b8422340b50763d8..c24eb1a76aae7a5b8c8dff14b06a10ce76bf32d1 100644 --- a/components/susignup-admin.php +++ b/components/susignup-admin.php @@ -1,6 +1,6 @@ <?PHP /*** - * SU Signup admin + * SU Signup admin * Allows us to search the SU api for a given student number and checks if they're a SUCS member. * If they are - allows account renewal * If not - allows signup to be bootstrapped as per susignup component @@ -10,7 +10,7 @@ include("../lib/member_functions.php"); include("../lib/date.php"); include("../suapi.inc.php"); -//Restrict access to staff. +//Restrict access to staff. $permission="sucsstaff"; $apibaseurl="https://$suapi_user:$suapi_pass@su-api.sucs.org/memberships/Membership.asmx"; @@ -24,13 +24,6 @@ if (isset($session->groups[$permission])) { $mode = urldecode($_REQUEST['mode']); } - //Set up SUCS DB Connection. - //Note that $DB is the generic sucssite connection - - $sucsDB = NewADOConnection('postgres8'); - $sucsDB->Connect('dbname=sucs user=apache'); - $sucsDB->SetFetchMode(ADODB_FETCH_ASSOC); - if ($mode == 'search') { if (empty($_REQUEST['sid']) || empty($_REQUEST['snsubmit'])) { $mode = 'error'; diff --git a/components/susignup.php b/components/susignup.php index c7eb1a441d36c0b8fe2cc9e7f32fa6a0d9e7136c..7b19e0cb41a0246f6f5c08008e92281a705a19b6 100755 --- a/components/susignup.php +++ b/components/susignup.php @@ -12,10 +12,10 @@ $mode = 'login'; //login if(!empty($_REQUEST['sid'])&&!empty($_REQUEST['transactionID'])){ //set signup details - + $sid = $_REQUEST['sid']; $transactionID = $_REQUEST['transactionID']; - + //set POST variables $url = "https://$suapi_user:$suapi_pass@su-api.sucs.org/memberships/Membership.asmx/GetMemberByTransactionID"; $fields = array( @@ -36,21 +36,21 @@ if(!empty($_REQUEST['sid'])&&!empty($_REQUEST['transactionID'])){ curl_setopt($ch,CURLOPT_RETURNTRANSFER,TRUE); //execute post $result = curl_exec($ch); - + //close connection curl_close($ch); if(!$result){ $mode = "error"; $smarty->assign("error_text", "Invalid query returned"); - } else { + } else { libxml_use_internal_errors(true); $xml=simplexml_load_string($result); if (!$xml||isset($xml->head->title)) { $mode='error'; $smarty->assign("error_text", "An error occurred communicating with the SUSU API"); } else{ - $re1='.*?'; - $re2='(\\{.*?\\})'; + $re1='.*?'; + $re2='(\\{.*?\\})'; if ($c=preg_match_all ("/".$re1.$re2."/is", $result, $matches)) { $json_string=$matches[1][0]; @@ -61,16 +61,9 @@ if(!empty($_REQUEST['sid'])&&!empty($_REQUEST['transactionID'])){ if($array['cardNumber'] == $sid && $sid != ""){ $mode = 'form'; - // connect to sucs database - $sucsDB = NewADOConnection('postgres8'); - // SET THIS FOR DEBUG MODE // $sucsDB->debug = true; - // SET THIS TO YOUR DB FOR TESTING - $sucsDB->Connect('dbname=sucs user=apache'); - $sucsDB->SetFetchMode(ADODB_FETCH_ASSOC); - $fullName = $array['firstName']." ".$array['lastName']; $query = "INSERT INTO transactions (transactionID,fullName,emailAddress,cardNumber,personID) values(?, ?, ?, ?, ?)"; $attribs[] = $transactionID; @@ -86,7 +79,7 @@ if(!empty($_REQUEST['sid'])&&!empty($_REQUEST['transactionID'])){ unset($attribs); $attribs[]=$transactionID; if($sucsDB->Execute($query,$attribs)) { - + $query = "SELECT * FROM transactions WHERE transactionID = ?"; $attribs= array(); $attribs[]=$transactionID; @@ -145,7 +138,7 @@ if(!empty($_REQUEST['sid'])&&!empty($_REQUEST['transactionID'])){ } if($valid) - { + { unset($attribs); unset($query); $query = "SELECT * FROM members WHERE sid = ?"; @@ -160,7 +153,7 @@ if(!empty($_REQUEST['sid'])&&!empty($_REQUEST['transactionID'])){ $q="UPDATE members SET paid=?, lastupdate=DEFAULT, lastedit=? WHERE username=?;"; $r=$sucsDB->Execute($q, array(paidUntil(time()), '99999', $data->fields['username'])); if (!$r) { - mail( + mail( $error_email, "SUSignup Error", "An error occured in the susignup system at stage 2.5\n Love the signup system.\n\nP.S. The Error is:\n ".$sucsDB->ErrorMsg(), @@ -178,7 +171,7 @@ if(!empty($_REQUEST['sid'])&&!empty($_REQUEST['transactionID'])){ $message .= "**** Payment was made via the SU payments system ****\n"; $message .= "Regards\n The SU Renewals script"; mail("treasurer@sucs.org","Account Renewal",$message); - + $message = "Your Swansea University Computer Society (SUCS) membership has been renewed\n\n"; $message .= "Username: ".$renew_name."\n"; $message .= "If you do not know or have forgotten your password, please email admin@sucs.org to arrange for it to be changed.\n\n"; @@ -204,21 +197,21 @@ if(!empty($_REQUEST['sid'])&&!empty($_REQUEST['transactionID'])){ "From: \"SUCS Admin\" <admin@sucs.org>" ); } - } + } } else { - $pass = make_password(); + $pass = make_password(); unset($query); $query = "insert into signup (password,sid,issuedby) values( ?, ?, ?) returning id"; unset($attribs); $attribs[]=$pass; $attribs[]=$array['cardNumber']; $attribs[]='99999'; - + $iddata = $sucsDB->Execute($query,$attribs); $id = $iddata->fields['id']; if (!$iddata) { $mode="error"; - mail( + mail( $error_email, "SUSignup Error", "An error occured in the susignup system at stage 3\n Love the signup system.\n\nP.S. The Error is:\n ".$sucsDB->ErrorMsg(), @@ -250,8 +243,8 @@ if(!empty($_REQUEST['sid'])&&!empty($_REQUEST['transactionID'])){ } } } - } - } + } + } } } } diff --git a/htdocs/index.php b/htdocs/index.php index 9d9ebe112721f692c8d810e936d48bd7bfd954c6..1cdc92a6ddb050ed92fd56a568f5a1337036d4e1 100644 --- a/htdocs/index.php +++ b/htdocs/index.php @@ -37,12 +37,17 @@ $smarty->plugins_dir[] = $base."plugins"; $smarty->assign("baseurl", $baseurl); -// Initialise the database +// Initialise the sucssite database conn require("/usr/share/php/adodb/adodb.inc.php"); $DB = NewADOConnection('postgres9'); $DB->Connect('dbname='.$dbname.' user='.$dbuser); $DB->SetFetchMode(ADODB_FETCH_ASSOC); +// Initialise the sucs database conn +$sucsDB = NewADOConnection('postgres9'); +$sucsDB->Connect('dbname='.$sucsdbname.' user='.$dbuser); +$sucsDB->SetFetchMode(ADODB_FETCH_ASSOC); + // Include the session library require($base."lib/session.php"); $session = new Session; diff --git a/settingstemplate b/settingstemplate index 34dc10faf13f6a31c11370e6895877ffd518b062..9006d50b55590dd0f71b9049409c2616605b66ed 100644 --- a/settingstemplate +++ b/settingstemplate @@ -4,6 +4,7 @@ $base = "$BASEDIR/"; $baseurl = "/~$USERNAME/sucssite"; $preferred_hostname = "sucs.org"; $dbname="beta"; +$sucsdbname="sucs"; $dbuser="$USERNAME"; // Settings for current election (god knows why they are here):