/etc/apt/apt.conf gets cleared every time I change proxy settings under settings->network->Network proxy
Solution 1
In Ubuntu 12.04 LTS:
When you come home, try not applying no-proxy
system-wide. This doesn't edit the apt.conf
file, yet software center uses no proxy. Works for me, dunno how.
Solution 2
You could put the proxy configuration in /etc/apt/apt.conf.d/70proxy.conf
, create this file and put your proxy config in there.
Acquire::http::Proxy "http://whatever:port";
Then when you get home, you can just rename that file. Note that only files ending in .conf (or files with no extension) will be considered by apt, so you can potentially just rename it to /etc/apt/apt.conf.d/70proxy.disabled and it will not be considered.
You can then automate it with stuff like this, you can create a .bash_aliases
file in your home directory and put this in it:
export APT_PROXY_BASE=/etc/apt/apt.conf.d/70proxy
alias enable-proxy="[ -f ${APT_PROXY_BASE}.disabled ] && sudo mv ${APT_PROXY_BASE}.disabled ${APT_PROXY_BASE}.conf"
alias disable-proxy="[ -f ${APT_PROXY_BASE}.conf ] && sudo mv ${APT_PROXY_BASE}.conf ${APT_PROXY_BASE}.disabled"
To enable the proxy, just issue
enable-proxy
and to disable:
disable-proxy
Beware, I didn't test it :) it's just meant to get you on the right track.
Related videos on Youtube
Muriuki David
Updated on September 18, 2022Comments
-
Muriuki David over 1 year
Does anybody know how I can get the name of the file that has just been uploaded and then pass it to the index() function so it can be inserted into my database?
It's written in codeigniter and here is the code from my Form Controller.
Thanks.
public function index() { $this->load->library('form_validation'); $this->form_validation->set_rules('nominee', 'Nominee', 'required'); $this->form_validation->set_rules('email', 'Email', 'required|valid_email|is_unique[self_nominees.email]'); $this->form_validation->set_rules('location', 'Location', 'required'); $this->form_validation->set_rules('category', 'Category', 'required'); $this->form_validation->set_rules('description', 'Description', 'required'); $this->form_validation->set_rules('imageupload', 'Image Upload', 'callback__image_upload'); $this->form_validation->set_rules('videoupload', 'Video Upload', 'callback__video_upload'); if ($this->form_validation->run() == FALSE) { //Load the form $this->template('form.php'); } else { //Run code to add into the database $formdata = $this->input->post(NULL, TRUE); // this prevent from XSS attacks $this->load->model('users'); $this->users->self_nominate($formdata['nominee'], $formdata['email'], $formdata['location'], $formdata['category'], $formdata['description'], 'image', 'video'); //Load the thankyou page $this->template('thankyou.php'); } } /*---------------------------------------------------------------- Image Upload Function ----------------------------------------------------------------*/ function _image_upload() { $this->load->library('upload'); // Check if there was a file uploaded if (!empty($_FILES['imageupload']['name'])) { // Specify configuration for File 1 $config['upload_path'] = 'uploads/images'; $config['allowed_types'] = 'gif|jpg|png'; $config['max_size'] = '100'; $config['max_width'] = '1024'; $config['max_height'] = '768'; // Initialize config for File 1 $this->upload->initialize($config); // Upload file 1 if ($this->upload->do_upload('imageupload')) { $data = $this->upload->data(); return true; } else { $imageerrors = $this->upload->display_errors(); $this->form_validation->set_message('_image_upload', $imageerrors); return false; } } }
-
Muriuki David about 12 yearsthanks for pointing me on the right track. i thought Aliases are used to rename commands, and sometimes to include options, and the general format is alias mycommand='UNIXcommand' if so then i have problems understanding the ones you gave for enable-proxy and disable-proxy, i dont see an "=" sign, instead it's a whitespace and the commands aren't in quotation. i also dont quite understand what -f option is used for here. If you could please elaborate a little more, i'd appreciate a lot.
-
BlitZz about 12 yearsLike I said, I didn't test it :) yes, I'm missing the '=' sign. I fixed it now.
-
BlitZz about 12 yearsthe
[ -f $filename ]
construct returns a "true" or success value if the named file exists. I'm using this to avoid errors if you try to move a non-existing file; this could happen if you issued 'disable-proxy' twice in a row. So if the file does not exist, the alias will not even attempt to move it. -
Muriuki David about 12 yearsyeah, thats much better, didnt work though, logged out, logged back in and in terminal, disable-proxy or enable-proxy are not found. I ma thinking setting this up for at environment level would make sure wen i open a new terminal, its available. dont know how to do that though. FYI, it works if i do the commands in a terminal session.
-
BlitZz about 12 yearsApologies again, I updated with the correct location to put the aliases (.bash_aliases).
-
Muriuki David about 12 yearsyeah, had just seen that in another forum, confirms it for me b4 i try. thanks
-
Muriuki David about 12 yearsWorks, but i have to make sure i have run disable-proxy in terminal before i change proxy option in the system network settings , which is necessary for chrome to work. if i dont, my proxy settings in the apt.conf.d/70proxy.conf get lost/cleared still
-
Admin over 11 yearsYeh, I have used this (Not in the script above). It works great and im assuming this is how i get the data. But my question is. How can i pass it from the _image_upload() function back to index() so i can insert it?
-
David over 11 yearsI'm confused. Where is the
image_upload()
function located? Is it a model? If it's a model, justreturn
the value and have the controller get it like this:$new_file = $this->your_model->image_upload();
-
David over 11 yearsBe advised, file uploads are usually handled by the controller, and in that case, transfer the file name using CodeIgniter's
$this->session
class. -
Admin over 11 yearsimage_upload() is in the controller too. and video_upload() is below that, i just didnt include it in the code above as it would be the same. I have tried things like: $data = array('upload_data' => $this->upload->data()); $image_name = $data['upload_data']['file_name']; and just get undefined variable errors.
-
David over 11 yearsThat should work... but are you sure you're executing
$this->upload->do_upload()
? If the variables aren't there, the upload probably didn't happen.$this->upload->display_errors();
should help you find out. -
Admin over 11 yearsyep, its working because the file is uploading fine. if there are errors it doesnt upload and displays them fine. its just not submitting the filename in the db
-
David over 11 yearsIf you have a file that's being uploaded along with a form, why not run it inside
index()
? Then you have access to the variables right there. -
Admin over 11 yearsI had that, but i needed it be optional. you dont always upload a file. do you think it has something to do with returning the variable?
-
David over 11 yearsIf it's optional, then just do this:
if($_FILES AND isset($_FILES['field_name']['name'])) )
. That will keep everything in-house. -
David over 11 yearsThe code snippet in your question is completely irrelevant. I'm not sure how you get the file uploaded if the form submits to
index()
-
Admin over 11 yearsbecause of this: $this->form_validation->set_rules('imageupload', 'Image Upload', 'callback__image_upload');
-
David over 11 yearsAh. I see. In any case, I personally feel you would be better of with the
if
statement in theindex()
function. -
Admin over 11 yearsYeah, I had that and there were too many other problems. Like if i did submit an image, the image errors would not prevent the form from submitting. This time it works perfect bar inserting the filename into the db.
-
David over 11 yearsThe problem is, your callback has no way of communicating with your
index()
method. There's just no way. SESSION variables would work, but that's sloppy. If you run$this->upload->data()
in index(), it doesn't know if an upload even occurred, because is hasn't onindex()
. It looks like you have to move it. :/ -
Admin over 11 yearsyeah thats the problem. how about if i return an array?
-
Admin over 11 years
-
David over 11 yearsI repeat, you cannot have a callback function in a CodeIgniter form_validation series communicate back with the source method. You have to use SESSION, a database - something.
-
OrangeDog over 9 yearsNeeds a semicolon in the .conf or it doesn't work.