Jump to content

jonsjava

Members
  • Posts

    1,579
  • Joined

  • Last visited

Posts posted by jonsjava

  1. I had someone on a budget once (read: $10/month).  My solution, while not elegant, worked.

     

    1. Ensure your code is in Git
    2. Configure the deploy user to have access to Git via SSH
    3. Clone the repo into the directory you wish to serve it out of
    4. Create a cron that runs ever x minutes/hours that will do the following:
      cd /path/to/your/code && git reset --hard && git pull origin master
      

    This solved their problem.  There are better solutions (Jenkins, for example), but if you want simple, cron + git works.

  2. I have an open source project (https://github.com/jonsjava/patchdashboard)

     

    Here's my .htaccess for this:

    RewriteEngine On
    RewriteBase "/pm/"
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule /patches/server/(.*)$ patch_list?server= [QSA,NC,L]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule /packages/server/(.*)$ packages?server= [QSA,NC,L]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule /search/exact/(.*)$ search?package=&exact=true [QSA,NC,L]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule /search/(.*)$ search?package= [QSA,NC,L]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule /rewrite_check/(.*)$ rewrite_check.php [QSA,NC,L]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^([^/]*)$ index.php?page= [QSA,L]
    

    Basically, I want it so that no matter where they drop this script ("/", "/patch_dashboard/", "/pb/", etc.) it will redirect as intended.

     

    In the example I provided, the document root is "/pm/". When I try to hit a page ("http://dev2.curltools.com/pm/patches/server/demo1" for example), it gives a 404.

     

    If I hard code in each rule the base path, it just redirects everything to the main page.

     

    Any help would be greatly appreciated.

  3. Forgot to mention: this does not switch the proxy every 5 minutes. It merely says that if a proxy has a start time greater than 5 minutes, switch it.  If this isn't called within that 5 minute window, it will do no good. It might be better to use cron for this.

  4. This was bashed together, not tested, and not made in good coding standards.  My IDE screamed at me the whole time, but I put my headphones on while it wept.

     

    function getProxy(){
        /* Database connection stuff goes here */
        $base_sql = "SELECT proxy  FROM `proxies` WHERE date_started > NOW() - INTERVAL 5 MINUTE and used=0;";
        $get_expired_sql = "SELECT id  FROM `proxies` WHERE USED=0 ORDER BY id ASC limit 1;";
        $expired_sql = "UPDATE proxies SET used=1 WHERE id='$id'; SELECT proxy FROM proxies WHERE used=0 LIMIT 1 ORDER BY id ASC;";
        $reset_proxy_sql = "UPDATE proxies SET used=0; SELECT proxy FROM proxies WHERE used=0 LIMIT 1 ORDER BY id ASC;";
        /* First, lets see if we have an active proxy */
        $res = mysql_query($base_sql);
        if (mysql_num_rows($res) == 0){
            // Well, that one is expired. Lets see which one is next
            $res = mysql_query($get_expired_sql);
            $row = mysql_fetch_assoc($res);
            $id = $row['id'];
            $res = mysql_query($expired_sql);
            $row = mysql_fetch_assoc($res);
            if (mysql_num_rows($row) == 0){
                // Well, we're out of current proxies. time to reset
                $res = mysql_query($reset_proxy_sql);
                $row = mysql_fetch_assoc($res);
                $proxy = $row['proxy'];
                mysql_query("UPDATE proxies set date_started=NOW() where proxy='$proxy';");
            }
            else{
                $proxy = $row['proxy'];
                mysql_query("UPDATE proxies set date_started=NOW() where proxy='$proxy';");
            }
        }
        else{
            $row = mysql_fetch_assoc($res);
            $proxy = $row['proxy'];
        }
        return $proxy;
    }
    

     

    ** EDIT: forgot to return something...*sigh*

    ***EDIT 2: Man, I need to spend more than 5 minutes on code. I forgot to update the proxies to tell it the start time.

  5. When a proxy expires, you would do this:

     

     

    UPDATE proxies SET used=1 WHERE proxy='CURRENT PROXY IP GOES HERE'; SELECT proxy FROM proxies WHERE used=0 LIMIT 1 ORDER BY id ASC;

     

    If that comes up with zero results, you run this:

     

    UPDATE proxies SET used=0; SELECT proxy FROM proxies WHERE used=0 LIMIT 1 ORDER BY id ASC;
  6. Have you went to the WSDL page with a SOAP browser to see the defined methods?  Unfortunately, SOAP is something you have to learn.  Not quite something most people will code for you.  Just go http://59.162.33.102/ArzooWS/services/DOMFlightAvailability%22 and click on the part you want to do.  It will tell you the fields and what you can request.

     

    Again, there is a learning curve to SOAP, but there are tons of resources out there to help you learn it.

  7. not quite.

     

    NOW() is what you want, so it would be:

     

     

    SELECT proxy  FROM `proxies` WHERE date_started > NOW() - INTERVAL 5 MINUTE and used=0;

     

    This will find any proxy who has a start time more recent than 5 minutes before the current time (i.e., it's still current)

     

    make sure to count the results before using them, and if they are zero, rinse and repeate.

  8. add a column with datetime, and name it "date_started" with an index on it.

     

    When the time now - INTERVAL 5 MINUTE > date_started, mark it used, and go on to the next.

     

    run a select COUNT(id) on proxies where used != 1 when you mark one used.  If count comes back zero, update table proxies set used = 0; then start over

     

    (I intentionally didn't give the exact proper SQL syntax, so you have a little work to do)

  9. The OP is a kid (watch the video).  Based on the voice, I would guess around 12 or thereabouts.  Matt, let me say this to you, from a fathers perspective:  Think before you act.  What you are building I fully understand seems like an awesome idea to you, but it's been done time and time again. 

     

    Based on the speed that your page loaded in your browser, I'm going to guess shared hosting. 

     

    *did some research -- back*

     

    Ok, kid. you don't want any part of the hosting you're with.  2 reasons why: no email provider in their right mind will allow mail from that hosting.  They are full, and I mean chock full of spam sites.  They will be black listed across the board, and any information you provided to sign up is most likely being used for nefarious means.

     

    Also, sites like this get flagged by 3-letter agencies so fast it is amazing you don't see them outside your house right now.  Don't worry, that was  a figure of speech.  Basically, people who host on this type of site are usually people like Dotcom (but less rich).

     

    Even thoug I aplaud your first real project, I would recommend that you do something....less spammy.  If you need pointers on what project to take up, let me know.  I'll help you code one, even.

     

    Jon

  10. Here's an easier way, if you don't mind my complete rewrite of your way of donig it:

     

    <?php
    function RandomPassword($len){
        $char_array = array();
        for ($i =48; $i<=126;$i++){
            $char_array[] = char($i);
        }
        $count = 0;
        $pass = "";
        while ($count < $len){
            $pass .= $char_array[array_rand($char_array)];
            $count++;
        }
        return $pass;
    }
    //Usage example:
    
    $pass = RandomPassword(rand(8,15));
    echo $pass;
    ?>
    

     

    The function will generate an array of characters based on the ASCII table, then select random characters until it reaches the length you select.  In my sample call, it selects a random password with a random length between 8 and 15 characters long.

     

    EDIT: forgot a couple things

     

    EDIT 2: Man, I need sleep. Forgot that if I start with "0", the proper number will be one less than your required lenght.

  11. As it stands, that's decent validation. If you wanted to get all fancy on it, you could take your error array, as well as the POST array, and push it to $_SESSION, redirect back to the form, and have the form pick up the values. If you go that route, you can set it so all error fields aren't re-populated in the form. This way, the customers won't lose any data other than the bad data.

  12. Do you have your log levels in apache to warn? If so, you can check the log files for apache to find the error. As a linux administrator for a hosting company, I can say that 99.99999% of all 500 errors are caused by errors in the code. It may be an .htaccess directive, in which case, you can just edit the vhost configuration and set

     

    AllowOverride None

    to

    AllowOverride All

    and restart apache. If that doesn't fix it, I can say that it is almost assured that it will be code.

  13. I hate to ask, but did you restart apache after changing the php.ini and the httpd.conf file?

     

    service httpd reload

     

    Also, edit this line:

     

    KeepAliveTimeout 30

     

    So that it says:

    KeepAliveTimeout 3600

     

    With that said, it would be best to CLI this, so you don't have to worry about the Apache timeout:

     

    /usr/bin/php -q /path/to/php_file.php
    

  14. The best solution would be to set a rewrite condion that says "If not from MY site, follow this rule":

    (change example\.com to your site)

    RewriteCond %{HTTP_REFERER} !^http://(www\.)?example\.com(/.*)*$ [NC]
    RewriteRule ^images/([^\s]+(\.(?i)(jpg|png|gif|bmp))$)$ image.php?id=$1 [R=301,NC,L]
    

  15. I failed to mention how to ensure that these work:

     

    FOR CentOS/RHEL/Fedora:

    ensure that the folder /etc/httpd/vhosts/ exists

    ensure that the /etc/httpd/conf/httpd.conf has the following line in it somewhere

    Include vhosts/*.conf
    

     

    FOR Ubuntu/Debain:

    make sure that www-data user is the user that runs apache2

  16. I got bored recently, so I created a couple tools:

     

    c.jonsjava.com (creates vhosts on CentOS/RHEL/Fedora servers)

    u.jonsjava.com (creates vhosts on Debian/Ubuntu servers)

     

    How it works

     

    from the command line, run the following

     

    curl http://example.com.c.jonsjava.com | bash

    or

    curl http://example.com.u.jonsjava.com | bash

     

    When you do this, it will generate a shell script to create all the folders and files needed to run another vhost on your server.

     

    Here's the output of the first command

    $ curl http://example.com.c.jonsjava.com
    
    #!/bin/bash
    mkdir -p /var/www/vhost/example.com && chown apache:apache /var/www/vhost/example.com
    DATA="<VirtualHost *:80>
            ServerName example.com
            ServerAlias www.example.com
            DocumentRoot var/www/vhosts/example.com
            <Directory var/www/vhosts/example.com>
                    Options Indexes FollowSymLinks MultiViews
                    AllowOverride All
            </Directory>
    
            CustomLog /var/log/httpd/example.com-access.log combined
            ErrorLog /var/log/httpd/example.com-error.log
    
            # Possible values include: debug, info, notice, warn, error, crit,
            # alert, emerg.
            LogLevel warn
    </VirtualHost>
    
    
    
    #<VirtualHost _default_:443>
    #        ServerName example.com
    #        DocumentRoot var/www/vhosts/example.com
    #        <Directory var/www/vhosts/example.com>
    #                Options Indexes FollowSymLinks MultiViews
    #                AllowOverride All
    #        </Directory>
    #
    #        CustomLog /var/log/httpd/example.com-ssl-access.log combined
    #        ErrorLog /var/log/httpd/example.com-ssl-error.log
    #
            # Possible values include: debug, info, notice, warn, error, crit,
            # alert, emerg.
    #        LogLevel warn
    #
    #        SSLEngine on
    #        SSLCertificateFile    /etc/pki/tls/certs/localhost.crt
    #        SSLCertificateKeyFile /etc/pki/tls/private/localhost.key
    #
    #        <FilesMatch \"\.(cgi|shtml|phtml|php)$\">
    #                SSLOptions +StdEnvVars
    #        </FilesMatch>
    #
    #        BrowserMatch \"MSIE [2-6]\" \
    #                nokeepalive ssl-unclean-shutdown \
    #                downgrade-1.0 force-response-1.0
    #        BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown
    #</VirtualHost>"
    echo "$DATA" > /etc/httpd/vhosts/example.com.conf && service httpd restart
    

     

    And for ubuntu:

     

    $ curl http://example.com.u.jonsjava.com
    
    #!/bin/bash
    mkdir -p /var/virtalwww/example.com && chown www-data:www-data /var/virtualwww/example.com
    DATA="<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot /var/virtualwww/example.com
    ServerName example.com
    ServerAlias www.example.com
    <Directory />
    	Options FollowSymLinks
    	AllowOverride None
    </Directory>
    <Directory /var/virtualwww/example.com>
    	Options Indexes FollowSymLinks MultiViews
    	AllowOverride None
    	Order allow,deny
    	allow from all
    </Directory>
    
    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
    <Directory \"/usr/lib/cgi-bin\">
    	AllowOverride None
    	Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
    	Order allow,deny
    	Allow from all
    </Directory>
    
    ErrorLog /var/log/apache2/example.com-error.log
    
    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn
    
    CustomLog /var/log/apache2/example.com-access.log combined
    
        Alias /doc/ \"/usr/share/doc/\"
        <Directory \"/usr/share/doc/\">
            Options Indexes MultiViews FollowSymLinks
            AllowOverride None
            Order deny,allow
            Deny from all
            Allow from 127.0.0.0/255.0.0.0 ::1/128
        </Directory>
    
    </VirtualHost>"
    echo "$DATA" > /etc/apache2/sites-available/example.com && ln -s /etc/apache/sites-available/example.com /etc/apache2/sites-enabled/example.com && /etc/init.d/apache2 restart
    
    

     

    I built this script because I add vhosts all day every day on thousands of servers, and I got tired of sed'ing the config files all the time.

     

    If you have ideas on how I can make this more useful, please let me know!

     

    Oh, and for clarification, it is always DOMAIN.TLD.[c/u].jonsjava.com

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.