/etc/apt/apt.conf gets cleared every time I change proxy settings under settings->network->Network proxy

155

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.

Share:
155

Related videos on Youtube

Muriuki David
Author by

Muriuki David

Updated on September 18, 2022

Comments

  • Muriuki David
    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
    Muriuki David about 12 years
    thanks 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
    BlitZz about 12 years
    Like I said, I didn't test it :) yes, I'm missing the '=' sign. I fixed it now.
  • BlitZz
    BlitZz about 12 years
    the [ -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
    Muriuki David about 12 years
    yeah, 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
    BlitZz about 12 years
    Apologies again, I updated with the correct location to put the aliases (.bash_aliases).
  • Muriuki David
    Muriuki David about 12 years
    yeah, had just seen that in another forum, confirms it for me b4 i try. thanks
  • Muriuki David
    Muriuki David about 12 years
    Works, 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
    Admin over 11 years
    Yeh, 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
    David over 11 years
    I'm confused. Where is the image_upload() function located? Is it a model? If it's a model, just return the value and have the controller get it like this: $new_file = $this->your_model->image_upload();
  • David
    David over 11 years
    Be advised, file uploads are usually handled by the controller, and in that case, transfer the file name using CodeIgniter's $this->session class.
  • Admin
    Admin over 11 years
    image_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
    David over 11 years
    That 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
    Admin over 11 years
    yep, 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
    David over 11 years
    If 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
    Admin over 11 years
    I 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
    David over 11 years
    If it's optional, then just do this: if($_FILES AND isset($_FILES['field_name']['name'])) ). That will keep everything in-house.
  • David
    David over 11 years
    The 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
    Admin over 11 years
    because of this: $this->form_validation->set_rules('imageupload', 'Image Upload', 'callback__image_upload');
  • David
    David over 11 years
    Ah. I see. In any case, I personally feel you would be better of with the if statement in the index() function.
  • Admin
    Admin over 11 years
    Yeah, 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
    David over 11 years
    The 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 on index(). It looks like you have to move it. :/
  • Admin
    Admin over 11 years
    yeah thats the problem. how about if i return an array?
  • Admin
    Admin over 11 years
  • David
    David over 11 years
    I 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
    OrangeDog over 9 years
    Needs a semicolon in the .conf or it doesn't work.