diff --git a/.gitignore b/.gitignore index 96374c4..32c8834 100644 --- a/.gitignore +++ b/.gitignore @@ -41,3 +41,6 @@ $RECYCLE.BIN/ Network Trash Folder Temporary Items .apdisk + +INSTALL.php +config.php diff --git a/.htaccess b/.htaccess index 9862c54..b099100 100644 --- a/.htaccess +++ b/.htaccess @@ -1,2 +1,2 @@ -Options All -Indexes -DirectoryIndex api.php +Options ALL -Indexes +DirectoryIndex api.php \ No newline at end of file diff --git a/api.php b/api.php index 4dfc75c..93b81e1 100644 --- a/api.php +++ b/api.php @@ -10,11 +10,23 @@ function hash_equals($a, $b) { } } -$itemName = $_POST['item']; -$itemCount = $_POST['count']; -$jsonData = $_POST['jsonArray']; -$function = $_POST['function']; +if(isset($_POST['item'])) + $itemName = $_POST['item']; + +if(isset($_POST['count'])) + $itemCount = $_POST['count']; + +if(isset($_POST['jsonArray'])) + $jsonData = $_POST['jsonArray']; + +if(!isset($_POST['function'])) + die("No function"); + +if(!isset($_POST['auth'])) + die("No auth"); + $auth = $_POST['auth']; +$function = $_POST['function']; include('config.php'); @@ -44,10 +56,13 @@ function hash_equals($a, $b) { include $dbConnector; - + /* WHAT? if (!hash_equals($authKey, crypt($auth, $authKey))){ die (json_encode(array('type' => API_ERROR_403, 'content' => 'Authentication failed.'))); } + */ + if($auth!==$authKey) + die (json_encode(array('type' => API_ERROR_403, 'content' => 'Authentication failed.'))); $db = NEW DataBase($dbConfig); diff --git a/config.php b/config.php deleted file mode 100644 index 7278a42..0000000 --- a/config.php +++ /dev/null @@ -1,28 +0,0 @@ - "shoppinglist.sqlite"); - /*########################################################## - # MySQL Config # - ############################################################*/ - $MySQLConfig = array('host' => "host",'db' => "db",'user' => "user",'password' => "password",); -?> - diff --git a/mysql_connector.php b/mysql_connector.php index 58075a6..0718997 100644 --- a/mysql_connector.php +++ b/mysql_connector.php @@ -1,5 +1,5 @@ API_ERROR_MISSING_PARAMETER, 'content' => 'parameter missing for deleteMultiple'))); - } + function deleteMultiple($jsonData) { + if(empty($jsonData)) + die(json_encode(array('type' => API_ERROR_MISSING_PARAMETER, 'content' => 'parameter missing for deleteMultiple'))); + //iterate over all items in json array + $array = json_decode( $jsonData, true ); + if(count($array) ==0) + die(json_encode(array('type' => API_ERROR_MISSING_PARAMETER, 'content' => 'parameter missing for deleteMultiple'))); + //connect to db $handler = new mysqli($this->server, $this->username, $this->password, $this->database); @@ -90,14 +93,12 @@ function deleteMultiple($jsonData) if ($handler->connect_error) { die(json_encode(array('type' => API_ERROR_DATABASE_CONNECT, 'content' => $handler->connect_error))); } - //iterate over all items in json array - $array = json_decode( $jsonData, true ); + + //prepare query + $stmt = $handler->prepare("DELETE from ShoppingList WHERE item = ?"); + $stmt->bind_param('s', $item['itemTitle']); foreach($array as $item) { - //prepare query - $stmt = $handler->prepare("DELETE from ShoppingList WHERE item = ?"); - $stmt->bind_param('s', $item['itemTitle']); - //execute query and check if successful if (!$stmt->execute()){ $result = json_encode(array('type' => API_SUCCESS_DELETE, 'content' => ' Multiple items deleted'));