Showing posts with label script. Show all posts
Showing posts with label script. Show all posts

Thursday, 27 November 2014

Adding Google street view to Joomla Estate Agencie JEA

So, even though I have only edited the code in minor ways, it actually took me a long time to do it, but here is the final result! Posted here on JEA forums

Hi, I've had a go at this myself, and finally came up with a solution.
The first thing I did was to go into my template and create an override for JEA Property.
I then edited the "default_googlemap.php" file. From line 44 to the bottom, replace the script with this script:
$script = <<
 
function initMap(mapOptions, panoOptions, MarkerLatlng) {
    map = new google.maps.Map(document.id('jea_property_map'), mapOptions);
    var marker = new google.maps.Marker({
        position: MarkerLatlng, 
        map: map, 
        title: '{$this->row->ref}'
    });
    var panorama = new google.maps.StreetViewPanorama(document.getElementById('jea_property_map_pano'), panoOptions);
  map.setStreetView(panorama);
}
 
window.addEvent("domready", function(){
    var longitude  = {$longitude};
    var latitude   = {$latitude};
 
    if (longitude && latitude) {
        var myLatlng = new google.maps.LatLng(latitude, longitude);
        var options = {
          zoom : 15,
          center : myLatlng,
          mapTypeId : google.maps.MapTypeId.ROADMAP
        };
        var panoramaOptions = {
    position: myLatlng,
  };
        initMap(options, panoramaOptions, myLatlng);
 
    } else {
        var geocoder = new google.maps.Geocoder();
        var opts = {'address':'$address', 'language':'$lang', 'region':'$region'};
        geocoder.geocode(opts, function(results, status) {
            if (status == google.maps.GeocoderStatus.OK) {
                var myLatlng = results[0].geometry.location;
                var options = {
                  center : myLatlng,
                  mapTypeId : google.maps.MapTypeId.ROADMAP
                };
                var panoramaOptions = {
    position: myLatlng,
  };
                initMap(options, panoramaOptions, myLatlng);
                map.fitBounds(results[0].geometry.viewport);
             }
        });
    }
});
 
EOD;
 
$this->document->addScriptDeclaration($script);
?>
 
I've only modified the original code to add panoramaOptions variable, and pass it to the initMap function. I then added the panorama variable.
 
At the bottom I also added a div tag called "jea_property_map_pano", but you have to give it a height property otherwise you won't be able to see it. The street view loads up in this div tag.

Thursday, 4 October 2012

sendLogon.app and installer

Well, after much troubles over getting NHR to also run sendLogon on startup, I decided to just make an application which ran the sendLogon script:

/usr/bin/sendLogon 145.xxx.xxx.xxx 5438 $(logname)



  1. I simply made it in Automator:
  2. Next I made an installation package to install it along with the sendLogon command program
I used Apple Remote Desktop's "Task Server" to install it on all managed machines. And finally I used Workgroup Manager to have it as a Login Item on the managed machines.

I think it works out better this way, as there is a little bit more control over it.

Monday, 13 August 2012

Current NHR LIclean.hook

So, after a few years of using NHR I've had to add a few more exceptions. Instead of writing them down I thought I'd might as well just paste the LIclean.hook file here:



#!/bin/sh
#set -xv; exec 1>>/tmp/out 2>&1
PATH=/bin:/usr/bin:/usr/sbin export PATH



#The line above is used for logging and troubleshooting only - if you need to troubleshoot this script, remove the "#" from the line.  Once you are done, put the "#" back at the beginning of the line.
logger "LoginHook: Starting for $1"

#Update on June 27, 2006 - added support for 10.3 clients and other improvements
#Update on July 10, 2006 - added feature so that all local users will bypass redirection.
#Update on October 18, 2006 - added $1 directory in /tmp for better folder structure.
#Update on July 13, 2007 - added Leopard compatibility
#Update on July 19, 2007 - added line to delete Clip Gallery Preferences, if they have not already been removed from the local admin's account.
#Update on April 28, 2008 - took out iHook application, as some users didn't like seeing the iHook window during login.
#Update on August 20, 2008 - due to ACL's put on user home folders starting with 10.5.4, this will now remove the ACL so that redirection can still take place on the folders with Deny Delete ACL's.
#Update on September 3, 2008 - added Office 2008 support
#Update on September 17, 2008 - deleted EOF commands, as it was causing issues with some PPC machines.
#Update on October 5, 2008 - added support for SMART board software, as they store caches in ~/Library/Application Support
#Update on March 5, 2009 - fixed issue with finding local users that matched part of the username (added -x to grep)
#Update on March 11, 2009 - added support for Adobe Acrobat 9
#Update on April 17, 2009 - added support for Adobe CS4
#Update on August 17, 2009 - added support for iMovie 09 with network homes
#Update on September 23, 2009 - added support for users with "." in their shortnames (thanks to Ben Gollmer for this addition)

LocalAdminUser=`dscl . -list /Users uid |grep 501 |awk '{print$1}'`
Local=`dscl . -list /Users |grep -x $1`

#This script will re-direct several folders from a user's network home location to the local machine to help with performance.

if [[ "$1" == "$Local" ]]; then
        exit 0
fi

eval home_loc=~$1

#This section will verify that there are no DENY DELETE ACL's on the folders - and if so, remove the ACL so that redirection can still take place.

aclline=`ls -led "$home_loc"/Library/Caches | grep "deny delete" | head -1 | awk -F: '{print $1}' | sed 's/^[ \t]*//'`
chmod -a# $aclline "$home_loc"/Library/Caches

aclline=`ls -led "$home_loc"/Library/Fonts | grep "deny delete" | head -1 | awk -F: '{print $1}' | sed 's/^[ \t]*//'`
chmod -a# $aclline "$home_loc"/Library/Fonts

aclline=`ls -led "$home_loc"/Library/Application\ Support/SMART\ Technologies\ Inc/Gallery | grep "deny delete" | head -1 | awk -F: '{print $1}' | sed 's/^[ \t]*//'`
chmod -a# $aclline "$home_loc"/Library/Application\ Support/SMART\ Technologies\ Inc/Gallery

#This section will delete the Fonts, Microsoft User Data, AppleWorks User Data, SMART Board Gallery folder and Microsoft Preferences folders from the current user's network home location
rm -rf "$home_loc"/Library/Caches
rm -rf "$home_loc"/Library/Fonts
rm -rf "$home_loc"/Documents/Microsoft\ User\ Data
rm -rf "$home_loc"/Documents/AppleWorks\ User\ Data
rm -rf "$home_loc"/Library/Preferences/Microsoft
rm -rf "$home_loc"/Library/Application\ Support/Microsoft/Office
rm -rf "$home_loc"/Library/Application\ Support/SMART\ Technologies\ Inc/Gallery
rm -rf "$home_loc"/Library/Application\ Support/Adobe
rm -rf "$home_loc"/Library/Application\ Support/Google

#This section will clean up the local drive, so that iMovie 09 will work with network homes
rm -rf /iMovie\ Events
rm -rf /iMovie\ Projects

#This section will make a folder for the current user in /tmp
mkdir /tmp/$1/
mkdir /tmp/$1/Adobe
#mkdir /tmp/$1/Adobe/Acrobat
#mkdir /tmp/$1/Adobe/Illustrator\ CS4
mkdir /tmp/$1/Google

#This will copy several Microsoft folders of the local admin user (make sure this account was the first account set up on the client - with UID 501) to /tmp.
cp -R /Users/$LocalAdminUser/Library/Preferences/Microsoft /tmp/$1/Microsoft/
rm -f "/tmp/$1/Microsoft/Clip Gallery Preferences"
cp -R /Users/$LocalAdminUser/Library/Application\ Support/Microsoft/Office /tmp/$1/Office2008
cp -R /Users/$LocalAdminUser/Documents/Microsoft\ User\ Data /tmp/$1/Microsoft\ User\ Data/

#This will create the iMovie 09 folders needed to work with network homes
mkdir "$home_loc"/Movies/iMovie\ Events
mkdir "$home_loc"/Movies/iMovie\ Projects

#This will create an AppleWorks User Data folder in /tmp.
mkdir /tmp/$1/Appleworks

#This will create the user's Caches folder in /tmp.
mkdir /tmp/$1/Caches

#This will check for the Notebook application (SMART) and create a SMART folder in /tmp (if needed).
SMART=`test -e /Applications/Notebook\ Software/Notebook.app && echo Yes`

if [[ "$SMART" == "Yes" ]]; then
mkdir /tmp/$1/SMART
mkdir -p "$home_loc"/Library/Application\ Support/SMART\ Technologies\ Inc/
fi

#This will change ownership of all files in /tmp/$1 to the current user
chown -R `dscl /Search -read /Users/$1 UniqueID | awk '{print $2}'` /tmp/$1

#This will create the Microsoft and Adobe folders, inside the Application Support folder, for the user.
mkdir "$home_loc"/Library/Application\ Support/Microsoft
#mkdir "$home_loc"/Library/Application\ Support/Adobe

#This last section will set up symbolic links for the current user.
ln -s /tmp/$1/Caches/ "$home_loc"/Library/Caches
ln -s /Library/Fonts/ "$home_loc"/Library/Fonts
ln -s /tmp/$1/Appleworks "$home_loc"/Documents/AppleWorks\ User\ Data
ln -s /tmp/$1/Microsoft/ "$home_loc"/Library/Preferences/Microsoft
ln -s /tmp/$1/Microsoft\ User\ Data/ "$home_loc"/Documents/Microsoft\ User\ Data
ln -s /tmp/$1/Office2008/ "$home_loc"/Library/Application\ Support/Microsoft/Office
ln -s /tmp/$1/SMART/ "$home_loc"/Library/Application\ Support/SMART\ Technologies\ Inc/Gallery
#ln -s /tmp/$1/Adobe/Acrobat/ "$home_loc"/Library/Application\ Support/Adobe/Acrobat
#ln -s /tmp/$1/Adobe/Illustrator\ CS4/ "$home_loc"/Library/Application\ Support/Adobe/Illustrator\ CS4
ln -s /tmp/$1/Adobe/ "$home_loc"/Library/Application\ Support/Adobe
ln -s "$home_loc"/Movies/iMovie\ Events /iMovie\ Events
ln -s "$home_loc"/Movies/iMovie\ Projects /iMovie\ Projects
ln -s /tmp/$1/Google "$home_loc"/Library/Application\ Support/

logger - "LoginHook:  Finished for $1"

#sendLogon extras (IP address and Port number has been taken out)

/usr/bin/sendLogon 123.456.32.1 1234 $1
/usr/bin/sendLogon 123.456.32.2 1234 $1
/usr/bin/sendLogon 123.456.32.3 1234 $1





I've commented out a few lines so I could see what I've done in the past.


Addition:

so, I've now found that Adobe Bridge has trouble opening. After some investigation it looks like Bridge 4 (CS5) doesn't like symbolic links, but prefers to use the networked folder.

After looking into all the Adobe Applications, the only one now which needs the symbolic link is Adobe Acrobat Pro. So I'm re-writing this script to create a symbolic link from ~/Library/Application Support/Adobe/Acrobat a the local folder.

I'm also getting rid of the Adobe symbolic link so that bridge works.



Addition (08/11/2012)

A few months on and I soon realised that although Illustrator is behaving much better then it did do in the past, I found that if it did not have a symbolic link to the local drive it would have trouble saving and exporting files to the desktop, making it appear that the files were saved, when in fact they had 0kb! This caused a bit of trouble with students at the time, and backups had to be retrieved.

I then added a symlink with ~/Library/Application Support/Adobe/Adobe Illustrator CS5.

I also realised that if it was a new student which didn't have an Application Support folder, NHR would be unable to create an Adobe folder inside this. I hence added a few lines to make the folders:
~/Library/
~/Library/Application Support/
~/Library/Application Support/Adobe/

Thursday, 12 July 2012

sendLogon and NHR for OS X 10.7

So, I'm just setting up some new machines with OS X 10.7.4 installed. I tried to install the NHR and sendlogon scripts which I implemented here, but looking into it, it doesn't seem to work.

The NHR side which redirects folders from the networked home drive to a local folder works beautifully, but when I browse the internet, it doesn't let me on sites which i am authorised to go on? So, to conclude, the LIsendLogon.hook isn't running properly.

The one thing I wanted to happen was to get the loginhook to run a script which in turn ran a sendLogon script and the NHR script. But it was an 'either/or' situation. I could never have both scripts running no mater how hard I tried.

After trying many different things, I ended by just giving up and putting the lines for sendLogon into the LIclean.hook script at the bottom. Very frustrating.

I did find an interesting and useful article on running a centralised login script here.

I also found a nice little course on the subject of scripting which I found very useful here and another here

Friday, 13 April 2012

OS X automatically changing a password


This is a follow up from the post which describes the problems with 'locking' down a printer. I've finally decided that we are locking down the computer attached to the printer, and changing it's password each day so only people who know the password can print.

So, I've just tested "passwd" command and found it quite useful. It has given me a few ideas.


  • When typing "passwd" when you're already logged in
    • it assumes you're changing your password
    • It asks for your old one, a new one, and retype the new one. Done.
  • When typing in from an admin account "passwd stephenl"
    • it asks you as if you were the user whose password is being changed as before.
  • When doing this through root login (i.e. from Apple Remote Desktops send command)
    • it just asks for a new password twice. Easy.


So, I worked out two ways I could do this:

  1. I could simply have some scheduled tasks setup in ARD which sends these commands on certain days
  2. I could set up a totally self sufficient system when the machine is switched on, it looks at the day, and determines which password to use.
Number 1 is the easiest as I know how to do this.
Number 2 is harder as I'd have to write a script which:
  1. loads at startup
  2. uses root to change passwords
  3. finds out what day it is
  4. changes the password accordingly
Now I've written it out in logical order it doesn't sound too difficult.

Just found this post which describes how to simply make a startup script


Monday, 14 November 2011

Getting NHR to work on 10.6 and later

After a lot of grumbles, it turns out that there is a great need here to have NHR working again, specifically to redirect the ~/Library/Caches folders of the Active Directory networked users.

I've stated on many previous occasions when it hasn't worked with:




So I've finally got around to looking into why NHR hasn't been working with OS X 10.6.6.

So I installed it on a nice little MacBook Pro. Doesn't work. First I thought I'd check it installed alright and in Console I saw no errors.

Next I checked permissions and found I couldn't look in the folder /etc/hooks. I also couldn't run the script login.hook without using 'sudo'.

I logged in under root, reset the permissions so that everyone could read and write:
sudo chmod 777 /etc/login.hook
sudo chmod 777 /etc/logout.hook
sudo chmod 777 /etc/hooks
sudo chmod 777 /etc/hooks/*

Still wouldn't work.

When I tried to run the login.hook and Llcleanbasic.hook files it came up with:
LoginHook: Executing /etc/hooks/LIcleanbasic.hook...
Usage: grep [OPTION]... PATTERN [FILE]...
Try `grep --help' for more information.
After looking in the Llcleanbasic.hook file I found the first line of script ran as follows:
Local=`dscl . -list /Users |grep -x $1`
Typing this in the terminal comes up with the same message, which persuades me that it is this which is throwing the whole script off. Basically this part of the script and an if statement below it, finds out if the user is listed in the local users list. It must have changed in the later versions of OS X.

I decided to not have this part of the script run as to me it doesn't matter if local users also have the script running as I'm only going to have it affect the Caches folder. As such, I commented it out as well as the if statement which ran after it. This is what it ended up looking like:

#Local=`dscl . -list /Users |grep -x $1`

#This script will re-direct several the Caches and Fonts folders from a user's network home location to the local machine to help with performance.

#if [[ "$1" == "$Local" ]]; then
#        exit 0
#fi

After doing this it ran perfectly!!!!

A couple of things left to do:

  1. Get the logout script to work
  2. try is running it with it's original permissions to see if that also helped.

So, I also had to change the logout script accordingly as well, commenting out the Local='dscl......... and the if statement below it. After this it all worked perfectly.

Also, a point to note is that when logged in as anyone other then root, when you add login and logout hooks it is important to understand user hooks, and all user hooks (not the correct terminology but hopefully describes what I want).

So, when logged in NOT as root, if you use the command:
defaults write com.apple.loginwindow LoginHook /private/etc/login.hook 

it'll only give this user the hook. To do it system wide.
sudo defaults write com.apple.loginwindow LoginHook /private/etc/login.hook 

Tuesday, 1 November 2011

Can't place images in Illustrator - blank box - OS X 10.6.6 Active Directory

I had this problem a few years ago, and it's recently popped up again. The problem is that when Active Directory Users (with home drives on Windows servers) try and place a picture within an Illustrator document, they just get a blank box with an X through it.

The way I found in fixing it previously was to install NHR (previously documented in my blog), which basically replaces the ~/Library/Caches folder with a symlink to a temporary folder on the local hard drive. It then deleted this when the networked user logged out.

The trouble I'm having now is that I can't get NHR to work with OS X 10.6.6. It simply doesn't want to run on login, maybe not even at all. The work around that I'm formulating is to simply make a little shell script which runs at login and does what NHR did.

I've now made a little Automator application which runs the terminal script:


mkdir /Users/Shared/temp
mkdir /Users/Shared/temp/Caches
rm -R ~/Library/Caches
ln -s /Users/Shared/temp/Caches ~/Library/



This has fixed the problem with the users who run the Automator Application, although when they login to a machine which doesn't have this "/Users/Shared/temp/Caches" folder they will encounter problems.

I shall make a new post describing how I made the startup script.

Friday, 30 September 2011

Making a pkg file for installing sendLogon for Bloxx on OS X

In a previous post I described how we're getting a new web filtering system called Bloxx, which needs the sendLogon program to be installed and run as a login script on all the Apple Macs (OS X).

I used Iceberg free application to make the PKG file as I've used it before with relative ease, and also couldn't find the latest official Apple PKG maker app!!

Its all working now so here's how I did it:
  1. Made a new project in Iceburg, and made a nice little folder to hold all the files needed (makes it easier to find things)
  2. I filled in the top section "Settings"
  3. Next was the "Scripts" section. I had to make a script which changed the com.apple.loginwindow plist file to add the LoginHook /usr/bin/login.sh
    1. I ran nano from the command line (nano ~Desktop/sendLogonfiles/Install\ sendLogon/writeloginhook.sh)
       and typed:
    2.  #!/bin/tcsh
      sudo defaults write com.apple.loginwindow LoginHook /usr/bin/login.sh
    3. I found I had to put "sudo" into the script so that it had the right permissions to write to the file. Not sure why else it didn't work?
    4. I saved the file and made the file executable - chmod 755 ~Desktop/sendLogonfiles/Install\ sendLogon/writeloginhook.sh
  4. I then added this script to the "PostFlight" script, and set the path to "Relative". Note - I found an article here documenting the definition of each of these types of scripts. Most were concerned with whether this was an upgrade or not, and would only run once.
  5. Finally was the "Files" section. 
    1. I firstly put the files in the project folder.
    2. I set these files with the correct permissions (as in the tutorial folder for sendLogon). chmod 755
    3. Then, in Iceberg, I had to add the folders; /usr/ and /usr/bin/, which were not there.
    4. I then made the "Default Destination" the /usr/bin/ folder
    5. Finally I added the login.sh file and the sendLogon file.
I've just tested this through the Apple Remote Desktop Task Server on a single MacBook Pro and worked a charm (had to ring ICT though to add its' IP address to the Bloxx list of computers with sendLogon working)

Note: There is potential also for adding to this a little script which changes the proxy settings to the system and maybe also Firefox, but it would be easier to control these settings through a .pac file or .wpad file.

Wednesday, 21 September 2011

Notify users when their disk space is running low

Well, after my last post about listing problems to fix and make my job that much easier, I thought I'd look up a script I had a while back which notified users when their disk space was running low. It really did save a lot of time and effort, as users would know exactly what the problem was: That their disk space was running LOW!

I couldn't make the script on my own back then (and still couldn't now) so I put up a "Help me" topic on the Apple Discussions and low and behold, someone came to help, amazing!

Here's the code, although you might have to read the discussion to get the right syntax as it didn't post quite right:

--****BEGIN SCRIPT
idle
on idle
set message_ to "Stephen! Don't trouble the technician, delete some files!"
set MinAllowFS to 20
try
set bootDiskInfo to do shell script "diskutil list | grep 'stephen'"
set bootDiskID to last word of bootDiskInfo
set FSinfo to do shell script "diskutil info " & bootDiskID & " | grep 'Free Space'"
set ActFS to word 3 of FSinfo

--Pick one or more of the following responses by removing the comment ("")

--if ActFS < MinAllowFS then beep 3

--if ActFS < MinAllowFS then display dialog message_

if ActFS < MinAllowFS then say "[[rate 180]]" & message_
end try
return 10 --<< Here's where you set the repeat rate in seconds
end idle
--
****END SCRIPT


The message wasn't quite what I had in mind. I wanted to inform the students that their disk space was running low and might cause some problems. They should take action by moving files off their home space, and emptying the trash. Something more along the lines of:

set message_ to "Your home space is running low, this may cause applications to crash and even corrupt you files. Please move some files off your home drive and don't forget to Empty the Trash."

The MinAllowFS is the threshold for the message to kick in, currently set to 20MB

As I wanted it to run for any networked user that was logged in, I ended up using the command "df -k -m" instead of "diskutil list". This lists all volumes mounted and the amount of space left in MB (-m). This df command is more useful then the 'diskutil' command as it gives us the free space straight away. The specific line from this list contains the word "students" so this line would read:

set bootDiskInfo to do shell script "df -k -m | grep 'students'"

Word 4 of this is the amount of disk space left, in MB

set ActFS to word 4 of bootDiskInfo

So the whole script should read:

--****BEGIN SCRIPT
idle
on idle
set message_ to "Your home space is running low, this may cause applications to crash and even corrupt you files. Please move some files off your home drive and don't forget to Empty the Trash."
set MinAllowFS to 20
try
set bootDiskInfo to do shell script "df -k -m | grep 'students'"
set ActFS to word 4 of bootDiskInfo

--Pick one or more of the following responses by removing the comment ("")

--if ActFS < MinAllowFS then beep 3

if ActFS < MinAllowFS then display dialog message_

--if ActFS < MinAllowFS then say [[rate 180]] & message_


end try
return 300 --<< Here's where you set the repeat rate in seconds
end idle
--
****END SCRIPT



------------------ 28/09/2013 ----------------
I've just came back to this post and finally got around to implementing it. I ended up with a problem having two lines of output from the df command, because two lines contain the word 'student'. To solve this, I had to use the grep -v option, which is the inverse of the grep command, finding the lines without it in. So trigger is on the line I don't want so the command I used was:

df -k -m | grep 'students' | grep -v 'trigger'


Script is now:


--****BEGIN SCRIPT
idleon idleset message_ to "Your home space is running low, this may cause applications to crash and even corrupt your files. Please move some files off your home drive and don't forget to Empty the Trash."
set MinAllowFS to 10
tryset bootDiskInfo to do shell script "df -k -m | grep 'students' | grep -v 'trigger'"
set ActFS to word 6 of bootDiskInfo
--Pick one or more of the following responses by removing the comment ("")
--if ActFS < MinAllowFS then beep 3
if ActFS < MinAllowFS then display dialog message_
--if ActFS < MinAllowFS then say [[rate 180]] & message_
end tryreturn 300 --<< Here's where you set the repeat rate in seconds
end idle

Now I have written a few programs, I'm getting the hang of writing them properly. A few things I would like to adjust are:

  1. verify (assert!) that ActFS is set to an appropriate number (not a letter or symbol)
  2. check if it is a member of staff and not a student and look for "staff" instead
  3. feed back to the user how much disk space there is free, total disk quota.
  4. give user the option of running a utility which will help identify larger files and folders
  5. contact administrator for help (either by remote desktop or email)

Tuesday, 13 September 2011

Network Home Redirector - reverting back

Back when we had OS X 10.5 installed throughout the computer suites we had to run a script at startup which created a symlink for Caches in the users Library folder. These scripts were called NHR (Network Home Redirector) This linked to a folder stored locally, as the caches folder stored on the Active Directory smb shares had permissions issues for some applications.

The only thing which didn't work quite as planned was the fact that the logout scripts never ran, and so people were left with the symlink in their Library folder.

Now we have updated to OS X 10.6.6, this permissions issue seems to have resolved itself. But anyone who logged in last year has now got a symlink for their Caches folder, and not a folder! To resolve it I plan to make a small script which, upon login, looks for a symlink, deletes it and makes a nice new folder.


I've had a look at the man page for 'ls' function, and if you use the -l command in it, it shows you more info on the files and folders. Any with a 'l' at the beginning of the line are symbolic links. I ran the command with the grep command to pick out the Caches folder:

ls -l Library/ | grep 'Caches'
lrwxrwxrwx+ 1 leachs  CHSTFADMIN\teaching_global     19 15 Sep 14:00 Caches -> /tmp/leachs/Caches/
So thats a good start.