Skip to content
This repository has been archived by the owner on May 14, 2020. It is now read-only.

Commit

Permalink
Fast fix
Browse files Browse the repository at this point in the history
  • Loading branch information
dzove855 committed Dec 7, 2018
1 parent ce069e3 commit a6a3bb5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 36 deletions.
12 changes: 4 additions & 8 deletions config/route.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,16 @@
#ROUTE['/login':'GET':'none']='saml::buildAuthnRequest'
#ROUTE['/':'GET':'connect']="html::print::out ${html_dir}/home.html"

api_command="api::call::function"
api_command="Api::call::function"
default_api_function="dbconnector"

# router="route::api::mode"
# router="route::check"
router="route::api::mode"
router="Route::api::mode"

# Defaults routes
#AUTH['/':'GET']="htpasswd"
#AUTH['/':'POST']="htpasswd"
#AUTH['/':'GET']="none"
AUTH['/':'GET']="none"

#RIGHTS['/':'GET']="none"

auth_method="key::auth::start"
authorization_key="vehbo"
auth_check="auth::api"
RIGHTS['/':'GET']="none"
42 changes: 14 additions & 28 deletions func/dbconnector.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
function db-get ()
{
db-get(){
local matcher="$1" action="$2" _select _where _limit mysql_command="mysql-connect-slave" table display

table="${DB_GET[$matcher:'table']:-$matcher}"
Expand All @@ -25,31 +24,25 @@ function db-get ()
mysql-to-json "$display" "select $_select from $table $_where $_limit"
}

function db-put ()
{
db-put(){
local matcher="$1" action="$2" _query _json _update value result table

[[ -z "$action" ]] && return

[[ -z "${POST['json']}" ]] && return
[[ -z "${POST[*]}" ]] && return

[[ -z "${DB_PUT[$matcher:'where']}" ]] && return

table="${DB_PUT[$matcher:'table']:-$matcher}"

_json="$(echo "${POST['json']}" | jq .data)"

[[ -z "$_json" ]] && return

json-to-array arr "$_json"

_query="update $table set"

for value in "${!arr[@]}"
for value in "${!POST[@]}"
do
result="${arr[$value]}"
result="${POST[$value]}"

# escape ;
value="${value/data:}"
value="${value%%;*}"
result="${result%%;*}"

Expand All @@ -65,8 +58,7 @@ function db-put ()

}

function db-delete ()
{
db-delete(){
local matcher="$1" action="$2" table

[[ -z "$action" ]] && return
Expand All @@ -78,27 +70,23 @@ function db-delete ()
mysql-connector-master "delete from $table where ${DB_DELETE[$matcher:'where']}='$action'" &>/dev/null && echo '{ "msg": "Sccesfully removed!" }'
}

function db-post ()
{
db-post(){
local matcher="$1" _query _json _insert value result table

[[ -z "$matcher" ]] && return

[[ -z "${POST['json']}" ]] && return
[[ -z "${POST[*]}" ]] && return

table="${DB_POST[$matcher:'table']:-$matcher}"

_json="$(echo "${POST['json']}" | jq .data)"

json-to-array arr "$_json"

_query="insert into $table set"

for value in "${!arr[@]}"
for value in "${!POST[@]}"
do
result="${arr[$value]}"
result="${POST[$value]}"

# escape ;
value="${value/data:}"
value="${value%%;*}"
result="${result%%;*}"

Expand All @@ -113,8 +101,7 @@ function db-post ()
mysql-connector-master "$_query" &>/dev/null && echo '{ "msg": "Succesfully added!" }'
}

function dbconnector ()
{
dbconnector(){
local matcher action method

matcher="${uri[1]%%;*}"
Expand All @@ -134,8 +121,7 @@ function dbconnector ()

}

function fail()
{
fail(){
http::send::status 500
echo '{ "msg": "Method not allowed!"'
}
Expand Down

0 comments on commit a6a3bb5

Please sign in to comment.