/** * Checks the options from the command line * * @return * @access public */ public static function CheckOptions() { if (self::$errormessage) { return; } $options = getopt("u:d:a:t:b:"); // get 'user' if (isset($options['u']) && !empty($options['u'])) { self::$user = strtolower(trim($options['u'])); } else { if (isset($options['user']) && !empty($options['user'])) { self::$user = strtolower(trim($options['user'])); } } // get 'device' if (isset($options['d']) && !empty($options['d'])) { self::$device = strtolower(trim($options['d'])); } else { if (isset($options['device']) && !empty($options['device'])) { self::$device = strtolower(trim($options['device'])); } } // get 'action' $action = false; if (isset($options['a']) && !empty($options['a'])) { $action = strtolower(trim($options['a'])); } elseif (isset($options['action']) && !empty($options['action'])) { $action = strtolower(trim($options['action'])); } // get 'type' if (isset($options['t']) && !empty($options['t'])) { self::$type = strtolower(trim($options['t'])); } elseif (isset($options['type']) && !empty($options['type'])) { self::$type = strtolower(trim($options['type'])); } // if type is set, it must be one of known types or a 44 byte long folder id if (self::$type !== false) { if (self::$type !== self::TYPE_OPTION_EMAIL && self::$type !== self::TYPE_OPTION_CALENDAR && self::$type !== self::TYPE_OPTION_CONTACT && self::$type !== self::TYPE_OPTION_TASK && self::$type !== self::TYPE_OPTION_NOTE && strlen(self::$type) !== 44) { self::$errormessage = "Wrong 'type'. Possible values are: " . "'" . self::TYPE_OPTION_EMAIL . "', '" . self::TYPE_OPTION_CALENDAR . "', '" . self::TYPE_OPTION_CONTACT . "', '" . self::TYPE_OPTION_TASK . "', '" . self::TYPE_OPTION_NOTE . "' " . "or a 44 byte long folder id (as hex)."; return; } } // get 'backend' if (isset($options['b']) && !empty($options['b'])) { self::$backend = strtolower(trim($options['b'])); } elseif (isset($options['backend']) && !empty($options['backend'])) { self::$backend = strtolower(trim($options['backend'])); } // get a command for the requested action switch ($action) { // list data case "list": if (self::$user === false && self::$device === false) { self::$command = self::COMMAND_SHOWALLDEVICES; } if (self::$user !== false) { self::$command = self::COMMAND_SHOWDEVICESOFUSER; } if (self::$device !== false) { self::$command = self::COMMAND_SHOWUSERSOFDEVICE; } break; // list data // list data case "lastsync": self::$command = self::COMMAND_SHOWLASTSYNC; break; // remove wipe device // remove wipe device case "wipe": if (self::$user === false && self::$device === false) { self::$errormessage = "Not possible to execute remote wipe. Device, user or both must be specified."; } else { self::$command = self::COMMAND_WIPEDEVICE; } break; // remove device data of user // remove device data of user case "remove": if (self::$user === false && self::$device === false) { self::$errormessage = "Not possible to remove data. Device, user or both must be specified."; } else { self::$command = self::COMMAND_REMOVEDEVICE; } break; // resync a device // resync a device case "resync": case "re-sync": case "sync": case "resynchronize": case "re-synchronize": case "synchronize": // full resync if (self::$type === false) { if (self::$user === false || self::$device === false) { self::$errormessage = "Not possible to resynchronize device. Device and user must be specified."; } else { self::$command = self::COMMAND_RESYNCDEVICE; } } else { self::$command = self::COMMAND_RESYNCFOLDER; } break; // clear loop detection data // clear loop detection data case "clearloop": case "clearloopdetection": self::$command = self::COMMAND_CLEARLOOP; break; // clear loop detection data // clear loop detection data case "fixstates": case "fix": self::$command = self::COMMAND_FIXSTATES; break; // map users for 'combined' backend // map users for 'combined' backend case "map": if (self::$user === false || self::$backend === false || self::$type === false) { self::$errormessage = "Not possible to map. User, backend and target user must be specified."; } else { self::$command = self::COMMAND_MAP; } break; // unmap users for 'combined' backend // unmap users for 'combined' backend case "unmap": if (self::$user === false || self::$backend === false) { self::$errormessage = "Not possible to unmap. User and backend must be specified."; } else { self::$command = self::COMMAND_UNMAP; } break; default: self::UsageInstructions(); } }
/** * Checks the options from the command line * * @return * @access public */ public static function CheckOptions() { if (self::$errormessage) { return; } $options = getopt("u:d:a:"); // get 'user' if (isset($options['u']) && !empty($options['u'])) { self::$user = strtolower(trim($options['u'])); } else { if (isset($options['user']) && !empty($options['user'])) { self::$user = strtolower(trim($options['user'])); } } // get 'device' if (isset($options['d']) && !empty($options['d'])) { self::$device = trim($options['d']); } else { if (isset($options['device']) && !empty($options['device'])) { self::$device = trim($options['device']); } } // get 'action' $action = false; if (isset($options['a']) && !empty($options['a'])) { $action = strtolower(trim($options['a'])); } elseif (isset($options['action']) && !empty($options['action'])) { $action = strtolower(trim($options['action'])); } // get a command for the requested action switch ($action) { // list data case "list": if (self::$user === false && self::$device === false) { self::$command = self::COMMAND_SHOWALLDEVICES; } if (self::$user !== false) { self::$command = self::COMMAND_SHOWDEVICESOFUSER; } if (self::$device !== false) { self::$command = self::COMMAND_SHOWUSERSOFDEVICE; } break; // list data // list data case "lastsync": self::$command = self::COMMAND_SHOWLASTSYNC; break; // remove wipe device // remove wipe device case "wipe": if (self::$user === false && self::$device === false) { self::$errormessage = "Not possible to execute remote wipe. Device, user or both must be specified."; } else { self::$command = self::COMMAND_WIPEDEVICE; } break; // remove device data of user // remove device data of user case "remove": if (self::$user === false && self::$device === false) { self::$errormessage = "Not possible to remove data. Device, user or both must be specified."; } else { self::$command = self::COMMAND_REMOVEDEVICE; } break; // resync a device // resync a device case "resync": case "re-sync": case "sync": case "resynchronize": case "re-synchronize": case "synchronize": if (self::$user === false || self::$device === false) { self::$errormessage = "Not possible to resynchronize device. Device and user must be specified."; } else { self::$command = self::COMMAND_RESYNCDEVICE; } break; // clear loop detection data // clear loop detection data case "clearloop": case "clearloopdetection": self::$command = self::COMMAND_CLEARLOOP; break; default: self::UsageInstructions(); } }