diff --git a/.drone.yml b/.drone.yml index bc3505d..36d1fac 100644 --- a/.drone.yml +++ b/.drone.yml @@ -2,6 +2,7 @@ kind: pipeline type: docker name: DAFLPipeline + trigger: event: - push @@ -52,3 +53,34 @@ steps: COMMAND: create OVERWRITE: true depends_on: [ web-server ] + +# docker image build +- name: php_script + image: plugins/docker + settings: + dockerfile: ./Sources/php_script/Dockerfile + context: Sources/php_script + registry: hub.codefirst.iut.uca.fr + repo: hub.codefirst.iut.uca.fr/dorian.hodin/dafl_music + username: + from_secret: SECRET_USERNAME + password: + from_secret: SECRET_PASSWD + +# container deployment +- name: deploy-php + image: hub.codefirst.iut.uca.fr/thomas.bellembois/codefirst-dockerproxy-clientdrone:latest + environment: + IMAGENAME: hub.codefirst.iut.uca.fr/dorian.hodin/dafl_music:latest + CONTAINERNAME: php_script + COMMAND: create + OVERWRITE: true + CODEFIRST_CLIENTDRONE_ENV_HOST: + from_secret: db_host + CODEFIRST_CLIENTDRONE_ENV_DATABASE: + from_secret: db_database + CODEFIRST_CLIENTDRONE_ENV_USER: + from_secret: db_user + CODEFIRST_CLIENTDRONE_ENV_PASSWORD: + from_secret: db_password + depends_on: [ php_script ] \ No newline at end of file diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml index 7643783..6db4707 100644 --- a/.idea/codeStyles/Project.xml +++ b/.idea/codeStyles/Project.xml @@ -98,7 +98,6 @@ http://schemas.android.com/apk/res/android - ANDROID_ATTRIBUTE_ORDER
diff --git a/.idea/dafl_music.iml b/.idea/dafl_music.iml new file mode 100644 index 0000000..7d01c35 --- /dev/null +++ b/.idea/dafl_music.iml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Dart_Packages.xml b/.idea/libraries/Dart_Packages.xml index f8237c9..04e2ec7 100644 --- a/.idea/libraries/Dart_Packages.xml +++ b/.idea/libraries/Dart_Packages.xml @@ -5,686 +5,686 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.idea/libraries/Dart_SDK.xml b/.idea/libraries/Dart_SDK.xml index cb79f3d..3dbed52 100644 --- a/.idea/libraries/Dart_SDK.xml +++ b/.idea/libraries/Dart_SDK.xml @@ -1,25 +1,25 @@ - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..639900d --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml index 85c8ded..c753441 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -2,7 +2,7 @@ - + \ No newline at end of file diff --git a/.idea/php.xml b/.idea/php.xml new file mode 100644 index 0000000..97a38d7 --- /dev/null +++ b/.idea/php.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/Sources/dafl_project_flutter/lib/position/location.dart b/Sources/dafl_project_flutter/lib/position/location.dart index 1978152..3be754f 100644 --- a/Sources/dafl_project_flutter/lib/position/location.dart +++ b/Sources/dafl_project_flutter/lib/position/location.dart @@ -6,7 +6,7 @@ import '../main.dart'; class Location { static Future> sendCurrentLocation() async { - Uri uri = Uri.parse("http://89.83.53.34/phpmyadmin/dafldev/insert.php"); + Uri uri = Uri.parse("https://codefirst.iut.uca.fr/containers/php_script-dorianhodin/insert.php"); LocationPermission permission; permission = await Geolocator.checkPermission(); if (permission == LocationPermission.denied) { @@ -31,13 +31,23 @@ class Location { static Future> getData() async { Map spot = {}; String actualUser = MyApp.controller.currentUser.usernameDafl; - Uri uri = Uri.parse("http://89.83.53.34/phpmyadmin/dafldev/distance.php"); + Uri uri = Uri.parse("https://codefirst.iut.uca.fr/containers/php_script-dorianhodin/distance.php"); http.Response response = await http.post(uri, body: { "id": actualUser, }); var data = jsonDecode(response.body); - data.forEach((s)=> spot.putIfAbsent(s['user'], () => s['music'])); - return spot; + if (data.runtimeType==String) { + if (data=="Failed to connect to MySQL, connection timeout"){ + return Future.error(data); + }else if (data=="The POST didn't return any values"){ + return Future.error(data); + }else{ + return Future.error(data); //ERROR No user found in the database + } + }else { + data.forEach((s) => spot.putIfAbsent(s['user'], () => s['music'])); + return spot; + } } } diff --git a/Sources/php_script/Dockerfile b/Sources/php_script/Dockerfile new file mode 100644 index 0000000..aa601a1 --- /dev/null +++ b/Sources/php_script/Dockerfile @@ -0,0 +1,4 @@ +FROM php:8.1-apache +RUN apt-get update && apt-get upgrade -y +RUN docker-php-ext-install mysqli +COPY ./script /var/www/html diff --git a/Sources/php_script/script/config.php b/Sources/php_script/script/config.php new file mode 100644 index 0000000..c604963 --- /dev/null +++ b/Sources/php_script/script/config.php @@ -0,0 +1,15 @@ +fetch_row()){ //For all the row in the database + if (strcmp($row[0], $id) == 0) { //If the user is found in the database + $lat1 = $row[1]; //Set $lat1 to the latitude of the current user + $lng1 = $row[2]; //Set $lng1 to the longitude of the current user + } + } + if ($lat1 == 0 && $lng1 == 0) { //Check if the user get found in the database + print(json_encode("ERROR No user found in the database")); //Return a json string, so the dart script can interpret the error + exit(1); //Exit the actual script + } + $results = mysqli_query($connect, $query); //Execute again the SQL command to restart the fetch_row() + while ($row = $results->fetch_row()) { //For all the row in the database + if (strcmp($row[0], $id) != 0) { //If the row is not the row of the current user + $lat2 = $row[1]; //Set $lat2 to the latitude of the user who is in the actual row + $lng2 = $row[2]; //Set $lng2 to the latitude of the user who is in the actual row + $userID = $row[0]; //Set $userID to the username of the user who is in the actual row + $idMusic = $row[3]; //Set $idMusic to the id of the actual song of the user who is in the actual row + $dist = meters($lat1, $lng1, $lat2, $lng2); //With the function meters, calcul of the distance between the current user and the user who is in the actual row + if ($dist <= 100) { //If the user in the actual row is less than 100 meters away of the current user + $listUser[] = ['user' => $userID, 'music' => $idMusic]; //Add the username and the ID of the song that user who is in the actual row is listening + } + } + } + print(json_encode($listUser)); //Return a json string of the list listUser +}else{ //If the method POST return nothing + print (json_encode("The POST didn't return any values")); //Return a json string, so the dart script can interpret the error +} + + + diff --git a/Sources/php_script/script/index.php b/Sources/php_script/script/index.php new file mode 100644 index 0000000..f6595e4 --- /dev/null +++ b/Sources/php_script/script/index.php @@ -0,0 +1,5 @@ + \ No newline at end of file diff --git a/Sources/php_script/script/insert.php b/Sources/php_script/script/insert.php new file mode 100644 index 0000000..84ffd22 --- /dev/null +++ b/Sources/php_script/script/insert.php @@ -0,0 +1,26 @@ +10;"; + $results = mysqli_query($connect, $query); + */ + $query = "DELETE FROM gps WHERE id='$id';"; //Delete the actual line and replace this line with the next lines + $results = mysqli_query($connect, $query); //Execute the SQL command + + $query = "INSERT INTO gps (id,latitude,longitude,idMusic,dateLog) + VALUES('$id','$latitude','$longitude','$idMusic',CURRENT_TIMESTAMP);"; //Insert into the database the new data and new information about this user + $results = mysqli_query($connect, $query); //Execute the SQL command +}else{ //If the method POST return nothing + print (json_encode("The POST didn't return any values")); //Return a json string, so the dart script can interpret the error +} \ No newline at end of file