Browse Source

add path check

causefx 8 years ago
parent
commit
ec45c212f7
5 changed files with 56 additions and 6 deletions
  1. 0 3
      api/functions/api-functions.php
  2. 15 0
      api/functions/organizr-functions.php
  3. 19 0
      api/index.php
  4. 3 2
      api/pages/wizard.php
  5. 19 1
      js/custom.js

+ 0 - 3
api/functions/api-functions.php

@@ -87,9 +87,6 @@ function login($array){
     }
     }
 }
 }
 function createDB($path,$filename) {
 function createDB($path,$filename) {
-    if(file_exists($path.$filename)){
-        unlink($path.$filename);
-    }
     try {
     try {
     	$createDB = new Dibi\Connection([
     	$createDB = new Dibi\Connection([
     		'driver' => 'sqlite3',
     		'driver' => 'sqlite3',

+ 15 - 0
api/functions/organizr-functions.php

@@ -666,6 +666,21 @@ function getAuthBackends(){
     ksort($backendOptions);
     ksort($backendOptions);
     return $backendOptions;
     return $backendOptions;
 }
 }
+function wizardPath($array){
+    $path = $array['data']['path'];
+    if(file_exists($path)){
+        if(is_writable($path)){
+            return true;
+        }
+    }else{
+        if(is_writable(dirname($path, 1))){
+            if(mkdir($path, 0760, true)) {
+                return true;
+            }
+        }
+    }
+    return 'permissions';
+}
 /*
 /*
 function sendEmail($email = null, $username = "Organizr User", $subject, $body, $cc = null, $bcc = null){
 function sendEmail($email = null, $username = "Organizr User", $subject, $body, $cc = null, $bcc = null){
 	try {
 	try {

+ 19 - 0
api/index.php

@@ -397,6 +397,25 @@ switch ($function) {
                 break;
                 break;
         }
         }
         break;
         break;
+    case 'v1_wizard_path':
+        switch ($method) {
+            case 'POST':
+                if(!file_exists('config'.DIRECTORY_SEPARATOR.'config.php')){
+                    $result['status'] = 'success';
+                    $result['statusText'] = 'success';
+                    $result['data'] = wizardPath($_POST);
+                }else{
+                    $result['status'] = 'error';
+                    $result['statusText'] = 'Wizard has already been run';
+                    $result['data'] = null;
+                }
+                break;
+            default:
+                $result['status'] = 'error';
+                $result['statusText'] = 'The function requested is not defined for method: '.$method;
+                break;
+        }
+        break;
     case 'v1_login':
     case 'v1_login':
         switch ($method) {
         switch ($method) {
             case 'POST':
             case 'POST':

+ 3 - 2
api/pages/wizard.php

@@ -127,7 +127,7 @@ $pageWizard = '
                 console.log( post );
                 console.log( post );
                 organizrAPI(\'POST\',\'api/?v1/wizard_config\',post).success(function(data) {
                 organizrAPI(\'POST\',\'api/?v1/wizard_config\',post).success(function(data) {
             		var html = JSON.parse(data);
             		var html = JSON.parse(data);
-                    if(html.data == \'true\'){
+                    if(html.data == true){
                         location.reload();
                         location.reload();
                     }else if(html.data == \'token\'){
                     }else if(html.data == \'token\'){
 						console.error(\'Organizr Function: Could not create Token\');
 						console.error(\'Organizr Function: Could not create Token\');
@@ -261,7 +261,7 @@ $pageWizard = '
                             <div class="wizard-pane" role="tabpanel">
                             <div class="wizard-pane" role="tabpanel">
                                 <div class="panel panel-danger">
                                 <div class="panel panel-danger">
                                     <div class="panel-heading">
                                     <div class="panel-heading">
-                                        <i class="ti-alert fa-fw"></i> <span lang="en">Attenetion</span>
+                                        <i class="ti-alert fa-fw"></i> <span lang="en">Attention</span>
                                         <div class="pull-right"><a href="#" data-perform="panel-collapse"><i class="ti-minus"></i></a> <a href="#" data-perform="panel-dismiss"><i class="ti-close"></i></a> </div>
                                         <div class="pull-right"><a href="#" data-perform="panel-collapse"><i class="ti-minus"></i></a> <a href="#" data-perform="panel-dismiss"><i class="ti-close"></i></a> </div>
                                     </div>
                                     </div>
                                     <div class="panel-wrapper collapse in" aria-expanded="true">
                                     <div class="panel-wrapper collapse in" aria-expanded="true">
@@ -283,6 +283,7 @@ $pageWizard = '
                                     <div class="input-group">
                                     <div class="input-group">
                                         <div class="input-group-addon"><i class="ti-server"></i></div>
                                         <div class="input-group-addon"><i class="ti-server"></i></div>
                                         <input type="text" class="form-control wizardInput" name="location" id="form-location" placeholder="'.dirname(__DIR__, 3).'">
                                         <input type="text" class="form-control wizardInput" name="location" id="form-location" placeholder="'.dirname(__DIR__, 3).'">
+                                        <span class="input-group-btn"><button class="btn btn-info testPath" lang="en" type="button">Test</button></span>
                                     </div>
                                     </div>
                                 </div>
                                 </div>
                             </div>
                             </div>

+ 19 - 1
js/custom.js

@@ -1372,11 +1372,29 @@ $(document).on('change', '#authPlexMachineSelector', function(e) {
     $('#settings-main-form [name=plexID]').val($(this).val());
     $('#settings-main-form [name=plexID]').val($(this).val());
     $('#settings-main-form [name=plexID]').change();
     $('#settings-main-form [name=plexID]').change();
 });
 });
-
 $(document).on("click", ".closeErrorPage", function () {
 $(document).on("click", ".closeErrorPage", function () {
     $('.error-page').html('');
     $('.error-page').html('');
     $('.error-page').fadeOut();
     $('.error-page').fadeOut();
 });
 });
+// test Location
+$(document).on("click", ".testPath", function () {
+    var path = $("#form-location").val();
+    if (typeof path == 'undefined' || path == '') {
+        message('Path Error',' Please enter a path for DB','bottom-right','#FFF','warning','10000');
+    }else{
+        organizrAPI('POST','api/?v1/wizard_path',{path:path}).success(function(data) {
+            var html = JSON.parse(data);
+            console.log(html)
+            if(html.data == true){
+                message('Path',' Path is good to go','bottom-right','#FFF','success','10000');
+            }else{
+                message('Path Error',' Path is not writable','bottom-right','#FFF','warning','10000');
+            }
+        }).fail(function(xhr) {
+            console.error("Organizr Function: Connection Failed");
+        });
+    }
+});
 /* ===== Open-Close Right Sidebar ===== */
 /* ===== Open-Close Right Sidebar ===== */
 
 
 $(document).on("click", ".right-side-toggle", function () {
 $(document).on("click", ".right-side-toggle", function () {