edit .conf file in /etc linux (java SE)
Hi everyone!
This time I have a java SE web start application hosted in a Linux/Debian server
I need to edit a .conf file from the /etc directory folder in the Debian server but I have no idea how to access this file if it's not within the public /www folder. I think it has to do with apache users and permissions, but my linux knowledges are just few
Thanks in advanced!
Re: edit .conf file in /etc linux (java SE)
You need sudo permissions to edit files in that directory. What are you trying to do by editing this file? If you need to edit files that require root/sudo access, in my opinion you should probably rethink the design.
Re: edit .conf file in /etc linux (java SE)
I am trying to modify a .conf file in the /etc/asterisk (a voice ip PBX) that gives permissions to callers. I dont know much about debian or linux, it would be easy to modify a file in the www folder, but how can I access this file instead?
I need to remove or add some lines to the .conf file eventually.
thanks 4 ur answer
Re: edit .conf file in /etc linux (java SE)
I am not familiar with that file or library so I cannot guide towards alternatives. Unfortunately I can only encourage you to search for alternatives - permissions are setup on linux for a reason and whatever is attempting to modify the file most likely needs sudo access, but in doing could open up a lot of security holes.
Re: edit .conf file in /etc linux (java SE)
I only need to modify one .conf file from /etc/asterisk , I have no problem giving rights to edit it. In fact, I made Apache to show me the file to the public and I can retrieve it from the server (read it), but when I need to save the changes (or replace the file at the same directory) I am having problems because I originally have a URL text, then parse it to String in the application, and then need to upload or rewrite it to the URL. That last step is giving me an headache!
Thanks in advanced for your help copeg.
Re: edit .conf file in /etc linux (java SE)
I have tried some codes, but none of them work :(
Just as simple as trying to create and write a .txt in the server
// Open an output stream
URI uri = new URI("http://172.16.64.54/test/myfile.txt");
File file= new File(uri);
fout = new FileOutputStream(file);
// Print a line of text
new PrintStream(fout).println("hello world!");
// Close our output stream
fout.close();
throws Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: URI scheme is not "file"
Obviously I dont know how to manage Files and URLs when writting. The folder test is created with all permissions (777)
I really need to write or copy a file to the server. Any ideas?
Re: edit .conf file in /etc linux (java SE)
I'm not sure what the problem is here. It looks like you have the permission problem taken care of (though a non-executable file in Unix should be 666, not 777) but now you're trying to update a file via HTTP? You can't do that. Not even close. You will need something on the server side to do the update. In Java you'd need a Tomcat/Glassfish/<your favorite app server> to do that. If you are just running Apache you may need something like PHP or even CGI.
Can you describe a bit more about the over all architecture of the system?
Re: edit .conf file in /etc linux (java SE)
There is a server (Debian) that host the .jar files (in the public /www directory of Apache). I execute them thru java web start (it downloads the resources to the local machine) on Windows. I need to modify or replace a file located in /etc/asterisk folder within the debian server. How can I upload or copy a file to the debian directories from a java .jar running in a windows client?
Re: edit .conf file in /etc linux (java SE)
As stdunbar mentioned, you need something server side to do this. If you are only running apache, then you need some script to be executed. You can do so by creating a script that your apache configuration is capable of running (perl, php, etc...) and is accessible via a URL. The script accepts the info to change, and writes it to the file. The client (webstart) app then accesses this script through its respective URL
Re: edit .conf file in /etc linux (java SE)
ok I understand, maybe I can make a php or perl script to do this. How do I give the information to the script? Is there any class in java to communicate with a server side script? thanks for your help!
Re: edit .conf file in /etc linux (java SE)
Quote:
Originally Posted by
luisp88
ok I understand, maybe I can make a php or perl script to do this. How do I give the information to the script? Is there any class in java to communicate with a server side script? thanks for your help!
If you do not have some type of RMI or java server set up so that you remotely communicate with the server (apache does not by default as far as I am aware), then you can pass the information as POST using a URL
Lesson: Working with URLs (The Java™ Tutorials > Custom Networking)
Server side, the script retrieves the post information, validates the information, and uses it as needed.
Re: edit .conf file in /etc linux (java SE)
Thanks for the link, I am already trying to figure it out.
Its a good idea to use URL passing to edit a whole .conf file? I mean its a long string, there is no problem sending it to a php script via url?
I dont know about servlets, but I think they dont work in Apache, its better to set up a server that executes them ? (I think tomcat and glassfish are the ones)
thanks a lot copeg
Re: edit .conf file in /etc linux (java SE)
Ok I made a php script to edit the .conf file and it works fine giving apache the permissions. But the problem is sending the information from JAVA to PHP script.
JAVA:
URL url = new URL("http://172.16.64.54/prueba/url.php");
URLConnection conn = url.openConnection();
conn.setDoOutput(true);
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
wr.write("test);
wr.flush();
and the PHP script is supposed to be executed, but it doesnt. When I type the php script in the browser, it works (forget about the passing arguments) but when I execute my java program, it doesnt execute!
Is there another class to work with http urls?
Re: edit .conf file in /etc linux (java SE)
You may need to read the response for the request to be sent. I'm fairly sure it's a 'lazy' process. Read the API docs for HttpUrlConnection - I think reading a response header or the response body will complete the exchange.
Re: edit .conf file in /etc linux (java SE)
I made it work, thanks a lot. I will check HttpUrlConnection for more information.