public function buildSideNavView($for_app = false)
 {
     $nav = new AphrontSideNavFilterView();
     $nav->setBaseURI(new PhutilURI($this->getApplicationURI()));
     $name = null;
     if ($for_app) {
         $name = $this->getRequest()->getURIData('username');
         if ($name) {
             $nav->setBaseURI(new PhutilURI('/p/'));
             $nav->addFilter("{$name}/", $name);
             $nav->addFilter("{$name}/calendar/", pht('Calendar'));
         }
     }
     if (!$name) {
         $viewer = $this->getRequest()->getUser();
         id(new PhabricatorPeopleSearchEngine())->setViewer($viewer)->addNavigationItems($nav->getMenu());
         if ($viewer->getIsAdmin()) {
             $nav->addLabel(pht('User Administration'));
             if (PhabricatorLDAPAuthProvider::getLDAPProvider()) {
                 $nav->addFilter('ldap', pht('Import from LDAP'));
             }
             $nav->addFilter('logs', pht('Activity Logs'));
             $nav->addFilter('invite', pht('Email Invitations'));
         }
     }
     return $nav;
 }
 public function buildSideNavView()
 {
     $nav = new AphrontSideNavFilterView();
     $nav->setBaseURI(new PhutilURI($this->getApplicationURI()));
     $viewer = $this->getRequest()->getUser();
     id(new PhabricatorPeopleSearchEngine())->setViewer($viewer)->addNavigationItems($nav->getMenu());
     if ($viewer->getIsAdmin()) {
         $nav->addLabel(pht('User Administration'));
         if (PhabricatorLDAPAuthProvider::getLDAPProvider()) {
             $nav->addFilter('ldap', pht('Import from LDAP'));
         }
         $nav->addFilter('logs', pht('Activity Logs'));
     }
     return $nav;
 }
 public function execute(PhutilArgumentParser $args)
 {
     $console = PhutilConsole::getConsole();
     $console->getServer()->setEnableLog(true);
     PhabricatorLDAPAuthProvider::assertLDAPExtensionInstalled();
     $provider = PhabricatorLDAPAuthProvider::getLDAPProvider();
     if (!$provider) {
         $console->writeOut("%s\n", pht('The LDAP authentication provider is not enabled.'));
         exit(1);
     }
     if (!function_exists('ldap_connect')) {
         $console->writeOut("%s\n", pht('The LDAP extension is not enabled.'));
         exit(1);
     }
     $adapter = $provider->getAdapter();
     $console->writeOut("%s\n", pht('Enter LDAP Credentials'));
     $username = phutil_console_prompt(pht('LDAP Username: '******'You must enter an LDAP username.'));
     }
     phutil_passthru('stty -echo');
     $password = phutil_console_prompt(pht('LDAP Password: '******'stty echo');
     if (!strlen($password)) {
         throw new PhutilArgumentUsageException(pht('You must enter an LDAP password.'));
     }
     $adapter->setLoginUsername($username);
     $adapter->setLoginPassword(new PhutilOpaqueEnvelope($password));
     $console->writeOut("\n");
     $console->writeOut("%s\n", pht('Connecting to LDAP...'));
     $account_id = $adapter->getAccountID();
     if ($account_id) {
         $console->writeOut("%s\n", pht('Found LDAP Account: %s', $account_id));
     } else {
         $console->writeOut("%s\n", pht('Unable to find LDAP account!'));
     }
     return 0;
 }
 private function processSearchRequest($request)
 {
     $panel = new PHUIBoxView();
     $admin = $request->getUser();
     $search = $request->getStr('query');
     $ldap_provider = PhabricatorLDAPAuthProvider::getLDAPProvider();
     if (!$ldap_provider) {
         throw new Exception(pht('No LDAP provider enabled!'));
     }
     $ldap_adapter = $ldap_provider->getAdapter();
     $ldap_adapter->setLoginUsername($request->getStr('username'));
     $ldap_adapter->setLoginPassword(new PhutilOpaqueEnvelope($request->getStr('password')));
     // This causes us to connect and bind.
     // TODO: Clean up this discard mode stuff.
     DarkConsoleErrorLogPluginAPI::enableDiscardMode();
     $ldap_adapter->getAccountID();
     DarkConsoleErrorLogPluginAPI::disableDiscardMode();
     $results = $ldap_adapter->searchLDAP('%Q', $search);
     foreach ($results as $key => $record) {
         $account_id = $ldap_adapter->readLDAPRecordAccountID($record);
         if (!$account_id) {
             unset($results[$key]);
             continue;
         }
         $info = array($account_id, $ldap_adapter->readLDAPRecordEmail($record), $ldap_adapter->readLDAPRecordRealName($record));
         $results[$key] = $info;
         $results[$key][] = $this->renderUserInputs($info);
     }
     $form = id(new AphrontFormView())->setUser($admin);
     $table = new AphrontTableView($results);
     $table->setHeaders(array(pht('Username'), pht('Email'), pht('Real Name'), pht('Import?')));
     $form->appendChild($table);
     $form->setAction($request->getRequestURI()->alter('import', 'true')->alter('search', null))->appendChild(id(new AphrontFormSubmitControl())->setValue(pht('Import')));
     $panel->appendChild($form);
     return $panel;
 }