From: Maxious Date: Fri, 16 Sep 2011 03:53:46 +0000 Subject: Purge openid-php X-Git-Url: http://maxious.lambdacomplex.org/git/?p=busui.git&a=commitdiff&h=0dc105deddf45bf359e88445ba8371b31ec212e4 --- Purge openid-php --- --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ /labs/tiles/16 /labs/tiles/17 /labs/tiles/19 +/nbproject/private/ --- a/about.php +++ b/about.php @@ -21,10 +21,6 @@ , ACT Buses by David Sullivan) and Android (MyBus 2.0 by Imagine Team)
-GTFS-realtime API; -Alerts and Trip Updates (but only Cancelled or Stop Skipped) -Default format binary but can get JSON by adding ?ascii=yes -

Disclaimer: The content of this website is of a general and informative nature. Please check with printed timetables or those available on http://action.act.gov.au before your trip. Whilst every effort has been made to ensure the high quality and accuracy of the Site, the Author makes no warranty, --- a/aws/busuiphp.sh +++ b/aws/busuiphp.sh @@ -9,6 +9,7 @@ chcon -R -t httpd_sys_content_rw_t /var/www/labs/tiles chmod -R 777 /var/www/labs/tiles +mkdir /var/www/lib/openid-php/oid_store chcon -R -t httpd_sys_content_rw_t /var/www/lib/openid-php/oid_store chmod -R 777 /var/www/lib/openid-php/oid_store --- a/include/common-auth.inc.php +++ b/include/common-auth.inc.php @@ -1,62 +1,15 @@ begin($oid_identifier); - - // Create attribute request object - // See http://code.google.com/apis/accounts/docs/OpenID.html#Parameters for parameters - // Usage: make($type_uri, $count=1, $required=false, $alias=null) - $attribute[] = Auth_OpenID_AX_AttrInfo :: make('http://axschema.org/contact/email', 2, 1, 'email'); - $attribute[] = Auth_OpenID_AX_AttrInfo :: make('http://axschema.org/namePerson/first', 1, 1, 'firstname'); - $attribute[] = Auth_OpenID_AX_AttrInfo :: make('http://axschema.org/namePerson/last', 1, 1, 'lastname'); - - // Create AX fetch request - $ax = new Auth_OpenID_AX_FetchRequest; - - // Add attributes to AX fetch request - foreach($attribute as $attr) { - $ax -> add($attr); - } - - // Add AX fetch request to authentication request - $auth -> addExtension($ax); - $_SESSION['returnURL'] = curPageURL(); - // Redirect to OpenID provider for authentication - $url = $auth -> redirectURL(getTrustRoot(), $_SESSION['returnURL']); - header('Location: ' . $url); + global $openid; + if(!$openid->mode) { + $openid->required = array('contact/email'); + $openid->identity = 'https://www.google.com/accounts/o8/id'; + header('Location: ' . $openid->authUrl()); + } } @@ -64,21 +17,11 @@ { if ($_SESSION['authed'] == true) return true; - - // Create file storage area for OpenID data - $store = new Auth_OpenID_FileStore('lib/openid-php/oid_store'); - // Create OpenID consumer - $consumer = new Auth_OpenID_Consumer($store); - // Create an authentication request to the OpenID provider - $response = $consumer -> complete($_SESSION['returnURL']); - - if ($response -> status == Auth_OpenID_SUCCESS) { - // Get registration informations - $ax = new Auth_OpenID_AX_FetchResponse(); - $obj = $ax -> fromSuccessResponse($response); - $email = $obj -> data['http://axschema.org/contact/email'][0]; - var_dump($email); - if ($email != "maxious@gmail.com") { + global $openid; + + if($openid->mode) { + $attr = $openid->getAttributes(); + if ($attr["contact/email"] != "maxious@gmail.com") { die("Access Denied"); } else { $_SESSION['authed'] = true; @@ -87,5 +30,4 @@ login(); } } - if ($_REQUEST['janrain_nonce']) auth(); ?> --- a/include/common-template.inc.php +++ b/include/common-template.inc.php @@ -32,7 +32,7 @@ -' . $pageTitle . ' - Canberra Bus Timetable +' . $pageTitle . ' @@ -98,11 +98,8 @@ function success(position) { $('#error').val('Location now detected. Please wait for data to load.'); $('#geolocate').val(position.coords.latitude+','+position.coords.longitude); -$.ajax({ async: false, -success: function(){ - location.reload(true); - }, -url: \"include/common.inc.php?geolocate=yes&lat=\"+position.coords.latitude+\"&lon=\"+position.coords.longitude }); +$.ajax({ url: \"include/common.inc.php?geolocate=yes&lat=\"+position.coords.latitude+\"&lon=\"+position.coords.longitude }); +location.reload(true); } function error(msg) { $('#error').val('Error: '+msg); @@ -159,11 +156,11 @@ echo '
Buses are running on an altered timetable today due to industrial action/public holiday. See http://www.action.act.gov.au for details.
'; } } - if ($GTFSREnabled) { - $serviceAlerts = getServiceAlertsAsArray("agency","0"); - foreach ($serviceAlerts['entity'] as $entity) { - echo "
".date("F j, g:i a",strtotime($entity['alert']['active_period'][0]['start']))." to ". date("F j, g:i a", strtotime($entity['alert']['active_period'][0]['end']))."{$entity['alert']['header_text']['translation'][0]['text']}
Warning: {$entity['alert']['description_text']['translation'][0]['text']} -
Source
"; + if ($serviceAlertsEnabled) { + $serviceAlerts = getServiceAlerts("network","network"); + foreach ($serviceAlerts['entities'] as $entity) { + echo "
".date("F j, g:i a",strtotime($entity['alert']['active_period']['start']))." to ". date("F j, g:i a", strtotime($entity['alert']['active_period']['end']))."{$entity['alert']['header_text']['translation']['text']}
Warning: {$entity['alert']['description_text']['translation']['text']} +
Source
"; } } } --- a/include/common-transit.inc.php +++ b/include/common-transit.inc.php @@ -45,7 +45,7 @@ return ""; } } -if ($GTFSREnabled) { + $serviceAlertCause = Array( "UNKNOWN_CAUSE" => "Unknown cause", "OTHER_CAUSE" => "Other cause", @@ -71,22 +71,7 @@ "UNKNOWN_EFFECT" => "Unknown effect", "STOP_MOVED" => "Stop moved"); -set_include_path(get_include_path() . PATH_SEPARATOR . $labsPath."lib/Protobuf-PHP/library/DrSlump/"); - -include_once("Protobuf.php"); -include_once("Protobuf/Message.php"); -include_once("Protobuf/Registry.php"); -include_once("Protobuf/Descriptor.php"); -include_once("Protobuf/Field.php"); - -include_once($labsPath."lib/Protobuf-PHP/gtfs-realtime.php"); -include_once("Protobuf/CodecInterface.php"); -include_once("Protobuf/Codec/PhpArray.php"); -include_once("Protobuf/Codec/Binary.php"); -include_once("Protobuf/Codec/Binary/Writer.php"); -include_once("Protobuf/Codec/Json.php"); - -function getServiceAlerts($filter_class = "", $filter_id = "") { +function getServiceAlerts($filter_class, $filter_id) { /* also need last modified epoch of client gtfs @@ -106,82 +91,40 @@ street inform: route inform, trip inform, stop inform route patch: trip remove */ - $fm = new transit_realtime\FeedMessage(); -$fh = new transit_realtime\FeedHeader(); -$fh->setGtfsRealtimeVersion(1); -$fh->setTimestamp(time()); -$fm->setHeader($fh); +$return = Array(); +$return['header']['gtfs_realtime_version'] = "1"; +$return['header']['timestamp'] = time(); +$return['header']['incrementality'] = "FULL_DATASET"; +$return['entities'] = Array(); foreach(getCurrentAlerts() as $alert) { -$fe = new transit_realtime\FeedEntity(); - $fe->setId($alert['id']); - $fe->setIsDeleted(false); - $alert = new transit_realtime\Alert(); - $tr = new transit_realtime\TimeRange(); - $tr->setStart($alert['start']); - $tr->setEnd($alert['end']); - $alert-> addActivePeriod($tr); - $informedEntities = getInformedAlerts($alert['id'],$_REQUEST['filter_class'],$_REQUEST['filter_id']); + $informedEntities = getInformedAlerts($alert['id'],$_REQUEST['filter_class'],$_REQUEST['filter_id']); if (sizeof($informedEntities) >0) { - $informed = Array(); - $es = new transit_realtime\EntitySelector(); - if ($informedEntity['informed_class'] == "agency") { - $es->setAgencyId($informedEntity['informed_id']); + $entity = Array(); + $entity['id'] = $alert['id']; + $entity['alert']['active_period']['start'] = $alert['start']; + $entity['alert']['active_period']['end'] = $alert['end']; + $entity['alert']['url']['translation']['text'] = $alert['url']; + $entity['alert']['url']['translation']['language'] = 'en'; + $entity['alert']['header_text']['translation']['text'] = $alert['header']; + $entity['alert']['header_text']['translation']['language'] = 'en'; + $entity['alert']['description_text']['translation']['text'] = $alert['description']; + $entity['alert']['description_text']['translation']['language'] = 'en'; + + foreach ($informedEntities as $informedEntity) { + $informed = Array(); + $informed[$informedEntity['informed_class']."_id"] = $informedEntity['informed_id']; + if ($informedEntity['informed_action'] != "") $informed["x-action"] = $informedEntity['informed_action']; + $informed[$informedEntity['class']."_type"] = $informedEntity['type']; + $entity['informed'][] = $informed; } - if ($informedEntity['informed_class'] == "stop") { - $es->setStopId($informedEntity['informed_id']); - } - if ($informedEntity['informed_class'] == "route") { - $es->setRouteId($informedEntity['informed_id']); - } - if ($informedEntity['informed_class'] == "trip") { - $td = new transit_realtime\TripDescriptor(); - $td->setTripId($informedEntity['informed_id']); - $es->setTrip($td); - } - $alert-> addInformedEntity($es); + $return['entities'][] = $entity; } - $alert->setCause(constant("transit_realtime\Alert\Cause::".$alert['cause'])); - $alert->setEffect(constant("transit_realtime\Alert\Effect::".$alert['effect'])); - $tsUrl = new transit_realtime\TranslatedString(); - $tUrl = new transit_realtime\TranslatedString\Translation(); - $tUrl->setText($alert['url']); - $tUrl->setLanguage("en"); - $tsUrl->addTranslation($tUrl); - $alert->setUrl($tsUrl); - $tsHeaderText= new transit_realtime\TranslatedString(); - $tHeaderText = new transit_realtime\TranslatedString\Translation(); - $tHeaderText->setText($alert['header']); - $tHeaderText->setLanguage("en"); - $tsHeaderText->addTranslation($tHeaderText); - $alert->setHeaderText($tsHeaderText); - $tsDescriptionText= new transit_realtime\TranslatedString(); - $tDescriptionText = new transit_realtime\TranslatedString\Translation(); - $tDescriptionText->setText($alert['description']); - $tDescriptionText->setLanguage("en"); - $tsDescriptionText->addTranslation($tDescriptionText); - $alert->setDescriptionText($tsDescriptionText); - $fe->setAlert($alert); -$fm->addEntity($fe); } -return $fm; -} -function getServiceAlertsAsArray($filter_class = "", $filter_id = "") { - $codec = new DrSlump\Protobuf\Codec\PhpArray(); - return $codec->encode(getServiceAlerts($filter_class, $filter_id)); -} - -function getServiceAlertsAsBinary($filter_class = "", $filter_id = "") { - $codec = new DrSlump\Protobuf\Codec\Binary(); - return $codec->encode(getServiceAlerts($filter_class, $filter_id)); -} - -function getServiceAlertsAsJSON($filter_class = "", $filter_id = "") { - $codec = new DrSlump\Protobuf\Codec\Json(); - return $codec->encode(getServiceAlerts($filter_class, $filter_id)); +return $return; } function getServiceAlertsByClass() { $return = Array(); - $alerts = getServiceAlertsAsArray("",""); + $alerts = getServiceAlerts("",""); foreach ($alerts['entities'] as $entity) { foreach ($entity['informed'] as $informed) { foreach($informed as $key => $value){ @@ -191,70 +134,10 @@ $id = $value; } } - $return[$class][$id][] = $entity; + $return[$class][$id][]['entity'] = $entity; + $return[$class][$id][]['action'] = $informed["x-action"]; } } } - -function getTripUpdates($filter_class = "", $filter_id = "") { - $fm = new transit_realtime\FeedMessage(); -$fh = new transit_realtime\FeedHeader(); -$fh->setGtfsRealtimeVersion(1); -$fh->setTimestamp(time()); -$fm->setHeader($fh); -foreach(getCurrentAlerts() as $alert) { - $informedEntities = getInformedAlerts($alert['id'],$_REQUEST['filter_class'],$_REQUEST['filter_id']); - $stops = Array(); - $routestrips = Array(); - if (sizeof($informedEntities) >0) { - if ($informedEntity['informed_class'] == "stop" && $informed["x-action"] == "remove") { - $stops[] = $informedEntity['informed_id']; - } - if (($informedEntity['informed_class'] == "route" || $informedEntity['informed_class'] == "trip") && $informed["x-action"] == "patch" ) { - $routestrips[] = Array( "id" => $informedEntity['informed_id'], - "type"=>$informedEntity['informed_class']); - } - } -foreach ($routestrips as $routetrip) { -$fe = new transit_realtime\FeedEntity(); - $fe->setId($alert['id'].$routetrip['id']); - $fe->setIsDeleted(false); - $tu = new transit_realtime\TripUpdate(); - $td = new transit_realtime\TripDescriptor(); - if ($routetrip['type'] == "route") { - $td->setRouteId($routetrip['id']); - } else if ($routetrip['type'] == "trip") { - $td->setTripId($routetrip['id']); - } - $tu->setTrip($td); - foreach ($stops as $stop) { - $stu = new transit_realtime\TripUpdate\StopTimeUpdate(); - $stu->setStopId($stop); - $stu->setScheduleRelationship(transit_realtime\TripUpdate\StopTimeUpdate\ScheduleRelationship::SKIPPED); - $tu->addStopTimeUpdate($stu); - } - $fe->setTripUpdate($tu); -$fm->addEntity($fe); -} - -} -return $fm; - -} -function getTripUpdatesAsArray($filter_class = "", $filter_id = "") { - $codec = new DrSlump\Protobuf\Codec\PhpArray(); - return $codec->encode(getTripUpdates($filter_class, $filter_id)); -} - -function getTripUpdatesAsBinary($filter_class = "", $filter_id = "") { - $codec = new DrSlump\Protobuf\Codec\Binary(); - return $codec->encode(getTripUpdates($filter_class, $filter_id)); -} - -function getTripUpdatesAsJSON($filter_class = "", $filter_id = "") { - $codec = new DrSlump\Protobuf\Codec\Json(); - return $codec->encode(getTripUpdates($filter_class, $filter_id)); -} -} ?> --- a/include/common.inc.php +++ b/include/common.inc.php @@ -10,7 +10,7 @@ "database", "other" ); -$GTFSREnabled = true; +$serviceAlertsEnabled = true; $cloudmadeAPIkey = "daa03470bb8740298d4b10e3f03d63e6"; $googleMapsAPIkey = "ABQIAAAA95XYXN0cki3Yj_Sb71CFvBTPaLd08ONybQDjcH_VdYtHHLgZvRTw2INzI_m17_IoOUqH3RNNmlTk1Q"; $otpAPIurl = 'http://localhost:8080/opentripplanner-api-webapp/'; @@ -32,8 +32,8 @@ function isDebugServer() { - return php_sapi_name() == "cli" || isset($_SERVER['SERVER_NAME']) && ( $_SERVER['SERVER_NAME'] == "azusa" || $_SERVER['SERVER_NAME'] == "vanille" -|| $_SERVER['SERVER_NAME'] == "localhost" || $_SERVER['SERVER_NAME'] == "127.0.0.1") ; + return php_sapi_name() == "cli" || isset($_SERVER['SERVER_NAME']) && ( $_SERVER['SERVER_NAME'] == "10.0.1.154" || $_SERVER['SERVER_NAME'] == "10.1.0.4" || $_SERVER['SERVER_NAME'] == +"localhost" || $_SERVER['SERVER_NAME'] == "127.0.0.1") ; } include_once ("common-geo.inc.php"); @@ -49,9 +49,7 @@ function isAnalyticsOn() { - $user_agent = $_SERVER['HTTP_USER_AGENT']; - return !isDebugServer() && !preg_match('/cloudkick/i', $user_agent) && !preg_match('/googlebot/i', $user_agent) && -!preg_match('/baidu/i', $user_agent); + return !isDebugServer(); } function isDebug($debugReason = "other") { --- a/include/db/servicealert-dao.inc.php +++ b/include/db/servicealert-dao.inc.php @@ -17,7 +17,7 @@ function getServiceAlert($alertID) { global $conn; - $query = "SELECT id,extract('epoch', start) as start, extract('epoch', end) as end,cause,effect,header,description,url from servicealerts_alerts where id = :servicealert_id"; + $query = 'SELECT * from servicealerts_alerts where id = :servicealert_id'; debug($query, "database"); $query = $conn -> prepare($query); $query -> bindParam(":servicealert_id", $alertID); @@ -30,16 +30,15 @@ } -function updateServiceAlert($alertID, $start, $end, $header, $description, $url) +function updateServiceAlert($alertID, $start, $end, $description, $url) { global $conn; - $query = 'update servicealerts_alerts set start=:start, "end"=:end, header=:header, description=:description, url=:url where id = :servicealert_id'; + $query = 'update servicealerts_alerts set start=:start, "end"=:end, description=:description, url=:url where id = :servicealert_id'; debug($query, "database"); $query = $conn -> prepare($query); $query -> bindParam(":servicealert_id", $alertID); $query -> bindParam(":start", $start); $query -> bindParam(":end", $end); - $query -> bindParam(":header", $header); $query -> bindParam(":description", $description); $query -> bindParam(":url", $url); $query -> execute(); @@ -52,15 +51,14 @@ return $query -> fetch(PDO :: FETCH_ASSOC); } - function addServiceAlert($start, $end, $header, $description, $url) + function addServiceAlert($start, $end, $description, $url) { global $conn; - $query = 'INSERT INTO servicealerts_alerts (start, "end", header, description, url) VALUES (:start, :end, :header, :description, :url) '; + $query = 'INSERT INTO servicealerts_alerts (start, "end", description, url) VALUES (:start, :end, :description, :url) '; debug($query, "database"); $query = $conn -> prepare($query); $query -> bindParam(":start", $start); $query -> bindParam(":end", $end); - $query -> bindParam(":header", $header); $query -> bindParam(":description", $description); $query -> bindParam(":url", $url); $query -> execute(); @@ -76,7 +74,7 @@ function getCurrentAlerts() { global $conn; - $query = "SELECT id,extract('epoch', start) as start, extract('epoch', end) as end,cause,effect,header,description,url from servicealerts_alerts where NOW() > start and NOW() < \"end\""; + $query = 'SELECT * from servicealerts_alerts where NOW() > start and NOW() < "end"'; // debug($query, "database"); $query = $conn -> prepare($query); $query -> execute(); @@ -90,7 +88,7 @@ function getFutureAlerts() { global $conn; - $query = "SELECT id,extract('epoch', start) as start, extract('epoch', end) as end,cause,effect,header,description,url from servicealerts_alerts where NOW() > start or NOW() < \"end\""; + $query = 'SELECT * from servicealerts_alerts where NOW() > start or NOW() < "end"'; // debug($query, "database"); $query = $conn -> prepare($query); $query -> execute(); --- a/labs/servicealert_editor.php +++ b/labs/servicealert_editor.php @@ -5,14 +5,16 @@ /** * Currently support: * network inform - * stop remove: route patch, stop remove + * stop remove: trip patch, route inform * - stop search - * street inform: route inform, stop inform + * street inform: route inform, trip inform, stop inform * - street search + * trip remove: route patch, stop inform + * - trip search by route */ if (isset($_REQUEST['saveedit'])) { - if ($_REQUEST['saveedit'] != "") updateServiceAlert($_REQUEST['saveedit'], $_REQUEST['startdate'], $_REQUEST['enddate'], $_REQUEST['header'], $_REQUEST['description'], $_REQUEST['url']); + if ($_REQUEST['saveedit'] != "") updateServiceAlert($_REQUEST['saveedit'], $_REQUEST['startdate'], $_REQUEST['enddate'], $_REQUEST['description'], $_REQUEST['url']); else addServiceAlert($_REQUEST['startdate'], $_REQUEST['enddate'], $_REQUEST['description'], $_REQUEST['url']); echo "Saved " . $_REQUEST['saveedit']; die(); @@ -24,7 +26,7 @@ die(); } if ($_REQUEST['networkinform']) { - addInformedAlert($_REQUEST['networkinform'], "agency", "0", "inform"); + addInformedAlert($_REQUEST['networkinform'], "network", "network", "inform"); echo "Added network inform for" . $_REQUEST['networkinform']; die(); } @@ -32,27 +34,58 @@ addInformedAlert($_REQUEST['stopsearch'], "stop", $_REQUEST['stopid'], "remove"); echo "Added stop remove for" . $_REQUEST['stopsearch'] . ", stop" . $_REQUEST['stopid'] . "
\n"; - foreach ($service_periods as $sp) { - echo "Remove from $sp routes
\n"; + foreach ($service_periods as $sp) { + echo "Patching $sp trips
\n"; + foreach (getStopTrips($_REQUEST['stopid'], $sp) as $trip) { + addInformedAlert($_REQUEST['stopsearch'], "trip", $trip['trip_id'], "patch"); + echo "Added trip patch for" . $_REQUEST['stopsearch'] . ", trip" . $trip['trip_id'] . "
\n"; + + } + echo "Informing $sp routes
\n"; foreach (getStopRoutes($_REQUEST['stopid'], $sp) as $route) { - addInformedAlert($_REQUEST['stopsearch'], "route", $route['route_id'], "patch"); - echo "Added route patch for" . $_REQUEST['stopsearch'] . ", route" . $route['route_id'] . "
\n"; + addInformedAlert($_REQUEST['stopsearch'], "route", $route['route_id'], "inform"); + echo "Added route inform for" . $_REQUEST['stopsearch'] . ", route" . $route['route_id'] . "
\n"; } } die(); } +if ($_REQUEST['routesearch']) { + echo "Informing route
\n"; + $stops = Array(); + echo "Informing trips
\n"; + foreach(getRouteTrips() as $trip) { + addInformedAlert($_REQUEST['stopsearch'], "trip", $trip['trip_id'], "patch"); + echo "Added trip patch for" . $_REQUEST['stopsearch'] . ", trip" . $trip['trip_id'] . "
\n"; + viaPoints($tripID, "", false); + } + + echo "Informing stops
\n"; + foreach($stops as $stop) { + addInformedAlert($_REQUEST['stopsearch'], "stop", $_REQUEST['stopid'], "remove"); + echo "Added stop remove for" . $_REQUEST['stopsearch'] . ", stop" . $_REQUEST['stopid'] . "
\n"; + } + die(); + } if ($_REQUEST['streetsearch']) { - echo "Informing stops of street
\n"; + echo "Informing stops
\n"; foreach(getStopByName() as $stop) { - addInformedAlert($_REQUEST['stopsearch'], "stop", $_REQUEST['stopid'], "inform"); + addInformedAlert($_REQUEST['stopsearch'], "stop", $_REQUEST['stopid'], "remove"); echo "Added stop inform for" . $_REQUEST['stopsearch'] . ", stop" . $_REQUEST['stopid'] . "
\n"; foreach ($service_periods as $sp) { + echo "Patching $sp trips
\n"; + foreach (getStopTrips($_REQUEST['stopid'], $sp) as $trip) { + addInformedAlert($_REQUEST['stopsearch'], "trip", $trip['trip_id'], "patch"); + echo "Added trip inform for" . $_REQUEST['stopsearch'] . ", trip" . $trip['trip_id'] . "
\n"; + + } echo "Informing $sp routes
\n"; foreach (getStopRoutes($_REQUEST['stopid'], $sp) as $route) { addInformedAlert($_REQUEST['stopsearch'], "route", $route['route_id'], "inform"); - echo "Added route inform for stop" . $_REQUEST['stopsearch'] . ", route" . $route['route_id'] . "
\n"; + echo "Added route inform for" . $_REQUEST['stopsearch'] . ", route" . $route['route_id'] . "
\n"; + + } } die(); @@ -89,11 +122,6 @@ else echo date("c", strtotime("23:59")); ?>" /> -
- - -