Skip to content

Commit

Permalink
Merge pull request #1150 from sandialabs/smb-authentication-updates
Browse files Browse the repository at this point in the history
Smb authentication updates
  • Loading branch information
Mletter1 committed Dec 5, 2023
2 parents d2b0559 + 584c911 commit 821e651
Show file tree
Hide file tree
Showing 8 changed files with 151 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ server-root: "/"
show-tracebacks: True
socket-host: "0.0.0.0"
socket-port: 8092
smb-remote-hosts: ["example.test"]
smb-remote-hosts: ["examples.host.com"]
smb-domains: ["domain.com"]
ssl-certificate: {"cert-path": "", "key-path": ""}
sso-auth-server: {"url": ""}
support-email: {"address":"nobody@example.com", "subject":"Slycat Support Request"}
Expand Down
47 changes: 47 additions & 0 deletions docs/source/GET-methods/GET-Configuration-SMB-Domains.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
GET SMB Domain Names
========================

.. http:get:: /configuration/smb-domains
Retrieves a list of SMB domain names, which get returned as JSON

:responseheader Content-Type: application/json

**Sample Request**

.. sourcecode:: http

GET /api/configuration/smb-domains HTTP/1.1
Host: localhost:9000
Connection: keep-alive
Accept: application/json, text/javascript, */*; q=0.01
DNT: 1
X-Requested-With: XMLHttpRequest
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.80 Safari/537.36
Referer: https://localhost:9000/models/b26d9a5d7b2f44729bffccad51fdfcf9?bid=405d84f7553f53736beabdf874d55356
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9
Cookie: slycatauth=e9528234ede94e159fc21ef2f744323f; slycattimeout=timeout

**Sample Response**

.. sourcecode:: http

HTTP/1.1 200 OK
X-Powered-By: Express
content-length: 43
expires: 0
server: CherryPy/14.0.0
pragma: no-cache
cache-control: no-cache, no-store, must-revalidate
date: Fri, 14 Jun 2019 19:41:58 GMT
content-type: application/json
connection: close

{"domains":['domain_1', 'domain_2', 'domain_3']}

See Also
--------

- :http:post:`/api/configuration/smb-domains`

1 change: 1 addition & 0 deletions docs/source/GET-methods/GET-rest-api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ GET METHODS
:maxdepth: 1

GET-Bookmark.rst
GET-Configuration-SMB-Domains.rst
GET-Home.rst
GET-Model-Arrayset-Data.rst
GET-Model-Arrayset-Metadata.rst
Expand Down
1 change: 1 addition & 0 deletions packages/slycat/web/server/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ def abspath(path):
dispatcher.connect("get-configuration-parsers", "/configuration/parsers", slycat.web.server.handlers.get_configuration_parsers, conditions={"method" : ["GET"]})
dispatcher.connect("get-configuration-remote-hosts", "/configuration/remote-hosts", slycat.web.server.handlers.get_configuration_remote_hosts, conditions={"method" : ["GET"]})
dispatcher.connect("get-configuration-smb-remote-hosts", "/configuration/smb-remote-hosts", slycat.web.server.handlers.get_configuration_smb_remote_hosts, conditions={"method" : ["GET"]})
dispatcher.connect("get-configuration-smb-domains", "/configuration/smb-domains", slycat.web.server.handlers.get_configuration_smb_domains, conditions={"method" : ["GET"]})
dispatcher.connect("get-configuration-support-email", "/configuration/support-email", slycat.web.server.handlers.get_configuration_support_email, conditions={"method" : ["GET"]})
dispatcher.connect("get-configuration-injected-code", "/configuration/injected-code", slycat.web.server.handlers.get_configuration_injected_code, conditions={"method" : ["GET"]})
dispatcher.connect("get-configuration-ga-tracking-id", "/configuration/ga-tracking-id", slycat.web.server.handlers.get_configuration_ga_tracking_id, conditions={"method" : ["GET"]})
Expand Down
13 changes: 13 additions & 0 deletions packages/slycat/web/server/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3156,6 +3156,19 @@ def get_configuration_smb_remote_hosts():
return json_hostnames
return {"hostnames":[]}

@cherrypy.tools.json_out(on=True)
def get_configuration_smb_domains():
"""
Returns the SMB domains from the slycat web server
configuration file
:return: domain names
"""
if "smb-domains" in cherrypy.request.app.config["slycat-web-server"]:
domains = cherrypy.request.app.config["slycat-web-server"]["smb-domains"]
json_domains = {"domains": domains}
return json_domains
return {"domains":[]}

@cherrypy.tools.json_out(on=True)
def get_configuration_support_email():
return cherrypy.request.app.config["slycat-web-server"]["support-email"]
Expand Down
84 changes: 71 additions & 13 deletions web-server/components/SmbAuthentication.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ export default class SmbAuthentication extends React.Component<any,any> {
session_exists: null,
password: "",
share: display.share?display.share:null,
domain: display.domain?display.domain:null,
domains: [],
hostnames : [],
loadingData: this.props.loadingData,
initialLoad: false,
Expand All @@ -45,8 +47,8 @@ export default class SmbAuthentication extends React.Component<any,any> {
initialLoad:true,
loadingData:false
}, () => {
this.props.callBack(this.state.hostname, this.b64EncodeUnicode(this.state.username),
this.b64EncodeUnicode(this.state.password), this.state.share, this.state.session_exists);
this.props.callBack(this.state.hostname, this.b64EncodeUnicode(this.state.username + '@' + this.state.domain),
this.b64EncodeUnicode(this.state.password), this.state.share, this.state.domain, this.state.session_exists);
});
}).catch(response => {
this.setState({
Expand All @@ -55,7 +57,7 @@ export default class SmbAuthentication extends React.Component<any,any> {
loadingData:false
}, () => {
this.props.callBack(this.state.hostname, this.b64EncodeUnicode(this.state.username),
this.b64EncodeUnicode(this.state.password), this.state.share, this.state.session_exists);
this.b64EncodeUnicode(this.state.password), this.state.share, this.state.domain, this.state.session_exists);
});
});
};
Expand All @@ -82,9 +84,23 @@ export default class SmbAuthentication extends React.Component<any,any> {
})
};

/**
* gets a list of all the known domain names that we can connect to
* via ssh
*
* @memberof SmbAuthentication
*/
getDomains = async () => {
return client.get_configuration_smb_domains_fetch()
.then((json)=>{
this.setState({domains:json.domains});
})
}

async componentDidMount(){
await this.checkRemoteStatus(this.state.hostname);
await this.getRemoteHosts();
await this.getDomains();
if(this.poll){
clearInterval(this.poll);
}
Expand Down Expand Up @@ -134,29 +150,36 @@ export default class SmbAuthentication extends React.Component<any,any> {
localStorage.setItem("slycat-smb-remote-controls-share", value);
this.setState({share: value},() => {
this.checkRemoteStatus(this.state.hostname);
this.props.callBack(this.state.hostname, this.b64EncodeUnicode(this.state.username),
this.b64EncodeUnicode(this.state.password), this.state.share, this.state.session_exists);
this.props.callBack(this.state.hostname, this.b64EncodeUnicode(this.state.username + '@' + this.state.domain),
this.b64EncodeUnicode(this.state.password), this.state.share, this.state.domain, this.state.session_exists);
});
break;
case "domain":
localStorage.setItem("slycat-smb-remote-controls-domain", value);
this.setState({domain: value},() => {
this.props.callBack(this.state.hostname, this.b64EncodeUnicode(this.state.username + '@' + this.state.domain),
this.b64EncodeUnicode(this.state.password), this.state.share, this.state.domain, this.state.session_exists)
})
break;
case "username":
localStorage.setItem("slycat-smb-remote-controls-username", value);
this.setState({username: value},() => {
this.props.callBack(this.state.hostname, this.b64EncodeUnicode(this.state.username),
this.b64EncodeUnicode(this.state.password), this.state.share, this.state.session_exists);
this.props.callBack(this.state.hostname, this.b64EncodeUnicode(this.state.username + '@' + this.state.domain),
this.b64EncodeUnicode(this.state.password), this.state.share, this.state.domain, this.state.session_exists);
});
break;
case "hostname":
localStorage.setItem("slycat-smb-remote-controls-hostname", value);
this.checkRemoteStatus(value);
this.setState({hostname: value},() => {
this.props.callBack(this.state.hostname, this.b64EncodeUnicode(this.state.username),
this.b64EncodeUnicode(this.state.password), this.state.share, this.state.session_exists);
this.props.callBack(this.state.hostname, this.b64EncodeUnicode(this.state.username + '@' + this.state.domain),
this.b64EncodeUnicode(this.state.password), this.state.share, this.state.domain, this.state.session_exists);
});
break;
case "password":
this.setState({password: value},() => {
this.props.callBack(this.state.hostname, this.b64EncodeUnicode(this.state.username),
this.b64EncodeUnicode(this.state.password), this.state.share, this.state.session_exists);
this.props.callBack(this.state.hostname, this.b64EncodeUnicode(this.state.username + '@' + this.state.domain),
this.b64EncodeUnicode(this.state.password), this.state.share, this.state.domain, this.state.session_exists);
});
break;
default:
Expand Down Expand Up @@ -201,7 +224,7 @@ export default class SmbAuthentication extends React.Component<any,any> {
if (e.key === 'Enter') {
let last_key = e.key;
this.props.callBack(this.state.hostname, this.b64EncodeUnicode(this.state.username),
this.b64EncodeUnicode(this.state.password), this.state.share, this.state.session_exists, last_key);
this.b64EncodeUnicode(this.state.password), this.state.share, this.state.domain, this.state.session_exists, last_key);
}
}

Expand Down Expand Up @@ -245,7 +268,7 @@ export default class SmbAuthentication extends React.Component<any,any> {
}

/**
* maps the hostnames as dropdowns items JSX
* maps the hostnames as dropdown items JSX
*
* @memberof SmbAuthentication
*/
Expand All @@ -262,6 +285,24 @@ export default class SmbAuthentication extends React.Component<any,any> {
return hostnamesJSX;
}

/**
* maps the domains as dropdown items JSX
*
* @memberof SmbAuthentication
*/
getDomainsJSX = () => {
const domainsJSX = this.state.domains.map((domain, i) => {
return (
<li key={i}>
<a className='dropdown-item' onClick={(e:any)=>this.onValueChange(e.target.text, "domain")}>
{domain}
</a>
</li>
)
});
return domainsJSX;
}

/**
* JSX for SlycatRemoteControls
*
Expand Down Expand Up @@ -292,6 +333,23 @@ export default class SmbAuthentication extends React.Component<any,any> {
</div>
</div>
</div>
<div className='form-group row mb-3'>
<label className='col-sm-2 col-form-label'>Domains</label>
<div className='col-sm-9'>
<div className='input-group'>
<div className='input-group-prepend'>
<button className='btn btn-secondary dropdown-toggle'
type='button' id='dropdownMenuButton'
data-toggle='dropdown' aria-haspopup='true' aria-expanded='false' />
<ul className='dropdown-menu' aria-labelledby='dropdownMenuButton'>
{this.getDomainsJSX()}
</ul>
</div>
<input className='form-control' value={this.state.domain?this.state.domain:""} type='text'
onChange={(e)=>this.onValueChange(e.target.value, "domain")} />
</div>
</div>
</div>
{this.getFormInputsJSX()}
</form>
);
Expand Down
13 changes: 13 additions & 0 deletions web-server/js/slycat-web-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,19 @@ module.get_configuration_smb_remote_hosts_fetch = async function () {
});
};

module.get_configuration_smb_domains_fetch = async function () {
return fetch(`${api_root}configuration/smb-domains`, {
credentials: 'same-origin',
cache: 'no-store',
dataType: 'json'
}).then(async function (response) {
if (!response.ok) {
throw `bad response with: ${response.status} :: ${response.statusText}`;
}
return response.json();
});
}

module.get_configuration_version = function (params) {
$.ajax({
dataType: 'json',
Expand Down
3 changes: 3 additions & 0 deletions web-server/plugins/slycat-parameter-image/js/wizard-ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ function constructor(params) {
username: null,
password: null,
share: null,
domain: null,
status: null,
status_type: null,
enable: true,
Expand Down Expand Up @@ -260,13 +261,15 @@ function constructor(params) {
username,
password,
share,
domain,
session_exists,
last_key
) {
component.remote.hostname(hostname);
component.remote.username(username);
component.remote.password(password);
component.remote.share(share);
component.remote.domain(domain);
component.remote.session_exists(session_exists);
//If the user hits enter key, try to connect
if (last_key === "Enter") {
Expand Down

0 comments on commit 821e651

Please sign in to comment.