Browse Source

aggiunto mkdir

cek 7 years ago
parent
commit
622e14e0cc

+ 3 - 0
arav_up_api/index.php

@@ -81,6 +81,9 @@ function parseRequest() {
 
     $requestHandler = null;
 
+
+
+
     // Looking for the best function for this request:
     switch ($request['path']) {
         case 'upload':

+ 24 - 11
arav_up_api/requests/requestPostCreateDirectory.php

@@ -2,6 +2,7 @@
 require_once('request.php');
 require_once('../arav_up_inclu/base64codec.php');
 require_once('../arav_up_inclu/utils.php');
+require_once('../arav_up_inclu/fileops.php');
 
 class arkiwiRequestPostCreateDirectory extends arkiwiRequest
 {
@@ -14,31 +15,43 @@ class arkiwiRequestPostCreateDirectory extends arkiwiRequest
         $extra = $this->getRequestExtra();
 
         $this->item64 = $extra[0];
-        $this->path = "/".decoder($extra[0]);
+        $this->path = DIRECTORY_SEPARATOR.decoder($extra[0]);
     }
 
 	public function run() {
-		if($this->request['method'] != 'POST') {
+		$result = false;
+
+        if($this->request['method'] != 'POST') {
 			$this->setBodyError(500, "arkiwiRequestPostCreateDirectory: POST method required.");
 			return;
 		}
 
+
         if (!startsWith($this->path,$_SESSION['authstate']['dir'])) {
             report(REPPRIO::FATAL, "No permission to create a new directory inside ".$this->path);
             $this->setBodyError(401, "No permission to create a new directory inside ".$this->path);
             return;
         }
 
-		$input = file_get_contents('php://input');
-
-        report(1, "AAAAA ".$input);
+        $input = file_get_contents('php://input');
+        $obj = json_decode($input);
 
+        if (property_exists($obj, 'directory')) {
+            $result = data_mkdir($this->path, $obj->directory);
+        }
+        else {
+            report(REPPRIO::FATAL, "No new directory name found.");
+            $this->setBodyError(401, "No new directory name found.");
+            return;
+        }
 
-		$this->setCode(201);
-		$this->setBodyJSON(true);
-	}
-
-	private function addKeyValue($k, $v) {
-		$this->metadata[$k] = $v;
+        if ($result) {
+            $this->setCode(201);
+            $this->setBodyJSON(true);
+        }
+        else {
+            $this->setCode(201);
+            $this->setBodyJSON(false);
+        }
 	}
 }

+ 2 - 0
arav_up_api/requests/requestPostModifyMetadata.php

@@ -19,6 +19,8 @@ class arkiwiRequestPostModifyMetadata extends arkiwiRequest
     }
 
 	public function run() {
+        report(REPPRIO::DEBUG, "Entering arkiwiRequestPostModifyMetadata");
+
 		if($this->request['method'] != 'POST') {
 			$this->setBodyError(500, "arkiwiRequestPostModifyMetadata: POST method required.");
 			return;

+ 6 - 0
arav_up_client/mkdir.php

@@ -63,6 +63,12 @@
 
     <input type="hidden" id="document-type" value="<?php echo $query['type']; ?>"/>
     <input type="hidden" id="document-value" value="<?php echo $query['value']; ?>"/>
+
+    <script>
+    $(function() {
+        initializeCreateDirectory('<?php echo $GLOBALS["conf"]["api_endpoint"] ?>');
+    });
+    </script>
 </body>
 
 </html>

+ 4 - 4
arav_up_client/scripts/arkiwi.js

@@ -69,7 +69,7 @@ ARKIWI.Uploader.prototype.listMetadata = function (item64, callback) {
             if (status != 'parsererror')
                 throw 'Arkiwi.listMetadata(): status ' + status + ' error ' + error;
             else {
-                if (callback != undefined)
+                if (callback)
                     callback(JSON.parse("[]"));
             }
         },
@@ -96,7 +96,7 @@ ARKIWI.Uploader.prototype.modifyMetadata = function (item64, jsonKVString, callb
             throw 'Arkiwi.modifyMetadata(): status ' + status + ' error ' + error;
         },
         success: function (result, status, xhr) {
-            if (callback != undefined)
+            if (callback)
                 callback(result);
         },
         complete: function (xhr, status) {}
@@ -111,9 +111,9 @@ ARKIWI.Uploader.prototype.createDirectory = function (item64, newDirectory, call
         async: true,
         cache: false,
         context: this,
-        data: newDirectory,
+        data: JSON.stringify({directory : newDirectory}),
         dataType: 'text',
-        contentType: "text/plain ",
+        contentType: "html/text",
         error: function (xhr, status, error) {
             throw 'Arkiwi.createDirectory(): status ' + status + ' error ' + error;
         },

+ 17 - 2
arav_up_client/scripts/main.js

@@ -78,14 +78,29 @@ function initializeEdit(endpoint) {
     })
 };
 
-function createDirectory(endpoint) {
+function initializeCreateDirectory(endpoint) {
     arkiwi = new ARKIWI.Uploader(endpoint);
+    $('#confirm-button').click(function(e) {
+        createDirectory();
+        e.preventDefault();
+    });
+    $('#confirm-button').prop("disabled", false);
+};
+
+function createDirectory() {
     documentType = $('#document-type').val();
     documentValue = $('#document-value').val();
     newDirectory = $('#mkdirInput').val();
 
     arkiwi.createDirectory(documentValue, newDirectory, function (result) {
-
+        if (result == 'true') {
+            $('#file-form').detach();
+            $('body').append('<span>messaggio di grande complimentazione o redirect alla pagina di arkiwi con la cartella appena creata, CRI vedi tu quando fai grafica. Probabilmente serve che io ti dia i mezzi per costriure l\'url</span>')
+        }
+        else {
+            $('#file-form').detach();
+            $('body').append('<span>messaggio di grande cordoglio, CRI vedi tu quando fai grafica</span>')
+        }
     });
 };
 

+ 4 - 2
arav_up_confs.php

@@ -48,13 +48,15 @@ $GLOBALS["conf"]["report_threshold"] = 0;
 
 $GLOBALS["conf"]["dirmetadatafile"] = "dir.data";
 
-$GLOBALS["conf"]["user_db"] = "./arav_up_users/arav_users.sqlite3";
+//$GLOBALS["conf"]["user_db"] = "./arav_up_users/arav_users.sqlite3";
+$GLOBALS["conf"]["user_db"] = "/home/cek/git/arkiwiapi/arav_up_users/arav_users.sqlite3";
 
 $GLOBALS["conf"]["data_basedir"] = "/tmp"; // dove stanno i doc fisici
 $GLOBALS["conf"]["metadata_basedir"] = "/tmp"; // dove stanno i metadati derivati
 
 //campi di configurazione per il client html
-$GLOBALS["conf"]["api_endpoint"] = "http://upload.arkiwi.org/arav_up_api";
+//$GLOBALS["conf"]["api_endpoint"] = "http://upload.arkiwi.org/arav_up_api";
+$GLOBALS["conf"]["api_endpoint"] = "http://arkiwi-dev/arav_up_api";
 
 //campi di configurazione per la parte "CAZZACCROCCHIO"
 $GLOBALS["conf"]["assetstore_endpoint"] = "http://assetstore.arkiwi.org";

+ 41 - 168
arav_up_inclu/auth.php

@@ -1,176 +1,48 @@
 <?php
 
-function auth_actions($posts,$gets){
-    // logout
-    if($posts["auth_action"]=="logout"){
-    unsetauth();
-    }
-    // login locale
-    elseif($posts["auth_action"]=="local_login" AND isset($posts["username"])){
-    local_login($posts["username"],$posts["password"]);
-    }
-    // richiesta auth openid (fase 1)
-    elseif($posts["auth_action"] == "openid_login"){
-    $authresult = req_openid_auth($posts['openid_identifier']);
-    }
-
-    // fai auth openid (fase 2)
-    elseif(isset($gets['openid_mode'])) {
-    do_openid_auth($gets['openid_mode']);
-    }
-}
-
-
-// stocca sessione
-function storeauth($iddata){
-    global $aravNamespace;
-    $aravNamespace = new Zend_Session_Namespace('arav');
-    $aravNamespace->iddata = $iddata;
-    $aravNamespace->stabledata = array_intersect_key($_SERVER, array_flip($GLOBALS["conf"]["stablestoredfields"]));
-    $aravNamespace->volatiledata = array_intersect_key($_SERVER, array_flip($GLOBALS["conf"]["volatilestoredfields"]));
-}
-
-function unsetauth(){
-    global $aravNamespace;
-    // $aravNamespace->stabledata = NULL;
-    Zend_Session::destroy(true);
-}
-
-
-// determina se e' autenticato
-function isauth(){
-    global $aravNamespace;
-    $aravNamespace = new Zend_Session_Namespace('arav');
-
-    if($aravNamespace->stabledata == array_intersect_key($_SERVER, array_flip($GLOBALS["conf"]["stablestoredfields"]))){
-    $retaggio = array("esito" => TRUE);
-    foreach ($aravNamespace as $index => $value) {
-        $retaggio[$index] = $value;
-    }
-    }
-    else{
-        $retaggio = array("esito" => FALSE);
-    }
-    return $retaggio;
-}
-
-
-// #### OPENID #######
-
-// auth openid, fase 1
-function req_openid_auth($openid_identifier){
-    Zend_Loader::loadClass('Zend_OpenId_Consumer');
-    Zend_Loader::loadClass('Zend_OpenId_Extension_Sreg');
-
-    $status = "";
-    $sreg = new Zend_OpenId_Extension_Sreg(array('nickname'=>true,
-                             'email'=>false,
-                             'fullname'=>false), null, 1.1);
-    $consumer = new Zend_OpenId_Consumer();
-    if (!$consumer->login($openid_identifier, NULL, NULL, $sreg)) {
-    $status = array("esito" => "USER_NE", "userid" => htmlspecialchars($id));
-    }
-    return $status;
-}
-
-// fai auth openid (fase 2)
-function do_openid_auth($openid_mode){
-    if ($openid_mode == "id_res") {
-    Zend_Loader::loadClass('Zend_OpenId_Consumer');
-    Zend_Loader::loadClass('Zend_OpenId_Extension_Sreg');
-
-    $sreg = new Zend_OpenId_Extension_Sreg(array(
-                             'nickname'=>true,
-                             'email'=>false,
-                             'fullname'=>false), null, 1.1);
-
-    $consumer = new Zend_OpenId_Consumer();
-    if ($consumer->verify($_GET, $id,$sreg)) {
-        $status = array("esito" => "AUTH_OK", "userid" => htmlspecialchars($id));
-    } else {
-        $status = array("esito" => "USER_NE", "userid" => htmlspecialchars($id));
-    }
-    } else if ($openid_mode == "cancel") {
-    $status = array("esito" => "USER_NE", "userid" => htmlspecialchars($id));
-    }
-
-    $data = $sreg->getProperties();
-
-    if ($status["esito"] == "AUTH_OK"){
-    $usergroup = get_openid_usergroup($id);
-    $authdata["ACL"] = get_acl($usergroup);
-    $authdata["IDENTITY"] = $id;
-    $authdata["NICK"] = htmlspecialchars($data["nickname"]);
-    storeauth($authdata);
-    }
-    else{
-    unsetauth();
-    }
-}
-
-// #####  mappatura gruppi #####
-
-// user -> usergroup su tabella openid
-function get_openid_usergroup($openid){
-    Zend_Loader::loadClass('Zend_Db_Adapter_Pdo_Sqlite');
-    $dbAdapter = new Zend_Db_Adapter_Pdo_Sqlite(array('dbname' => $GLOBALS["conf"]["user_db"],'sqlite3' => true ));
-    $query = "SELECT usergroup FROM openid WHERE openid = '$openid'";
-    $result = $dbAdapter->fetchCol($query);
-    return $result[0];
-}
-
-// #### LOGIN LOCALE ########
-
-// effettua il login locale
-function local_login($username, $password){
-    $username = preg_replace("/[^a-zA-Z0-9\-\_]/", "", $username);
-    $authresult = do_local_auth($username,hash("sha256",$password));
-
-    if ($authresult["esito"] == "AUTH_OK"){
-    $usergroup = get_local_usergroup($authresult["userid"]);
-    $authdata["ACL"] = get_acl($usergroup);
-
-    $authdata["IDENTITY"] = $authresult["userid"];
-    $authdata["NICK"] = htmlspecialchars($authresult["userid"]);
-
-    storeauth($authdata);
-    }
-    else{
-    unsetauth();
-    }
-}
-
 // autentica sul db locale
 function do_local_auth($username, $password){
     try {
-    // Create (connect to) SQLite database in file
-    $file_db = new PDO("sqlite:".$GLOBALS["conf"]["user_db"]);
-    report(1,"connected to auth db");
-    // Set errormode to exceptions
-    $file_db->setAttribute(PDO::ATTR_ERRMODE,
-                   PDO::ERRMODE_EXCEPTION);
-    $query_userexist = "SELECT username FROM users WHERE username = '$username'";
-    report(1,"query $query_userexist");
-    $ueresult = $file_db->query($query_userexist);
-    $uerow = $ueresult->fetch(PDO::FETCH_ASSOC);
-
-    if($uerow["username"] == $username){
-        report(1,"username exists");
-        // controlla passwd e piglia su dati
-        $query_checkpwd = "SELECT users.username,groups.dir FROM users,groups WHERE users.username = '$username' AND users.password = '$password' AND users.usergroup = groups.usergroup";
-        report(1,"query: $query_checkpwd");
-        $cpresult = $file_db->query($query_checkpwd);
-        $cprow = $cpresult->fetch(PDO::FETCH_ASSOC);
-        if($cprow["username"] == $username){
-        $esito = "AUTH_OK";
-        }
-        else {
-        $esito = "PASS_IV";
-        }
-    } else {
-        $esito = "USER_NE";
-    }
-    report(1,"esito $esito");
+	// Create (connect to) SQLite database in file
+	$file_db = new PDO("sqlite:".$GLOBALS["conf"]["user_db"]);
+	report(1,"connected to auth db");
+	// Set errormode to exceptions
+	$file_db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+
+	$query_userexist = "SELECT username FROM users WHERE username = :username";
+	$uestmt = $file_db->prepare($query_userexist);
+	$uestmt->bindParam(':username', $username);
+	$uestmt->execute();
+	$uerow = $uestmt->fetch(PDO::FETCH_ASSOC);
+
+	if($uerow["username"] == $username){
+	    report(1,"username exists");
+	    // controlla passwd e piglia su dati
+
+	    /*
+	     $query_checkpwd = "SELECT users.username,groups.dir FROM users,groups WHERE users.username = :username AND users.password = :password AND users.usergroup = groups.usergroup";
+	     $cpstmt = $file_db->prepare($query_checkpwd);
+	     $cpstmt->bindParam(':username', $username);
+	     $cpstmt->bindParam(':password', $password);
+	     $cpstmt->execute();
+	     $cprow = $cpstmt->fetch(PDO::FETCH_ASSOC);
+	     */
+
+	    $query_checkpwd = "SELECT users.username,groups.dir FROM users,groups WHERE users.username = '$username' AND users.password = '$password' AND users.usergroup = groups.usergroup";
+	    report(1,"query: $query_checkpwd");
+	    $cpresult = $file_db->query($query_checkpwd);
+	    $cprow = $cpresult->fetch(PDO::FETCH_ASSOC);
+
+	    if($cprow["username"] == $username){
+		$esito = "AUTH_OK";
+	    }
+	    else {
+		$esito = "PASS_IV"; // pwd sbajata!
+	    }
+	} else {
+	    $esito = "USER_NE"; // non esiste
+	}
+	report(1,"esito $esito");
     }
     catch(PDOException $e){
         report(3,$e->getMessage());
@@ -189,4 +61,5 @@ function is_inside_dir($object,$dir){
     if( strpos(realpath($object), realpath($dir)) === 0) return true;
     return false;
 }
+
 ?>

+ 18 - 0
arav_up_inclu/fileops.php

@@ -0,0 +1,18 @@
+<?php
+require_once('report.php');
+
+function data_mkdir($path, $newdir){
+     // pulisci
+     $newdir = basename(trim($newdir));
+     $newdirpath = realpath($GLOBALS["conf"]["data_basedir"].DIRECTORY_SEPARATOR.$path).DIRECTORY_SEPARATOR.$newdir;
+
+    report(1, "BABABA ".$newdirpath);
+
+     if (!file_exists($newdirpath)) {
+        return mkdir($newdirpath, 0755, false);
+     }
+
+     return false;
+ }
+
+?>

+ 0 - 80
arav_up_inclu/interface.php

@@ -1,80 +0,0 @@
-<?php
-
-function data_upload($path){
-    $path = decoder($path);
-    if(check_acl($path)){
-	Zend_Loader::loadClass('Zend_File_Transfer_Adapter_Http');
-	$adapter = new Zend_File_Transfer_Adapter_Http();
-	$adapter->setDestination($path);
-	$adapter->addValidator('Extension', false, array('ogg', 'oga', 'ogv', 'webm'));
-	$adapter->addValidator('FilesSize',false, array('min' => '40kB', 'max' => '200MB'));
-	$adapter->addValidator('NotExists', false, $path);
-	$adapter->isValid($file);
-	
-	if (!$adapter->receive()) {
-	    $messages = $adapter->getMessages();
-	    echo implode("\n", $messages);
-	}
-    }
-}
-
-function data_mkdir($path,$newdir){
-    // pulisci
-    $newdir = basename(trim($newdirname));
-    $newdirpath = $path."/".$newdir;
-    if(dirfilter($newdirpath) and check_acl($newdirpath)){
-	$absnewdirpath = $GLOBALS["conf"]["data_basedir"]."/".$newdirpath;
-	mkdir($absnewdirpath);
-    }
-}
-
-function data_delete($path){
-    if(check_acl($path)){
-	$abspath = $GLOBALS["conf"]["data_basedir"]."/".$path;
-	if(is_dir($abspath) AND dirfilter($path)){
-	    unlink($abspath);
-	}
-	elseif(is_file($abspath) AND filefilter($path)){
-	    rmdir($abspath);
-	}
-    }
-}
-
-function metadata_edit($path){
-    $reserved_elements = array("path", "action", "newa", "update", "metadataformat", "xmldata");
-    if(check_acl($path)){
-
-	$data = array_diff_key($_POST, array_flip($reserved_elements));
-	require 'arav_inclu/injectors.php';
-	// sostituire solo i metadati specificati
-	if($_POST["update"] == TRUE){
-	    require_once 'arav_inclu/extractors.php';
-	    $obj_md = extract_info_metadata($path);
-	    $data = array_merge($obj_md,$data);
-	}
-	// stocca
-	if($_POST["metadataformat"] == "xml"){
-	    report(1,"xml metadata edit ".$_POST["xmldata"] );
-	    $metadata_array = array();
-	    $doc = new DOMDocument();
-	    $doc->loadXML($_POST["xmldata"],LIBXML_NOBLANKS);
-	    
-	    dom2array($doc,"",$metadata_array);
-	    //  print_r($metadata_array);
-	    
-	    store_md_array($metadata_array,$path);
-	}
-	else{
-	    store_md_array($data,$path);	
-	}
-	
-
-    }
-}
-
-// controlla se sta in acl
-function check_acl($objpath){
-        return TRUE;
-}
-
-?>

BIN
arav_up_users/arav_users.sqlite3


+ 1 - 0
index.html

@@ -0,0 +1 @@
+uuuuu, de uploder!