Changeset 1e37648
- Timestamp:
- Aug 28, 2015, 3:29:08 PM (11 years ago)
- Branches:
- master
- Children:
- b858e6f
- Parents:
- 851179e
- Location:
- src/webservice
- Files:
-
- 5 added
- 1 deleted
- 11 edited
-
CMakeLists.txt (modified) (2 diffs)
-
config/config.php.in (modified) (1 diff)
-
config/internalconfig.php.in (added)
-
htaccess.in (modified) (1 diff)
-
htdocs/404.html (deleted)
-
htdocs/SiWeather/Webservice/Setup.php (modified) (4 diffs)
-
htdocs/SiWeather/Webservice/WebserviceConfig.php (modified) (4 diffs)
-
htdocs/inc/envsetup.php (modified) (1 diff)
-
htdocs/inc/footer.php (added)
-
htdocs/inc/header.php (added)
-
htdocs/index.php (modified) (2 diffs)
-
htdocs/resources/css/webservice.css (modified) (3 diffs)
-
htdocs/setup.php (modified) (1 diff)
-
htdocs/templates/404.php (added)
-
htdocs/templates/setup.php (added)
-
testconfig/testconfig.php.in (modified) (1 diff)
-
tests/StationsTest.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/webservice/CMakeLists.txt
r851179e r1e37648 21 21 22 22 SET(WEBSERVICE_OUTPUT_DIRECTORY "${WEB_OUTPUT_DIRECTORY}/webservice") 23 SET(WEBSERVICE_OUTPUT_APP_DIRECTORY "${WEBSERVICE_OUTPUT_DIRECTORY}/${WEBSERVICE_API_VERSION}") 23 24 SET(WEBSERVICE_TEST_OUTPUT_DIRECTORY "${WEB_TEST_OUTPUT_DIRECTORY}/webservice") 24 25 … … 37 38 38 39 CONFIGURE_FILE("config/config.php.in" "${WEBSERVICE_OUTPUT_DIRECTORY}/config/config.php") 40 CONFIGURE_FILE("config/internalconfig.php.in" "${WEBSERVICE_OUTPUT_APP_DIRECTORY}/inc/internalconfig.php") 39 41 # workaround to copy "hidden" file .htaccess. copy command ignores it 40 CONFIGURE_FILE("htaccess.in" "${WEBSERVICE_OUTPUT_ DIRECTORY}/.htaccess")42 CONFIGURE_FILE("htaccess.in" "${WEBSERVICE_OUTPUT_APP_DIRECTORY}/.htaccess") 41 43 42 44 FILE(GLOB src_HTDOCS "htdocs/*.*") 43 45 ADD_CUSTOM_TARGET(webservice-prepare ALL 44 COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_CURRENT_SOURCE_DIR}/htdocs" "${WEBSERVICE_OUTPUT_ DIRECTORY}"46 COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_CURRENT_SOURCE_DIR}/htdocs" "${WEBSERVICE_OUTPUT_APP_DIRECTORY}" 45 47 # DEPENDS "${WEBSERVICE_OUTPUT_DIRECTORY}/${STAFF_WSDL_FILE}" 46 48 COMMENT "Preparing webservice" 47 49 SOURCES ${src_HTDOCS} 48 50 ) 49 # ADD_CUSTOM_TARGET(webservice-install ALL50 # COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_CURRENT_SOURCE_DIR}/htdocs" "${WEBSERVICE_OUTPUT_DIRECTORY}"51 # # DEPENDS "${WEBSERVICE_OUTPUT_DIRECTORY}/${STAFF_WSDL_FILE}"52 # COMMENT "Preparing webclient"53 # SOURCES ${src_HTDOCS}54 # )55 56 57 58 59 60 61 62 63 51 64 52 ####################### -
src/webservice/config/config.php.in
r851179e r1e37648 20 20 21 21 $config = [ 22 "version" => "@VERSION@",23 "webserviceApiVersion" => "@WEBSERVICE_API_VERSION@",24 22 "mode" => "@WEBSERVICE_MODE@", 25 "webserviceBaseUrl" => "http://localhost@WEBSERVICE_BASE_URL@ /",23 "webserviceBaseUrl" => "http://localhost@WEBSERVICE_BASE_URL@@WEBSERVICE_API_VERSION@", 26 24 "spatialiteExtension" => "mod_spatialite.so", 27 25 "geoipservice" => "http://freegeoip.net/json", -
src/webservice/htaccess.in
r851179e r1e37648 22 22 # Requires AllowOverride All directive in your apache config 23 23 RewriteEngine On 24 RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f 25 RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-d 26 RewriteRule ^@WEBSERVICE_API_VERSION@ @WEBSERVICE_BASE_URL@/index.php [QSA,L] 24 RewriteBase @WEBSERVICE_BASE_URL@@WEBSERVICE_API_VERSION@ 25 RewriteCond %{REQUEST_FILENAME} !-f 26 RewriteCond %{REQUEST_FILENAME} !-d 27 RewriteRule ^ index.php$1 [QSA,NC,L] -
src/webservice/htdocs/SiWeather/Webservice/Setup.php
r851179e r1e37648 306 306 307 307 public function apiCheckWithRewrite(&$errorMessage){ 308 $apiVersion = $this->_webserviceConfig->getConfig("webserviceApiVersion"); 309 if(!$apiVersion || empty($apiVersion)){ 310 $errorMessage = _("Could not determine API version"); 311 return false; 312 } 313 314 return $this->apiCheck($apiVersion ."/stations", $errorMessage); 308 return $this->apiCheck("stations", $errorMessage); 315 309 } 316 310 … … 326 320 327 321 private function apiCheck($url, &$errorMessage){ 328 $baseUrl = $this->_webserviceConfig-> getConfig("webserviceBaseUrl");322 $baseUrl = $this->_webserviceConfig->webserviceBaseUrl(); 329 323 if(!$baseUrl || empty($baseUrl)){ 330 324 $errorMessage = _("No webservice base url given!"); … … 332 326 } 333 327 328 # base_url needs to end with a /, otherwise the last element is chopped 334 329 $client = new \GuzzleHttp\Client 335 330 ( … … 347 342 $result = $response->getStatusCode(); 348 343 if($result != 200){ 349 $errorMessage = \Translator::swGettext("Got http error %s (%s) ", $result, $response->getReasonPhrase());344 $errorMessage = \Translator::swGettext("Got http error %s (%s) at url %s", $result, $response->getReasonPhrase(), $baseUrl ."/". $url); 350 345 return false; 351 346 } -
src/webservice/htdocs/SiWeather/Webservice/WebserviceConfig.php
r851179e r1e37648 24 24 25 25 function __construct(){ 26 require(__DIR__ ."/../../ config/config.php");26 require(__DIR__ ."/../../../config/config.php"); 27 27 $this->_config = $config; 28 28 $this->loadAdditionalConfiguration(); … … 35 35 private function loadAdditionalConfiguration(){ 36 36 $this->_config["dataDirectory"] = "data"; 37 38 require(__DIR__ ."/../../inc/internalconfig.php"); 39 foreach(array_keys($internalconfig) as $key){ 40 if(array_key_exists($key, $this->_config)){ 41 error_log("Internal config entry ". $key ." already exists --> Keeping existing value and discard internal config value"); 42 } 43 else{ 44 $this->_config[$key] = $internalconfig[$key]; 45 } 46 } 37 47 } 38 48 … … 47 57 return $this->dataDirectory(); 48 58 } 59 if($key == "webserviceBaseUrl"){ 60 // error_log("Use dataDirectory() function to access this value"); 61 return $this->webserviceBaseUrl(); 62 } 49 63 50 64 return $this->_config[$key]; … … 52 66 53 67 public function dataDirectory(){ 54 return __DIR__ ."/../../". $this->_config["dataDirectory"]; 68 return __DIR__ ."/../../../". $this->_config["dataDirectory"]; 69 } 70 71 public function webserviceBaseUrl(){ 72 $baseUrl = $this->_config["webserviceBaseUrl"]; 73 if(substr($baseUrl, strlen($baseUrl) - 1, 1) != "/"){ 74 $baseUrl .= "/"; 75 } 76 return $baseUrl; 55 77 } 56 78 -
src/webservice/htdocs/inc/envsetup.php
r851179e r1e37648 20 20 21 21 // set_include_path(get_include_path() . PATH_SEPARATOR . __DIR__ ."/../../vendor/"); 22 $composerAutoloader = require(__DIR__ ."/../../ vendor/autoload.php");22 $composerAutoloader = require(__DIR__ ."/../../../vendor/autoload.php"); 23 23 if(is_object($composerAutoloader)){ 24 24 $composerAutoloader->add("SiWeather\\Webservice\\", __DIR__ ."/../"); -
src/webservice/htdocs/index.php
r851179e r1e37648 46 46 array 47 47 ( 48 "mode" => "production"48 "mode" => $settings->getConfig("mode"), 49 49 ) 50 50 ); 51 $app->setName(" siweather");51 $app->setName("SiWeather Webservice"); 52 52 53 53 // Only invoked if mode is "production" 54 54 $app->configureMode('production', function () use ($app) { 55 55 $app->config(array( 56 'log.enable' => true, 57 'debug' => false 56 "log.enable" => true, 57 "log.level" => \Slim\Log::WARN, 58 "debug" => false, 58 59 )); 59 60 }); … … 61 62 $app->configureMode('development', function () use ($app) { 62 63 $app->config(array( 63 'log.enable' => false, 64 'debug' => true 64 "log.enable" => true, 65 "log.level" => \Slim\Log::DEBUG, 66 "debug" => true 65 67 )); 66 68 }); 67 69 68 // $app->notFound(function () use ($app) { 69 // $app->render(getConfig("webserviceBaseUrl")+ "404.html"); 70 // }); 70 $app->notFound(function () use ($app) { 71 $html = ""; 72 if($app->config("debug")){ 73 ob_start(); 74 phpinfo( INFO_VARIABLES ^ INFO_ENVIRONMENT ); 75 $html = ob_get_contents(); 76 ob_end_clean(); 77 } 78 $app->render("404.php", array("dump" => $html)); 79 }); 71 80 72 // $app->get("/stations", "stations"); 81 $app->get("/setup", function () use ($app){ 82 $app->render("setup.php"); 83 }); 84 73 85 $app->get("/stations", "stations"); 74 86 $app->get("/stations/:uuid", function ($uuid){ 75 87 echo "stations 123"; 76 88 }); 89 90 91 77 92 $app->run(); 78 93 -
src/webservice/htdocs/resources/css/webservice.css
r851179e r1e37648 1 1 .success { 2 color: # 45A545;2 color: #66BD66; 3 3 font-weight: bold; 4 4 } … … 7 7 color: #8C1C00; 8 8 font-weight: bold; 9 } 10 11 .lierror { 12 list-style-type: none; 13 background-image: url("../icons/dialog-cancel.png"); 14 background-repeat: no-repeat; 15 background-position: left center; 16 background-size: auto 1em; 17 padding-left: 1.5em; 18 } 19 20 .lisuccess { 21 list-style-type: none; 22 background-image: url("../icons/dialog-ok-apply.png"); 23 background-repeat: no-repeat; 24 background-position: left center; 25 background-size: auto 1em; 26 padding-left: 1.5em; 27 } 28 29 .header { 30 margin-top: 1em; 31 padding-top: 0.5em; 32 padding-left: 2em; 33 color: #ACDFAC; 34 text-align: left; 35 font-size: 9pt; 36 border-width: 0; 37 border-bottom-width: 2px; 38 border-color: #ACDFAC; 39 border-style: solid; 40 } 41 42 .header h1 { 43 font-size: 16pt; 9 44 } 10 45 … … 26 61 } 27 62 28 .footnotes a { 29 color: #ACDFAC; 63 a { 64 color: #6BA3A3; 65 text-decoration: none; 66 /* font-weight: bold; */ 30 67 } 68 69 a:hover { 70 color: #6BA3A3; 71 text-decoration: underline; 72 } -
src/webservice/htdocs/setup.php
r851179e r1e37648 19 19 */ 20 20 21 require(__DIR__ ."/inc/envsetup.php"); 22 23 function printError($message) 24 { 25 echo "<div class=\"error\">\n"; 26 echo " <h3>". _("The following error occured:") ."</h3>\n"; 27 echo $message; 28 echo "</div>\n"; 29 } 30 31 function printResult($result, $message) 32 { 33 $class = "success"; 34 $icon = "dialog-ok-apply.png"; 35 if(!$result){ 36 $class = "error"; 37 $icon = "dialog-cancel.png"; 38 } 39 echo "<li class=\"". $class ."\"><img src=\"resources/icons/". $icon ."\"/>". $message ."</li>\n"; 40 } 21 require(__DIR__ ."/templates/setup.php"); 41 22 42 23 ?> 43 44 <html>45 <head>46 <title><?php _("SiWeather Webservice Configuration"); ?></title>47 <link rel="stylesheet" type="text/css" href="resources/css/webservice.css"/>48 </head>49 <body>50 <h1><?php _("Welcome for the setup of the webservice backend for SiWeather"); ?></h1>51 <ul>52 <?php53 54 $setup = new SiWeather\Webservice\Setup();55 56 $errorMessage = "";57 $result = $setup->dataDirectoryCheck($errorMessage);58 if($result == SiWeather\Webservice\DataDirectoryChecks::NotExist && $result != SiWeather\Webservice\DataDirectoryChecks::Success){59 $result = $setup->dataDirectoryCreate($errorMessage);60 }61 62 if($result != SiWeather\Webservice\DataDirectoryChecks::Success){63 printResult(false, myGettext("Data directory not accessible (%s)", $errorMessage));64 }65 else{66 printResult(true, _("Data directory checked"));67 $result = $setup->databaseDirectoryCheck($errorMessage);68 if($result != SiWeather\Webservice\DatabaseChecks::Success){69 printResult(false, $errorMessage);70 }71 else{72 printResult(true, _("Database directory checked"));73 $result = $setup->databaseFileCheck($errorMessage);74 if($result != SiWeather\Webservice\DatabaseChecks::Success){75 printResult(false, $errorMessage);76 }77 else{78 printResult(true, _("Database file checked"));79 if(!$setup->databaseConnection($errorMessage)){80 printResult(false, $errorMessage);81 }82 else{83 $prefix = "Database up and running";84 $versionSqlite = $setup->databaseVersionSqlite($errorMessage);85 if($versionSqlite <= 0){86 printResult(false, Translator::swGettext("%s (Could not determine SQLite version: %s)", $prefix, $errorMessage));87 }88 else{89 $versionSpatalite = $setup->databaseVersionSpatalite($errorMessage);90 if($versionSpatalite <= 0){91 printResult(false, Translator::swGettext("%s (Could not determine Spatalite version: %s)", $prefix, $errorMessage));92 }93 else{94 printResult(true, Translator::swGettext("%s (SQLite: %s, Spatalite: %s)", $prefix, $versionSqlite, $versionSpatalite));95 }96 }97 }98 }99 }100 }101 102 $webserviceConfig = new SiWeather\Webservice\WebserviceConfig();103 if(!$setup->apiCheckWithoutRewrite($errorMessage)){104 printResult(false, Translator::swGettext("Could not connect to webservice without rewrite (%s)", $errorMessage));105 }106 else{107 $url = $webserviceConfig->getConfig("webserviceBaseUrl") ."/index.php/";108 printResult(true, Translator::swGettext("Webservice withpout rewrite accessible at %s", "<a href=\"". $url ."\">". $url ."</a>"));109 }110 if(!$setup->apiCheckWithRewrite($errorMessage)){111 printResult(false, Translator::swGettext("Could not connect to webservice with rewrite (%s)", $errorMessage));112 }113 else{114 $url = $webserviceConfig->getConfig("webserviceBaseUrl") ."/". $webserviceConfig->getConfig("webserviceApiVersion");115 printResult(true, Translator::swGettext("Webservice withp rewrite accessible at %s", "<a href=\"". $url ."\">". $url ."</a>"));116 }117 118 ?>119 </ul>120 <?php121 // $webserviceConfig = new SiWeather\Webservice\WebserviceConfig();122 $apiVersion = $webserviceConfig->getConfig("webserviceApiVersion");123 echo " <div class=\"footer\">\n";124 echo " ". Translator::swGettext("SiWeather webservice %s with API version %s), ", $webserviceConfig->getConfig("version"), $apiVersion) ."<br/>\n";125 echo " ". Translator::swGettext("Webservice accessible at %s/%s/ or", $webserviceConfig->getConfig("webserviceBaseUrl"), $apiVersion) ."<br/>\n";126 echo " ". $webserviceConfig->getConfig("webserviceBaseUrl") ."/index.php/\n";127 echo " <div class=\"footnotes\">\n";128 echo " ". _("This site uses icons from Oxygen icon theme (License: LGPLv3,") ."<a href=\"http://www.kde.org/\">http://www.kde.org</a>)\n";129 echo " </div>\n";130 echo " </div>\n";131 ?>132 </body>133 </html> -
src/webservice/testconfig/testconfig.php.in
r851179e r1e37648 20 20 21 21 $testconfig = [ 22 "webserviceDirectory" => "@WEBSERVICE_OUTPUT_ DIRECTORY@",22 "webserviceDirectory" => "@WEBSERVICE_OUTPUT_APP_DIRECTORY@", 23 23 ]; 24 24 -
src/webservice/tests/StationsTest.php
r851179e r1e37648 29 29 $this->assertNotNull($this->_testconfig); 30 30 31 require($testconfig["webserviceDirectory"] ."/inc/envsetup.php"); 31 32 require_once($testconfig["webserviceDirectory"] ."/SiWeather/Webservice/WebserviceConfig.php"); 32 33 … … 45 46 public function testStationRewrite() 46 47 { 47 $apiVersion = $this->_webserviceConfig->getConfig("webserviceApiVersion"); 48 $this->assertInternalType('string', $apiVersion); 49 $this->assertTrue(!empty($apiVersion)); 50 51 $stations = $this->query($apiVersion ."/stations"); 48 $stations = $this->query("stations"); 52 49 53 50 $this->assertInternalType("array", $stations); … … 56 53 57 54 protected function query($url){ 58 $baseUrl = $this->_webserviceConfig-> getConfig("webserviceBaseUrl");59 $this->assertInternalType('string', $baseUrl );60 $this->assertTrue(!empty($baseUrl) );55 $baseUrl = $this->_webserviceConfig->webserviceBaseUrl(); 56 $this->assertInternalType('string', $baseUrl, "baseUrl is not of type string: ". $baseUrl); 57 $this->assertTrue(!empty($baseUrl), "baseUrl is empty: ". $baseUrl); 61 58 $client = new GuzzleHttp\Client 62 59 ( … … 68 65 ); 69 66 $response = $client->get($url); 70 $this->assertNotNull($response );71 $this->assertEquals($response->getStatusCode(), 200 );72 $this->assertEquals($response->getReasonPhrase(), "OK" );67 $this->assertNotNull($response, "Response is empty. Url: ". $baseUrl . $url); 68 $this->assertEquals($response->getStatusCode(), 200, "Status code != 200. Url: ". $baseUrl . $url); 69 $this->assertEquals($response->getReasonPhrase(), "OK", "Reason phrase not empty. Url: ". $baseUrl . $url); 73 70 74 71 $body = $response->getBody(); 75 $this->assertTrue(!empty($body) );72 $this->assertTrue(!empty($body), "Response body is empty. Url: ". $baseUrl . $url); 76 73 $json = json_decode($body); 77 $this->assertNotNull($json );74 $this->assertNotNull($json, "Json decode returned null. Url: ". $baseUrl . $url ."\nBody: ". $body); 78 75 return $json; 79 76 }
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/siweather/chrome/site/your_project_logo.png)