Skip to content

Commit

Permalink
First release
Browse files Browse the repository at this point in the history
  • Loading branch information
DrorHarari committed Mar 15, 2019
0 parents commit 468f56d
Show file tree
Hide file tree
Showing 8 changed files with 314 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto
108 changes: 108 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# The binary keypirinha package
*.keypirinha-package

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
etc/google.vcf
etc/ad-make-contacts.bat
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019 Dror Harari

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
Keypirinha Plugin: Rdp
=========
# Launch previously opened Rdp sessions

This plugin for Keypirinha lets you type Rdp and part of the name of a machine you previously connected to and it will launch the Windows RDP program (MSTSC) to connect to that machine.

## Usage ##
Open the LaunchBox and type:
```
Rdp <tab> <partial-machine-name> <enter>
```
## Installation and Setup ##
The easiest way to install Rdp is to use the [PackageControl](https://github.com/ueffel/Keypirinha-PackageControl) plugin's InstallPackage command.

For manual installation simply download the rdp.keypirinha-package file from the Releases page of this repository to:

* `Keypirinha\portable\Profile\InstalledPackages` in **Portable mode**

**Or**

* `%APPDATA%\Keypirinha\InstalledPackages` in **Installed mode**


## Credits ##

* Icon by David Cross, Hungary (https://webhostingmedia.net/)

## Release Notes ##

**V0.1**
- Initial release
31 changes: 31 additions & 0 deletions etc/build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# The build.py script is assumed to be located in the package's etc folder
from pathlib import Path
import os
import zipfile
import msvcrt

PACKAGE_NAME="rdp"
FILES=["Rdp.py","Rdp.ico","LICENSE"]

ETC_FOLDER=Path(__file__).parent
PACKAGE_FOLDER=ETC_FOLDER.parent
PACKAGE_FILE=Path.joinpath(PACKAGE_FOLDER, f"{PACKAGE_NAME}.keypirinha-package")

print(f"Creating package file {PACKAGE_FILE}")

try:
zf = zipfile.ZipFile(PACKAGE_FILE,'w',zipfile.ZIP_DEFLATED)
for f in FILES:
zf.write(Path.joinpath(Path('..'), f), f)

zf.close()
except Exception as exc:
# Package is corrupted - better delete it
if zf:
zf.close()
os.remove(PACKAGE_FILE)
print(f"Failed to create package {PACKAGE_NAME}. {exc}")
msvcrt.getch()
os._exit(1)

print(f"Done")
41 changes: 41 additions & 0 deletions etc/mstsc-options.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
[Window Title]
Remote Desktop Connection Usage

[Content]
MSTSC [<connection file>] [/v:<server[:port]>] [/g:<gateway>] [/admin] [/f[ullscreen]] [/w:<width> /h:<height>] [/public] | [/span] [/multimon] [/edit "connection file"] [/restrictedAdmin] [/remoteGuard] [/prompt] [/shadow:<sessionID> [/control] [/noConsentPrompt]]

"connection file" -- Specifies the name of an .RDP file for the connection.

/v:<server[:port]> -- Specifies the remote PC to which you want to connect.

/g:<gateway> -- Specifies the RD Gateway server to use for the connection. This parameter is only read if the endpoint remote PC is specified with /v.

/admin -- Connects you to the session for administering a remote PC.

/f -- Starts Remote Desktop in full-screen mode.

/w:<width> -- Specifies the width of the Remote Desktop window.

/h:<height> -- Specifies the height of the Remote Desktop window.

/public -- Runs Remote Desktop in public mode.

/span -- Matches the remote desktop width and height with the local virtual desktop, spanning across multiple monitors, if necessary. To span across monitors, the monitors must be arranged to form a rectangle.

/multimon -- Configures the Remote Desktop Services session monitor layout to be identical to the current client-side configuration.

/edit -- Opens the specified .RDP connection file for editing.

/restrictedAdmin -- Connects you to the remote PC in Restricted Administration mode. In this mode, credentials won’t be sent to the remote PC, which can protect you if you connect to a PC that has been compromised. However, connections made from the remote PC might not be authenticated by other PCs, which might impact application functionality and compatibility. This parameter implies /admin.

/remoteGuard -- Connects your device to a remote device using Remote Guard. Remote Guard prevents credentials from being sent to the remote PC, which can help protect your credentials if you connect to a remote PC that has been compromised. Unlike Restricted Administration mode, Remote Guard also supports connections made from the remote PC by redirecting all requests back to your device.

/prompt -- Prompts you for your credentials when you connect to the remote PC.

/shadow:<sessionID> -- Specifies the ID of the session to shadow.

/control -- Allows control of the session when shadowing.

/noConsentPrompt -- Allows shadowing without user consent.


Binary file added rdp.ico
Binary file not shown.
80 changes: 80 additions & 0 deletions rdp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import keypirinha as kp
import keypirinha_util as kpu
import os
import winreg
import platform

class Rdp(kp.Plugin):
ITEMCAT_RDP = kp.ItemCategory.USER_BASE + 1
MSTSC = f'{os.environ["WINDIR"]}\\system32\\mstsc.exe'
RDP_SERVERS = r"Software\Microsoft\Terminal Server Client\Servers"

def __init__(self):
super().__init__()

def on_start(self):
self.access_mode = winreg.KEY_READ
if '32bit' in platform.architecture():
self.access_mode |= winreg.KEY_WOW64_64KEY

def on_activated(self):
pass

def on_deactivated(self):
pass

def on_events(self, flags):
if flags & kp.Events.PACKCONFIG:
self.on_catalog()

def on_catalog(self):
catalog = [
self.create_item(
category = kp.ItemCategory.REFERENCE,
label = "Rdp",
short_desc = "Open a recent RDP session",
target = "Rdp",
args_hint = kp.ItemArgsHint.REQUIRED,
hit_hint = kp.ItemHitHint.NOARGS)
]

self.set_catalog(catalog)

def on_suggest(self, user_input, items_chain):
suggestions = []

if user_input is None:
return
else:
user_input = user_input.lower()

servers = winreg.OpenKeyEx(winreg.HKEY_CURRENT_USER, self.RDP_SERVERS, 0, self.access_mode)

n_subkeys, n_values, mod_time = winreg.QueryInfoKey(servers)
for i in range(n_subkeys):
server_key = winreg.EnumKey(servers, i).lower()
if not user_input.lower() in server_key:
continue

user = ""
try:
server = winreg.OpenKey(winreg.HKEY_CURRENT_USER, f'{self.RDP_SERVERS}\\{server_key}', 0, self.access_mode)
user = f' as {winreg.QueryValueEx(server, "UsernameHint")[0]}'
except:
pass
suggestions.append(self.create_item(
category=self.ITEMCAT_RDP,
label=f'Connect to {server_key}{user}',
short_desc=f'Connect to {server_key}',
target=server_key,
args_hint=kp.ItemArgsHint.FORBIDDEN,
hit_hint=kp.ItemHitHint.IGNORE))

self.set_suggestions(suggestions, kp.Match.ANY, kp.Sort.NONE)

def on_execute(self, item, action):
if not item:
return

kpu.shell_execute(self.MSTSC, args=f'/v:{item.target()}', working_dir='', verb='',
try_runas=False, detect_nongui=False, api_flags=None, terminal_cmd=None, show=-1)

0 comments on commit 468f56d

Please sign in to comment.