packages feed

WL500gPControl 0.3.2 → 0.3.4

raw patch · 6 files changed

+174/−18 lines, 6 filesdep +Win32dep +directorydep +filepath

Dependencies added: Win32, directory, filepath

Files

LICENSE view
@@ -0,0 +1,29 @@+Copyright 2009, Vasyl Pasternak+All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++- Redistributions of source code must retain the above copyright notice,+this list of conditions and the following disclaimer.+ +- Redistributions in binary form must reproduce the above copyright notice,+this list of conditions and the following disclaimer in the documentation+and/or other materials provided with the distribution.+ +- Neither name of the University nor the names of its contributors may be+used to endorse or promote products derived from this software without+specific prior written permission. ++THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY COURT OF THE UNIVERSITY OF+GLASGOW AND THE CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,+INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE+UNIVERSITY COURT OF THE UNIVERSITY OF GLASGOW OR THE CONTRIBUTORS BE LIABLE+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR+SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER+CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT+LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY+OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH+DAMAGE.
+ README view
@@ -0,0 +1,45 @@++Asus WL500g Premium command-line tool++Latest releases could be obtained from +http://hackage.haskell.org/packages/archive/WL500gPControl++Author: Vasyl Pasternak++This program access to the WL500g Premium router through the web admin+interface and performs following actions:++ - query connection status+ - query log+ - sends connect command+ - sends disconnect command+ - sends clear log command+ - reconnects the WAN (disconnect -> wait -> connect)++Connection info consists of login user name, login password and router+host name (or IP address) and stored in credeintials file++Credentials file format: ++user: <login name>+password: <login password>+host: <router's host name or IP address>++Default credentials file stored in the+'$HOME/.WL500gPControl/credentials' file on Linux or in the +'C:\Documents And Settings\<username>\Application Data\WL500gPControl\credentials' +file on Windows.++Also you can specify another credentials file in each call to the WL500gPControl+tool. Its name should be the last parameter to the command.++WL500gPControl accepts following parameters:++-c, --connect                    Send connect command to the router+-d, --disconnect                 Send disconnect command to the router+-r[wait], --recornnect[=wait]    Reconnect, wait parameter specifies the period+                                 between disconnect and connect (in seconds)+-s, --status                     Prints connection status+-l[N], --log[=N]                 Prints last N lines of the router's log+-x, --log-clear                  Clear log+
WL500gPControl.cabal view
@@ -1,14 +1,54 @@ name:                           WL500gPControl-version:                        0.3.2+version:                        0.3.4 cabal-version:                  >= 1.2 license:                        BSD3 license-file:                   LICENSE author:                         Vasyl Pasternak <vasyl.pasternak@gmail.com>+maintainer:                     Vasyl Pasternak <vasyl.pasternak@gmail.com> category:                       Network, UI synopsis:                       A simple command line tools to control the                                  Asus WL500gP router+description:                    ++ The package consists of two command-line utilities to manage the /Asus WL500g Premium/+ router without logging to its admin page.+ .+ The main utility is @WL500gPControl@ is used to ask the status of the connection + (@Connected@/@Disconnected@), connection parameters (@DNS servers@, @Local IP@, + @Foreign IP@ etc, log), and perform connection, disconnection and reconnection.+ .+ Other utility - @WL500gPStatus@ created only to ease integration into <xmobar> + and return only @Connected@ or @Disconnected@ string, enclosed into format + tags (when option @-c@ is given).+ .+ The last argument of these two utilities is a credentials file. It has simple format:+ .+ @++        user: \<user name\>+        password: \<password\>+        host: \<host name or IP address\>++ @ + .+ The password should be in plain text, so it is recommended to protect this + file from reading for everyone except you.+ .+ If credentials file is not given, than programs will try to use default + credential file, which should be located:+ .+ * on Linux: @$HOME\/.WL500gPControl\/credentials@+ . + * on Windows: @C\:\\Documents And Settings\\user\\Application Data\\WL500gPControl\\credentials@+ .+ Sometimes paths could be different. To determine the read path to the + default credentials file run @WL500gPControl -s@ and look at the error string, where+ will be sayed where it searches credentials file.+                                 build-type:                     Simple +extra-source-files:             README+ executable WL500gPStatus            main-is:             Status/Main.hs            build-depends:       base < 4, WL500gPLib >= 0.3@@ -17,7 +57,16 @@  executable WL500gPControl            main-is:             Control/Main.hs-           build-depends:       base < 4, WL500gPLib >= 0.3, mtl, unix+           if !os(windows)+              build-depends:       base < 4, filepath, directory, +                                   WL500gPLib >= 0.3, mtl, unix+              extensions:          CPP+              cpp-options:         -DUNIX+           else+              build-depends:       base < 4, filepath, directory, +                                   WL500gPLib >= 0.3, mtl, Win32 +              extensions:          CPP+              cpp-options:         -DWIN32            hs-source-dirs:      src            other-modules:       Common 
src/Common.hs view
@@ -2,6 +2,7 @@ module Common      (      defaultCredsFile+    ,toCredsFile     ,parseCredsFile     )where @@ -11,14 +12,24 @@ import qualified Network.Asus.WL500gP as W import Data.Char (toLower) import Control.Monad (liftM)+import System.Directory (getAppUserDataDirectory, createDirectoryIfMissing)+import System.FilePath ((</>))     -homeDirectory = unsafePerformIO $ getEnv "HOME"+appName = "WL500gPControl"+appConfDir = getAppUserDataDirectory appName -defaultCredsFile = printf "%s/.wl500gp" homeDirectory :: String+initConfDir = appConfDir >>= createDirectoryIfMissing True +defaultCredsFile = liftM (</> "credentials") appConfDir -parseCredsFile :: String -> IO (Maybe W.Connection)-parseCredsFile fname = +toCredsFile :: Maybe String -> IO String+toCredsFile Nothing = defaultCredsFile+toCredsFile (Just f) = return f                      ++parseCredsFile :: Maybe String -> IO (Maybe W.Connection)+parseCredsFile Nothing = do+  initConfDir >> defaultCredsFile >>= parseCredsFile . Just+parseCredsFile (Just fname) =      let toPair (a:b:[]) = (map toLower a, b)         toPair _ = ("", "")         parse = filter (/= ("", "")) . map (toPair . words) . lines
src/Control/Main.hs view
@@ -11,8 +11,19 @@ import Data.Either (either) import Data.List (intersperse) import Control.Monad.Trans (liftIO)+#ifdef UNIX import System.Posix.Unistd (sleep)+#elif defined WIN32+import System.Win32.Process+#endif  +#ifdef UNIX+pause = sleep+#elif defined WIN32+-- Win32 sleep function uses miliseconds as argument+pause = sleep . fromIntegral . (* 1000)+#endif+ data Operation = Connect                 | Disconnect                 | Reconnect Int@@ -37,27 +48,31 @@     ]  -- returns the list of flags and the config filename-parseOpts :: [String] -> IO (Operation, String)+parseOpts :: [String] -> IO (Operation, Maybe String) parseOpts argv =      case getOpt Permute options argv of       (o, n, []) -> let creds = if null n -                                 then defaultCredsFile -                                 else (head n)+                                 then Nothing +                                 else Just (head n)                         op = if null o                                then Status                               else (head o)                     in return (op, creds)       (_, _, errs) -> do          progName <- getProgName-        let header = printf "Usage: %s OPERATION CREDENTIAL_FILE" progName+        cf <- defaultCredsFile+        let header = printf "Usage: %s OPERATION CREDENTIAL_FILE \n%s" +                     progName +                     ("Default credentials file is: " ++ cf)         ioError (userError (concat errs ++ usageInfo header options))        main :: IO () main = do   (oper, creds) <- getArgs >>= parseOpts+  cfname <- toCredsFile creds   parseCredsFile creds >>= maybe -                     (ioError $ userError $ printf "Failed to open credentials file '%s'" creds) +                     (ioError $ userError $ printf "Failed to open credentials file '%s'" cfname)                       (switch oper)  brace :: String -> String -> W.Conn () -> W.Conn ()@@ -71,7 +86,7 @@        ClearLog -> brace "Erasing log.." "Done" W.clearLog        Reconnect n -> brace "Reconnecting..." "Done" $                        sequence_ [W.disconnectWan-                                ,liftIO (sleep n >> return ())+                                ,liftIO (pause n >> return ())                                 ,W.connectWan]        Status -> W.readStatus >>= liftIO . either (ioError . userError) showStatus        Log n -> W.readLog >>= liftIO . either (ioError . userError) (showLog n)
src/Status/Main.hs view
@@ -6,6 +6,7 @@ import Text.Printf (printf) import Common import Data.Either (either)+import Data.List (delete)  data Status = StatusConnected | StatusDisconnected | StatusError String deriving Eq @@ -16,13 +17,19 @@ main :: IO () main = do   args <- getArgs-  -- config file name should be the last argument-  let configFile = if null args -                   then defaultCredsFile-                   else head (reverse args)   -- '-c' - for colorized output-  let outString = printStatus ("-c" `elem` args)-  let configError = outString (StatusError $ printf "Failed to open file %s " configFile)+  let (outString, ol) = if "-c" `elem` args+                        then (printStatus True, delete "-c" args)+                        else (printStatus False, args)+                             +  -- config file name should be the last argument+      configFile = if null ol+                   then Nothing+                   else Just $ head (reverse args)+  +  cfile <- toCredsFile configFile+  +  let configError = outString (StatusError $ printf "Failed to open file %s " cfile)   let getStatus conn =            either (outString . StatusError)                   (outString . fromConnStatus . W.connectionStatus) =<<