<commit_before><?php
/* Copyright (C) 2010-2013 by Contrail Consortium. */



require_once('../__init__.php');
require_module('logging');
require_module('service');
require_module('service/factory');
require_module('https');

if (!isset($_SESSION['uid'])) {
	throw new Exception('User not logged in');
}

$sid = $_POST['sid'];
$service_data = ServiceData::getServiceById($sid);
$service = ServiceFactory::create($service_data);

if($service->getUID() !== $_SESSION['uid']) {
    throw new Exception('Not allowed');
}

if (!isset($_POST['sshkey'])) {
	echo json_encode(array(
		'error' => 'ssh key not uploaded'
	));
	exit();
}

/* Check if the uploaded key is valid */


$tmp = array_search('uri', @array_flip(stream_get_meta_data($GLOBALS[mt_rand()]=tmpfile())));
file_put_contents($tmp, $_POST['sshkey']);

$params = array(
	'key' => '@'.$tmp,
	'method' => 'upload_authorized_key'
);

try {
	$response = HTTPS::post($service->getManager(), $params);
	echo json_encode($response);
} catch (Exception $e) {
	echo json_encode(array('error' => $e->getMessage()));
}
?>
<commit_msg>Fixed uploading ssh key from frontend<commit_after><?php
/* Copyright (C) 2010-2013 by Contrail Consortium. */



require_once('../__init__.php');
require_module('logging');
require_module('service');
require_module('service/factory');
require_module('https');

if (!isset($_SESSION['uid'])) {
	throw new Exception('User not logged in');
}

$sid = $_POST['sid'];
$service_data = ServiceData::getServiceById($sid);
$service = ServiceFactory::create($service_data);

if($service->getUID() !== $_SESSION['uid']) {
    throw new Exception('Not allowed');
}

if (!isset($_POST['sshkey'])) {
	echo json_encode(array(
		'error' => 'ssh key not uploaded'
	));
	exit();
}

/* Check if the uploaded key is valid */


$tmp = array_search('uri', @array_flip(stream_get_meta_data($GLOBALS[mt_rand()]=tmpfile())));
file_put_contents($tmp, $_POST['sshkey']);

$params = array(
	'key' => '@'.$tmp,
	'method' => 'upload_authorized_key',
	'service_id' => $service->getSID()
);

try {
	$response = HTTPS::post($service->getManager(), $params);
	echo json_encode($response);
} catch (Exception $e) {
	echo json_encode(array('error' => $e->getMessage()));
}
?>

{'fraction_non_alphanumeric': 0.21090581342947273, 'fraction_numerical': 0.007210455159981974, 'mean_word_length': 6.52542372881356, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '924741', 'n_tokens_mistral': 770, 'n_tokens_neox': 732, 'n_words': 151}