From 9cf9201462d768378d6b3e07f5a4e4c687d5e146 Mon Sep 17 00:00:00 2001 From: Rafasaeza Date: Tue, 16 Apr 2024 13:16:55 +0200 Subject: [PATCH] prueba --- z1/docker-compose.yml | 27 ++++++++++++++++++++ z1/includes/config/database.php | 13 ++++++++++ z1/includes/create.php | 18 ++++++++++++++ z1/includes/delete.php | 20 +++++++++++++++ z1/index.php | 44 +++++++++++++++++++++++++++++++++ z1/nginx/Dockerfile | 2 ++ z1/nginx/default.conf | 38 ++++++++++++++++++++++++++++ z1/php/Dockerfile | 3 +++ z1/sh/remove-app.sh | 1 + z1/sh/start-app.sh | 2 ++ z1/sh/stop-app.sh | 1 + z1/src/prueba.css | 43 ++++++++++++++++++++++++++++++++ 12 files changed, 212 insertions(+) create mode 100644 z1/docker-compose.yml create mode 100644 z1/includes/config/database.php create mode 100644 z1/includes/create.php create mode 100644 z1/includes/delete.php create mode 100644 z1/index.php create mode 100644 z1/nginx/Dockerfile create mode 100644 z1/nginx/default.conf create mode 100644 z1/php/Dockerfile create mode 100644 z1/sh/remove-app.sh create mode 100644 z1/sh/start-app.sh create mode 100644 z1/sh/stop-app.sh create mode 100644 z1/src/prueba.css diff --git a/z1/docker-compose.yml b/z1/docker-compose.yml new file mode 100644 index 0000000..ddee207 --- /dev/null +++ b/z1/docker-compose.yml @@ -0,0 +1,27 @@ +version: '3.8' +services: + php: + build: + context: ./php/ + container_name: programwithgio-app + restart: always + volumes: + - ./:/var/www/html + nginx: + build: + context: ./nginx/ + container_name: programwithgio-nginx + restart: always + volumes: + - ./:/var/www/html + depends_on: + - php + ports: + - 8080:80 + mysql: + image: mysql:latest + restart: always + environment: + MYSQL_ROOT_PASSWORD: password + volumes: + - ./data:/var/lib/mysql diff --git a/z1/includes/config/database.php b/z1/includes/config/database.php new file mode 100644 index 0000000..472c97e --- /dev/null +++ b/z1/includes/config/database.php @@ -0,0 +1,13 @@ +set_charset('utf8'); + if(!$db){ + echo 'Error no se pudo conectar'; + exit; + } + return $db; +} \ No newline at end of file diff --git a/z1/includes/create.php b/z1/includes/create.php new file mode 100644 index 0000000..87f746e --- /dev/null +++ b/z1/includes/create.php @@ -0,0 +1,18 @@ +connect_errno) { + // Print the connection error message + echo "Failed to connect to MySQL: " . mysqli_connect_error(); + // You can also log the error message to a file or other logging mechanism + // error_log("Failed to connect to MySQL: " . mysqli_connect_error()); + exit(); // Exit the script if there's a connection error +} +if($_POST){ + $note = mysqli_real_escape_string($db,$_POST['note']);; + $query = "insert into nota (noteContent) values ('$note')"; + mysqli_query($db,$query); +} +mysqli_close($db); +header("Location:../index.php"); \ No newline at end of file diff --git a/z1/includes/delete.php b/z1/includes/delete.php new file mode 100644 index 0000000..3331b0b --- /dev/null +++ b/z1/includes/delete.php @@ -0,0 +1,20 @@ +connect_errno) { + // Print the connection error message + echo "Failed to connect to MySQL: " . mysqli_connect_error(); + // You can also log the error message to a file or other logging mechanism + // error_log("Failed to connect to MySQL: " . mysqli_connect_error()); + exit(); // Exit the script if there's a connection error +} + + +if($_POST){ + $noteID = $_POST['id'];; + $query = "delete from nota where id = $noteID"; + mysqli_query($db,$query); +} +mysqli_close($db); +header("Location:../index.php"); \ No newline at end of file diff --git a/z1/index.php b/z1/index.php new file mode 100644 index 0000000..cb1938f --- /dev/null +++ b/z1/index.php @@ -0,0 +1,44 @@ +connect_errno) { + // Print the connection error message + echo "Failed to connect to MySQL: " . mysqli_connect_error(); + // You can also log the error message to a file or other logging mechanism + // error_log("Failed to connect to MySQL: " . mysqli_connect_error()); + exit(); // Exit the script if there's a connection error +} + +$getNotes = "select * from notag" ; +$notes = mysqli_query($db,$getNotes); +mysqli_close($db); +?> + + + + + + + Document + + +
+ +

Notes manager

+
+ + + +
+ +
+

+
+ + +
+
+ +
+ + \ No newline at end of file diff --git a/z1/nginx/Dockerfile b/z1/nginx/Dockerfile new file mode 100644 index 0000000..9561de2 --- /dev/null +++ b/z1/nginx/Dockerfile @@ -0,0 +1,2 @@ +FROM nginx:alpine +COPY ./default.conf /etc/nginx/conf.d/default.conf \ No newline at end of file diff --git a/z1/nginx/default.conf b/z1/nginx/default.conf new file mode 100644 index 0000000..50b27e1 --- /dev/null +++ b/z1/nginx/default.conf @@ -0,0 +1,38 @@ +server { + + listen 80 default_server; + root /var/www/html; + index index.html index.php; + + charset utf-8; + + location / { + try_files $uri $uri/ /index.php?$query_string; + } + + location = /favicon.ico { access_log off; log_not_found off; } + location = /robots.txt { access_log off; log_not_found off; } + + access_log off; + error_log /var/log/nginx/error.log error; + + sendfile off; + + client_max_body_size 100m; + + location ~ .php$ { + fastcgi_split_path_info ^(.+.php)(/.+)$; + fastcgi_pass php:9000; + fastcgi_index index.php; + include fastcgi_params; + fastcgi_read_timeout 300; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + fastcgi_intercept_errors off; + fastcgi_buffer_size 16k; + fastcgi_buffers 4 16k; + } + + location ~ /.ht { + deny all; + } + } \ No newline at end of file diff --git a/z1/php/Dockerfile b/z1/php/Dockerfile new file mode 100644 index 0000000..fea565c --- /dev/null +++ b/z1/php/Dockerfile @@ -0,0 +1,3 @@ +FROM php:fpm-alpine + +RUN docker-php-ext-install mysqli && docker-php-ext-enable mysqli \ No newline at end of file diff --git a/z1/sh/remove-app.sh b/z1/sh/remove-app.sh new file mode 100644 index 0000000..58694d0 --- /dev/null +++ b/z1/sh/remove-app.sh @@ -0,0 +1 @@ +docker-compose down \ No newline at end of file diff --git a/z1/sh/start-app.sh b/z1/sh/start-app.sh new file mode 100644 index 0000000..0ec18f5 --- /dev/null +++ b/z1/sh/start-app.sh @@ -0,0 +1,2 @@ +echo 'starting app...' +docker-compose up -d \ No newline at end of file diff --git a/z1/sh/stop-app.sh b/z1/sh/stop-app.sh new file mode 100644 index 0000000..1fbb5f5 --- /dev/null +++ b/z1/sh/stop-app.sh @@ -0,0 +1 @@ +docker-compose stop \ No newline at end of file diff --git a/z1/src/prueba.css b/z1/src/prueba.css new file mode 100644 index 0000000..2f35249 --- /dev/null +++ b/z1/src/prueba.css @@ -0,0 +1,43 @@ +/* Utilities*/ +.button{ + display: inl; + color:white; + text-decoration: none; + font-weight: bold; + text-align: center; + padding: 1rem; + border-radius: 2rem; + text-transform: uppercase; + margin: 1rem 1rem; + border: none; +} +.greenButton{ + background-color: green; +} +.redButton{ + background-color: red; + width: -moz-available; +} +input[type="text"]{ + padding: 1rem; + border-radius: 2rem +} + +.contenedor{ + display: flex; + flex-direction: column; + align-items: center; +} +.note{ + background-color: bisque; + display: grid; + grid-template-columns: repeat(2,1fr); + align-items: center; + width: 20rem; + padding:1rem; + border-radius: 2rem; + margin-top: 1rem; +} +.addNote{ + width: 20rem; +} \ No newline at end of file