Example #1
0
 public function generate_html()
 {
     if ($this->nextpass->account->logged_in === false) {
         $html_code = $this->nextpass->page->generate_html("login", $this->page);
         $this->properties = $html_code['properties'];
         $html_code = $html_code['html'];
     } else {
         $this->title = "Passwords";
         $this->h1 = "Passwords";
         require_once dirname(__FILE__) . "/../class/PasswordList.php";
         $password_list = new PasswordList($this->nextpass->html_code, $this->nextpass->db, $this->nextpass->account, $this->nextpass->debug);
         $password_list->set_category(0);
         $html_code = $password_list->generate_html();
     }
     return $html_code;
 }
Example #2
0
 public function generate_html()
 {
     // allow the api to be accessed from outside the server
     header("Access-Control-Allow-Origin: *");
     $answer = array();
     if ($this->subpage1 == "status") {
         $answer['version'] = "0.1";
         $answer['secure'] = !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443;
     } else {
         if ($this->subpage1 == "login") {
             if (empty($_POST['username']) or empty($_POST['password'])) {
                 $answer['error'] = "Missing Username or Password";
             } else {
                 if ($this->nextpass->account->logged_in === true) {
                     $answer['error'] = "Already logged in!";
                 } else {
                     $username = $_POST['username'];
                     $password = $_POST['password'];
                     $login = $this->nextpass->account->login($username, $password);
                     if ($login !== true) {
                         $answer['error'] = "Wrong E-Mail/Username or Password!";
                     }
                 }
             }
         } else {
             if ($this->subpage1 == "check_login") {
                 $answer['login_status'] = $this->nextpass->account->logged_in;
             } else {
                 if ($this->subpage1 == "logout") {
                     if ($this->nextpass->account->logged_in !== true) {
                         $answer['error'] = "Already logged out!";
                     } else {
                         $logout = $this->nextpass->account->logout();
                         if ($logout !== true) {
                             $answer['error'] = "Unknown Error!";
                         }
                     }
                 } else {
                     if ($this->subpage1 == "get_passwords_for_website") {
                         if ($this->nextpass->account->logged_in !== true) {
                             $answer['error'] = "Not logged in!";
                         } else {
                             if (empty($_POST['website'])) {
                                 $answer['error'] = "Missing Website";
                             } else {
                                 $password_list = new PasswordList($this->nextpass->html_code, $this->nextpass->db, $this->nextpass->account, $this->nextpass->debug);
                                 $password_list->set_website($_POST['website']);
                                 $passwords = $password_list->generate_array();
                                 $answer['passwords'] = $passwords;
                             }
                         }
                     } else {
                         if ($this->subpage1 == "get_password_list") {
                             if ($this->nextpass->account->logged_in !== true) {
                                 $answer['error'] = "Not logged in!";
                             } else {
                                 $password_list = new PasswordList($this->nextpass->html_code, $this->nextpass->db, $this->nextpass->account, $this->nextpass->debug);
                                 $password_list->set_category(0);
                                 $passwords = $password_list->generate_array();
                                 $answer['passwords'] = $passwords;
                             }
                         } else {
                             if ($this->subpage1 == "get_password") {
                                 if ($this->nextpass->account->logged_in !== true) {
                                     $answer['error'] = "Not logged in!";
                                 } else {
                                     if (empty($this->subpage2) or !ctype_digit($this->subpage2)) {
                                         $answer['error'] = "Missing password id";
                                     } else {
                                         $password_obj = new Password($this->nextpass->db, $this->nextpass->account, $this->nextpass->debug);
                                         $found = $password_obj->set_id($this->subpage2);
                                         if ($found === false) {
                                             $answer['error'] = "Could not find Password";
                                         } else {
                                             $answer['title'] = $password_obj->get_title();
                                             $answer['website'] = $password_obj->get_website();
                                             $answer['username'] = $password_obj->get_username();
                                             $answer['password'] = $password_obj->show();
                                         }
                                     }
                                 }
                             } else {
                                 if ($this->subpage1 == "edit_password" or $this->subpage1 == "add_password") {
                                     if ($this->nextpass->account->logged_in !== true) {
                                         $answer['error'] = "Not logged in!";
                                     } else {
                                         if ($this->subpage1 == "edit_password" and (empty($this->subpage2) or !ctype_digit($this->subpage2))) {
                                             $answer['error'] = "Missing password id";
                                         } else {
                                             if (empty($_POST['password'])) {
                                                 $answer['error'] = "Missing password array";
                                             } else {
                                                 if ($this->subpage1 == "edit_password") {
                                                     $old_password_obj = new Password($this->nextpass->db, $this->nextpass->account, $this->nextpass->debug);
                                                     $old_password_obj->set_id($this->subpage2);
                                                 }
                                                 $password = json_decode($_POST['password'], true);
                                                 $title = isset($password['title']) ? $password['title'] : false;
                                                 $website = isset($password['website']) ? $password['website'] : false;
                                                 $username = isset($password['username']) ? $password['username'] : false;
                                                 $password = isset($password['password']) ? $password['password'] : false;
                                                 if (empty($title) or empty($password)) {
                                                     $answer['error'] = "Title or Password missing!";
                                                 } else {
                                                     $password_obj = new Password($this->nextpass->db, $this->nextpass->account, $this->nextpass->debug);
                                                     $add_password = $password_obj->add($title, $website, $username, $password);
                                                     if ($add_password !== true) {
                                                         $answer['error'] = "Something went wrong!";
                                                     } else {
                                                         if ($this->subpage1 == "edit_password") {
                                                             $delete_old_password = $old_password_obj->delete();
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 } else {
                                     if ($this->subpage1 == "delete_password") {
                                         if ($this->nextpass->account->logged_in !== true) {
                                             $answer['error'] = "Not logged in!";
                                         } else {
                                             if (empty($this->subpage2) or !ctype_digit($this->subpage2)) {
                                                 $answer['error'] = "Missing password id";
                                             } else {
                                                 $old_password_obj = new Password($this->nextpass->db, $this->nextpass->account, $this->nextpass->debug);
                                                 $old_password_obj->set_id($this->subpage2);
                                                 $delete_old_password = $old_password_obj->delete();
                                                 if ($delete_old_password !== true) {
                                                     $answer['error'] = "Something went wrong!";
                                                 }
                                             }
                                         }
                                     } else {
                                         $answer['error'] = "Wrong API Call!";
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     if (!empty($answer['error'])) {
         $answer['success'] = false;
     } else {
         $answer['success'] = true;
     }
     echo json_encode($answer);
     return false;
 }