Showing posts with label customize. Show all posts
Showing posts with label customize. Show all posts

Saturday, November 21, 2020

Run PowerShell Scripts like Normal

 This is going to be a quick post, how to run a PowerShell script with a double click rather than right clicking and telling it to "Run with PowerShell." I get all the security measures, I really do. However, I want to run things when I want them and how I want them rather than making an intermediary Batch file to do so.


So it's real simple, right click your .ps1 file and go to the "Run with" option. Select the powershell.exe in C:\Windows\System32\WindowsPowerShell\v1.0 and set that as the default. Like magic, you can now double click your PowerShell scripts to run them.


The main reason I wanted this was to be able to create macros with PowerShell for my macro keys. I could have gone about it other ways, but I wanted to use PowerShell because recently I have really been digging deep into it for work. Hope this helps people.

Wednesday, September 2, 2020

Starting Out as a Computer Tech (part 2)

Previously I covered some basic tasks you may need for dealing with a domain and Active Directory. Now I would like to cover some more local tasks. Even if a computer is on a domain, there is some necessary local management that may be necessary. Common tasks while locally managing a computer may include adding/altering/editing local users, cleaning out files, installing/troubleshooting programs, managing printers, changing default applications, changing display settings, and so on. There are actually a lot of things you still need to do locally. Some of these things can be done remotely, but they alter the local computer, not the domain. As a result, we will consider this local administration.


In my current environment I work with, every year we inadvertently need to change local administrators for some higher privileged computers. By this, I mean we add the domain account to be recognized as a local administrator when they log in. This is not necessarily the best way to do things, but quick and dirty tends to be the go to for a lot of IT people on all levels. On Windows 10 you go to the settings cog on the start menu. The category we need to look in is Accounts. On the left-hand side, there will be "Other users." To add a domain account, you will click "Add a work or school user." For a domain user, we add the domain before a backslash (\), like this: example\some_user. You then select the level you want the user at, like Administrator. When a user is added, they will appear in a list below the option to add a user. When you click on the user, there is a "Change account type" and "Remove" option.


The same things can be done with Powershell. For this we need knowledge of four commands: Get-LocalGroup, Get-LocalGroupMember, Add-LocalGroupMember, and Remove-LocalGroupMember. We can list all the group names with Get-LocalGroup. After you have a list of the group names and decide which one you want, for example Administrators, you can check what users are in the group by doing something like Get-LocalGroupMember -Group Administrators. When we want to add a user to a group to make them an administrator, we run a command like Add-LocalGroupMember -Group Administrators -Member example\some_user. Much in the same way, we can remove users with Remove-LocalGroupMember -Group Administrators -Member example\some_user. As mentioned before, the big advantage of Powershell in a lot of cases is doing things remotely.


The Command Prompt also offers the same functionality as different commands, specifically through the net command. The quick translation would look like this:

Get-LocalGroup would be net localgroup

Get-LocalGroupMember -Group Administrators would be net localgroup administrators

Add-LocalGroupMember -Group Administrators -Member example\some_user would be net localgroup administrators /add example\some_user

Remove-LocalGroupMember -Group Administrators -Member example\some_user would be net localgroup administrators /delete example\some_user

 

 Cleaning out files is another common task you may need to do. The first general maintenance cleanup task will be using Disk Cleanup. You can get to it by searching in the start menu for Disk Cleanup or Windows+r and running cleanmgr.exe. Disk Cleanup is something you may want to use to keep free space clear from various temporary files and Windows updates. You may need to tell it to include system files after the first scan if Windows update files are not showing up. Just go and select anything on the list you do not think you need and let it clean up the space.


Sometimes stuff may glitch out and the hard drive will be out of space and no files seem to be found. The times I have run into this, it was temporary files that decided they were permanent. You may need to go to C:\Windows\Temp and manually delete those files. The same can be done with Powershell by doing Remove-Item -Path C:\Windows\Temp\* -Force -Recurse.


The last bit of cleanup of files I often need to do is for network profiles stuck locally. This requires two steps. The first is to delete the folder under C:\Users that needs to be removed. The second step requires deleting a registry key. To delete the registry key, the first thing you need to do is launch regedit through regedit.exe with either Windows+r or the start menu. Navigate the tree to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList to find where all the profiles are. When you click on the items in the ProfileList, there will be keys on the right-hand side. ProfileImagePath will be the value that points to the profile folder. Delete the item on the left-hand side with a ProfileImagePath that matches a user folder you deleted. Whenever you are done, be sure to restart the computer.


Installing and troubleshooting programs is fairly straight-forward. You may need to check when you right-click a program and select Run as administrator. You may also need to right-click, go to properties, select the compatibility tab and select a compatibility mode. Be sure if you do that, you go through the "Change settings for all users" button at the bottom.


Moving on to one of the most hated topics, printers. The nature of a printer containing mechanically moving parts, software/drivers, and in some cases networking makes them a very difficult animal to deal with. For now, let's talk about installing and setting default printers. The problem I run into with printers is their user specific nature. To be guaranteed a printer gets installed and setup correctly you should try to do it entirely while logged in as the user that needs it, add it, and set it to default. Some printers may need you to download a driver or run a CD, some may need you to add it via the network. I will not go into any more detail than that, I hate dealing with printers and wish you luck in doing as little as possible with them.


Changing default applications is a user specific task that will probably cause a brain aneurysm for most techs. What should be a simple task often confuses people and Microsoft seems to often make no effort to make this any easier. The easiest way to set a default application to run a file type, is to right click, select "Open with" and make sure when you pick the program the checkbox is selected with "Always use this app to open ____ files." Sometimes this is not an immediate option. For that we go to the Settings cog on the start menu. Go to the Apps category and select Default apps on the left. The first list is of the basics like what to open websites or emails with. Just click on the icon and pick the program you want. At the bottom, you have "Choose default apps by file type." This is the pain one. Click on it to see the massive list of files types. There is no easy way to jump to a specific point, so you scroll down to the file type you want to alter the program for and change it by clicking on the icon next to the file type. I have to frequently do this with PDFs because for some reason it breaks a lot and resets back to Edge from Adobe Reader DC.


Since I work in a school system, changing display settings is an every day thing. Computers are connected to projectors here and second monitors there and it always seems people want it set up differently. There are also "problems" people report because of it. So let's go over how to change things. The first, and easiest when at a computer, is to press Windows+p to bring up a quick display menu on the right-hand side of your screen. There are four options PC only, Duplicate, Extend, Second screen/projector only. Duplicate shows both displays the same, extend has two separate desktop spaces, and the other two should be self-explanatory. The catch is often that Duplicate almost always messes up the resolution and extend might have the wrong screen as the "primary" display, making for a difficult time logging in. To access more settings, you can go to the start menu cog wheel Settings, go to the System category and Display on the left-hand side. This will show you your displays and you can tell it to "Identify" with the button below to tell you which screen is which. After they are identified, you can then easily drag the screens around on the settings to align them how they are in real life, they do not have to be an even match, or can be on top of each other, all sorts of things. To make one of them a primary display, select the screen and at the bottom there is a check box for "Make this my main display." You can also adjust your resolution and change the same settings that you get when you press Windows+p. There are also ways to do things over a CLI, but I'll talk about those later.


So here's a scenario I get all the time. A work order will say "Computer not coming on" or "screen is black and I can't log in, but I can see the mouse." So what is the problem? The answer is it's connected to a projector that is off, the projector is marked as the main display, and it's extended. The quick solution is to turn on the projector, press Windows+p, and then select Duplicate. To a tech it may seem simple and obvious, but normal people do not think "display settings," they think "it doesn't work" and get stuck panicking most of the time.


This is just a brief overview of some basic points required for being IT. There is still a lot more to cover. I hope someone somewhere finds this helpful.

Sunday, February 17, 2019

How to Linux or Something Like That

I am by no means a Linux expert, but at work I am the one they tend to defer to with "how do I Linux" questions. So maybe it would be worthwhile to make a small beginner guide on how to at least pretend you know what you're doing. So let's get out the basic "gotchas" of Linux and some semantics.

Linux is a kernel. Linux is to Ubuntu (or whatever you flavor is) as Windows NT is to Windows 7. I sometimes com across those snarky "Linux isn't an OS" comments online and it gets annoying, but this is the brief explanation to those.

Linux itself comes in different distributions referred to as "distros" or "flavors." If you're gonna talk about Mint, flavors seems like the better term, although it may get weird when you talk about Puppy being your favorite flavor. Sometimes different distributions are just the same one with a different desktop environment (DE) or software pre-loaded on it. Some desktops include things like Gnome, KDE, X11, xfce, MATE, LXQt, etc. There are a lot of desktop environments. To further add to some confusion, there are also window managers (WM) like xmonad, i3, and a million other ones. When discussing with others the environments they use, it can get complicated and layered because everyone uses a million and one things just to stick two windows on the screen at just the right location and spacing.

Personally, I use things mostly default because I often have to move around to a lot of different environments. I use CentOS minimal (no DE), Kali, Windows 7, Windows 10, Mac OSX Sierra, Ubuntu and various derivatives of, just to name a few.

If you're looking to pick the right distro for you, you can check out Distro Watch, they keep up to date on everything. Browsing there, you can find quite literally hundreds to choose from. Each one varies to some extent with the file structure, commands, or general way of doing things.

One of the big things for people starting out is the package manager. Without being able to install software, there are limitations for those that don't just make things themselves and package managers are the biggest help. It's one of the things that I loved when starting out with Linux. You can download or keep up-to-date all of your software in a simple manor. Each distro has its own way of doing things. Debian based has aptitude, RedHat based has yum, Arch based has pacman, and so on. Most have some form of package tool and special format.

I'm on Kali right now, so if I want to update all of my stuff, I may do something like:

apt-get update && apt-get upgrade -y

This is really dependent on what distro you're on, what kind of updates you're getting (like if you're on a rolling distro), and the like.

Now a brief look at file structures. The root file is /. It contains a handful of folders such as bin (user binaries), boot (boot files), dev (device files), etc (configuration files), home (user folders), lib (libraries), mnt (mount), opt (optional apps, usually ones you install outside of a package manager will end up here), proc (process information), root (root user, not to be confused with the file root), sbin (system binaries), srv (service data), tmp (temporary files), usr (user programs), and var (variable files such as logs, default web root for web services, etc.). Chances are you actually have many more than that, and it all depends on the distribution. I'm personally a fan of how Linux handles devices in the dev folder allowing you access to devices in similar ways you interact with files.

Shells. Your shell on a Linux system is an invaluable tool for when all else fails. Knowing how to use it is immensely helpful, and customizing it to make it your own is very satisfying. Most variations seem to default to Bash (Bourne Again Shell), based off of the Bourne Shell. There are numerous other variations such as Korn shell (ksh), Almquist Shell (ash), Dash (default for recent debian distros), C shell (csh), tcsh (unix compatible c shell that Mac used for a while), Friendly Interactive shell (fish), Z shell (zsh), and many more. Most of them have cross compatibility with minor changes here and there for syntax and the big distinction being how they handle interactive sessions.

Personally, I use zsh with Oh-my-zsh!, and tmux (a terminal multiplexer) when I'm getting down and dirty. For scripting, I stick to good ol' Bash... or Python or Tcl, depends on what I'm doing really. Tcl seems to pop up at random and I use it at work for a custom backup script for the many switches we have (with expect).

Some of the more basic things you would do to get started on Linux and really grab into the shell is basic file navigation and text editing. When it comes to text editing, I love Vim. My favorite thing about Vim/Vi is how quick and easy it is to do stuff when you know what you're doing. My second favorite things is when people copy a command with vi or vim in it and have no idea what they're doing. You see kids, Vi is a visual text editor that requires knowing commands in it to edit, save, and even exit it. There is also nano, which is to speed with most newcomers, but not every distro comes with it. So let's go over a quick and incomplete Vi/Vim lesson!

To quit the program you type :q
To move the cursor, you can use arrows or h (left), j (down), k (up), l (right)
To insert text (go into insertion mode), i inserts on the cursor, a inserts after, I inserts at the very beginning, A at the very end of the line
To stop inserting, press esc
Backspace doesn't always work, delete always does, x will delete when not in insertion mode
To save you type :w
To save and quit you can type :wq or :x
To quit without saving, you type :q!

There are also ways to copy and paste, regex substitute, find, and all sorts of things. If you start getting used to it now, you can soon start to learn all the other cool things.

Let's say we want to edit the hostname on a computer. We do something along the lines of:

cd /etc
vim hostname

Then press i, type in the hostname, press esc, then :wq
We can then restart the computer. So what are some quick and easy commands to get started?

cd <directory> (change directory)
mkdir <directory> (make directory)
touch <file> (create a file)
rm <file> (remove a file)
cp <file1> <file2> (copy a file)
mv <file1> <file2> (move or rename a file)

There are a lot of commands, and it changes from system to system to some degree. Without getting into one specifically, it's hard to go too in-depth.

So how do you pick a distro for you to get started? Major distributions are a good start with the large communities and lots of documentation and tutorials. Ubuntu, Mint, CentOS, Debian, Fedora, Manaro are just a handful of some of the major ones. I personally started out with Ubuntu. With Ubuntu I could do everything with GUI and introduce myself into command line stuff at my own pace. After that, I learned how to configure and run systems entirely from the command line.

Thursday, July 6, 2017

ChocolateyGUI Invalid Path with OneGet

So recently while browsing around some stuff about about Windows 10, I found out about OneGet. This is a package manager manager in Powershell. I think this could be super useful. So one of the package managers I added was Chocolatey. I also wanted to install the GUI for I figure it may be easier to browse packages that way. Upon installation and execution, I got met with a huge error screen along the lines of:

System.IO.InvalidDataException: invalid Chocolatey Path. Check that chocolateyInstall is correct in the app.config

So on and so fourth. After reading through the git page on this error and taking some time to consider the confusion around "how did you install chocolatey?" I realized that specifically it's not actually installed when you just add it to OneGet. So here's the fix. After you add chocolatey, you need to INSTALL it. Just like this:

Install-Package chocolatey

After that, it should run without a hitch. Hope this helps someone out there. Package managers are great, aren't they?

Sunday, May 14, 2017

Kali Live with Persistence and Updating

So recently I was trying to set up Kali Linux on a live USB fully updated. I kept running into a few problems with it that ultimately are based on how the instructions online are worded. After modifying the steps, I managed to create a fully updated Kali Linux live USB and hopefully you can set one up as well by following these instructions.

So the obvious first step is to download the most recent ISO image that you plan on using. At the time of this writing, that would be 2017.1 and I will be using the 64 bit, so my ISO file is named:
kali-linux-2017.1-amd64.iso

Starting from Windows, I use a program called Rufus to create a live USB. It's a very handy program to keep around and my go to for this stuff on Windows. At work, it's gotten disks working with less effort than all the random tools my co-workers download from the random tutorials they read and with no installation required you can keep it on removable medium and have it with you for when you need it. So download that as well, pop your USB drive in and load up Rufus. Then you need to select your ISO file.

After selecting the ISO, the drop down should say something about it being a DD image, and that's exactly what we want. Tell it to start and let the magic happen.


Starting from Linux, we are going to ignore the dd command (dd if=kali-linux-2017.1-amd64.iso of=/dev/sdb bs=512k) because that's both complicated and pointless. A much simpler way to get this done with a LOT less to remember is the cat command. Assuming the drive is /dev/sdb, we simply do: cat kali-linux-2017.1-amd64.iso > /dev/sdb
Simple, easy to remember since it's not using a different syntax style than other bash commands and straight forward. I've also read online that cat is quicker and has less overhead than dd, but I do not know enough about them to confirm or deny these claims. I just think it's a lot easier and gets the job done just as well.

Now with this drive ready to boot from, we shall move on to the next step through Kali because then we know we have the simple and easy tools we need to get the persistence set up. So boot on into Kali and select Live, NOT PERSISTENCE. We need to create the persistence partition. In the actual instructions, they list off some commands than every time I try, they do not work. Even when in Kali Live itself. The commands themselves are a bit beyond my understanding, but that seems to happen every time someone makes a "copy and paste" tutorial because they need to compensate for dynamic possibilities. I, on the other hand, think gparted is a perfectly acceptable solution for today's day in age. If you want to do this via command, I suggest you learn the parted command and do it yourself rather than copy-paste.

So first, press the windows key on your keyboard or bump the top left corner with your mouse. That should bring you to the activities view. Type in "gp" and an icon for gparted should show up, click on that to open it up.

Right click on the empty space and select New. Create an ext3 partition with the label persistence.

Now click on the apply arrow.




Now we are entering the home stretch. The command portion. Open up a terminal, it's the little black icon on the left dock. Enter in these commands:
mount /dev/sdb3 /mnt
echo "/ union" > /mnt/persistence.conf
umount /mnt

Now we reboot the computer to Live with persistence. On some random installation like this, I have run into just a black screen with a pointer. To fix that, I pressed ctrl+alt+f2, which should bring you into TTY2. Then run the command:
kill -9 $(pgrep gnome)
This then dumped me back over to TTY1 and after some time the desktop came back up on TTY3 (ctrl+alt+f3). In the meantime, I just updated on TTY2.

So to finish things off with a clean and easy update:
apt-get update && apt-get upgrade -y

Hopefully this will help anyone struggling with this process. I did notice a lot of people ran into the same problems I did, so now to list off those problems and what caused them for me:

Out of space because updates going into the disk image.
This was caused by booting into persistence and trying to do things before persistence was set up which then lead to an non-bootable USB.

Boots to a black screen with a cursor.
I don't know the cause of it, but killing all gnome related processes seems to correct it. While performing this process 

Could not write files while updating.
This was another case of not having the persistence set up properly.

Monday, September 23, 2013

Verizon Samsung Galaxy SIII Rooting and Unauthorized Software

*** This includes information for getting back the original phone setup without losing data and can be used for rooting and unlocking the bootloader (see near end of post)

I was playing around with my GS3 that I had rooted, and I wanted to try out a custom ROM. I didn't bother reading about it and am still pretty new to smart phones, so I risked screwing up or even bricking my phone. So I got the custom ROM on their and restarted my phone and was met with a yellow triangle and a warning about detecting unauthorized software and to take my phone to the nearest Verizon store to fix it.

After a bit of searching, I found a way to fix it. So the first thing you need is a Windows computer. This won't work on Wine and can be a bit buggy through a virtual machine. Keep in mind, no data will be lost, but this will reset the system back a ways.
  1. Install the Samsung USB driver
  2. Download Odin 3.07
  3. Download Kies Home GS3
  4. Boot the phone into Odin recovery by holding down the volume down, home and power button at the same time (don't let go when it vibrates the first time)
  5. Start up Odin and connect the phone, one of the boxes should turn blue which means it's ready
  6. On the bootloader, browse to Kies, it will take a while for it to check out, once done just run it
Now the next time you restart, all should be back to the way it was, only a bit out of date.

Now onto rooting and unlocking the bootloader. This can be done with Linux or Windows, but for it to work on Linux, you need Java up to the very latest version, probably want to use the official version.
  1. Download Casual
  2. Turn on USB debugging (System settings -> Developer options)
  3. Connect and select to root
  4. To unlock the bootloader, first install the Clockworkmod Recovery
  5. Then select to unlock the bootloader
Like magic, everything works, hopefully. After I got it all working, I used ROM Manager to install the Cyanogen Mod.

Wednesday, July 17, 2013

Multiple Operating Systems on One Flashdrive from Linux

Recently I decided to take some old flash drives I have not been using and turn them into tools for things like security and data recovery. The problem became I had so many tools I wanted to cram on them, but only a handful of flashdrives. Furthermore, a good portion of what I wanted was small and putting them on their own dedicated drive was a bad use of space.

So now the hunt was on to turn one of the larger flash drives into a multi-boot. Normally I use UNetBootin to create bootable flash drives. I did this for Kali and PartedMagic because I started with making those tools first. Now after much trying to use UNetBootin to create multiple operating systems on one drive, tried multiple partitions, I went to Google. Google gave some possible ways to do it, but they were inefficient. So finally I found something late at night.

Multisystem is a quick and easy way to set this up. Despite it being in French (according to Google), but I only speak English and can work it with no problem, so it's all good. You can load operating systems onto it by dragging and dropping. You can view more options by clicking the button on the left hand side with the eyeball. To see what any of the buttons do, just hover over them. Everything else should be pretty straight-forward.

Now after doing all of this, I found one slight problem. Installing tinycore is done slightly incorrect and makes it so that you can't setup programs for loading on the boot as a result. So if you want to set up tinycore, here's what you should do after it is all set up. First, you want to browse the files. Change the folder "cde" to "tce". Next, open up boot/grub/grub.cfg. Look for something along the line of this in the file:

#MULTISYSTEM_MENU_DEBUT|12-07-2013-00:13:33-278461639|cde|multisystem-tinycore|12Mio|
menuentry "Tiny Core Linux" {
linux /cde/boot/vmlinuz quiet cde showapps desktop=flwm_topside
initrd /cde/boot/core.gz
}
#MULTISYSTEM_MENU_FIN|12-07-2013-00:13:33-278461639|cde|multisystem-tinycore|12Mio|

Now you want to change it so that all the places it says "cde" say "tce". So the end result of the example posted looks like this.

#MULTISYSTEM_MENU_DEBUT|12-07-2013-00:13:33-278461639|tce|multisystem-tinycore|12Mio|
menuentry "Tiny Core Linux" {
linux /tce/boot/vmlinuz quiet tce showapps desktop=flwm_topside
initrd /tce/boot/core.gz
}
#MULTISYSTEM_MENU_FIN|12-07-2013-00:13:33-278461639|tce|multisystem-tinycore|12Mio|

I have not come across any other problems yet, but I haven't really messed around with everything on it yet.

Tuesday, April 2, 2013

Arduino Wii Nunchuck on Linux

I came across a DIY project over on the website for Maker magazine to connected a Wii Nunchuck to your computer as a mouse using an Arduino board and Python. Problem was, they only made it for Windows (they also suck at Python programming, but whatever). So after quite a bit of work over the past three days, I finally got it working.

The problem is Windows is not very secure and anything running on it can really do whatever it pleases, like say move the mouse around or click on things, without much effort. Linux has a bit more to it.

I went in originally planning on using libX11.so through ctypes.cdll, but setting up an event on that was not only pure hell, I don't even know if it is possible. Plan B presented itself as Xlib. The documents are not that complete, examples seem to be scarce and I don't have much in the way of patience.

You can check everything out here, I'm going to skim over the details and then show the Python code, all commented.

First thing first, get the library for interfacing the Nunchuck here. The readme there should tell you how to use it.

Next you want to jam some wires into your Nunchuck (the jumper wires from the starter kit fit fine without breaking anything) like so and connect it to your board to the corresponding holes.


From there you want to upload the example code for the Wii Nunchuck library so we can just process the data as a string rather than a bytestream.

Now we just need to run some Python code and you get all the mouse control I could jam into the thing (two buttons, joystick and accelerometer gave me just enough room for everything a standard modern day mouse has).

#!/usr/bin/env python
import serial, sys, Xlib, Xlib.display, Xlib.ext.xtest

# This will be later on, setting it now
global d, root

# The port to which your Arduino board is connected
# Change for your system and board
port = '/dev/serial/by-id/usb-Arduino__www.arduino.cc__0043_64131383331351306291-if00'

# The baudrate of the Arduino program
baudrate = 19200

# Variables indicating the center position (no movement) of the controller
# Increase the amount of play if to sensitive, decrease if not sensitive enough
# Increase speed to cut it down, decrease to raise it (1 is the highest)
midAccelX   = 515 # Accelerometer X
midAccelY   = 590 # Accelerometer Y
midAccelZ   = 710 # Accelerometer Z (not used)
midAnalogY  = 134 # Analog Y
midAnalogX  = 127 # Analog X
tollerance  = 5   # Amount of play
accelToll   = 80  # Amout of accelerometer play
speed       = 4   # difference / speed = movement

# Generic mouse movement
def move_mouse(x,y):
    x = int((x - midAnalogX) / speed)
    y = int((midAnalogY - y) / speed)

    # Make sure it's not just white noise
    if abs(x) < tollerance:
        x = 0
    # Move in the right direction the right amount
    else:
        if x < 0:
            x += tollerance
        else:
            x -= tollerance

    # Same deal, filtering white noise
    if abs(y) < tollerance:
        y = 0
    # Move in the right direction the right amount
    else:
        if y < 0:
            y += tollerance
        else:
            y -= tollerance

    # Save the Xorg processing if we're not moving
    if x != 0 or y != 0:
        d.warp_pointer(x, y, src_window = root)
        d.flush()

# Simulated button down
def mouse_down(button):
    Xlib.ext.xtest.fake_input(d, Xlib.X.ButtonPress, button)
    d.sync()

#simulated button up
def mouse_up(button):
    Xlib.ext.xtest.fake_input(d, Xlib.X.ButtonRelease, button)
    d.sync()

def main():
    # Connect to the serial port
    try:
        ser = serial.Serial(port, baudrate)
    except Exception as err:
        sys.stderr.write(str(err) + "\n")
        return 0

    # Mouse buttons
    leftDown = False
    rightDown = False
    middleDown = False

    # While the serial port is open
    while ser.isOpen():
        # Read and process the line
        line = ser.readline()
        line = line.strip('\r\n')
        line = line.split(' ')

        # Not sane yet, nothing to see here
        if len(line) != 7:
            continue

        # Alias the info so we can make sense of the rest
        try:
            analogX = int(line[0])
            analogY = int(line[1])
            accelX  = int(line[2])
            accelY  = int(line[3])
            accelZ  = int(line[4])
            zButton = int(line[5])
            cButton = int(line[6])

        # It hiccuped, ignore and move on
        except ValueError:
            continue

        # Left Mouse Button (Z)
        # Button down, don't need to press again if it's already down
        if zButton and not leftDown:
            leftDown = True
            mouse_down(Xlib.X.Button1)
        # Release the button
        elif leftDown and not zButton:
            leftDown = False
            mouse_up(Xlib.X.Button1)

        # Gestures to map more buttons since we only have two
        # It's the C button
        if cButton:
            # Tilt right, right click
            if (not rightDown) and accelX - midAccelX > accelToll:
                rightDown = True
                mouse_down(Xlib.X.Button3)
            elif rightDown and accelX - midAccelX <= accelToll:
                rightDown = False
                mouse_up(Xlib.X.Button3)

            # Tilt left, middle click
            if (not middleDown) and midAccelX - accelX > accelToll:
                middleDown = True
                mouse_down(Xlib.X.Button2)
            elif rightDown and accelX - midAccelX <= accelToll:
                middleDown = False
                mouse_up(Xlib.X.Button2)

            # Tilt forward, scroll up
            if accelY - midAccelY > accelToll:
                mouse_down(Xlib.X.Button4)
                mouse_up(Xlib.X.Button4)
            # Tilt back, scroll down
            elif midAccelY - accelY > accelToll:
                mouse_down(Xlib.X.Button5)
                mouse_up(Xlib.X.Button5)
        # Cleanup any buttons down when gesture stops
        else:
            if rightDown:
                rightDown = False
                mouse_up(Xlib.X.Button3)

            if middleDown:
                middleDown = False
                mouse_up(Xlib.X.Button2)

        # Move the mouse
        move_mouse(analogX, analogY)

    # After the program is over, close the serial port connection
    ser.close()

if __name__ == '__main__':
    # Create display and get the root
    d = Xlib.display.Display(None)
    root = d.screen().root
    try:
        main()

    except KeyboardInterrupt:
        print ""

    except Exception as err:
        sys.stderr.write(str(err) + "\n")

    # Regardless of what happens, close the display
    finally:
        d.close()

Remember to change your port for your board and system and adjust any values to adjust to your sensitivity and any excess give or lack there of that it may have.

Thursday, June 28, 2012

MyBB Registered-only view BBCode

Decided to make another quick MyBB addon, this adds some BBCode. You can use [paranoid][/paranoid] tags to prevent non-registered and banned members from viewing stuff selectively. I am using it to cover up various resource links. If you are logged in, it will appear like nothing is changed, you can only tell what's covered up by logging out or being banned.

[Download v1.0]

Maintained: https://github.com/anarchywolf46/MyBB-Plugins

Friday, June 22, 2012

Firebug Quick Info (remove)

One of the things that has been annoying me on firebug, is the quick info popup. It's always in the way. So I looked up how to disable it because I didn't have a clue where the options where. In my version of firefox, under Tools > Web Development > Firebug > Options and clicked to uncheck the "Quick Info" option. I think on older versions it was just under the Tools menu. Either way, if you didn't know how to do that, now you know.

Monday, March 19, 2012

NoScript URL Javascript

I've been messing around with javascript and helping someone learn it, and one thing I've noticed is a lot of people seem to have NoScript now. NoScript is an addon that can allow you to selectively run or block javascript. While this is great, there is one option I don't see openly on the options for it. Whenever trying to run javascript in the url bar, it's blocked. While this is good for people dumb enough to run javascript directly from someone not trustworthy (I have used url run javascript to get someone's cookie information and hijack their session), it can be a problem when just messing around with stuff for someone who knows what they are doing but doesn't know about the way to allow url run javascript.

So to find the option, first go to the about:config (enter about:config in your url). Then in the filter, enter noscript.allowURLBarJS. You can right click and select the toggle option or simply double click the result you get. Once set to true, should be able to run url javascript, but only on sites that the domain is allowed to run javascript. Running javascript in the url still sandboxes it in to whatever tab you're on.

Whatever you do, be careful what you run when using this, can lead to information being taken to breaking some stuff. Other times, can be just a way to mess around with a site you're on quickly and easily, like bookmarklets.