Jump to content

chadrt

Members
  • Posts

    124
  • Joined

  • Last visited

Posts posted by chadrt

  1. In my db I have 2 tables I need to pull data from and run a count if somehow.  The db_cust table has all the customer data.  The db_devices has a few thousand entries on devices that are either being billed, promotional, cancelled etc.  So I am looking for a way to have a single query that will look at the db_devices and count each device that has a "billable" example below...

    CUSTOMER NAME   -   BILLABLES
    Test Customer     -                   5
    Great Customer    -                 38
    Really Great Customer      -   235
     

    it would look at db_devices.agencyname and count each instance of where that field contains a "1" as that is the billable int.

     

    customer 4567 (Test Customer) has 38 devices listed but some are cancelled, lost and some are free for being nice etc etc and 5 are billable it would return a 5 for the count if bill_type='1'

  2. I have a small linux server setup with FreePBX on it.  I have it locked down with Fail2Ban and for some odd reason I keep getting major hack attempts.  I have the settings set to a pretty restrictive set 3 bad attempts in 30 minutes and you get banned for 1 hour.  This has helped knock down a ton of attempts on the system but there are a few who get way beyond the threshold I have setup.  I get emails from Fail2Ban that say things like "banned after 146 attempts, banned after 138 attempts, etc"  so why is it allowing that many attempts before banning the ip's.  Now if I notice many blocks to the same ip over the course of a few hours I will go in and permanently add that ip to the iptables drop list.  But that is not my concern, my concern is that Fail2Ban is allowing so many before dumping them into the abyss.  My passwords are super strong and not anything remotely available in any dictionary in the world and are notoriously 12-18 characters long with uppers, lowers, numbers and special characters all jumbled up in a fashion that I have laid out in my head and never written down.

     

    Has anyone else gone thru this as well?

  3. Here is what I have so far...

    #!/bin/bash
    
    ### DELETED THE CONTENTS OF THESE VARIABLES FOR POSTING PURPOSES
    TO="" # WHO IS TO RECEIVE THE EMAIL
    FROM="" # WHO IS THE EMAIL FROM USUALLY SAME AS THE USER
    SERV="" # THE SERVER TO USE AND THE PORT server:port IS THE FORMAT
    USER="" # USERNAME OF THE OUTBOUND SERVER
    PASS="" # PASSWORD OF THE OUTBOUND SERVER
    SUB="bla bla bla"
    
    ###### So I have tried both of these ######
    MSG= 'echo $(expr '(' $(date -d 2015/08/17 +%s) - $(date +%s) + 86399 ')' / 86400) " Days Until Close"'
    #MSG= /path/to/daysuntil.sh # This contains the line from above runnnig this alone works fine!
    
    /usr/bin/sendEmail -f $FROM -t $TO -u $SUB -m $MSG -s $SERV -xu $USER -xp $PASS
    
    
  4. OK so here is a small revision tell me what you think.  I had to do some digging in php manual but I think this will solve any hack like attempts...

    <?php
    #### CHAD'S (K0KAD) SCRIPT TO CHANGE VOLUME FROM A WEB PAGE ON IRLP NODES ####
    #### Place script into the control directory so it is protected by Apache from outsiders
    #### Put a link into the index.php file that will take you to this page.
    #### Place a "--exclude index.php" into the custom/update-files-list file so that it wont get replaced each night
    #### Make sure you have a suitable entry in your sudoers file /etc/sudoers so that user "repeater" can use save
    #### aumix settings.  Else it will revert anytime the node reboots or power failure etc.
    
    
    
    if((int)$_GET['a'] >=1 && (int)$_GET['a'] <=100) {
    $amount =  (int)$_GET['a'];
    }else{
    $error = "<font color=red>Please enter a value between 1 and 100 only!<br></font>";
    }
    
    if((int)$_GET['c'] >=1 && (int)$_GET['c'] <=10) {
    $channel =  (int)$_GET['c'];
    
    
    ### PHP's Switch function to determine the command sent to the terminal ###
    switch ($channel){
    	case "1":
    		shell_exec("aumix -v $amount");
                    shell_exec('sudo aumix -S');
                    $success = "<font color=blue><b>Successfully updated volume!</b></font>";
    		break;
    	case "2":
    		shell_exec("aumix -w $amount");
                    shell_exec('sudo aumix -S');
                    $success = "<font color=blue><b>Successfully updated volume!</b></font>";
    		break;
    	case "3":
    		shell_exec("aumix -p $amount");
                    shell_exec('sudo aumix -S');
                    $success = "<font color=blue><b>Successfully updated volume!</b></font>";
    		break;	
    	case "4":
    		shell_exec("aumix -l $amount");
                    shell_exec('sudo aumix -S');
                    $success = "<font color=blue><b>Successfully updated volume!</b></font>";
    		break;	
    	case "5":
    		shell_exec("aumix -m $amount");
                    shell_exec('sudo aumix -S');
                    $success = "<font color=blue><b>Successfully updated volume!</b></font>";
    		break;
    	case "6":
    		shell_exec("aumix -W $amount");
                    shell_exec('sudo aumix -S');
                    $success = "<font color=blue><b>Successfully updated volume!</b></font>";
    		break;
    	case "7":
    		shell_exec("aumix -i $amount");
                    shell_exec('sudo aumix -S');
                    $success = "<font color=blue><b>Successfully updated volume!</b></font>";
    		break;
    	case "8":
    		shell_exec("aumix -1 $amount");
                    shell_exec('sudo aumix -S');
                    $success = "<font color=blue><b>Successfully updated volume!</b></font>";
    		break;
            default:
    		echo "";
                    break;
    }
    }else{
    $error2 = "<font color=red>Please select an appropriate channel from the drop down list!<br></font>";
    }
    
    ### READ THE CONTENTS OF AUMIX     
    $volumes = shell_exec('aumix -q');
    
    
    echo "<b>Current Volume Levels:</b><br>";
    echo "<pre>$volumes</pre><p>";
    echo $error;
    echo $error2;
    echo $success;
    
    ##### End of PHP Scripting the rest is pure HTML so we can close the PHP script tag here 
    ?>
    
    <form method=get>
    <p><b>Change Volume Level:</b><br>
    <select name="c" id="c">
    <option value="">CHOOSE CHANNEL</option>
    <option value="1">vol</option>
    <option value="2">pcm</option>
    <option value="3">speaker</option>
    <option value="4">line</option>
    <option value="5">mic</option>
    <option value="6">pcm2</option>
    <option value="7">igain</option>
    <option value="8">line1</option>
    </select> <br>New Value:
    <input type="text" value="" size="5" maxlength="3" name="a">
    <br><input type="submit" value="Submit">
    </form><br><p><br><a href="index.php">Return to Control Page</a>
    
  5. @requinix

     

    Thank you, changing the single quotes to double fixed the script!!!

     

    The directory that all this is located in is only accessible by 3 people who are close friends of mine.  Secured by use of .htaccess  But I thought I would release the code to rest of the ham population so I will go ahead and impliment the other things you talked about to help secure the page a little bit better.  I was thinking about the fact that I am using $_GET and that while my page is only allowing 3 digits into the form or the select box that it could be used to inject malicious code by entering volume.php?c=<malicious code>&a=<malicious code> or someone could build their own page that POSTs the malicious code.  So I think that all the input should be striped?  As well as making sure that only integers are used in the volume

  6. Here is the script...

    <?php
    #### CHAD'S SCRIPT TO CHANGE VOLUME FROM A WEB PAGE ON IRLP NODES ####
    
    $channel = $_GET['c'];
    $amount = $_GET['a'];
    
    echo $channel; //These Work Great
    echo $amount;  //These Work Great
    
    ### PHP's Switch function to determine the command sent to the terminal ###
    switch ($channel){
    	case "vol":
    		shell_exec('aumix -v $amount'); // When I use the varriable does not work!
                    shell_exec('aumix -S');
    		break;
            case "vol2": // Test case
                    shell_exec('aumix -v 15'); // When I manually specify the volume amount it works great!
                    shell_exec('aumix -S');
            break;
    	case "pcm":
    		shell_exec('aumix -w $amount');
                    shell_exec('aumix -S');
    		break;
    	case "speaker":
    		shell_exec('aumix -p $amount');
                    shell_exec('aumix -S');
    		break;	
    	case "line":
    		shell_exec('aumix -l $amount');
                    shell_exec('aumix -S');
    		break;	
    	case "mic":
    		shell_exec('aumix -m $amount');
                    shell_exec('aumix -S');
    		break;
    	case "pcm2":
    		shell_exec('aumix -W $amount');
                    shell_exec('aumix -S');
    		break;
    	case "igain":
    		shell_exec('aumix -i $amount');
                    shell_exec('aumix -S');
    		break;
            default:
    		echo "";
                    break;
    }
    
    ### READ THE CONTENTS OF AUMIX     
    $volumes = shell_exec('aumix -q');
    
    
    
    ### Begin echoing the HTML to provide the controls ###
    echo "<b>Current Volume Levels:</b><br>";
    echo "<pre>$volumes</pre><p>";
    
    ##### End of PHP Scripting the rest is pure HTML so we can close the PHP script tags here 
    ?>
    
    <br><br><form method=get>
    <p><b>Change Volume Level:</b><br>
    <select name="c" id="c">
    <option value="">CHOOSE CHANNEL</option>
    <option value="vol">vol</option>
    <option value="pcm">pcm</option>
    <option value="speaker">speaker</option>
    <option value="line">line</option>
    <option value="mic">mic</option>
    <option value="cd">cd</option>
    <option value="pcm2">pcm2</option>
    <option value="igain">igain</option>
    <option value="line1">line1</option>
    </select> <br>New Value:
    <input type="text" value="" size="5" maxlength="3" name="a">
    <br><input type="submit" value="Submit">
    </form>
    

    That is the entire script in all its "lack of glory".  I commented the script here to show what is working and what is not.  I can echo the varriables just fine but when I try to call it from with the shell_exec then I am assuming it is providing a blank response or one that the shell cannot understand.

     

     

  7. I hope I am able to explain this properly.  I am trying to build a way to adjust the volume of a remote computer used in conjuction wtih a ham radio, so I need to be able to give a couple guys the ability to adjust the volume without giving them SSH.  So I thought PHP could do this easilly!  But with limited knowledge I am struggling with the first few lines.

     

    When run in a SSH session:

     

    vol 12, 12, P
    pcm 84, 84
    speaker 39, 39
    line 72, 72, P
    mic 75, 75, R
    cd 100, 100, P
    pcm2 66, 66
    igain 5, 5
    line1 100, 100, P
    phin 100, 100, P
    phout 100, 100, P
    video 100, 100, P

     

    When run from PHP script:

     

    vol 12, 12, P pcm 84, 84 speaker 39, 39 line 72, 72, P mic 75, 75, R cd 100, 100, P pcm2 66, 66 igain 5, 5 line1 100, 100, P phin 100, 100, P phout 100, 100, P video 100, 100, P video 100, 100, P

     

    As you can see it is a huge run on that to the untrained eye would be quite confusing.  I would like the PHP script to display the information as it does on the console screen.

     

    The command that is doing this is:

    <?php
    
    echo system("aumix -q");
    
    ?>
    

    If I am in the wrong section please let me know but think this qualifies as basic PHP coding help...

     

    Thank you to anyone and everyone!!  Have a beautiful day.

  8. OK so today it is not working again when I run my script it says:

     

     

    PHP Parse error:  syntax error, unexpected '$yesterday' (T_VARIABLE) in /root/fcc/update.php on line 17

     

     

    I used Barand's solution from above:

    $yesterday = strtolower((new DateTime('yesterday'))->format('D'));

    What is really odd about the whole thing is that it was working and there hae been absolutely NO changes since it was working a couple weeks ago.  How odd!!

  9. I have "mysql  Ver 14.14 Distrib 5.5.41, for debian-linux-gnu (x86_64) using readline 6.2" I am lucky in a sense that I have complete control over the server as I have root priviledges.  If I were trying to run this on a shared hosting env I might very well have to use a different command.  From what I have read it is security issue on shared env's so it disabled by default.

  10. I am not very proficient at MySQL so this came as a shock today.  I have moved an entire set of scripts from one machine to another and after ironing out some of the kinks I was hit this error "The used command is not allowed with this MySQL version" and just when I thought it was all over with.  LOL

     

    This is the command being run...

     

    load data local infile './AM.dat' into table AM fields terminated by '|';

  11. My PHP skills are very limited so I end up hacking up scripts from other borrowing from one to make another.  LOL  This is how I accomplished the task that I had.

    $days = array("sun","mon","tue","wed","thu","fri","sat");
    $today = date("w");
    if ($today==0){
    $yesterday = "sat";
    }else{
    $yesterday = $days[$today -1];
    if ($yesterday==0){
    die("Script terminated no updates are performed on Sundays!\n");
    }
    }
    

    My code is not ellegant by any means but I think it will work what do you all think?

     

    So I try to post my code these days as I think it should be rather than telling you all to do the coding for me!  My construct above should solve for the problem, if for some reason you feel there is a more elegant way of doing this then I am all ears.

     

    I have another script that reloads the database from scratch that usually runs from a separate cron job.  I see this script now the way I have formatted performing the work of the second script now too by integrating the code into the second "if" by removing the "die()" and replacing it with the scripting from the weekly reload script.

  12. I have a PHP script that downloads a file from a remote server but in order to download the correct file it has to subtract 1 day of the week.  It used to work quite some time ago so I dont know what is going on now.  The section of the script goes like this....

    $days = array("sun","mon","tue","wed","thu","fri","sat");
    $today = date("w");
    $yesterday = $days[$today - 1];
    

    Then it joins the 3 letter version of the day of week with a file name to grab the correct file download.  $yesterday is not returning the correct value instead I am getting an error...

    # ./update.php 
    PHP Notice:  Undefined offset: -1 in /root/fcc/work/update.php on line 6
    fetching l_am_.zip
    ncftpget: server said: l_am_.zip: No such file or directory.
    PHP Warning:  unlink(counts): No such file or directory in /root/fcc/work/update.php on line 23
    data set empty nothing to process 
    
    Sun, 01 February, 2015 6:29:06 PM
    

    So in the above error I can see that $yesterday is "Undefined offset" and because of that the file it tries to download is incorrect, it should have tried to download l_am_sat.zip and it left out the 3 letter date code.

  13. Ok so I have this script that I wrote and it works really good.  I wanted to display the number of records in a table and since the db only changes once per day I thought I would put the couner on the back end.  I have this script that changes the value of the text file every day.  But I would love it if it outputted with commas.

     

    Now it reads:

    1234070

     

    Want it to read:

    1,234,070

     

    Any thoughs?

    #!/usr/bin/php -q
    <?php
    $username=""; // READONLY USER USED HERE AND AUTH'D ON LOCALHOST ONLY
    $password="";
    $database="";
    $dbhost="";
    
    mysql_connect($dbhost,$username,$password);
    @mysql_select_db($database) or die( "Unable to connect to database please try again!");
    
    $counthd=mysql_query("SELECT count(*) as total from HD");
    $hdtotal=mysql_fetch_assoc($counthd);
    $dbcount = $hdtotal['total'];
    echo "";
    
    $myFile = "dbcounter.txt";
    $fh = fopen($myFile, 'w');
    fwrite($fh, "$dbcount");
    fclose($fh);
    
    ?>
    
  14. So I am developing some pages that show the time and use time and dates in the entries that will show in the database. I want to be able to simply change a database entry to something like -1 or +1 and have the hour of the date() that is being echoed update properly. I know how to call the entry in the database but I have been unsuccessfull in being able to change the date and time that is echoed based on that entrie.

     

    Examples:

     

    // This works
    <?php
    $offset = time() -3600;
    echo date("D, F jS g:i A",$offset);
    ?>
    // This pulls from the array because I can echo it
    $offsetquan = $thesetting['timezone']; // currently set to -1
    
    

     

    So in the above example I can effectively remove one hour so how would I take the database entry of "-1" and multiply that by 3600 to make the time offset a true -1hr. from the database?

     

    My feeble attempt: lol :)

     

    <?php
    $zoneoffset = "-1"*3600; // this echo's properly!
    $offset = time() $zoneoffset;  // this just kills the whole thing
    echo date("D, F jS g:i A",$offset);
    ?>
    

     

    In the example below it looks like a lot of work to get to where I am but I am trying work thru this in my head as I ask you all for help this helps me to see where I am attempting to go and lets you all know that I am really trying and not just seeking the quick fix. Thanks for the help by the way...

     

    <?php
    $test = -1;
    $zoneoffset = $test *3600; // this echo's properly!
    echo $zoneoffset; // see works well LOL
    $offset = time()-3600; // but if I try and put $zoneoffset in place of the -3600 it spits at me
    echo date("D, F jS g:i A",$offset);
    ?>
    

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