ndejong / pfsense_fauxapi

REST based API interface for pfSense 2.3.x and 2.4.x to facilitate devops
Apache License 2.0
354 stars 61 forks source link

Server returned HTTP response code: 500 for REST API call #16

Closed Vaibhav1587 closed 6 years ago

Vaibhav1587 commented 6 years ago

I'm trying to access the function_call API by making the HTTP request using JAVA code as follows,

phpFn = 'easyrule_block_alias_getid' and fnParams='wan'

HttpURLConnection con = (HttpURLConnection)url.openConnection();
        con.setRequestProperty("fauxapi-auth", getAuth());
        con.setRequestProperty("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8");
        con.setRequestProperty("Accept-Encoding", "gzip, deflate, br");
        con.setRequestProperty("Accept-Language", "en-US,en;q=0.9,hi;q=0.8");
        con.setRequestProperty("Cache-Control", "max-age=0");
        con.setRequestProperty("Connection", "keep-alive");
        con.setRequestProperty("Upgrade-Insecure-Requests", "11");
        con.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36");
        con.setRequestProperty("Origin", "");
        con.setAllowUserInteraction(true);
        con.setRequestMethod("POST");
        con.setDoInput(true);
        con.setDoOutput(true);

        OutputStream os = con.getOutputStream();
        BufferedWriter writer = new BufferedWriter(
                new OutputStreamWriter(os, "UTF-8"));
        writer.write("{\"function\":\""+phpFn+"\",\"int\":\""+fnParams[0]+"\"}");
        writer.flush();
        writer.close();
        os.close();
        con.connect();

same code works for the

get_services function of the

function_call

API.

ndejong commented 6 years ago

Hi

There are two problems here:- (a) it does not look like your input args are arranged correctly for this function (b) you'll need to uncomment the line entry for function easyrule_block_alias_getid in the file /etc/fauxapi/pfsense_function_calls.txt

I've tested the following Python example, that does indeed work once the respective entry in the file /etc/fauxapi/pfsense_function_calls.txt was enabled

print(json.dumps(
    FauxapiLib.function_call({
        'function': 'easyrule_block_alias_getid',
        'args': ['wan']
    }
)))