Jump to content

wiggst3r

Members
  • Posts

    94
  • Joined

  • Last visited

    Never

Posts posted by wiggst3r

  1. Hi

     

    I'm running a Ubuntu webserver, which has several services running.

     

    As the server is quite well used and has several sites hosted on it, I was wondering If anyone could help me with some code/script that will restart any service that goes down or stops.

     

    I'm looking to restart the following, If they ever stop:

     

    Apache

    Mongrel

    MySQL

    Cron

    Postfix

     

    I'm sure there could be an init script that could be run and will restart any of these services If they ever stop.

     

    Thanks

  2. Hi

     

    I have just converted an old site and alot of users still type in the URLs of the old site (or have them bookmarked etc)

     

    As some of the pages are simply folders, I'm looking to redirect the folder to another folder.

     

    I've used the following, which doesn't work.

     

    RewriteRule ^/home-insurance/.*$ /insurance/home-insurance/ [R=301]

     

     

    Any ideas what  I need to change?

     

    Thanks

  3. All I'd like to do is make sure that the file uploaded is either a word doc, jpg, gif, png or pdf. It can simply be a PDF or .doc file really, not fussed about the image files.

     

    I'm still not sure how I'd send the file as an attachment as I'm aware of mime-type issues and setting the right mime-type depending on the file uploaded.

     

    All help will be welcomed.

  4. Hi

     

    Thanks for the replies.

     

    How could I check (uing the if/switch) in my code:

     

    <?php
    
    function is_valid_email($email) 
    {
      $result = TRUE;
      if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$", $email)) {
        $result = FALSE;
      }
      return $result;
    }
    
    if(isset($_POST['submit']))
    {
        
    $error = '';
    $name = mysql_real_escape_string($_POST['name']);
    $email = mysql_real_escape_string($_POST['email']);
    $attached = $_POST['attached'];
    
       if(trim($name) == '')
       {
            echo   '<p>Please enter your name</p>';
       }
    
       if(trim($email) == '' || !is_valid_email($email))
       {
            echo   '<p>Please enter a valid email address</p>';
       }
    
    
    
    else
    {
    
    	$target_path = "temp/";
    
    	$target_path = $target_path . basename( $_FILES['attached']['name']);
    	$target_path = $target_path . basename( $_FILES['attached']['type']);  
    	$target_path = "temp/";
    
    
    	$target_path = $target_path . basename( $_FILES['attached']['name']); 
    
    	if(move_uploaded_file($_FILES['attached']['tmp_name'], $target_path)) {
    	    echo "The file ".  basename( $_FILES['attached']['name']). 
    	    " has been uploaded";
    	} 
    	else
    	{
    	    echo "There was an error uploading the file, please try again!";
    	}
    
    	$mime_type = "application/msword";
    
    	//Begin the message.  Be sure to change this how you want it.
    	$message = "Please find my CV attached";
    	$headers = "From: $email";
    	$to = "example@gmail.com";
    	$subject = "Job Application";
    
    	$from = $email;
    
    	mail($to,$subject,$message,$headers);
    	echo "<p>Thank you for submitting your details.</p>";
    
    }
    
    }
    
    ?>

  5. Hi

     

    I have a form, which when users fill out the results are sent to me in an email.

    I'm wanting to add a filed whereby someone can add a file when they fill out the form and this file will be sent along with the email as an attachment.

     

    Does anyone know how I can do this?

     

    Any examples of code that people have used before?

     

    Thanks

  6. Hi

     

    I'm trying to setup a redirect so when users go to my site by typing in either www.example.com or simply example.com they are always redirected to www.example.com

     

    My current virtual host is:

     

    <VirtualHost xx.xx.xx.xx:80>
            ServerAdmin test@exmple.com
            ServerName www.exmple.com
            ServerAlias exmple.com
            DocumentRoot /var/www/example/current/
    
            ErrorLog /var/log/apache2/error.log
    
            # Possible values include: debug, info, notice, warn, error, crit,
            # alert, emerg.
            LogLevel warn
    
            CustomLog /var/log/apache2/access.log combined
            ServerSignature On
    </VirtualHost>

     

    What do I need to cgane to achieve this?

     

    Thanks

  7. Yes I meant port as in NIC.

     

    Currently eh0 is the port in which users are going to connect via samba (windows) and SSH via Mac OS. (192.168.100.7)

    I wanted it so If I have one LAN/NIC port configured for all the internal connections via samba and ssh, then the second LAN/NIC could be used for internet traffic. This NIC is currently configured to get an IP address via DHCP, but this will change to a static one once I have chance to.

     

    The reason for this as the current fileserver has alot of large files which are transferred around the office. If I could simply use one NIC for this traffic and another NIC for internet, it may help.

     

    Would having both ports deal with intranet and internet traffic together be better than using one for intranet and one for internet?

     

    Thanks

  8. Hi

     

    I have a dual port motherboard (IN9 32X MAX) and I'd like to run a machine running Ubuntu server to utilise both ports.

     

    Currently I have of of them eth0, running on the IP of 192.168.100.7 which is static and the other IP (eth1) is by DHCP.

     

    The server is going to be a file server, with a static IP. Does this mean that both IP addresses for the NICs need to be the same?

     

    Also is there anyway in which you can specify which ports should use internet traffic and the other port just to focus on internal network traffic?

     

    Thank you

  9. Hi

     

    I have a large database of approx 50,000 records. There's two fields that are datetime fields. What I've done so far is to get the time between each date into days format and print them to the screen, e.g.

     

    In db:

    2009-04-03 00:00:00    2009-04-04 00:00:00

    2009-04-04 00:00:00    2009-04-05 00:00:00

    2009-04-05 00:00:00    2009-04-06 00:00:00

     

    In browser:

    1

    1

    1

     

    What I want to do is find an average based on the results.

     

    So it would do:

    1 + 1 + 1 / 3 (loop through each row and add it together -> store in variable and then count how many records there are and divide total difference in days by the total days)

     

    So running the script will output:

     

    Average time in days is: 1

     

    My code is as follows:

     

    <?php
    
    require_once('config.php');
    global $db;
    
    $result = $db->db_query(" SELECT * FROM messages where server_time between '2008-07-23 00:00:00' and '2008-07-27 00:00:00' and entered_at IS NOT NULL ");
    
    $output = $db->db_fetch($result);
    
    $array = array();
    
    while($one_row = $db->db_fetch($result))
    {
            $date_redeemed = strtotime($one_row['entered_at']);
            $time_of_record = strtotime($one_row['server_time']);
    
            $difference_in_seconds = $date_redeemed - $time_of_record;
    
            $difference_in_days = $difference_in_seconds / 86400;
    
            echo round($difference_in_days) . '<br/>';
    
    }
    
    ?>

     

    Thanks

  10. Hi

     

    I have a large site going live in about 3 weeks. During the testing process, I'd like to be able to test the site with fake users. I'm aware of such programs like ApacheBench, but these only test the HTTP header information.

     

    I'm looking for a tool, where the whole site content, including headers, images, html, css etc will be downloaded. Hopefully I can set the user number of users viewing pages at the same time (i.e. 5000 -10,000) and check If the server can handle this.

     

    I want to know If the server will handle the usual traffic I am expected to receive (large finance site) which will be quite high and therefore simply testing for HTTP requests isn't enough to guarantee the site will cope with heavy traffic.

     

    Thanks

  11. Hi

     

    I've currently got a server acting as a file server running Ubuntu 7.1.

     

    The server has 6 HDDs, 2 are the OS drives and 4 are in RAID 5.

     

    I'm looking to move the current setup to a new machine and I was wondering what the best steps would be?

     

    Could I create a disk image of the current server and copy that over to the new one and then just plug in the hard drives and RAID card?

     

    Thanks

  12. Hi

     

    I have a script that outputs a count to screen/terminal with a count of rows inserted into a db.

    As the db tble to be imported is approx 400,000 records, i want to output the count and details to a log file. So If the browser crashes or SSH connection times out. I know what row the import got upto.

     

    My script is as follows:

     

    <?php
    
    require(dirname(__FILE__) . "/../config.php");
    require(dirname(__FILE__) . "/../models/index_model.php");
    
    class MergeModel extends IndexModel
    {
    function MergeModel()
    {
    	$db = $this->connect_to_db();
    	//get all voda entries
    
    	$vodaphone_entries = $db->get_all('entries_vodaphone', false);
    	$count = 0;
    	while($one_voda_entry = $db->db_fetch($vodaphone_entries))
    	{
    		echo "\n$count";
    		$count++;
    		//we now have 1 vodafone entry - lets unset the id
    		$old_entry_id = $one_voda_entry['id'];
    		unset($one_voda_entry['id']);
    
    
    		//insert into normal entries table
    		$new_entry_id = $db->insert_row('entries', $one_voda_entry);
    		echo "entry $new_entry_id - ";
    		//we now have a new entry. lets get the friends for this person and insert them using the new id
    		$persons_friends = $db->get_rows_using_columns('added_friends_vodaphone', $constraints=array('entry_id' => $old_entry_id));
    
    		foreach($persons_friends as $one_friend)
    		{
    			//we now have 1 friend of this person. Lets insert them into the new DB
    			unset($one_friend['id']);
    
    			//set the entry id to be that of the new entry
    			$one_friend['entry_id'] = $new_entry_id;
    			echo "friend - ";
    			$db->insert_row('added_friends', $one_friend);
    
    		}
    
    		$persons_children = $db->get_rows_using_columns('children_vodaphone', $constraints=array('entry_id' => $old_entry_id));
    
    		foreach($persons_children as $one_child)
    		{
    			//we now have 1 friend of this person. Lets insert them into the new DB
    			unset($one_child['id']);
    			echo "kid - ";
    			//set entry id to be that of the new entry
    			$one_child['entry_id'] = $new_entry_id;
    			$db->insert_row('children', $one_child);
    		}
    
    	}   		
    }		
    }
    
    new MergeModel;
    
    ?>

     

    It outputs the following to screen:

     

    0entry 826013 -

    1entry 826014 -

    2entry 826015 -

    3entry 826016 - friend - friend - friend - friend - friend - kid - kid - kid -

     

    So I want all that to go into the log file.

     

    Thanks

  13. Ok, I sorted the above out with an if/else statement which seems to work.

     

    Now, the second part of my script.

     

    Each row in table one, has a field, called code

     

    As they are several codes rows could be something like this

    id, created_at, code

    1, 2008-11-17, email_17

    2, 2008-11-17, email_17

    3, 2008-11-18, email_17

    4, 2008-11-19, email_18

    5, 2008-11-19, email_19

    6, 2008-11-19, email_19

    7, 2008-11-20, email_19

    8, 2008-11-20, email_20

     

    So the outcome should be on screen:

     

    2008-11-17 - email_17 = 2

    2008-11-18 - email_17 = 1

    2008-11-19 - email_18 = 1

                      - email_19 = 2

    2008-11-20 - email_19 = 1

                      - email_20 = 1

     

    I'm not sure how to go about this.

     

    Would i need another loop?

     

    Thank you

  14. Hi

     

    I have a database with 2 tables.

    Table one has: id, created_at

    Table two has: id, created_at

    Table three has: id, total_1, total_2

     

    The script I'm writing, loops through table one and counts all the id's that have a created_at date of, 1st jan, 2nd jan etc.

    If there are any records with the date, such as there are 3 rows in table one which has the date of 1st jan, it puts the count into table two and the field total_1.

    The loop then checks how many ids have the same created_at date in table two. If there are 2 rows dated 1st jan, then this count is then inserted into total_2.

    So table three now has:

    id, total_1, total_2

    1, 3, 2

     

    The only problem I'm having is, that the start date is from 17th Nov. Every time i run my script, it keeps inserting the rows from 17th nov until today everytime.

     

    I need a check such to make sure that it only inserts dates/rows that have not already been in.

    I have records from 17th nov - 16th jan. So the next time it runs, for example tomorrow, then the only record inserted should be those records where table one and table two have created_at dates of 17th jan, rather than all the records from 17th nov - 17 jan.

     

    My code is as follows:

     

    <?php
    session_start();
    
    require(dirname(__FILE__) . "/../../config.php");
    require(dirname(__FILE__) . "/../../models/index_model.php");
    
    class AdminModel extends IndexModel
    {
    function AdminModel()
    {
    	$codes = array('Voucher 1', 'Voucher 2', 'Voucher 3');
    	$db = $this->connect_to_db();
    
    	$curr_date = '2008-11-17';
    	$date_now = date('Y-m-d', time() + 86400);
    	$today = date('Y-m-d', time());
    
    	while($curr_date != $date_now)
    	{
    		$tommorow = Date('Y-m-d', strtotime($curr_date) + 86400);
    
    		// Get total of vouchers from the daily cache table
    		$voucher_total_cached = $db->db_query(" SELECT * FROM entries WHERE created_at BETWEEN '$curr_date' AND '$tommorow' ");
    		$num_rows = $db->db_num_rows($voucher_total_cached);
    		echo '<br/>';
    
    		//insert the count from the vouchers for each date
    		//needs a check on here, so it doesn't keep inserting - possible if/else statement?
    		$voucher_total_cached_insert = $db->db_query(" INSERT INTO daily_entries_cache (date, total_vouchers ) VALUES ( '$curr_date', '$num_rows') ");
    
    		//can keep this - gets from cached table
    		echo "Total Vouchers filled in on $curr_date <strong>$num_rows</strong><br/>";
    
    		//get all added friends between dates we want
    		$friends_total_cached = $db->db_query(" SELECT * FROM added_friends WHERE created_at BETWEEN '$curr_date' AND '$tommorow' ");
    		$num_rows_friends = $db->db_num_rows($friends_total_cached);
    
    		//update the friends count in daily cache where the date is the one we need to update
    		$friends_total_cached_insert = $db->db_query(" UPDATE daily_entries_cache SET total_friends = '$num_rows_friends' WHERE date = '$curr_date' ");
    
    		//can keep this - gets from cached table
    		echo "Total Friends added on $curr_date <strong>$num_rows_friends</strong><br/><br />";
    
    
    		foreach($codes as $one_code)
    		{
    			//echo out the codes and the total count
    			$total_count = $db->db_fetch($db->db_query(" SELECT COUNT(id) as count FROM entries WHERE created_at BETWEEN '$curr_date' AND '$tommorow' AND offer = '$one_code' "));
    			echo "$one_code vouchers filled in on $curr_date <strong>{$total_count['count']}</strong><br/>";
    
    		}
    
    		echo '<br/>';
    		echo '========================================================';
    		echo '<br/>';
    
    		$curr_date = $tommorow;
    	}
    }
    }
    
    new AdminModel;
    ?>

×
×
  • 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.