Sponsor: VoiceMeUp - Corporate & Wholesale VoIP Services

VoIP Mailing List Archives
Mailing list archives for the VoIP community
 SearchSearch 

[Freeswitch-users] freeswitch won't open file


 
Post new topic   Reply to topic    VoIP Mailing List Archives Forum Index -> freeSWITCH Users
View previous topic :: View next topic  
Author Message
mrjoli021 at gmail.com
Guest





PostPosted: Fri Dec 04, 2020 3:21 pm    Post subject: [Freeswitch-users] freeswitch won't open file Reply with quote

Hello,


I have the following function that works normally on lua, but when I copied and pasted it into my freeswitch lua script, the file wont open.  I am trying to put the passwords I use in a json format outside the script, so that I can share the script.  I have installed the correct libraries for lunajson to work.  
Any suggestions?




--Reads json file and parses it
function returnJson(option)
    freeswitch.consoleLog("INFO", "Inside function\n")



    local file = io.open("password.json", "r")
    if not file then 
      return nil
    end
    local jsonString = file:read("*a")
    
    freeswitch.consoleLog("INFO", "File is open\n")
    file:close()
    jsonResult = lunajson.decode( jsonString )
    freeswitch.consoleLog("INFO", "Parsing json\n")
    return ( jsonResult[option] )
end



--SID = returnJson("SID")
--Token = returnJson("TOKEN")

------------------------------------------------------------------------------------------------------------

2020-12-04 14:38:13.637108 [ERR] mod_lua.cpp:203 /usr/share/freeswitch/scripts/test.lua:67: attempt to concatenate global 'SID' (a nil value)
stack traceback:
/usr/share/freeswitch/scripts/test.lua:67: in main chunk
Back to top
brian at freeswitch.com
Guest





PostPosted: Fri Dec 04, 2020 4:57 pm    Post subject: [Freeswitch-users] freeswitch won't open file Reply with quote

check permissions of the file.

On Fri, Dec 4, 2020 at 2:36 PM Joli Martinez <mrjoli021@gmail.com (mrjoli021@gmail.com)> wrote:

Quote:
Hello,


I have the following function that works normally on lua, but when I copied and pasted it into my freeswitch lua script, the file wont open.  I am trying to put the passwords I use in a json format outside the script, so that I can share the script.  I have installed the correct libraries for lunajson to work.  
Any suggestions?




--Reads json file and parses it
function returnJson(option)
    freeswitch.consoleLog("INFO", "Inside function\n")



    local file = io.open("password.json", "r")
    if not file then 
      return nil
    end
    local jsonString = file:read("*a")
    
    freeswitch.consoleLog("INFO", "File is open\n")
    file:close()
    jsonResult = lunajson.decode( jsonString )
    freeswitch.consoleLog("INFO", "Parsing json\n")
    return ( jsonResult[option] )
end



--SID = returnJson("SID")
--Token = returnJson("TOKEN")

------------------------------------------------------------------------------------------------------------

2020-12-04 14:38:13.637108 [ERR] mod_lua.cpp:203 /usr/share/freeswitch/scripts/test.lua:67: attempt to concatenate global 'SID' (a nil value)
stack traceback:
/usr/share/freeswitch/scripts/test.lua:67: in main chunk



_________________________________________________________________________

The FreeSWITCH project is sponsored by SignalWire https://signalwire.com
Enhance your FreeSWITCH install with disruptive priced SMS and PSTN services.
Build your next product on our scalable cloud platform.

Join our online community to chat in real time https://signalwire.community

Professional FreeSWITCH Services
sales@freeswitch.com (sales@freeswitch.com)
https://freeswitch.com

Official FreeSWITCH Sites
https://freeswitch.com/oss
https://freeswitch.org/confluence
https://cluecon.com

FreeSWITCH-users mailing list
FreeSWITCH-users@lists.freeswitch.org (FreeSWITCH-users@lists.freeswitch.org)
http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users
https://freeswitch.com



--



Brian West | Co-founder and Developer
Need Commercial support? email sales@freeswitch.com (sales@freeswitch.com)
FreeSWITCH Solutions | 17345 Civic Drive #2531 Brookfield, WI 53045
Email: brian@freeswitch.com (brian@freeswitch.com)
Mobile: 918-424-9378
Website: https://www.FreeSWITCH.com
[/url] [url=https://twitter.com/freeswitch]
Back to top
mrjoli021 at gmail.com
Guest





PostPosted: Fri Dec 04, 2020 6:37 pm    Post subject: [Freeswitch-users] freeswitch won't open file Reply with quote

Hello,

The file permissions are set to rw-r--r-- www-data:www-data same as every other file in the scripts directory.


Thanks,


On Fri, Dec 4, 2020 at 5:02 PM Brian West <brian@freeswitch.com (brian@freeswitch.com)> wrote:

Quote:
check permissions of the file.

On Fri, Dec 4, 2020 at 2:36 PM Joli Martinez <mrjoli021@gmail.com (mrjoli021@gmail.com)> wrote:

Quote:
Hello,


I have the following function that works normally on lua, but when I copied and pasted it into my freeswitch lua script, the file wont open.  I am trying to put the passwords I use in a json format outside the script, so that I can share the script.  I have installed the correct libraries for lunajson to work.  
Any suggestions?




--Reads json file and parses it
function returnJson(option)
    freeswitch.consoleLog("INFO", "Inside function\n")



    local file = io.open("password.json", "r")
    if not file then 
      return nil
    end
    local jsonString = file:read("*a")
    
    freeswitch.consoleLog("INFO", "File is open\n")
    file:close()
    jsonResult = lunajson.decode( jsonString )
    freeswitch.consoleLog("INFO", "Parsing json\n")
    return ( jsonResult[option] )
end



--SID = returnJson("SID")
--Token = returnJson("TOKEN")

------------------------------------------------------------------------------------------------------------

2020-12-04 14:38:13.637108 [ERR] mod_lua.cpp:203 /usr/share/freeswitch/scripts/test.lua:67: attempt to concatenate global 'SID' (a nil value)
stack traceback:
/usr/share/freeswitch/scripts/test.lua:67: in main chunk



_________________________________________________________________________

The FreeSWITCH project is sponsored by SignalWire https://signalwire.com
Enhance your FreeSWITCH install with disruptive priced SMS and PSTN services.
Build your next product on our scalable cloud platform.

Join our online community to chat in real time https://signalwire.community

Professional FreeSWITCH Services
sales@freeswitch.com (sales@freeswitch.com)
https://freeswitch.com

Official FreeSWITCH Sites
https://freeswitch.com/oss
https://freeswitch.org/confluence
https://cluecon.com

FreeSWITCH-users mailing list
FreeSWITCH-users@lists.freeswitch.org (FreeSWITCH-users@lists.freeswitch.org)
http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users
https://freeswitch.com



--



Brian West | Co-founder and Developer
Need Commercial support? email sales@freeswitch.com (sales@freeswitch.com)
FreeSWITCH Solutions | 17345 Civic Drive #2531 Brookfield, WI 53045
Email: brian@freeswitch.com (brian@freeswitch.com)
Mobile: 918-424-9378
Website: https://www.FreeSWITCH.com
[/url] [url=https://twitter.com/freeswitch]













_________________________________________________________________________

The FreeSWITCH project is sponsored by SignalWire https://signalwire.com
Enhance your FreeSWITCH install with disruptive priced SMS and PSTN services.
Build your next product on our scalable cloud platform.

Join our online community to chat in real time https://signalwire.community

Professional FreeSWITCH Services
sales@freeswitch.com (sales@freeswitch.com)
https://freeswitch.com

Official FreeSWITCH Sites
https://freeswitch.com/oss
https://freeswitch.org/confluence
https://cluecon.com

FreeSWITCH-users mailing list
FreeSWITCH-users@lists.freeswitch.org (FreeSWITCH-users@lists.freeswitch.org)
http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users
https://freeswitch.com
Back to top
david.villasmil.work a...
Guest





PostPosted: Sat Dec 05, 2020 4:07 am    Post subject: [Freeswitch-users] freeswitch won't open file Reply with quote

If you’re running fs as freeswitch, you need to give it permission to open those files. Something like chmod o+rw 

On Sat, 5 Dec 2020 at 00:22, Joli Martinez <mrjoli021@gmail.com (mrjoli021@gmail.com)> wrote:

Quote:
Hello,

The file permissions are set to rw-r--r-- www-data:www-data same as every other file in the scripts directory.


Thanks,


On Fri, Dec 4, 2020 at 5:02 PM Brian West <brian@freeswitch.com (brian@freeswitch.com)> wrote:

Quote:
check permissions of the file.

On Fri, Dec 4, 2020 at 2:36 PM Joli Martinez <mrjoli021@gmail.com (mrjoli021@gmail.com)> wrote:

Quote:
Hello,


I have the following function that works normally on lua, but when I copied and pasted it into my freeswitch lua script, the file wont open.  I am trying to put the passwords I use in a json format outside the script, so that I can share the script.  I have installed the correct libraries for lunajson to work.  
Any suggestions?




--Reads json file and parses it
function returnJson(option)
    freeswitch.consoleLog("INFO", "Inside function\n")



    local file = io.open("password.json", "r")
    if not file then 
      return nil
    end
    local jsonString = file:read("*a")
    
    freeswitch.consoleLog("INFO", "File is open\n")
    file:close()
    jsonResult = lunajson.decode( jsonString )
    freeswitch.consoleLog("INFO", "Parsing json\n")
    return ( jsonResult[option] )
end



--SID = returnJson("SID")
--Token = returnJson("TOKEN")

------------------------------------------------------------------------------------------------------------

2020-12-04 14:38:13.637108 [ERR] mod_lua.cpp:203 /usr/share/freeswitch/scripts/test.lua:67: attempt to concatenate global 'SID' (a nil value)
stack traceback:
/usr/share/freeswitch/scripts/test.lua:67: in main chunk



_________________________________________________________________________

The FreeSWITCH project is sponsored by SignalWire https://signalwire.com
Enhance your FreeSWITCH install with disruptive priced SMS and PSTN services.
Build your next product on our scalable cloud platform.

Join our online community to chat in real time https://signalwire.community

Professional FreeSWITCH Services
sales@freeswitch.com (sales@freeswitch.com)
https://freeswitch.com

Official FreeSWITCH Sites
https://freeswitch.com/oss
https://freeswitch.org/confluence
https://cluecon.com

FreeSWITCH-users mailing list
FreeSWITCH-users@lists.freeswitch.org (FreeSWITCH-users@lists.freeswitch.org)
http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users
https://freeswitch.com



--



Brian West | Co-founder and Developer
Need Commercial support? email sales@freeswitch.com (sales@freeswitch.com)
FreeSWITCH Solutions | 17345 Civic Drive #2531 Brookfield, WI 53045
Email: brian@freeswitch.com (brian@freeswitch.com)
Mobile: 918-424-9378
Website: https://www.FreeSWITCH.com
[/url] [url=https://twitter.com/freeswitch]













_________________________________________________________________________

The FreeSWITCH project is sponsored by SignalWire https://signalwire.com
Enhance your FreeSWITCH install with disruptive priced SMS and PSTN services.
Build your next product on our scalable cloud platform.

Join our online community to chat in real time https://signalwire.community

Professional FreeSWITCH Services
sales@freeswitch.com (sales@freeswitch.com)
https://freeswitch.com

Official FreeSWITCH Sites
https://freeswitch.com/oss
https://freeswitch.org/confluence
https://cluecon.com

FreeSWITCH-users mailing list
FreeSWITCH-users@lists.freeswitch.org (FreeSWITCH-users@lists.freeswitch.org)
http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users
https://freeswitch.com

_________________________________________________________________________

The FreeSWITCH project is sponsored by SignalWire https://signalwire.com
Enhance your FreeSWITCH install with disruptive priced SMS and PSTN services.
Build your next product on our scalable cloud platform.

Join our online community to chat in real time https://signalwire.community

Professional FreeSWITCH Services
sales@freeswitch.com (sales@freeswitch.com)
https://freeswitch.com

Official FreeSWITCH Sites
https://freeswitch.com/oss
https://freeswitch.org/confluence
https://cluecon.com

FreeSWITCH-users mailing list
FreeSWITCH-users@lists.freeswitch.org (FreeSWITCH-users@lists.freeswitch.org)
http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users
https://freeswitch.com


--
Regards,


David Villasmilemail: david.villasmil.work@gmail.com (david.villasmil.work@gmail.com)
phone: +34669448337
Back to top
mrjoli021 at gmail.com
Guest





PostPosted: Sat Dec 05, 2020 1:41 pm    Post subject: [Freeswitch-users] freeswitch won't open file Reply with quote

Hello,

It is not a permissions issue.  I have changed the permissions to rw for everyone and it will still not read the file.  


The password.json file is in the same directory as the script /usr/share/freeswitch/script.  I am using lua 5.2.3 and again, the same code works in my home directory.  I just copied the password.json file over and pasted the function into my code.  When I place the call freeswitch prints "Inside the function", so I know it gets there, but then freeswitch spits out  "attempt to index local 'file' (a nil value)"


What else could I be missing?


-------------------------------
--Reads json file and parses it
function returnJson(option)


    freeswitch.consoleLog("INFO", "Inside function\n")
    
    f = "password.json"
     
    local file = io.open(f, "r")
    if not file then 
      return nil
    end
    local jsonString = file:read("*a")


    freeswitch.consoleLog("INFO", "File is open\n")
    local file:close()


    local jsonResult = lunajson.decode( jsonString )
    freeswitch.consoleLog("INFO", "Parsing json\n")
    return ( jsonResult[option] )


end


SID = returnJson("SID")
Token = returnJson("TOKEN")







Thanks,




On Sat, Dec 5, 2020 at 4:19 AM David Villasmil <david.villasmil.work@gmail.com (david.villasmil.work@gmail.com)> wrote:

Quote:
If you’re running fs as freeswitch, you need to give it permission to open those files. Something like chmod o+rw 

On Sat, 5 Dec 2020 at 00:22, Joli Martinez <mrjoli021@gmail.com (mrjoli021@gmail.com)> wrote:

Quote:
Hello,

The file permissions are set to rw-r--r-- www-data:www-data same as every other file in the scripts directory.


Thanks,


On Fri, Dec 4, 2020 at 5:02 PM Brian West <brian@freeswitch.com (brian@freeswitch.com)> wrote:

Quote:
check permissions of the file.

On Fri, Dec 4, 2020 at 2:36 PM Joli Martinez <mrjoli021@gmail.com (mrjoli021@gmail.com)> wrote:

Quote:
Hello,


I have the following function that works normally on lua, but when I copied and pasted it into my freeswitch lua script, the file wont open.  I am trying to put the passwords I use in a json format outside the script, so that I can share the script.  I have installed the correct libraries for lunajson to work.  
Any suggestions?




--Reads json file and parses it
function returnJson(option)
    freeswitch.consoleLog("INFO", "Inside function\n")



    local file = io.open("password.json", "r")
    if not file then 
      return nil
    end
    local jsonString = file:read("*a")
    
    freeswitch.consoleLog("INFO", "File is open\n")
    file:close()
    jsonResult = lunajson.decode( jsonString )
    freeswitch.consoleLog("INFO", "Parsing json\n")
    return ( jsonResult[option] )
end



--SID = returnJson("SID")
--Token = returnJson("TOKEN")

------------------------------------------------------------------------------------------------------------

2020-12-04 14:38:13.637108 [ERR] mod_lua.cpp:203 /usr/share/freeswitch/scripts/test.lua:67: attempt to concatenate global 'SID' (a nil value)
stack traceback:
/usr/share/freeswitch/scripts/test.lua:67: in main chunk



_________________________________________________________________________

The FreeSWITCH project is sponsored by SignalWire https://signalwire.com
Enhance your FreeSWITCH install with disruptive priced SMS and PSTN services.
Build your next product on our scalable cloud platform.

Join our online community to chat in real time https://signalwire.community

Professional FreeSWITCH Services
sales@freeswitch.com (sales@freeswitch.com)
https://freeswitch.com

Official FreeSWITCH Sites
https://freeswitch.com/oss
https://freeswitch.org/confluence
https://cluecon.com

FreeSWITCH-users mailing list
FreeSWITCH-users@lists.freeswitch.org (FreeSWITCH-users@lists.freeswitch.org)
http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users
https://freeswitch.com



--



Brian West | Co-founder and Developer
Need Commercial support? email sales@freeswitch.com (sales@freeswitch.com)
FreeSWITCH Solutions | 17345 Civic Drive #2531 Brookfield, WI 53045
Email: brian@freeswitch.com (brian@freeswitch.com)
Mobile: 918-424-9378
Website: https://www.FreeSWITCH.com
[/url] [url=https://twitter.com/freeswitch]













_________________________________________________________________________

The FreeSWITCH project is sponsored by SignalWire https://signalwire.com
Enhance your FreeSWITCH install with disruptive priced SMS and PSTN services.
Build your next product on our scalable cloud platform.

Join our online community to chat in real time https://signalwire.community

Professional FreeSWITCH Services
sales@freeswitch.com (sales@freeswitch.com)
https://freeswitch.com

Official FreeSWITCH Sites
https://freeswitch.com/oss
https://freeswitch.org/confluence
https://cluecon.com

FreeSWITCH-users mailing list
FreeSWITCH-users@lists.freeswitch.org (FreeSWITCH-users@lists.freeswitch.org)
http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users
https://freeswitch.com

_________________________________________________________________________

The FreeSWITCH project is sponsored by SignalWire https://signalwire.com
Enhance your FreeSWITCH install with disruptive priced SMS and PSTN services.
Build your next product on our scalable cloud platform.

Join our online community to chat in real time https://signalwire.community

Professional FreeSWITCH Services
sales@freeswitch.com (sales@freeswitch.com)
https://freeswitch.com

Official FreeSWITCH Sites
https://freeswitch.com/oss
https://freeswitch.org/confluence
https://cluecon.com

FreeSWITCH-users mailing list
FreeSWITCH-users@lists.freeswitch.org (FreeSWITCH-users@lists.freeswitch.org)
http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users
https://freeswitch.com


--
Regards,


David Villasmilemail: david.villasmil.work@gmail.com (david.villasmil.work@gmail.com)
phone: +34669448337


_________________________________________________________________________

The FreeSWITCH project is sponsored by SignalWire https://signalwire.com
Enhance your FreeSWITCH install with disruptive priced SMS and PSTN services.
Build your next product on our scalable cloud platform.

Join our online community to chat in real time https://signalwire.community

Professional FreeSWITCH Services
sales@freeswitch.com (sales@freeswitch.com)
https://freeswitch.com

Official FreeSWITCH Sites
https://freeswitch.com/oss
https://freeswitch.org/confluence
https://cluecon.com

FreeSWITCH-users mailing list
FreeSWITCH-users@lists.freeswitch.org (FreeSWITCH-users@lists.freeswitch.org)
http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users
https://freeswitch.com
Back to top
mayamatakeshi at gmail...
Guest





PostPosted: Sat Dec 05, 2020 5:43 pm    Post subject: [Freeswitch-users] freeswitch won't open file Reply with quote

On Sun, Dec 6, 2020 at 3:42 AM Joli Martinez <mrjoli021@gmail.com (mrjoli021@gmail.com)> wrote:

Quote:
Hello,

It is not a permissions issue.  I have changed the permissions to rw for everyone and it will still not read the file.  


The password.json file is in the same directory as the script /usr/share/freeswitch/script.  I am using lua 5.2.3 and again, the same code works in my home directory.  I just copied the password.json file over and pasted the function into my code.  When I place the call freeswitch prints "Inside the function", so I know it gets there, but then freeswitch spits out  "attempt to index local 'file' (a nil value)"


What else could I be missing?




 
Hi, 
when I check the current folder inside the fs cli I get:


freeswitch@lab002> system pwd
/


So, if you use:


f = "password.json"
local file = io.open(f, "r")



freeswitch would try to open "/password.json"
So I think you should pass the full file path:
f = "/usr/share/freeswitch/script/password.json"
Back to top
mrjoli021 at gmail.com
Guest





PostPosted: Sat Dec 05, 2020 7:18 pm    Post subject: [Freeswitch-users] freeswitch won't open file Reply with quote

Hello,

Putting the complete path worked.  I honestly didn't think of that because they are in the same directory.


Thanks.


On Sat, Dec 5, 2020 at 5:37 PM mayamatakeshi <mayamatakeshi@gmail.com (mayamatakeshi@gmail.com)> wrote:

Quote:



On Sun, Dec 6, 2020 at 3:42 AM Joli Martinez <mrjoli021@gmail.com (mrjoli021@gmail.com)> wrote:

Quote:
Hello,

It is not a permissions issue.  I have changed the permissions to rw for everyone and it will still not read the file.  


The password.json file is in the same directory as the script /usr/share/freeswitch/script.  I am using lua 5.2.3 and again, the same code works in my home directory.  I just copied the password.json file over and pasted the function into my code.  When I place the call freeswitch prints "Inside the function", so I know it gets there, but then freeswitch spits out  "attempt to index local 'file' (a nil value)"


What else could I be missing?




 
Hi, 
when I check the current folder inside the fs cli I get:


freeswitch@lab002> system pwd
/


So, if you use:


f = "password.json"
local file = io.open(f, "r")



freeswitch would try to open "/password.json"
So I think you should pass the full file path:
f = "/usr/share/freeswitch/script/password.json"




_________________________________________________________________________

The FreeSWITCH project is sponsored by SignalWire https://signalwire.com
Enhance your FreeSWITCH install with disruptive priced SMS and PSTN services.
Build your next product on our scalable cloud platform.

Join our online community to chat in real time https://signalwire.community

Professional FreeSWITCH Services
sales@freeswitch.com (sales@freeswitch.com)
https://freeswitch.com

Official FreeSWITCH Sites
https://freeswitch.com/oss
https://freeswitch.org/confluence
https://cluecon.com

FreeSWITCH-users mailing list
FreeSWITCH-users@lists.freeswitch.org (FreeSWITCH-users@lists.freeswitch.org)
http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users
https://freeswitch.com
Back to top
Display posts from previous:   
Post new topic   Reply to topic    VoIP Mailing List Archives Forum Index -> freeSWITCH Users All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group

VoiceMeUp - Corporate & Wholesale VoIP Services