]> git.p6c8.net - jirafeau.git/blobdiff - script.php
Store filesize before encrypting the file
[jirafeau.git] / script.php
index 600b1d5cc9f702955a9a1d558e27fc1ef3cf0612..5f3bc6f359996bd866a89a5b410b9fd8921b05e2 100644 (file)
@@ -1,7 +1,9 @@
 <?php
 /*
  *  Jirafeau, your web file repository
+ *  Copyright (C) 2008  Julien "axolotl" BERNARD <axolotl@magieeternelle.org>
  *  Copyright (C) 2015  Jerome Jutteau <jerome@jutteau.fr>
+ *  Copyright (C) 2024  Jirafeau project <https://gitlab.com/jirafeau> (see AUTHORS.md)
  *
  *  This program is free software: you can redistribute it and/or modify
  *  it under the terms of the GNU Affero General Public License as
@@ -44,7 +46,7 @@ if ($_SERVER['REQUEST_METHOD'] == "GET" && count($_GET) == 0) {
     <div class="info">
     <h2>Scripting interface</h2>
     <p>This interface permits to script your uploads and downloads.</p>
-    <p>See <a href="https://gitlab.com/mojo42/Jirafeau/blob/master/script.php">source code</a> of this interface to get available calls :)</p>
+    <p>See <a href="<?php echo JIRAFEAU_WEBSITE ?>/blob/master/script.php">source code</a> of this interface to get available calls :)</p>
     <p>You may download a preconfigured <a href="script.php?lang=bash">Bash Script</a> to easily send to and get files from the API via command line.</p>
     </div>
     <br />
@@ -81,51 +83,22 @@ if (isset($_FILES['file']) && is_writable(VAR_FILES)
     $key = '';
     if (isset($_POST['key'])) {
         $key = $_POST['key'];
-        if ($cfg['download_password_requirement'] !== 'generated' && $cfg['download_password_policy'] === 'regex'){
-            if (!preg_match($cfg['download_password_policy_regex'], $key)){
+        if ($cfg['download_password_requirement'] !== 'generated' && $cfg['download_password_policy'] === 'regex') {
+            if (!preg_match($cfg['download_password_policy_regex'], $key)) {
                 echo 'Error 14: The download password is not complying to the security standards.';
                 exit;
             }
         }
-    }elseif ($cfg['download_password_requirement'] !== 'optional'){
+    } elseif ($cfg['download_password_requirement'] !== 'optional') {
         echo 'Error 13: The parameter password is required.';
         exit;
     }
 
-    $time = time();
     if (!isset($_POST['time']) || !$cfg['availabilities'][$_POST['time']]) {
         echo 'Error 4: The parameter time is invalid.';
         exit;
     } else {
-        switch ($_POST['time']) {
-            case 'minute':
-                $time += JIRAFEAU_MINUTE;
-                break;
-            case 'hour':
-                $time += JIRAFEAU_HOUR;
-                break;
-            case 'day':
-                $time += JIRAFEAU_DAY;
-                break;
-            case 'week':
-                $time += JIRAFEAU_WEEK;
-                break;
-            case 'fortnight':
-                $time += JIRAFEAU_FORTNIGHT;
-                break;
-            case 'month':
-                $time += JIRAFEAU_MONTH;
-                break;
-            case 'quarter':
-                $time += JIRAFEAU_QUARTER;
-                break;
-            case 'year':
-                $time += JIRAFEAU_YEAR;
-                break;
-            default:
-                $time = JIRAFEAU_INFINITY;
-                break;
-        }
+        $time = jirafeau_datestr_to_int($_POST['time']);
     }
 
     // Check file size
@@ -175,13 +148,13 @@ if (isset($_FILES['file']) && is_writable(VAR_FILES)
     $key = '';
     if (isset($_POST['key'])) {
         $key = $_POST['key'];
-        if ($cfg['download_password_requirement'] !== 'generated' && $cfg['download_password_policy'] === 'regex'){
-            if (!preg_match($cfg['download_password_policy_regex'], $key)){
+        if ($cfg['download_password_requirement'] !== 'generated' && $cfg['download_password_policy'] === 'regex') {
+            if (!preg_match($cfg['download_password_policy_regex'], $key)) {
                 echo 'Error 14: The download password is not complying to the security standards.';
                 exit;
             }
         }
-    }elseif ($cfg['download_password_requirement'] !== 'optional'){
+    } elseif ($cfg['download_password_requirement'] !== 'optional') {
         echo 'Error 13: The parameter password is required.';
         exit;
     }
@@ -202,7 +175,7 @@ if (isset($_FILES['file']) && is_writable(VAR_FILES)
     }
     if (strlen($d) > 0 && $d == $link['link_code']) {
         jirafeau_delete_link($link_name);
-        echo "Ok";
+        echo 'Ok';
         exit;
     }
     if ($link['time'] != JIRAFEAU_INFINITY && time() > $link['time']) {
@@ -244,8 +217,8 @@ if (isset($_FILES['file']) && is_writable(VAR_FILES)
 } elseif (isset($_GET['get_version'])) {
     echo JIRAFEAU_VERSION;
 } elseif (isset($_GET['lang'])) {
-    $l=$_GET['lang'];
-    if ($l == "bash") {
+    $l = $_GET['lang'];
+    if ($l == 'bash') {
         ?>
 #!/bin/bash
 
@@ -451,13 +424,13 @@ elseif (isset($_GET['init_async'])) {
     $key = '';
     if (isset($_POST['key'])) {
         $key = $_POST['key'];
-        if ($cfg['download_password_requirement'] !== 'generated' && $cfg['download_password_policy'] === 'regex'){
-            if (!preg_match($cfg['download_password_policy_regex'], $key)){
+        if ($cfg['download_password_requirement'] !== 'generated' && $cfg['download_password_policy'] === 'regex') {
+            if (!preg_match($cfg['download_password_policy_regex'], $key)) {
                 echo 'Error 14: The download password is not complying to the security standards.';
                 exit;
             }
         }
-    }elseif ($cfg['download_password_requirement'] !== 'optional'){
+    } elseif ($cfg['download_password_requirement'] !== 'optional') {
         echo 'Error 13: The parameter password is required.';
         exit;
     }
@@ -468,40 +441,11 @@ elseif (isset($_GET['init_async'])) {
         exit;
     }
 
-    $time = time();
     if (!isset($_POST['time']) || !$cfg['availabilities'][$_POST['time']]) {
         echo 'Error 22';
         exit;
     } else {
-        switch ($_POST['time']) {
-            case 'minute':
-                $time += JIRAFEAU_MINUTE;
-                break;
-            case 'hour':
-                $time += JIRAFEAU_HOUR;
-                break;
-            case 'day':
-                $time += JIRAFEAU_DAY;
-                break;
-            case 'week':
-                $time += JIRAFEAU_WEEK;
-                break;
-            case 'fortnight':
-                $time += JIRAFEAU_FORTNIGHT;
-                break;
-            case 'month':
-                $time += JIRAFEAU_MONTH;
-                break;
-            case 'quarter':
-                $time += JIRAFEAU_QUARTER;
-                break;
-            case 'year':
-                $time += JIRAFEAU_YEAR;
-                break;
-            default:
-                $time = JIRAFEAU_INFINITY;
-                break;
-        }
+        $time = jirafeau_datestr_to_int($_POST['time']);
     }
 
     if ($cfg['store_uploader_ip']) {

patrick-canterino.de