Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
## Which issue does this PR close?

<!--
We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123.
-->

- Closes #.

## Rationale for this change

<!--
Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.
-->

## What changes are included in this PR?

<!--
There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
-->

## Are these changes tested?

<!--
We typically require tests for all PRs in order to:
1. Prevent the code from being accidentally broken by subsequent changes
2. Serve as another way to document the expected behavior of the code

If tests are not included in your PR, please explain why (for example, are they covered by existing tests)?
-->

## Are there any user-facing changes?

<!--
If there are user-facing changes then we may require documentation to be updated before approving the PR.
-->

<!--
If there are any breaking changes to public APIs, please add the `api change` label.
-->
1 change: 1 addition & 0 deletions src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ tauri-plugin-fs = "2.0.0-rc"
tauri-plugin-log = "2.0.0-rc"
tauri-plugin-shell = "2"
dirs = "5.0"
libc = "0.2"
28 changes: 25 additions & 3 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,45 @@

pub mod commands;
pub mod utils;
pub mod sudo;

use sudo::{SudoCache, fast_sudo, clear_sudo_cache, direct_privilege_escalation, check_sudo_privileges};
use tauri::Manager;

fn main() {
dotenvy::dotenv().ok();

tauri::Builder::default()
.setup(|app| {
app.manage(SudoCache::new());

let cache = app.state::<SudoCache>();
let cache_clone = cache.inner().clone();

std::thread::spawn(move || {
loop {
std::thread::sleep(std::time::Duration::from_secs(300));
cache_clone.clear_expired(15);
}
});

Ok(())
})
.invoke_handler(tauri::generate_handler![
commands::shell::run_shell,
commands::shell::run_sudo_command,
commands::shell::get_current_dir,
commands::shell::list_directory_contents,
commands::shell::change_directory,
commands::ai::ask_llm,
commands::api_key::save_api_key,
commands::api_key::get_api_key,
commands::api_key::validate_api_key,
commands::api_key::delete_api_key
commands::api_key::delete_api_key,
fast_sudo,
clear_sudo_cache,
direct_privilege_escalation,
check_sudo_privileges
])
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
}
Empty file added src-tauri/src/sudo.rs
Empty file.
18 changes: 13 additions & 5 deletions src/components/PasswordDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ const PasswordDialog: React.FC<PasswordDialogProps> = ({ isOpen, onClose, onSubm
onSubmit(password);
};

const handleKeyDown = (e: React.KeyboardEvent) => {
if (e.key === 'Escape' && !isSubmitting) {
onClose();
}
};

if (!isOpen) return null;

return (
Expand All @@ -44,7 +50,7 @@ const PasswordDialog: React.FC<PasswordDialogProps> = ({ isOpen, onClose, onSubm
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M12 15v2m-6 4h12a2 2 0 002-2v-6a2 2 0 00-2-2H6a2 2 0 00-2 2v6a2 2 0 002 2zm10-10V7a4 4 0 00-8 0v4h8z" />
</svg>
</div>
<h3 className="text-xl font-bold text-white">Administrator Privileges Required</h3>
<h3 className="text-xl font-bold text-white">⚡ Fast Sudo Authentication</h3>
</div>

<p className="text-gray-300 mb-4">
Expand All @@ -54,7 +60,7 @@ const PasswordDialog: React.FC<PasswordDialogProps> = ({ isOpen, onClose, onSubm
{commandText}
</pre>

<form onSubmit={handleSubmit}>
<form onSubmit={handleSubmit} onKeyDown={handleKeyDown}>
<div className="mb-4">
<label htmlFor="password" className="block text-gray-400 mb-2">Password:</label>
<input
Expand All @@ -68,7 +74,7 @@ const PasswordDialog: React.FC<PasswordDialogProps> = ({ isOpen, onClose, onSubm
disabled={isSubmitting}
/>
<p className="text-xs text-gray-500 mt-1">
Your password will not be stored and is only used to execute this command.
Password will be cached for 15 minutes for faster subsequent commands.
</p>
</div>

Expand All @@ -94,7 +100,9 @@ const PasswordDialog: React.FC<PasswordDialogProps> = ({ isOpen, onClose, onSubm
Authenticating...
</>
) : (
'Submit'
<>
⚡ Authenticate
</>
)}
</button>
</div>
Expand All @@ -104,4 +112,4 @@ const PasswordDialog: React.FC<PasswordDialogProps> = ({ isOpen, onClose, onSubm
);
};

export default PasswordDialog;
export default PasswordDialog;
Empty file added src/hooks/useFastSudo.ts
Empty file.