public function revoke_app() { $this->assertLoggedIn(); $this->set('area', 'app'); try { $token = new OAuthToken($this->args('id')); if (!$token->isHydrated()) { throw new Exception("This app does not exist."); } if ($token->get('type') == 2 && $token->get('user_id') != User::$me->id) { throw new Exception("You are not authorized to delete this app."); } $app = $token->getConsumer(); if ($token->get('type') == 2) { $this->setTitle('Revoke App Permissions - ' . $app->getName()); } else { $this->setTitle('Deny App - ' . $app->getName()); } $this->set('token', $token); $this->set('app', $app); if ($this->args('submit')) { if ($token->get('type') == 2) { Activity::log("removed the app named " . $app->getLink() . "."); } else { Activity::log("denied the app named " . $app->getLink() . "."); } $token->delete(); $this->forwardToUrl("/apps"); } } catch (Exception $e) { $this->setTitle('Error'); $this->set('megaerror', $e->getMessage()); } }
public function driver_form() { try { //load our bot $bot = new Bot($this->args('id')); if (!$bot->isHydrated()) { throw new Exception("Could not find that bot."); } if (!$bot->isMine()) { throw new Exception("You cannot view that bot."); } if ($this->args('token_id') == 0) { $this->set('nodriver', "No driver was selected"); } else { //load our token $token = new OAuthToken($this->args('token_id')); if (!$token->isHydrated()) { throw new Exception("Could not find that computer."); } if (!$token->isMine()) { throw new Exception("This is not your computer."); } //what driver form to create? $driver = $this->args('driver'); //pass on our info. $this->set('bot', $bot); $this->set('driver', $driver); $this->set('token', $token); $devices = json::decode($token->get('device_data')); $this->set('devices', $devices); //pull in our driver config $driver_config = $bot->getDriverConfig(); //if we're using the same driver, pull in old values... if ($driver == $bot->get('driver_name')) { $this->set('driver_config', $driver_config); if (is_object($driver_config)) { $this->set('delay', $driver_config->delay); $this->set('serial_port', $driver_config->port); $this->set('baudrate', $driver_config->baud); } } else { if ($driver == "dummy") { $this->set('delay', '0.001'); } } //pull in our old webcam values too. if (is_object($driver_config) && !empty($driver_config->webcam)) { $this->set('webcam_id', $driver_config->webcam->id); $this->set('webcam_name', $driver_config->webcam->name); $this->set('webcam_device', $driver_config->webcam->device); $this->set('webcam_brightness', $driver_config->webcam->brightness); $this->set('webcam_contrast', $driver_config->webcam->contrast); } else { //some default webcam settings. $this->set('webcam_id', ''); $this->set('webcam_name', ''); $this->set('webcam_device', ''); $this->set('webcam_brightness', 50); $this->set('webcam_contrast', 50); } $this->set('driver_config', $driver_config); $this->set('baudrates', array(250000, 115200, 57600, 38400, 28880, 19200, 14400, 9600)); } } catch (Exception $e) { $this->set('megaerror', $e->getMessage()); } }
public function revoke_app() { $this->assertLoggedIn(); $this->set('area', 'app'); try { $token = new OAuthToken($this->args('id')); if (!$token->isHydrated()) { throw new Exception("This app does not exist."); } /** @var User $user */ $user = new User($token->get('user_id')); if ($user->isHydrated() && $user->id != User::$me->id) { throw new Exception("You are not authorized to delete this app."); } $form = new Form(); $field = WarningField::name('warning'); if ($token->isVerified()) { $this->setTitle('Revoke App Permissions - ' . $token->getName()); $form->submitText = "Revoke App Permissions"; $field->value("Are you sure you want to revoke access to this app? Any apps currently using these credentials to print will be broken"); } else { $this->setTitle('Deny App - ' . $token->getName()); $form->submitText = "Deny App"; $field->value("Are you sure you want to deny access to this app?"); } $form->add($field); $this->set('form', $form); if ($form->checkSubmitAndValidate($this->args())) { if ($token->isVerified()) { Activity::log("removed the app named " . $token->getLink() . "."); } else { Activity::log("denied the app named " . $token->getLink() . "."); } $token->delete(); $this->forwardToUrl("/apps"); } } catch (Exception $e) { $this->setTitle('Error'); $this->set('megaerror', $e->getMessage()); } }